Skip to content

[PR] fix: preserve successful responses beyond the fake-completion buffer cap - #7406

Open
Afloat16 wants to merge 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-20_preserve-oversize-fake-completion-responses
Open

Afloat16 wants to merge 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-20_preserve-oversize-fake-completion-responses

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Fixes #7405

Problem

The opt-in fake-completion path treats a capped error-body buffer as a complete successful response. It drains bytes beyond the inspection cap and then forwards only the prefix. Both proxy/plugin modes and initial/corrective responses are affected: text, real tool calls, usage and terminal events can disappear, and a JSON success can become unparseable.

Change

  • Buffer for inspection only while the complete response fits the cap. On overflow, replay all retained bytes and continue reading the original stream through the existing response pipes.
  • Classify and update the fake-completion streak only when the whole response was inspected. Exactly-at-cap responses still receive the existing check.
  • Transfer the live retry's cleanup to the consuming caller, after any raw-dump branch finishes, so idle termination and downstream cancellation remain active.
  • Keep the separate error-body reader's capped-prefix behavior unchanged.

The streaming fallback retains at most the inspected prefix plus the current upstream chunk before normal backpressure takes over; it does not claim that one arbitrarily large incoming chunk is smaller than the configured cap.

Config surface

No field, environment variable, default or persistence format is added. fakeCompletion.bufCapBytes remains the inspection-buffer guard (16 MiB by default); successful output is no longer silently truncated at that guard. fakeCompletion.retries=0 remains the default. The en/zh configuration references describe the overflow behavior.

Validation

Tested base: 1e357bf2d6632bfbd2a74ffb70ecee1af1ec7cc3.

  • Unchanged base: 5 behavior failures / 2 passing exact-cap controls.
  • Fixed branch: 74/74 targeted tests passed, zero skipped, across the new budget/stream tests and existing fake-completion, plugin retry, abort, raw-dump and backpressure suites.
  • Real proxy/plugin HTTP cases preserve initial and retried SSE, usage, completion frames and byte-exact late tool arguments; a JSON response remains parseable.
  • Boundary controls cover exact-cap inspection, the session streak, split UTF-8, source errors, unread-tail backpressure, cancellation before and during replay, and unchanged error-body truncation.
  • Real stalled retries still terminate under the idle watchdog; client cancellation also closes the retry with raw dumping enabled, leaving no live upstream timers.
  • npm run typecheck, npm run build, npm run check:unused-exports, npm run check:test-import-graph and git diff --check pass.
  • Codex preflight locates CLI 0.169.0 and the built artifact. The local Responses upstream at port 8199 is unavailable, so the live four-phase E2E has not run. Full regression remains the remote CI on this head.

Related history

All-author/all-state duplicate screening found no equivalent change. #378/#486 introduced the shared fake-completion behavior; #1904 concerns the request used for a hinted retry. #7203 bounds separate rejected compression-replay error bodies.

Stop bounded inspection at the first over-budget chunk and replay its
complete prefix and remaining stream through the existing response pipes.
Do not classify a partial response or alter its fake-completion streak.

Keep retry idle timers and client-abort listeners until the live response
and optional raw dump finish. Error-body truncation remains unchanged.

Validation: 5 baseline behavior failures and 2 passing exact-cap controls;
74 targeted tests pass. Typecheck, build and static gates pass. Codex
preflight finds the CLI/artifact but the live upstream is unavailable;
the real four-phase E2E and full remote CI remain pending.
@ranxianglei ranxianglei changed the title fix: preserve successful responses beyond the fake-completion buffer cap [PR] fix: preserve successful responses beyond the fake-completion buffer cap Nov 20, 2026

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Fake-completion buffering silently truncates successful responses

2 participants