Skip to content

fix(streaming): resume truncated Responses streams mid-stream - #14639

Merged
diegosouzapw merged 1 commit into
diegosouzapw:release/v3.8.51from
maxmad64bis:fix/responses-midstream-continuation
Sep 24, 2026
Merged

diegosouzapw merged 1 commit into
diegosouzapw:release/v3.8.51from
maxmad64bis:fix/responses-midstream-continuation

Conversation

@maxmad64bis

@maxmad64bis maxmad64bis commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ base-red inherited: #14547

Summary

Mid-stream continuation only understands chat-completions events behind a translated chat request: on the Responses upstream path the scan stays shut, the continuation body requires messages, and a short complete turn has no recognized terminal marker, so an enabled setting silently does nothing there. The recovery layer now scans Responses events (text and reasoning deltas, function-call signals gated on function_call items, completed/failed/incomplete terminals), replays received text as an assistant input item, and stitches the suffix plus a minimal response.completed snapshot in the upstream envelope so the downstream translator still decides stop versus tool_calls. Tool-call, overlap, and reasoning-only guards are unchanged; chat behavior is untouched.

Related Issues

Related to #4147 (origin: chat-only mid-stream continuation this PR extends to Responses)
Related to #11151 (prior: reasoning-only resume whose text-only guard this PR reuses)
Related to #11902 (orthogonal: client-side retryable signal; this PR is the server-side resume)

Validation

  • Change type: routing
  • Focused tests and category gates from the golden path
  • npm run lint
  • Reconciled with the current active release base; focused checks rerun afterward (rev-list HEAD..upstream/release/v3.8.51 = 0, unit 24/24 + neighbors 88/88 and touched-file ESLint clean rerun after push @ 0c4724fd)
  • Production-code changes include a new or updated automated test in this PR

Tests Added Or Updated

  • tests/unit/stream-continuation-responses.test.ts (new, 24 tests: Responses scan, terminal markers, continuation bodies, short-complete never resumed, cut-resume stitching, tool-call OFF/ON, translator traversal stop/tool_calls/idempotent; RED 7/17 on the base, GREEN 24/24 here)
  • Replayed neighbors: stream-continuation, stream-continuation-wiring, stream-recovery-toolcall, stream-recovery, stream-recovery-trace-logging, chatcore-stream-recovery-log-wiring — 88/88 pass

Coverage Notes

N/A — no coverage gate moved; new branches in streamRecovery.ts are covered by the new test (scan, continuation body, stitching per format).

Reviewer Notes

  • New probes, no behavior change by default: an all-chat stream never sets the Responses flag, and chat stitching is the pre-existing branch.
  • A short complete Responses turn ending in response.completed is never re-requested (flush, no retry); failed/incomplete end the turn without resume.
  • Update 2026-09-23 (post-ready CI, head 766ffdb): Fast Quality Gates flagged one owned-file regression (streamRecovery.ts complexity 5→8, cognitive 3→4, new-code mode), fixed by splitting into smaller helpers with identical semantics (amended, lease 0c4724fd → 766ffdb); local gate now complexityNewCode=0 / cognitiveComplexityNewCode=-1, unit 24/24 + neighbors 88/88 replayed. Remaining reds qualified as inherited (failures cite files outside this PR, unchanged since the merge-base, base-red issue 🔴 Release branch not green: release/v3.8.51 #14547, normalized failure lists identical to same-base feat(sse): distinguish content-stall from transport failure in stream error codes #14582): API Route Typecheck 4 errors (auggie.ts TS2769/TS18047, projectCombo.ts TS2459/TS2724, no PR file cited, comm -23 empty vs feat(sse): distinguish content-stall from transport failure in stream error codes #14582); typecheck:core single error in cliproxyAccountHealth.ts identical on the clean base checkout (out of scope); full npm run lint red on the base (🔴 Release branch not green: release/v3.8.51 #14547); check:docs-all DEEP_HEALTH_CHECK_ENABLED present on the untouched base (health/route.ts:46) outside the PR, existing flag of the resumed test kept as is.

@maxmad64bis
maxmad64bis force-pushed the fix/responses-midstream-continuation branch from 8b8bd4f to 0c4724f Compare September 23, 2026 13:12
@maxmad64bis
maxmad64bis marked this pull request as ready for review September 23, 2026 13:22
Mid-stream continuation only understood chat-completions SSE behind a
translated chat request: on the Responses upstream path the scan stayed
shut, the continuation body required messages, and a short complete turn
had no recognized terminal marker. The recovery layer now scans
Responses events (text and reasoning deltas, function-call signals gated
on function_call items, completed/failed/incomplete terminals), replays
received text as an assistant input item, and stitches the suffix plus a
minimal response.completed snapshot in the upstream envelope so the
downstream translator still decides stop versus tool_calls. Tool-call,
overlap, and reasoning-only guards are unchanged.
@diegosouzapw

Copy link
Copy Markdown
Owner

Substantial and well-tested extension — the fold/sink refactor of the scanner is a clean
response to the complexity-gate feedback, and the RED-7/17→GREEN-24/24 test evidence plus the
88/88 neighbour replay is exactly what this kind of change needs. Ran the new suite (24/24) on
a tree with the rest of this session's stall/buffered-turn batch merged in — no conflicts, no
shared files with #14691 despite the topical overlap. No blocking items.

@diegosouzapw
diegosouzapw merged commit 1aea068 into diegosouzapw:release/v3.8.51 Sep 24, 2026
9 of 16 checks passed
@maxmad64bis
maxmad64bis deleted the fix/responses-midstream-continuation branch September 24, 2026 21:15
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.

2 participants