You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[TASK] Refactor the AG-UI encoder into a per-run type shared by stdout and the WebSocket binding #1397
agui.Render is the one AG-UI encoder, but it only runs as a whole-stream loop: one RUN_STARTED when it starts and one terminal event when the channel closes. The daemon binding and the session worker need the same encoder driven one run per turn, so split it into a small per-run type both transports share. Use this split to close the gaps the stdout contract already documents but does not deliver.
Render becomes start(threadID, runID) + handle(event) + finish() error. Render itself stays as start, range and finish.
encoder.emit writes each event with exactly one Write, so a transport can map one Write to one frame without a line splitter.
headless --format ag-ui --session-id <id> emits the MESSAGES_SNAPSHOT that docs/ag-ui-output.md already promises right after RUN_STARTED. Nothing emits it today.
A cancelled turn ends as AG-UI spec 1.0 describes cancelled runs, with RUN_FINISHED outcome cancelled, not a RUN_ERROR. The Go SDK has no constant for it yet, but WithOutcome(RunFinishedOutcome{Type: "cancelled"}) passes validation.
The approval decision mapping lives in one place for every transport.
Acceptance Criteria
internal/protocols/agui exposes a per-run type (start / handle / finish) and Render is built on it
encoder.emit writes one event per Write call
Headless ag-ui output is byte-identical apart from the two changes below, and the existing agui_test.go expectations pass unedited
headless --format ag-ui --session-id on an existing conversation emits MESSAGES_SNAPSHOT right after RUN_STARTED, built by one snapshotMessages helper from the conversation entries: id, role, text content, assistant toolCalls, tool toolCallId, and error when the execution failed
A ChatCompleteEvent{Cancelled: true} ends the run with RUN_FINISHED outcome cancelled. A later ComputerUseResumedEvent clears it, so a computer-use pause and resume stays one successful run (TestRender_ComputerUsePauseResume unchanged)
render.ApprovalAction(ipc.ApprovalResponse) is the only mapping from a response to a decision (approved, scope: "always", anything else rejects), and render.AnswerApproval uses it
The encoder has a method for CUSTOM approval_resolved{tool_call_id}
docs/ag-ui-output.md documents the cancelled outcome
The AG-UI encoder is now a per-run type shared by stdout and the WebSocket binding, and the split closed the stdout contract gaps the docs promised but nothing delivered.
Changes
Per-run type - internal/protocols/agui now exposes RunEncoder (NewRunEncoder, Start(threadID, runID), Handle(event), Finish() error). Render keeps its exact Go signature and stays as start, range, finish: r := NewRunEncoder(w, model, repo, nil, jobs, approvals, questions); r.Start(sessionID, uuid.New().String()); for ev := range events { r.Handle(ev) }; return r.Finish(). The daemon binding and session worker from [FEATURE] EPIC - Consolidate events and external communication behind infer daemon #1396 can now drive one run per turn.
One Write per event - RunEncoder.emit writes each event with exactly one Write (one JSON event plus newline), and the extension bridge's chatEventWriter dropped its buffer-and-split loop: each write now maps to one chat_event frame.
Resume snapshot - internal/presentation/headless now drives the per-run encoder directly and passes the restored conversation (prepareConversation returns the loaded conversation entries, nil for fresh runs), so headless --format ag-ui --session-id <id> on an existing conversation emits the promised MESSAGES_SNAPSHOT right after RUN_STARTED, built by the new snapshotMessages helper: id, role, text content, assistant toolCalls, tool toolCallId, and error when the tool execution failed.
Cancelled outcome - A ChatCompleteEvent{Cancelled: true} ends the run with RUN_FINISHED outcome cancelled (WithOutcome(RunFinishedOutcome{Type: "cancelled"}), no SDK constant yet) instead of RUN_ERROR, and a later ComputerUseResumedEvent clears it so a computer-use pause and resume stays one successful run.
Single approval mapping - render.ApprovalAction(ipc.ApprovalResponse) is now the only mapping from a response to a decision (approved + scope: "always" auto-accepts, plain approved approves, anything else rejects), and render.AnswerApproval uses it.
approval_resolved - The encoder gained EmitApprovalResolved(toolCallID) for the CUSTOM approval_resolved{tool_call_id} event; stdout keeps emitting only approval_request so the wire stays limited to the two documented contract changes.
Docs - docs/ag-ui-output.md documents the cancelled outcome and the pause/resume behaviour.
Verification
All existing agui_test.go expectations pass with the file byte-for-byte unedited (byte-identical output apart from the snapshot and cancelled outcome); TestRender_ComputerUsePauseResume unchanged and green.
New coverage in internal/protocols/agui/run_encoder_test.go (cancelled outcome, resume clears it, snapshot mapping, one Write per event, approval_resolved) and TestApprovalAction in internal/platform/render/render_test.go.
task build, task fmt, full task test, task vet, and task lint all pass with 0 issues.
Board: #1397 moved to QA on Roadmap 2026. Follow-up tickets filed: [DOCS] on the docs repo (docs#857) and the downstream call-out for the desktop sidecar consumer (desktop#370).
Activity
edenreich commentedon Sep 29, 2026
@infer Can you work on this? use /ponytail:ponytail /go /go-concurrency /domain-driven-design /clean-code /clean-architecture
inference-gateway-maintainer commentedon Sep 29, 2026
Model:
ollama_cloud/glm-5.3-flash· View JobTodos
Pull Request
#1407
✅ Infer Result: Success
All verified: clean tree, in sync with origin, PR #1407 not a draft and viewable. Closing out the todos:
All work is committed, pushed, and verified. Here is the complete summary of what was delivered for issue #1397.
Done: PR #1407 (
fix/issue-1397, commit01740c2)The AG-UI encoder is now a per-run type shared by stdout and the WebSocket binding, and the split closed the stdout contract gaps the docs promised but nothing delivered.
Changes
internal/protocols/aguinow exposesRunEncoder(NewRunEncoder,Start(threadID, runID),Handle(event),Finish() error).Renderkeeps its exact Go signature and stays as start, range, finish:r := NewRunEncoder(w, model, repo, nil, jobs, approvals, questions); r.Start(sessionID, uuid.New().String()); for ev := range events { r.Handle(ev) }; return r.Finish(). The daemon binding and session worker from [FEATURE] EPIC - Consolidate events and external communication behind infer daemon #1396 can now drive one run per turn.RunEncoder.emitwrites each event with exactly oneWrite(one JSON event plus newline), and the extension bridge'schatEventWriterdropped its buffer-and-split loop: each write now maps to onechat_eventframe.internal/presentation/headlessnow drives the per-run encoder directly and passes the restored conversation (prepareConversationreturns the loaded conversation entries, nil for fresh runs), soheadless --format ag-ui --session-id <id>on an existing conversation emits the promisedMESSAGES_SNAPSHOTright afterRUN_STARTED, built by the newsnapshotMessageshelper:id,role, textcontent, assistanttoolCalls, tooltoolCallId, anderrorwhen the tool execution failed.ChatCompleteEvent{Cancelled: true}ends the run withRUN_FINISHEDoutcomecancelled(WithOutcome(RunFinishedOutcome{Type: "cancelled"}), no SDK constant yet) instead ofRUN_ERROR, and a laterComputerUseResumedEventclears it so a computer-use pause and resume stays one successful run.render.ApprovalAction(ipc.ApprovalResponse)is now the only mapping from a response to a decision (approved+scope: "always"auto-accepts, plainapprovedapproves, anything else rejects), andrender.AnswerApprovaluses it.approval_resolved- The encoder gainedEmitApprovalResolved(toolCallID)for the CUSTOMapproval_resolved{tool_call_id}event; stdout keeps emitting onlyapproval_requestso the wire stays limited to the two documented contract changes.docs/ag-ui-output.mddocuments thecancelledoutcome and the pause/resume behaviour.Verification
agui_test.goexpectations pass with the file byte-for-byte unedited (byte-identical output apart from the snapshot and cancelled outcome);TestRender_ComputerUsePauseResumeunchanged and green.internal/protocols/agui/run_encoder_test.go(cancelled outcome, resume clears it, snapshot mapping, oneWriteper event,approval_resolved) andTestApprovalActionininternal/platform/render/render_test.go.task build,task fmt, fulltask test,task vet, andtask lintall pass with 0 issues.Board: #1397 moved to QA on Roadmap 2026. Follow-up tickets filed: [DOCS] on the docs repo (docs#857) and the downstream call-out for the desktop sidecar consumer (desktop#370).
Model:
ollama_cloud/glm-5.3-flash· Exit Code:0· Duration: 27m 48sTokens: 16,722,363 in · 140,256 out · 16,862,619 total (84 requests)
Tool calls: 100 total · 100% success rate
Traces
Stats
Triggered by edenreich · Infer Action · OSS
feat(agui): split the AG-UI encoder into a per-run type shared by std…
feat(headless): add a --serve worker that runs one AG-UI run per user…
inference-gateway-releaser commentedon Sep 30, 2026
🎉 This issue has been resolved in version 0.219.0 🎉
The release is available on:
Your semantic-release bot 📦🚀