Repository navigation
Conversation
|
Thanks for the careful write-up. Resuming a broken anonymous stream is worth having, but a few things need fixing before it can land:
Also:
|
|
感谢细致的 review,七条意见已全部落实。先汇报各条的处理,再附上一份现网真实流量的验证数据。 七条 review 的落实情况
另外,针对 "思维链断流"(visible=0 但 reasoning>0 时原实现直接放弃)补了一个增强:截获的思考过程以语义化指令注入续写请求("不要重复推理,直接输出最终答案"),换新出口催产正文,而不是把思考文本当 content 硬拼给客户端。这一部分如认为超出本 PR 范围,可以拆成独立 PR。 现网验证(VPS 生产环境,fork 镜像
|
An anonymous SSE stream that dies mid-flight currently emits an in-band error and the client loses the rest of the answer. The free tier has no assistant prefill, so a bare trailing assistant message regenerates from scratch, but a delivered partial followed by a short continuation instruction continues cleanly (verified live, including with the core tool set present). ForwardStreamResumable relays one or more upstream segments into the same downstream stream. When a segment dies unexpectedly after visible text was delivered, forward of any tool call, and before the resume budget is spent, it asks the resumer for a continuation segment, closes the torn frame so the next segment cannot join it, trims the first overlap with the delivered tail (fail-open, decided across the first frames rather than within a single one), and keeps relaying. With no resumer it is byte-for-byte the historical ForwardStream. The gateway builds the continuation body from the original upstream body plus the partial and the instruction, cools down the exit that just broke (so the pool cursor rotates onto a different one instead of landing on the same dead exit), and fetches the next segment on its own budget derived from the client connection rather than the request-level retry budget, which may already be exhausted by the time the stream breaks. Tool calls, non-chat protocols, key tiers and canceled clients keep the old behavior, and the whole feature is one performance flag (stream_continuation, opt-in, default false). A reasoning-only break (visible text empty, reasoning non-empty) resumes by injecting the captured reasoning as context plus an instruction to skip the repeated reasoning and emit the final answer, instead of hard-joining thinking text into content. Continuation segments drop the replayed role frame, empty content frames and repeated reasoning frames; usage is accumulated per segment (input from the first segment, output across segments). The disabled path is free: with no resumer attached nothing is copied or counted, so the bytes and CPU match the previous implementation. Tested: go build ./..., go vet ./..., go test ./... all pass. Test files are intentionally not included, per this repository's convention; the feature was also exercised end-to-end against real anonymous-lane traffic on a self-hosted deployment, where it triggered on genuine mid-stream breaks.
68d7f75 to
fbc2ec6
Compare
|
已按你的要求 rebase 并清理,三条要求的状态如下。
另外两点说明:
本地门禁: |
|
已在 main 以 fac8dd3 安全重作並驗證,本 PR 由該提交取代,將納入 v1.5.2。retry.stream_resume_enabled 預設 false;只支援匿名 Chat→Chat,預設續傳 1 段、每段總期限 60 秒。保留完整 SSE 驗證與錯誤遮蔽,續段工具呼叫不會丟失,遇工具/取消/上游錯誤或不相容結構不再續傳;保留 ID/別名並累加各段實際用量。感謝提案;關閉舊分支而不直接合併。 |
Summary
An anonymous SSE stream that dies mid-flight currently surfaces an in-band error and the client loses the remainder of the answer. This adds an opt-in resume: when a stream dies unexpectedly after visible text was delivered, the gateway fetches a continuation segment on a new exit and splices its frames into the same downstream stream, so the client sees one continuous, error-free response.
Design
ForwardStreamResumable(new,internal/protocol/stream_resume.go) relays one or more upstream segments into the same writer. It only attempts a resume when: a resumer is provided, the resume budget is left, visible text or reasoning was delivered, no tool call appeared, and the client has not canceled.ForwardStreamis a thin wrapper over the new function with no resumer, so the historical path is byte-for-byte unchanged.stream_continuation_timeout_seconds), not on the request-level retry budget, which may already be exhausted by the time a stream breaks mid-flight. The number of resumes is capped bystream_continuation_max.tool_start/tool_deltaseen) and clients that canceled never resume; non-chat protocols and key tiers keep the old path; the partial is capped.continued,resume_kind,resume_attempts/resume_failuresandresume_skipped(with the skip reason) on the request line.Verification
gofmt -l .(no output),go build ./...,go vet ./...,go test ./...all clean against currentmain.Compatibility
stream_continuationis opt-in and defaults to false;stream_continuation_maxdefaults to 1 andstream_continuation_timeout_secondsdefaults to 60. Settingstream_continuation=falsekeeps the exact old behavior; the disabled path copies and counts nothing.Review notes
main; the branch is MERGEABLE again.servingBinding) was closed, so the exit-holder overlap it would have introduced no longer applies.