Skip to content

[Amber] Fix: feat(public-api): add /v1/sessions/:id/runs endpoint for AG-UI prompt delivery#755

Open
github-actions[bot] wants to merge 1 commit intomainfrom
amber/issue-753-feat-public-api-add-v1-sessions-id-runs-endpoint-f
Open

[Amber] Fix: feat(public-api): add /v1/sessions/:id/runs endpoint for AG-UI prompt delivery#755
github-actions[bot] wants to merge 1 commit intomainfrom
amber/issue-753-feat-public-api-add-v1-sessions-id-runs-endpoint-f

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Mar 1, 2026

Automated Fix by Amber Agent

This PR addresses issue #753 using the Amber background agent.

Changes Summary

  • Action Type: auto-fix
  • Commit: 6e4db1a
  • Triggered by: Issue label/command

Pre-merge Checklist

  • All linters pass
  • All tests pass
  • Changes follow project conventions (CLAUDE.md)
  • No scope creep beyond issue description

Reviewer Notes

This PR was automatically generated. Please review:

  1. Code quality and adherence to standards
  2. Test coverage for changes
  3. No unintended side effects

🤖 Generated with Amber Background Agent

Closes #753

…rompt delivery

Adds a new endpoint that accepts a simplified prompt and converts it to
AG-UI RunAgentInput format before proxying to the backend agui/run endpoint.
Returns {runId, threadId} for clients to track the run via the events stream.

Also fixes pre-existing gofmt formatting issues in middleware.go and main.go.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jeremyeder
Copy link
Contributor

Code Review: Critical/Blocker Issues

BLOCKER: CreateSessionRun buffers SSE stream instead of proxying it

File: components/public-api/handlers/sessions.goCreateSessionRun()

The AG-UI /agui/run endpoint returns a text/event-stream SSE response that can last minutes (the entire Claude session). The current implementation:

  1. io.ReadAll(resp.Body) — blocks until the stream ends
  2. json.Unmarshal(body, &runResp) — SSE data is not valid JSON

This means the endpoint will hang for the duration of the run and then fail with a JSON parse error.

Fix: Stream the SSE response directly to the caller:

// Set SSE headers
c.Header("Content-Type", "text/event-stream")
c.Header("Cache-Control", "no-cache")
c.Header("Connection", "keep-alive")
c.Status(http.StatusOK)

if flusher, ok := c.Writer.(http.Flusher); ok {
    flusher.Flush()
}

// Stream backend response body directly
buf := make([]byte, 4096)
for {
    n, readErr := resp.Body.Read(buf)
    if n > 0 {
        if _, writeErr := c.Writer.Write(buf[:n]); writeErr != nil {
            log.Printf("Client disconnected during session run %s: %v", sessionID, writeErr)
            return
        }
        if flusher, ok := c.Writer.(http.Flusher); ok {
            flusher.Flush()
        }
    }
    if readErr != nil {
        if readErr != io.EOF {
            log.Printf("Backend stream error for session run %s: %v", sessionID, readErr)
        }
        return
    }
}

CRITICAL: Remove unused RunResponse type

File: components/public-api/types/dto.go

RunResponse is no longer needed since we stream SSE instead of returning JSON. Remove to avoid confusion.

Tests need updating

The tests expect JSON responses (runId, threadId) but the endpoint now returns SSE. Tests should verify Content-Type: text/event-stream and that SSE data: events are present in the body.


I have the fix implemented and tested locally (all go test ./... pass). The fix is available at jeremyeder/platform:amber/pr-755 if you want to cherry-pick it: commit be7c142.

@ambient-code
Copy link

ambient-code bot commented Mar 3, 2026

Merge Readiness — Blockers Found

Check Status Detail
CI pass
Merge conflicts pass
Review comments FAIL Blocker: SSE stream buffered with ReadAll() instead of proxied — endpoint hangs
Jira hygiene warn No Jira reference found
Fork PR pass
Staleness pass

This comment is auto-generated by the PR Overview workflow and will be updated when the PR changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

amber-generated PR created by Amber background agent auto-fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(public-api): add /v1/sessions/:id/runs endpoint for AG-UI prompt delivery

1 participant