Skip to content

fix: read the output items the ChatGPT backend streams - #256

Merged
tenphi merged 1 commit into
mainfrom
fix/chatgpt-streamed-output
Nov 4, 2026
Merged

tenphi merged 1 commit into
mainfrom
fix/chatgpt-streamed-output

Conversation

@tenphi

@tenphi tenphi commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Problem

The ChatGPT subscription backend (https://chatgpt.com/backend-api/codex) now ends every Responses stream with a response.completed whose output is []. Each item (message, function call, reasoning) arrives only in its own response.output_item.done event.

readResponsesStream returned the terminal event's response alone, so every generative role on an auth: "chatgpt" provider failed with Responses API response had no output text. That covers derive, expansion, answer, vision and maintenance. The stream had completed with HTTP 200, so the call never reached the fallback provider.

A live probe against the backend confirmed the shape. A one-word answer and a single function call each arrived as one response.output_item.done event, followed by response.completed with output: [].

Fix

  • Keep response.output_item.done items by output_index.
  • When the terminal response's output is empty, use the streamed items instead.
  • A terminal response that carries its own output, as the public API's does, is returned unchanged.

Tests

  • Stream reader: the streamed items fill an empty terminal output, in index order.
  • Stream reader: a non-empty terminal output wins over streamed items.
  • Transport: ModelClient.chat answers from an item streamed apart from an empty response.completed. This reproduces the production failure, and the new tests fail on main.

Locally, build, typecheck, lint, knip and check:repository pass, and so does chatgpt.test.ts. Thirteen tests in ingest.test.ts time out on PDF extraction in this machine's sandbox. They fail the same way on unmodified main, so CI's macOS runner is the authority there.

Changeset: @tenphi/akno-core patch (fixed group, so all four packages go to 0.21.1).

🤖 Generated with Claude Code

The Codex backend now ends every stream with a `response.completed`
whose `output` is empty; each item arrives only in its own
`response.output_item.done` event. `readResponsesStream` returned the
terminal response alone, so every generative call on the subscription
failed with "Responses API response had no output text". The call had
completed, so it never reached the API-key fallback either.

Keep the streamed items by output index and use them when the terminal
output is empty. A terminal response that carries its own output, as
the public API's does, is returned unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@tenphi
tenphi merged commit 67d0642 into main Nov 4, 2026
3 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 4, 2026
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