Repository navigation
fix(ai): preserve final phase across resumed reasoning - #125149
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 17, 2026, 5:17 AM ET / 09:17 UTC. ClawSweeper reviewWhat this changesThis PR marks OpenAI-compatible completion text interrupted by resumed reasoning as commentary or final answer, then defers channel delivery until that phase is terminally known. Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessKeep open for maintainer review. The producer-owned approach matches the current ownership boundary and the supplied latest patch addresses the prior structured-output finding, but this checkout cannot load the exact PR head for a complete source review; the PR also carries the protected Priority: P1 Review scores
Verification
How this fits togetherOpenAI-compatible completion streams become assistant text and thinking blocks in two producers, then the embedded-agent subscriber extracts and sends visible text to channels. The PR carries a producer-owned terminal-phase fact into that delivery decision. flowchart LR
A[Provider stream] --> B[Completion producers]
B --> C[Thinking and text blocks]
C --> D[Terminal phase classification]
D --> E[Embedded-agent subscriber]
E --> F[Channel-visible reply]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +294, Tests +541, Other 0. Total +835 across 14 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep producer-owned phase classification, then refresh the exact merge result and verify both completion producers and terminal subscriber delivery still produce only the final text. Do we have a high-confidence way to reproduce the issue? Yes, from source: an OpenAI-compatible stream with reasoning, interim text, resumed reasoning, and final text reaches the unphased completion block path on current main. The reviewer did not execute the live provider flow in this read-only environment. Is this the best way to solve the issue? Yes in principle: the producer alone retains the raw reasoning/text ordering needed to classify phases, whereas the related consumer heuristic cannot reliably distinguish compatible-provider semantics. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 7ce934a8b5d0. LabelsLabel changes:
Label justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
f59b749 to
370f306
Compare
|
Maintainer decision (Ayaan, 2026-08-17): approve terminal-only channel delivery for phase-ambiguous reasoning-capable OpenAI-completions streams. The no-transient-interim-text guarantee takes priority over partial-reply latency on those streams; ordinary completions retain live partial delivery. Exact head 370f306 remains fully checked: 179 passed, 50 skipped, 0 failed, including production and test typechecks. |
Classify text interrupted by resumed reasoning at the OpenAI-completions producer boundary, so channels deliver only the confirmed final answer. Defer phase-ambiguous replies until terminal classification while preserving live partial delivery for ordinary completions. Co-authored-by: Ayaan Zaidi <[email protected]>
Since openclaw#125149 any OpenAI-completions stream that carries native reasoning hides every byte of visible text until the stream ends: the first reasoning chunk marks the message terminal-bound and arms the reasoning-tag partitioner's strict mode, and text sharing a chunk with reasoning is routed through the tag-aware path, which also arms strict mode. With a reasoning model on vLLM the answer therefore arrives as one delta at the end, minutes after the reasoning finished, even though the server streamed it token by token. That deferral exists so text interrupted by resumed reasoning can be classified as commentary or final answer at terminal. Reasoning that precedes every visible byte leaves nothing to reclassify, so defer only when reasoning resumes after visible text: mark the message terminal-bound and switch the partitioner to strict mode only then, and route same-chunk text through the tag-aware path only once the message is terminal-bound. Resumed-reasoning streams behave exactly as before. Measured against vLLM (qwen38-flash-next, reasoning low): before, one 2,924-character text delta at 16.8 s; after, 92 deltas starting 50 ms after the last thinking delta. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Since openclaw#125149 any OpenAI-completions stream that carries native reasoning hides every byte of visible text until the stream ends: the first reasoning chunk marks the message terminal-bound and arms the reasoning-tag partitioner's strict mode, and text sharing a chunk with reasoning is routed through the tag-aware path, which also arms strict mode. With a reasoning model on vLLM the answer therefore arrives as one delta at the end, minutes after the reasoning finished, even though the server streamed it token by token. That deferral exists so text interrupted by resumed reasoning can be classified as commentary or final answer at terminal. Reasoning that precedes every visible byte leaves nothing to reclassify, so defer only when reasoning resumes after visible text: mark the message terminal-bound and switch the partitioner to strict mode only then, and route same-chunk text through the tag-aware path only once the message is terminal-bound. Resumed-reasoning streams behave exactly as before. Measured against vLLM (qwen38-flash-next, reasoning low): before, one 2,924-character text delta at 16.8 s; after, 92 deltas starting 50 ms after the last thinking delta. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…0685) * fix(ai): stream completions text live when reasoning precedes it Since #125149 any OpenAI-completions stream that carries native reasoning hides every byte of visible text until the stream ends: the first reasoning chunk marks the message terminal-bound and arms the reasoning-tag partitioner's strict mode, and text sharing a chunk with reasoning is routed through the tag-aware path, which also arms strict mode. With a reasoning model on vLLM the answer therefore arrives as one delta at the end, minutes after the reasoning finished, even though the server streamed it token by token. That deferral exists so text interrupted by resumed reasoning can be classified as commentary or final answer at terminal. Reasoning that precedes every visible byte leaves nothing to reclassify, so defer only when reasoning resumes after visible text: mark the message terminal-bound and switch the partitioner to strict mode only then, and route same-chunk text through the tag-aware path only once the message is terminal-bound. Resumed-reasoning streams behave exactly as before. Measured against vLLM (qwen38-flash-next, reasoning low): before, one 2,924-character text delta at 16.8 s; after, 92 deltas starting 50 ms after the last thinking delta. * fix(ai): stream reasoning completions before final classification Stream visible Chat Completions text through initial and resumed reasoning while keeping final delivery limited to the confirmed answer. Preserve unfinished reasoning-tag privacy and content followed only by reasoning. Co-authored-by: Aron Hsiao <[email protected]> --------- Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: Aron Hsiao <[email protected]>
…nclaw#150685) * fix(ai): stream completions text live when reasoning precedes it Since openclaw#125149 any OpenAI-completions stream that carries native reasoning hides every byte of visible text until the stream ends: the first reasoning chunk marks the message terminal-bound and arms the reasoning-tag partitioner's strict mode, and text sharing a chunk with reasoning is routed through the tag-aware path, which also arms strict mode. With a reasoning model on vLLM the answer therefore arrives as one delta at the end, minutes after the reasoning finished, even though the server streamed it token by token. That deferral exists so text interrupted by resumed reasoning can be classified as commentary or final answer at terminal. Reasoning that precedes every visible byte leaves nothing to reclassify, so defer only when reasoning resumes after visible text: mark the message terminal-bound and switch the partitioner to strict mode only then, and route same-chunk text through the tag-aware path only once the message is terminal-bound. Resumed-reasoning streams behave exactly as before. Measured against vLLM (qwen38-flash-next, reasoning low): before, one 2,924-character text delta at 16.8 s; after, 92 deltas starting 50 ms after the last thinking delta. * fix(ai): stream reasoning completions before final classification Stream visible Chat Completions text through initial and resumed reasoning while keeping final delivery limited to the confirmed answer. Preserve unfinished reasoning-tag privacy and content followed only by reasoning. Co-authored-by: Aron Hsiao <[email protected]> --------- Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: Aron Hsiao <[email protected]>
Problem
OpenAI-compatible streams shaped as
reasoning -> interim content -> reasoning -> final contentleft both text segments unphased. Final delivery therefore joined the interim text into the user-visible answer. The failure also occurred with coalesced packets, structuredreasoning_details, hidden reasoning, and a trailing reasoning-only suffix.Root cause
The two OpenAI-completions producers decoded reasoning differently and treated resumed reasoning as another delta without closing the active text lane or retaining a boundary confirmed by later visible text. Packet boundaries accidentally determined text-block shape. The channel layer received ambiguous unphased text and correctly preserved it.
Fix
commentaryand the confirmed suffixfinal_answervisible -> thinking -> visiblestructured-detail order identically in both producersSupersedes #96969 with a producer-owned fix. Thanks @SymbolStar for the report and reproduction analysis. Addresses #96849.
Proof
Interim.Final.into one unphased blockgit diff --check: passedbuild-artifacts; this AI-only diff does not touchui/or its assets, and the same failure reproduced across all three proof headspnpm tsgo: blocked by untouchedpackages/terminal-core/src/ansi.ts:194(TS2554); hosted exact-head production and test type checks passedExact pushed head:
370f3067dfa71d7b80be1fe4da168bf0e160dc10.Production delta: +434/-146. Growth centralizes structured reasoning decoding, records pending/confirmed phase boundaries across the two existing producer implementations, retains explicit visible-detail provenance, exposes one allocation-free Markdown parser ownership fact, and carries one terminal-phase delivery fact. No channel/provider-specific guard or compatibility path. Test delta: +553/-6; assertion-safety baseline: +2/-2.
Delivery policy
Phase-ambiguous OpenAI-compatible reasoning streams intentionally use terminal-only user-visible delivery. A transient interim message or edit is the reported bug, not an acceptable streaming state. Ordinary completions without the producer-owned terminal-phase fact retain live partial delivery; compat-declared explicit visible details retain their visible provenance.
Phase-aware delivery contract
The owner regression drives both production producers through:
Both now emit thinking A,
INTERIMascommentary, thinking B, andFINALasfinal_answer. Canonical delivery therefore returns onlyFINAL. A trailing reasoning-only suffix leaves the last confirmed final boundary intact.Exact-head redacted trace through
processCompletionsStreamand the canonical embedded-agent delivery extractor:{ "exactHead": "370f3067dfa71d7b80be1fe4da168bf0e160dc10", "transport": "openai-completions", "blocks": [ { "type": "thinking", "text": "[redacted]" }, { "type": "text", "text": "INTERMEDIATE_MARKER", "phase": "commentary" }, { "type": "thinking", "text": "[redacted]" }, { "type": "text", "text": "FINAL_MARKER", "phase": "final_answer" } ], "delivered": "FINAL_MARKER", "intermediateDelivered": false, "finalDelivered": true, "hiddenReasoningDelivered": false }Exact-head Telegram proof
The real-user Telegram harness drove the changed
openai-completionspath on370f3067dfa71d7b80be1fe4da168bf0e160dc10. The fixture emitted hidden reasoning A, interim content, hidden reasoning B, then final content. Telegram recorded one SUT message at 4097 ms containing onlyOPENCLAW_E2E_REASONING_FINAL: zero edits, deletions, typing events, intermediate markers, or hidden-reasoning markers.ClawSweeper rank-up skip: no separate Telegram Desktop transcript. The exact-head real-user TDLib recording is stronger for this defect because it exhaustively records transient messages, edits, deletions, and typing events while driving the changed provider path; a Desktop snapshot would duplicate the final-state evidence without proving those absences.
The ephemeral harness set
agents.defaults.heartbeat.target=nonewith strict readback so an unrelated background heartbeat could not contaminate the turn. It recorded one provider request, drained zero pending updates, removed its scratch directory, and left no persistent config mutation.Pre-fix compatible-provider capture
Redacted Telegram harness capture on main drove the documented generic
openai-completionsroute with:Gateway evidence recorded
provider=openaiandapi=openai-completions. Telegram received one final SUT message after 4111 ms containing bothINTERMEDIATEandFINAL, with neither hidden reasoning marker. This proves the reported stream shape leaked interim visible content on main; it does not claim that the current MiniMax service still emits that shape. Bundled MiniMax defaults toanthropic-messages, while its optional OpenAI-compatible configuration remains documented.Overlap
Open PR #96969 is the only exact overlap. Its consumer heuristic drops legitimate unphased text across providers; this PR replaces it at the producer owner boundary. Broad searches found no second open repair.