Skip to content

fix(llm): preserve terminal output in Responses streams - #1879

Open
ydflow wants to merge 1 commit into
alibaba:mainfrom
ydflow:fix/responses-terminal-output
Open

ydflow wants to merge 1 commit into
alibaba:mainfrom
ydflow:fix/responses-terminal-output

Conversation

@ydflow

@ydflow ydflow commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Description

Ordinary Responses streams currently replace the terminal response's output with the collected response.output_item.done items. If an endpoint supplies a populated terminal response but omits some or all item-done events, OCR returns success while dropping text, function calls, and native reasoning. The ChatGPT-plan path already preserves populated terminal output.

Preserve populated terminal output for ordinary streams too, after validating the terminal status. Reconstruct from item-done events only when terminal output is empty. Strict ChatGPT completion checks and the existing stream-size limit remain in place.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

How Has This Been Tested?

The new tests failed against upstream 0d403392073bcb0d3894c5364b0a85e7b6a47e0d: terminal-only output became [], partial item events dropped the terminal answer, and the HTTP/SSE client returned no tool calls.

Regression coverage includes:

  • Complete terminal output with no item events or only a subset, including incomplete responses and usage preservation.
  • Nonempty output cannot bypass failed, cancelled, queued, in-progress, or unknown-status rejection.
  • A local HTTP/SSE server through the real client: function-call ID, name and arguments, plus encrypted reasoning in the native replay payload, survive a terminal-only response.

Validation:

  • make check: passed (license/English checks, tidy, formatting, vet).
  • make test with race detection and a coverage profile: all 25 root-module packages passed; total coverage 90.9%, internal/llm coverage 94.5%.
  • make build: passed.
  • Both merge orders with fix(llm): report a request's total wall clock, not just per-attempt timings #1788: passed with an identical final tree; combined LLM race tests also passed.

Test environment: Windows amd64, Go 1.26.10, GCC 16.2.0 and portable Git 2.56.0.windows.4. On this machine Make was invoked as mingw32-make with Git Bash and a local Go wrapper to keep the portable Git first on PATH. The initial run with system Git 2.33.1 failed in internal/tool because it lacks git grep --max-count; the full suite passes with supported Git. No source changes were made for that environment issue.

This is a deterministic compatibility fixture, not a claim of a live-provider incident. ocr review --audience agent --background ... was attempted but could not run because no OCR LLM endpoint is configured locally.

Checklist

  • Code follows the project's coding style; make check passes.
  • The contributor has personally reviewed the AI-produced diff and text before requesting a reviewer.
  • Added regression tests for the behavior change.
  • New and existing unit tests pass locally with these changes.
  • Documentation assessed: existing protocol/configuration behavior is restored; no configuration or documented interface changes.
  • Existing CLA signature verified through license/cla on fix(llm): report a request's total wall clock, not just per-attempt timings #1788; this PR's check will be verified after submission.
  • Contributor confirmation of the repository's AI-assisted development checklist.

AI disclosure: OpenAI Codex (GPT-6), the GitHub CLI, and local Go tooling were used for repository inspection, implementation, code inspection, and automated validation. Validation was performed by the assistant; a separate personal review by the contributor is not claimed. No AI commit trailers or explicit reviewer requests are included. Maintainer questions require the contributor's own understanding under the repository's contribution rules.

Related Issues / Overlap

No existing issue or PR addressing this terminal-output loss was found in the open Issue/PR inventory, related closed/merged searches, or patches of open PRs touching responses_client.go. #1604 changes truncation/finish-reason handling rather than this accumulator behavior.

#1788 shares responses_client.go but changes stream timing in a separate function. Both merge orders were checked against current main and produce the same tree; the combined LLM race suite also passes. This branch contains only this fix, with no commits from #1788.

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s).

@chaojixinren chaojixinren left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which actual provider exhibits this behavior, and what existing OCR configuration triggers it? Without a real reproduction, I’d treat this as low-priority compatibility hardening rather than a confirmed bug fix.

@NanaseInori NanaseInori left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed both changed files and the surrounding streaming accumulator/status handling at this head. The populated terminal output is now preserved only after status validation; empty terminal output still falls back to sorted item-done events. The strict ChatGPT completion gate and the existing size checks in add() remain in place. The new fixtures cover terminal-only/partial item delivery, unsuccessful statuses, usage, and function-call/encrypted-reasoning preservation. I found no blocking code defect in this change.

The terminal envelope is a sensible authority: the official Responses streaming reference defines response.completed as carrying the completed response. However, that does not establish that a real supported endpoint omits item-done events. The existing request for a concrete provider/configuration reproduction is still unanswered here. I would describe the present evidence as deterministic compatibility hardening and leave acceptance/priority to the maintainers, rather than claim a confirmed production incident.

The symptom search did not identify another direct terminal-output-preservation patch. No linked issue is claimed. This is a source-and-test review; I did not independently execute the repository suite, perform a live-provider run, or verify the reported merge-order experiments.

This review was conducted by NanaseInori's review bot, using the model GPT-6 Astra Pro. If you need a human review, please manually @NanaseInori.

This branch has not been deployed

No deployments
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.

3 participants