Repository navigation
Conversation
…after done A client that closes the socket right after the final SSE event lets the handler's main select win c.Request.Context().Done() and record client_gone before the scanner records the terminal reason it already reached. SetEndReason now lets a Done/EOF completion correct that earlier client_gone. The client-gone branch also skips relabeling a stream that already ended normally. Genuine mid-stream disconnects surface as scanner_error, so they stay client_gone. Closes QuantumNous#6649
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Walkthrough
ChangesStream completion handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Mergeability Score: ⚪ Minimal · up to This change corrects stream completion labels after a client disconnect without changing successful response, billing, or token behavior; no actionable merge-blocking risk remains beyond normal checks and review. Possibly related issues
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Tools execution failed with the following error: Failed to run tools: 14 UNAVAILABLE: Connection dropped Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
I found a Responses-specific follow-up that is still needed on top of this fix. I prepared a focused PR directly against this PR branch: zkasuran#1 It marks the native Responses terminal event as Done after forwarding it and adds a deterministic cancellation regression test. The relevant Go tests, a 20-run repetition of the new test, and |
|
关于楼上 @walker1211 提到的 Responses 缺口: |
51fdfc5 to
2b6f1df
Compare
…ct errors Stop Responses SSE after its completed event has been written, preserving upstream token and tool usage. Reconcile a concurrent client cancellation only after all scanner workers have joined and a completed response was successfully delivered. Bare EOF, failed writes and protocol errors do not qualify. Propagate SSE write/flush errors and suppress cleanup read errors. Integrates the completion handling from #6904 and #6951 and narrows the cancellation reconciliation proposed in #6808. Refs #6649. Co-authored-by: leecz <[email protected]> Co-authored-by: zkasuran <[email protected]> Co-authored-by: yinshaohua <[email protected]>
…ct errors (#7956) Stop Responses SSE after its completed event has been written, preserving upstream token and tool usage. Reconcile a concurrent client cancellation only after all scanner workers have joined and a completed response was successfully delivered. Bare EOF, failed writes and protocol errors do not qualify. Propagate SSE write/flush errors and suppress cleanup read errors. Integrates the completion handling from #6904 and #6951 and narrows the cancellation reconciliation proposed in #6808. Refs #6649. Co-authored-by: leecz <[email protected]> Co-authored-by: zkasuran <[email protected]> Co-authored-by: yinshaohua <[email protected]>
|
已整合至 #7956 并合并,因此关闭此 PR。感谢贡献,合并提交已保留 co-author 署名。 |
…ct errors (QuantumNous#7956) Stop Responses SSE after its completed event has been written, preserving upstream token and tool usage. Reconcile a concurrent client cancellation only after all scanner workers have joined and a completed response was successfully delivered. Bare EOF, failed writes and protocol errors do not qualify. Propagate SSE write/flush errors and suppress cleanup read errors. Integrates the completion handling from QuantumNous#6904 and QuantumNous#6951 and narrows the cancellation reconciliation proposed in QuantumNous#6808. Refs QuantumNous#6649. Co-authored-by: leecz <[email protected]> Co-authored-by: zkasuran <[email protected]> Co-authored-by: yinshaohua <[email protected]> (cherry picked from commit 0c2af97)
…ct errors (QuantumNous#7956) Stop Responses SSE after its completed event has been written, preserving upstream token and tool usage. Reconcile a concurrent client cancellation only after all scanner workers have joined and a completed response was successfully delivered. Bare EOF, failed writes and protocol errors do not qualify. Propagate SSE write/flush errors and suppress cleanup read errors. Integrates the completion handling from QuantumNous#6904 and QuantumNous#6951 and narrows the cancellation reconciliation proposed in QuantumNous#6808. Refs QuantumNous#6649. Co-authored-by: leecz <[email protected]> Co-authored-by: zkasuran <[email protected]> Co-authored-by: yinshaohua <[email protected]> (cherry picked from commit 0c2af97)
…ct errors (QuantumNous#7956) Stop Responses SSE after its completed event has been written, preserving upstream token and tool usage. Reconcile a concurrent client cancellation only after all scanner workers have joined and a completed response was successfully delivered. Bare EOF, failed writes and protocol errors do not qualify. Propagate SSE write/flush errors and suppress cleanup read errors. Integrates the completion handling from QuantumNous#6904 and QuantumNous#6951 and narrows the cancellation reconciliation proposed in QuantumNous#6808. Refs QuantumNous#6649. Co-authored-by: leecz <[email protected]> Co-authored-by: zkasuran <[email protected]> Co-authored-by: yinshaohua <[email protected]>
…ct errors (QuantumNous#7956) (#92) Stop Responses SSE after its completed event has been written, preserving upstream token and tool usage. Reconcile a concurrent client cancellation only after all scanner workers have joined and a completed response was successfully delivered. Bare EOF, failed writes and protocol errors do not qualify. Propagate SSE write/flush errors and suppress cleanup read errors. Integrates the completion handling from QuantumNous#6904 and QuantumNous#6951 and narrows the cancellation reconciliation proposed in QuantumNous#6808. Refs QuantumNous#6649. Co-authored-by: Calcium-Ion <[email protected]> Co-authored-by: leecz <[email protected]> Co-authored-by: zkasuran <[email protected]> Co-authored-by: yinshaohua <[email protected]>
…ct errors (QuantumNous#7956) Stop Responses SSE after its completed event has been written, preserving upstream token and tool usage. Reconcile a concurrent client cancellation only after all scanner workers have joined and a completed response was successfully delivered. Bare EOF, failed writes and protocol errors do not qualify. Propagate SSE write/flush errors and suppress cleanup read errors. Integrates the completion handling from QuantumNous#6904 and QuantumNous#6951 and narrows the cancellation reconciliation proposed in QuantumNous#6808. Refs QuantumNous#6649. Co-authored-by: leecz <[email protected]> Co-authored-by: zkasuran <[email protected]> Co-authored-by: yinshaohua <[email protected]>
…ct errors (QuantumNous#7956) Stop Responses SSE after its completed event has been written, preserving upstream token and tool usage. Reconcile a concurrent client cancellation only after all scanner workers have joined and a completed response was successfully delivered. Bare EOF, failed writes and protocol errors do not qualify. Propagate SSE write/flush errors and suppress cleanup read errors. Integrates the completion handling from QuantumNous#6904 and QuantumNous#6951 and narrows the cancellation reconciliation proposed in QuantumNous#6808. Refs QuantumNous#6649. Co-authored-by: leecz <[email protected]> Co-authored-by: zkasuran <[email protected]> Co-authored-by: yinshaohua <[email protected]>
Important
📝 变更描述 / Description
Streams that finished normally were sometimes labeled
client_goneinstream_status.end_reason, which the frontend shows as a stream error. When aclient (codex CLI, curl in stream mode) closes its socket right after the last
SSE event, the gin request context is canceled. In
StreamScannerHandlerthemain select can win
c.Request.Context().Done()and recordclient_gonein thesmall window before the scanner goroutine records the terminal reason it already
reached (
[DONE]or a clean EOF). BecauseSetEndReasonwas first-write-wins(
sync.Once), the scanner's laterDone/EOFwas dropped. HTTP 200, tokensand billing were all correct, only the label was wrong.
Fix:
SetEndReasonstill keeps the first reason, with one exception: a normalcompletion (
Done/EOF) corrects an earlierclient_gone. A genuinemid-stream disconnect surfaces as
scanner_errorafter the forced body close,not a completion, so it stays
client_gone.ended normally.
cleanup()still runs, so the upstream body is still closedand token generation still stops for an abandoned request.
EOFonly when there was no real scannererror, so a forced close cannot masquerade as a normal EOF.
Added a deterministic regression test in
relay/helperthat reproduces thedocumented ordering (
client_gonerecorded first, completion after) and assertsthe completion wins, plus that a real
scanner_errorafterclient_gonestaysclient_gone.🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
AI disclosure: this change was AI-assisted. I reviewed the diff, ran the builds
and tests below locally. I understand and can defend the change. Verified on
this branch with
GOWORK=off GOTOOLCHAIN=auto:The new test fails on unmodified
SetEndReason(staysclient_gone) and passeswith the fix, confirming it guards the real behavior.
Summary by CodeRabbit