Repository navigation
Description
Upstream source
- PR: fix(relayconvert): keep reasoning summary items active after mid-stream finish_reason / 修复 reasoning summary 在流中途 finish_reason 后失去 active item QuantumNous/new-api#7497
- Issue: [BUG] oai_chat_to_oai_responses 转换器:流中途出现 finish_reason 后 reasoning delta 失去 active item QuantumNous/new-api#7495
- Upstream base reproduced at
9a0be8750
Why this applies to api.lmm.best
apps/api-go/relaykit/relayconvert/internal/oai_chat/to_oai_responses_stream_resp.go has the same lifecycle bug as the upstream report.
Current LMM behavior:
appendReasoningDeltaopens a reasoning item only whenreasoningStarted == false.- A non-empty
finish_reasoncallsdoneDeltaEvents(), which setsreasoningDone = trueand emitsresponse.output_item.done. - If the same upstream stream later emits more
reasoning_content,reasoningStartedis still true, so LMM emits anotherresponse.reasoning_summary_text.deltafor the already-closedresp_*_reasoning_0item. - The final response also uses a single reasoning builder/item, so multiple reasoning segments are collapsed together.
This is a protocol/lifecycle bug for Chat Completions -> Responses streaming conversion. It does not depend on pricing, groups, routing or provider-specific business logic.
Why not cherry-pick the upstream PR yet
The upstream PR is still open and its first-contributor CI has not executed yet. More importantly, LMM's relaykit has diverged from the current upstream converter:
- LMM does not have the newer
EmitSequenceNumberstream state used by the upstream regression test. - LMM's reasoning output is represented through
ResponsesOutput.Content, while current upstream uses the newer reasoningSummaryrepresentation. - Current upstream stream state also contains newer annotation/hosted-tool lifecycle code that is absent from this fork.
So the bug is confirmed, but copying the upstream patch as-is would mix protocol-shape changes with the actual lifecycle fix.
Suggested minimal LMM adaptation
Keep the existing LMM converter shape and change only reasoning-segment lifecycle:
- Track a reasoning segment ordinal and persisted text per completed segment.
- If a new reasoning delta arrives after
reasoningDone, reset the current builder/state and open a new reasoning segment. - Allocate a fresh output index and item ID (
resp_*_reasoning_1,resp_*_reasoning_2, ...), never reuse a closed item. - Emit the required
response.output_item.addedbefore any delta for the new segment. If LMM addsresponse.reasoning_summary_part.added, do so consistently for every reasoning segment rather than only resumed segments. - Store each segment's text when it is closed so the final
response.completedoutput contains separate reasoning items in output order instead of concatenating them. - Do not change text/tool item behavior in the same patch unless a separate regression demonstrates the same bug there.
Acceptance criteria
- Regression sequence
reasoning -> tool call -> finish_reason=tool_calls -> reasoning -> finish_reason=stopproduces two distinct reasoning output items. - No
response.reasoning_summary_text.deltareferences an item after that item has emittedresponse.output_item.done. - The second reasoning segment gets a new
output_indexand a new item ID. - Final completed response preserves
round 1andround 2as independent reasoning outputs in order; they are not concatenated or overwritten. - Existing single-segment reasoning behavior remains unchanged apart from any intentionally added protocol-required
reasoning_summary_part.addedevent. - Tests cover both the emitted stream lifecycle and final completed response.
go testfor the relaykit conversion package and repository CI/release qualification pass.- No changes to pricing, group ratios, model price locks,
/fast, OAuth restrictions, routing policy, or administrator AI assistant behavior.
Metadata
Metadata
Assignees
Labels
No labels
Activity
LIghtJUNction commentedon Sep 21, 2026
Upstream #7512 has now merged as QuantumNous/new-api@4eb3b91 and provides the separate regression evidence this issue was waiting for: the same post-
finish_reasonlifecycle bug affects normal message/text items as well as reasoning items.Please expand the LMM-native fix/acceptance criteria accordingly:
response.completed.output;reasoning -> text -> tool_call -> finish_reason=tool_calls -> reasoning -> text -> stop, asserting separate reasoning and message segments before/after the tool call.Upstream #7512 also adds
reasoning_summary_part.added/donelifecycle events. Treat those as protocol-parity work only if LMM's current Responses event model supports them cleanly; the critical correctness requirement here is reopening both reasoning and message items instead of writing into closed items. No pricing/routing behavior should be coupled to this change.