Repository navigation
Conversation
li-xiu-qi
requested review from
MelodyVAR,
Uking-xxx,
ZouR-Ma and
liuedcson
as code owners
October 21, 2026 15:15
li-xiu-qi
marked this pull request as draft
October 28, 2026 17:54
li-xiu-qi
force-pushed
the
fix/thinking-before-answer
branch
from
October 28, 2026 18:39
a1a645b to
58381d6
Compare
li-xiu-qi
marked this pull request as ready for review
October 28, 2026 18:52
li-xiu-qi
marked this pull request as draft
October 29, 2026 09:10
…ams them last Provider streaming assembles message.content in arrival order, so turns that flush the reasoning stream after the answer text rendered the thinking block below the answer while other turns rendered it above. Normalize the render path: when no thinking block precedes the first answer block, hoist thinking ahead of the answer in both the pi and step skins. Alternating runs are left untouched.
li-xiu-qi
force-pushed
the
fix/thinking-before-answer
branch
from
October 29, 2026 09:13
58381d6 to
2dbe319
Compare
li-xiu-qi
marked this pull request as ready for review
October 29, 2026 12:10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #286
Problem
Under upstream model streaming protocols (such as the OpenAI Responses API streaming format and compatible gateways), reasoning events are occasionally flushed after the text generation events. Specifically, the SSE stream can emit
response.output_item.added (type: "message")followed by text deltas before emittingresponse.output_item.added (type: "reasoning")for the reasoning summary or signature.The client's provider streaming layer (
packages/providers/src/api/openai-responses-shared.ts) appends incoming blocks tooutput.contentin packet arrival order. Consequently, in those turns,message.contentis assembled with the answer block preceding the thinking block ([text, thinking]). Because the TUI transcript walksmessage.contentsequentially during rendering, the collapsed thinking block was painted below the answer in those turns, but jumped above the answer in turns where reasoning arrived first.Mutating
message.contentin the provider or session data layer would be architectural malpractice:message.contentis persisted and re-sent to upstream APIs as conversation context in subsequent turns. Arbitrarily reordering raw blocks risks schema rejection on strict APIs or corrupting prompt context.thinking -> toolCall -> thinking -> answer). Flattening or reordering blocks at the data layer would destroy causal execution sequence.Changes
withThinkingBeforeAnswer()inapps/cli/src/ui/view/transcript/assistant-message.tsas a pure, display-layer normalization function.AssistantMessageComponent.updateContent()(pi skin) andpartitionAssistantContent()(step skin).assistant-message.test.tsandstep-message.test.tsverifying that trailing thinking is hoisted, while leading and interleaved thoughts remain in place.Behavior and compatibility
message.contentitself is never mutated in place. No persisted session data, API wire format, provider request, or CLI configuration changes.Validation
[text, thinking]and thatwithThinkingBeforeAnswercleanly normalizes presentation without altering stored data.apps/cli/test/assistant-message.test.tsandapps/cli/test/step-message.test.ts.npx vitest run apps/cli/test/assistant-message.test.ts apps/cli/test/step-message.test.ts: all 29/29 tests pass (25 existing + 4 new).npx tsgo -p tsconfig.build.json --noEmitinapps/cli: clean.npx biome checkon changed files: clean.check:ui-layer,check:layer-direction,check:ts-relative-imports.apps/cliandpackages/*suite run on Windows: compared against an unmodified stash baseline, confirming zero candidate-introduced regressions. Fork/upstream Linux CI is clean.Limitations
Not applicable: this is a display-only rendering normalization covered by unit tests across both skins; no unresolved boundary or behavioral regression is known.