Skip to content

fix(streaming-overflow): preserve hadVisibleText state when escalating to recovery (v0.5.39)#144

Merged
royosherove merged 2 commits into
mainfrom
fix/streaming-hadvisibletext-state
May 16, 2026
Merged

fix(streaming-overflow): preserve hadVisibleText state when escalating to recovery (v0.5.39)#144
royosherove merged 2 commits into
mainfrom
fix/streaming-hadvisibletext-state

Conversation

@royosherove
Copy link
Copy Markdown
Member

Issue

Codex-identified P2 regression in v0.5.38: when a streaming text_delta event precedes a model_error overflow, the hadVisibleText flag is lost.

Root cause: handleStreaming throws StreamModelOverflowError on overflow, bypassing the normal return path. The gateway's hoisted-local streamHadVisibleText is only updated on success, so it stays false even though partial text was emitted.

UX impact: Recovery posts 'Please resend your last message' instead of 'Response was interrupted; session recovered'. After partial output, this misleads the user and encourages duplicate sends (re-executing tools).

Fix

Attach hadVisibleText to the StreamModelOverflowError object so it survives the throw. Extract it in gateway.ts catch via type-safe instanceof and pass to recovery helper.

Changes:

  • StreamModelOverflowError constructor: add hadVisibleText: boolean param
  • streaming.ts model_error handler: pass hasVisibleText when throwing
  • gateway.ts catch: extract hadVisibleText from error via instanceof check, pass to recovery
  • streaming-overflow.test.ts: fix test to extract state from error (was manually overriding to true, masking the bug)

Tests: 591 passing, no new failures.
Codex reviews: ✅ code review clean, ✅ arch review (type-safe instanceof) applied.

Closes Codex P2 feedback on PR #143.

…g to gateway recovery (Codex P2)

When a text_delta is emitted before a model_error overflow event, the
hadVisibleText flag was lost because handleStreaming() threw before
completing normally. The gateway catch then always saw hadVisibleText=false
and posted 'Please resend your last message' copy — misleading after
partial output.

Attach hadVisibleText to the StreamModelOverflowError so it survives the
throw. Extract it in gateway.ts catch and pass to recovery, which then
posts 'Response was interrupted; session recovered' wording for partial
output (correct UX, prevents duplicate side effects).

Test: updated streaming-overflow.test.ts to extract state from error
object instead of relying on gateway hoisted-local pattern (which was the
bug). All 591 tests green.
@royosherove royosherove merged commit 3c9e349 into main May 16, 2026
1 check passed
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