Repository navigation
fix(relayconvert): keep reasoning summary items active after mid-stream finish_reason / 修复 reasoning summary 在流中途 finish_reason 后失去 active item - #7497
Conversation
|
Understand this PR’s impact Explore downstream dependencies and potential security impact with Blast Radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. WalkthroughThe converter now creates separate reasoning output items when reasoning resumes after a mid-stream ChangesReasoning segment lifecycle
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Bug fix · Severity of issue fixed: Medium Sequence Diagram(s)sequenceDiagram
participant OAIChatStream
participant ResponsesConverter
participant ResponsesClient
OAIChatStream->>ResponsesConverter: emits finish_reason
ResponsesConverter->>ResponsesClient: completes current reasoning item
OAIChatStream->>ResponsesConverter: emits later reasoning delta
ResponsesConverter->>ResponsesClient: adds a new reasoning item and summary part
ResponsesConverter->>ResponsesClient: sends reasoning deltas and completion
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. A rabbit hops where reason streams Comment |
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
All reviewed changes have regression coverage and no blocking issues were identified.
Review effort: Lite
Findings: None
What changed in this PR
Fixes reasoning summary item lifecycle after a mid-stream finish_reason, preserving separate reasoning segments in Responses streams.
Changes:
- Adds
response.reasoning_summary_part.added. - Reopens reasoning with independent item IDs and output indexes.
- Preserves segmented reasoning in completed responses.
- Adds regression coverage for both sequence-number modes.
| File | Description |
|---|---|
relaykit/relayconvert/internal/oai_chat/to_oai_responses_stream_resp.go |
Implements segmented reasoning lifecycle and reconstruction. |
relaykit/relayconvert/internal/oai_chat/to_oai_responses_resp.go |
Adds the reasoning summary part event constant. |
relaykit/relayconvert/internal/oai_chat/to_oai_responses_resp_test.go |
Tests reopening and preserving reasoning segments. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Agent
Links
User request
"I want you to create a branch locally, fix only this bug, merge that branch into local main, and submit the PR from the branch."
Out of scope — refuse
Kind
Issue facts
finish_reasonarrives mid-stream,ChatToResponsesStreamStatecloses the reasoning output item but never resetsreasoningStarted/reasoningDone. If the same stream later emits morereasoning_content, the converter keeps sendingresponse.reasoning_summary_text.deltafor the already-closeditem_id/output_index, without a newresponse.output_item.addedorresponse.reasoning_summary_part.added.reasoning -> tool call -> mid-stream finish_reason -> reasoning again; real client logs showed thousands of occurrences across multiple days.QuantumNous/new-apimain@9a0be8750by feeding pure protocol frames directly to the converter, with no upstream service or channel involved.POST /v1/responses, OpenAI Chat Completions to OpenAI Responses streaming conversion; reasoning output itemitem_id,output_index, and summary-part lifecycle.Change
The fix repairs the reasoning summary segment lifecycle instead of continuing to emit deltas for a closed item:
response.reasoning_summary_part.addedevent constant.appendReasoningDeltastarts a new reasoning segment, allocates a new output index and_reasoning_Nitem ID, and emitsresponse.output_item.added,response.reasoning_summary_part.added, then the delta.doneDeltaEventsstores the current segment text before closing it; each segment gets its own done event and item.finalResponseresolves reasoning items from the output-order segment index so a later segment cannot overwrite an earlier one.EmitSequenceNumber=trueandfalse, covering active-item validity, part-added count, and two independent reasoning outputs in the completed response.Research
Duplicate / prior art
reasoning_summary_text.delta,reasoning_summary_part,finish_reason,oai_chat_to_oai_responses,7495.Docs and code
relaykit/README.mddescribes response-stream state conversion conventions.relaykit/relayconvert/internal/oai_chat/to_oai_responses_stream_resp.go: maintains reasoning/text/tool output-item lifecycle; this PR fixes reasoning segmentation.relaykit/relayconvert/internal/oai_chat/to_oai_responses_resp.go: Responses stream event constants.relaykit/relayconvert/response_registry.goandrelay/channel/openai/responses_via_chat.go: call path for this converter in the/v1/responsesstreaming path.Alternatives considered
_reasoning_0. Rejected: it still reuses a closed item ID and output index and cannot represent two independent summaries in the final response.reasoning_summary_part.addedwithout opening a new item. Rejected: deltas would still reference an item that is already done, so active-item validation would still fail.Files
relaykit/relayconvert/internal/oai_chat/to_oai_responses_resp.goresponse.reasoning_summary_part.addedrelaykit/relayconvert/internal/oai_chat/to_oai_responses_stream_resp.gorelaykit/relayconvert/internal/oai_chat/to_oai_responses_resp_test.gofinish_reasonBehavior
resp_1_reasoning_0; noreasoning_summary_part.added; the completed response has one reasoning item with textround 1round 2.round 1andround 2.Verification
Only what was actually run.
upstream/main@9a0be8750, targeted test first failed with:reasoning delta for "resp_1_reasoning_0" arrived without an active itemreasoning_summary_part.addedexpected2, actual02reasoning items, but had1withround 1round 2PASS: TestChatCompletionsStreamToResponsesReopensReasoningAfterMidStreamFinishReasonEmitSequenceNumbersub-tests passed.GOWORK=off go vet ./...passed for root andrelaykit.GOWORK=off go build ./...passed for root andrelaykit.relaykit:GOWORK=off go test ./...passed, including all existing relaykit tests.35559346672is currentlyaction_required(waiting for maintainer approval of the first-time contributor workflow); no jobs have executed yet.TestChatCompletionsStreamToResponsesReopensReasoningAfterMidStreamFinishReason.golang:1.26) for unit tests; SQLite fixtures in root module; no real provider calls.make testfails in this environment atTestResponsesWebSocketInitialUpstreamRejectionRefundsReservation(expected2990/ actual3000). This failure reproduces on unmodifiedupstream/main@9a0be8750with both Go 1.25.1 and Go 1.26 and is tracked by upstream PR test(billing): fix websocket rejection refund test after pre-consume dropped output estimation #7491. This PR does not modify controller or billing code.bun run typecheck/bun run testnot run; no frontend files changed, upstream CI covers them.Risks
finish_reason; single-segment reasoning now includes the protocol-requiredreasoning_summary_part.added.make testshould return to green; no further change is required in this PR.Scope check
中文版 / Chinese
Agent
Links
User request
"我希望你在本地,新建一个branch,专门修复这个bug,然后将这个分支合并到本地的main,但是要用分支提交PR"
Out of scope — refuse
Kind
Issue facts
finish_reason后,ChatToResponsesStreamState会关闭 reasoning output item,但不会复位reasoningStarted/reasoningDone。同一流后续再次出现reasoning_content时,转换器继续为已关闭的item_id/output_index发送response.reasoning_summary_text.delta,且不补发response.output_item.added或response.reasoning_summary_part.added。QuantumNous/new-apimain@9a0be8750上,用纯协议帧直接调用该转换器即可复现;不涉及任何上游服务或渠道。POST /v1/responses的 OpenAI Chat Completions → OpenAI Responses 流式转换;reasoning output item 的item_id、output_index和 summary part 生命周期。Change
修复 reasoning summary segment 的生命周期,而不是继续向已关闭的 item 发送 delta:
response.reasoning_summary_part.added事件常量。appendReasoningDelta开启新的 reasoning segment,分配新的 output index 和_reasoning_Nitem ID,并依次发送response.output_item.added、response.reasoning_summary_part.added和 delta。doneDeltaEvents在关闭当前 segment 前保存其文本;每个 segment 都有自己的 done 事件和 item。finalResponse按 output order 中的 segment 还原 reasoning item,避免后一段覆盖前一段。EmitSequenceNumber=true/false,验证 active item、part.added 数量以及最终 completed response 中两个独立 reasoning output。Research
Duplicate / prior art
reasoning_summary_text.delta、reasoning_summary_part、finish_reason、oai_chat_to_oai_responses、7495。Docs and code
relaykit/README.md描述了 response stream state 的转换约定。relaykit/relayconvert/internal/oai_chat/to_oai_responses_stream_resp.go:维护 reasoning/text/tool output item 生命周期;本 PR 修正 reasoning 分段。relaykit/relayconvert/internal/oai_chat/to_oai_responses_resp.go:Responses stream 事件常量。relaykit/relayconvert/response_registry.go与relay/channel/openai/responses_via_chat.go:该转换器在/v1/responses流式路径上的调用点。Alternatives considered
_reasoning_0。拒绝:仍然复用已关闭 item 的 ID 和 output index,且最终响应无法表示两段独立 summary。reasoning_summary_part.added,不开启新 item。拒绝:delta 仍会引用已经 done 的 item,active-item 校验仍会失败。Files
relaykit/relayconvert/internal/oai_chat/to_oai_responses_resp.goresponse.reasoning_summary_part.added事件常量relaykit/relayconvert/internal/oai_chat/to_oai_responses_stream_resp.gorelaykit/relayconvert/internal/oai_chat/to_oai_responses_resp_test.gofinish_reason后再次 reasoning 的回归测试Behavior
resp_1_reasoning_0;没有reasoning_summary_part.added;completed response 只有 1 个 reasoning item,文本为round 1round 2。round 1和round 2。Verification
仅记录实际运行内容。
upstream/main@9a0be8750上,定向测试先失败:reasoning delta for "resp_1_reasoning_0" arrived without an active itemreasoning_summary_part.addedexpected2,actual0round 1round 2PASS: TestChatCompletionsStreamToResponsesReopensReasoningAfterMidStreamFinishReasonEmitSequenceNumber子测试均通过。relaykit的GOWORK=off go vet ./...通过。relaykit的GOWORK=off go build ./...通过。relaykit:GOWORK=off go test ./...通过,包括全部既有 relaykit 测试。35559346672当前为action_required(等待维护者批准首次贡献者工作流),尚无 job 执行。TestChatCompletionsStreamToResponsesReopensReasoningAfterMidStreamFinishReason。golang:1.26)运行单元测试;root module 使用 SQLite fixture;未调用真实 provider。make test在当前环境失败于TestResponsesWebSocketInitialUpstreamRejectionRefundsReservation(expected2990/ actual3000)。该失败已在未修改的upstream/main@9a0be8750上、Go 1.25.1 与 Go 1.26 环境下复现,并由上游 PR test(billing): fix websocket rejection refund test after pre-consume dropped output estimation #7491 跟踪;本 PR 未修改 controller 或 billing 代码。bun run typecheck/bun run test未运行;本次无前端变更,由上游 CI 覆盖。Risks
finish_reason后再次出现 reasoning 的事件序列;单段 reasoning 现在会按协议补上reasoning_summary_part.added。make test预期恢复绿色;本 PR 不需要额外修改。Scope check