Skip to content

fix(stream): accept text-only clean EOF - #165

Open
honglihuang wants to merge 1 commit into
Quorinex:mainfrom
honglihuang:fix/clean-eof-stream
Open

honglihuang wants to merge 1 commit into
Quorinex:mainfrom
honglihuang:fix/clean-eof-stream

Conversation

@honglihuang

Copy link
Copy Markdown

Summary

Accept successful Kiro streams that end at a clean AWS EventStream frame boundary after assistant text, even when the upstream omits metadataEvent.stopReason.

Without this change, Kiro-Go emits response.failed after already streaming the full answer. Codex then replays the same request up to five times, producing duplicate full answers before ending with:

stream disconnected before completion: upstream truncated response without stop reason

Root cause

Some healthy Kiro IDC/CLI paths finish with complete assistant frames and a clean HTTP EOF but no explicit stop reason. classifyStreamIntegrity treated every such text response as truncated, even though malformed or actually partial frames are already detected earlier by the EventStream parser.

Changes

  • Treat assistant text followed by transport-clean EOF as complete.
  • Synthesize end_turn only after parsing reaches clean EOF successfully.
  • Recognize nested stopReason, stop_reason, finishReason, and finish_reason fields.
  • Preserve failures for reasoning-only responses, empty streams, partial frames, CRC errors, exception frames, resets, and timeouts.
  • Cover streaming and buffered Claude, Chat Completions, and Responses paths.

Live reproduction and verification

Verified against an affected local Codex setup using wire_api = "responses", model gpt-5.6-terra, Kiro-Go /v1/responses, and an IDC account.

Before:

Status=200 Created=1 Completed=0 Failed=1 Done=0
upstream truncated response without stop reason

After:

Status=200 Created=1 Completed=1 Failed=0 Done=1

The repeated Codex reconnects stopped in normal use.

Validation:

go test . ./auth ./config ./logger ./pool ./proxy -count=1
go vet . ./auth ./config ./logger ./pool ./proxy
go build .
git diff --check upstream/main...HEAD

All passed. The explicit package list avoids descending into a locally installed go/ toolchain directory; that directory is not part of the patch.

Relationship to existing work

This overlaps #161. The implementation keeps the original author attribution from that PR and this submission adds independent live validation from an affected Codex + Kiro environment. If maintainers prefer, this report can be treated as confirmation for #161 and one of the duplicate PRs can be closed.

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