Skip to content

fix(ai-gateway): close terminal SSE streams - #4882

Merged
chrarnoldus merged 2 commits into
mainfrom
daffy-geometry
Jul 30, 2026
Merged

fix(ai-gateway): close terminal SSE streams#4882
chrarnoldus merged 2 commits into
mainfrom
daffy-geometry

Conversation

@chrarnoldus

@chrarnoldus chrarnoldus commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • close Responses API streams after forwarding response.completed, response.incomplete, or response.failed
  • close Anthropic Messages streams after forwarding message_stop
  • normalize and forward [DONE] before immediately closing compatible Messages, Chat Completions, and Responses streams
  • cancel upstream readers, preserve raw stream capture, and discard events after protocol terminal markers
  • cover never-ending upstream streams for each terminal behavior

Testing

  • Not run locally per request; CI will validate the change.

@chrarnoldus chrarnoldus self-assigned this Jul 30, 2026
@kilo-code-bot

kilo-code-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

Incremental review of the terminal-marker handling extended to Chat Completions ([DONE]) and Anthropic Messages (message_stop/[DONE]) found no defects: post-terminal events and comments are correctly suppressed, the normalized [DONE] sentinel is emitted exactly once (the terminal branch returns before the EOF branch can re-emit it), and raw-body capture plus upstream cancellation match the new tests.

Files Reviewed (2 files)
  • apps/web/src/lib/rewriteModelResponse.ts
  • apps/web/src/lib/rewriteModelResponse.test.ts
Previous Review Summary (commit c85923a)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit c85923a)

Status: No Issues Found | Recommendation: Merge

Executive Summary

The change correctly detects terminal Responses API SSE events (response.completed/incomplete/failed), forwards them, cancels the upstream reader, and closes the downstream stream without waiting for EOF; the added tests cover forwarding, cancellation, and raw-body capture consistently with the implementation.

Files Reviewed (2 files)
  • apps/web/src/lib/rewriteModelResponse.ts
  • apps/web/src/lib/rewriteModelResponse.test.ts

Reviewed by claude-opus-5 · Input: 30 · Output: 10.3K · Cached: 739.9K

Review guidance: REVIEW.md from base branch main

@chrarnoldus chrarnoldus changed the title fix(ai-gateway): close terminal Responses streams fix(ai-gateway): close terminal SSE streams Jul 30, 2026
@chrarnoldus
chrarnoldus merged commit 59007a8 into main Jul 30, 2026
16 checks passed
@chrarnoldus
chrarnoldus deleted the daffy-geometry branch July 30, 2026 11:58
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