Skip to content

feat(agentstudio): stream single-turn completion events - #307

Open
leonardocuco wants to merge 1 commit into
feat/cec-1883-completionfrom
feat/cec-1883-completion-stream
Open

leonardocuco wants to merge 1 commit into
feat/cec-1883-completionfrom
feat/cec-1883-completion-stream

Conversation

@leonardocuco

@leonardocuco leonardocuco commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The single-turn completion command in #305 only supports a non-streaming response, so scripts cannot consume events as they arrive.

Change

Add --stream to agentstudio completions create. It requests AI SDK 5 SSE and writes each JSON event as one NDJSON line. It preserves the default non-streaming behavior, forwards approval events without approving them, reports stream errors and interruption, and requires a finish event. Server-side tools may execute.

The SDK SSE decoder does not expose the backend's final unterminated [DONE] marker, so this implementation validates the finish event instead. Multi-turn context and approval continuation remain separate C7 work.

Verification

  • go test ./..., go generate ./..., go build ./..., gofumpt and git diff --check.
  • Mocked tests cover fragmented events, ordering, approvals, cancellation, truncated/error streams, output errors and credential redaction. No real API calls.

Stacked on #305; retarget after C6 merges. Related to CEC-1883. No deployment or release during the code freeze.

@leonardocuco

Copy link
Copy Markdown
Contributor Author

Claude Code reviewed this change at b3a64a7 for the author: 7 findings, all minor, 0 fixed. None blocks the change, and nothing was pushed for them.

  • pkg/cmd/completions/create/stream.go:58: one event that is not a JSON object with a string type, or an error event whose errorText is not a string, aborts the stream with a generic error. Left: minor, depends on server behaviour.
  • pkg/cmd/completions/create/stream.go:86: the context check runs even after finish was printed, so a Ctrl-C or timeout in that window fails a completed stream. Left: narrow window.
  • pkg/cmd/completions/create/stream.go:30: the 5-minute timeout caps the whole stream and surfaces as a bare deadline error. Left: a design choice for the author.
  • pkg/cmd/completions/create/stream.go:89: a stream ending without finish always reports the same error, including a final frame with no trailing blank line. Left: minor.
  • pkg/cmd/completions/create/stream.go:33: the key-redaction closure duplicates the inline logic in the non-streaming path. Left: cleanup.
  • pkg/cmd/completions/create/stream.go:65: a server error event goes to stderr only, not to the NDJSON stdout. Left: design choice for the author.
  • pkg/cmd/completions/create/stream_test.go:143: the blocking-body test helper can panic on a second Read or Close. Left: test-only.

@leonardocuco
leonardocuco marked this pull request as ready for review December 1, 2026 12:50
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-01T12:51:13.910437Z b3a64a7 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant