Repository navigation
Chat: stream reasoning and split tool rendering - #59086
easonchen3 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6bcf01fa05
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (props.stream !== null || props.streamMessage) { | ||
| const key = `stream:${props.sessionKey}:${props.streamStartedAt ?? "live"}`; | ||
| if (props.stream.trim().length > 0) { | ||
| if ((props.stream?.trim().length ?? 0) > 0 || props.streamMessage) { | ||
| items.push({ |
There was a problem hiding this comment.
Suppress reasoning-only stream items when reasoning is hidden
When showThinking is off, this condition still adds a live stream item whenever streamMessage exists, even if the message only contains thinking blocks. In that path renderStreamingGroup receives showReasoning=false, so the bubble content is dropped and the UI renders an empty assistant row/footer instead of a reading indicator until answer text arrives. This is user-visible during reasoning-mode runs and is introduced by the new structured streaming path.
Useful? React with 👍 / 👎.
Greptile SummaryThis PR adds streaming reasoning (thinking) support through the gateway, reorders local-before-global event dispatch so the chat run registry is populated before thinking deltas arrive, and refactors the chat UI to render interleaved Key changes:
Confidence Score: 5/5Safe to merge — no P0/P1 issues found; all findings are minor style or documentation suggestions. The implementation correctly solves the ordering problem (local-before-global) with dedicated tests, properly wires the run registry so thinking deltas are never lost, and the streaming merge logic is sound for the replace-style snapshot deltas the server sends. The three P2 comments flag edge-case formatting behaviour in normalizeReasoningDisplayText, a dropped silent-reply guard that could theoretically resurface in a different delta path, and a cosmetic interleaved-block collapse in mergeTerminalAssistantMessage — none affect correctness on the happy path. ui/src/ui/controllers/chat.ts (merge helpers) and ui/src/ui/chat/message-extract.ts (reasoning normalizer) are the most logic-dense new additions and worth a second read. Prompt To Fix All With AIThis is a comment left during a code review.
Path: ui/src/ui/chat/message-extract.ts
Line: 125-133
Comment:
**Single-character strip applied to double-marker patterns**
`singleWrappedUnderscore` / `singleWrappedAsterisk` only checks that the line _starts and ends_ with the marker character — it does not verify that they are truly single markers. This means `**bold**` becomes `*bold*` (stripped of one `*` on each side) and `__text__` becomes `_text_` (stripped of one `_` each side). Both are then re-wrapped by `formatReasoningMarkdown` and can render with unintended markdown styling.
For reasoning text these are edge cases, but the guard should exclude double-marker sequences to avoid corrupting deliberately-formatted content:
```suggestion
const singleWrappedUnderscore =
trimmed.length >= 2 &&
trimmed.startsWith("_") &&
trimmed.endsWith("_") &&
!trimmed.startsWith("__") &&
!trimmed.endsWith("__");
const singleWrappedAsterisk =
trimmed.length >= 2 &&
trimmed.startsWith("*") &&
trimmed.endsWith("*") &&
!trimmed.startsWith("**") &&
!trimmed.endsWith("**");
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: ui/src/ui/controllers/chat.ts
Line: 286-298
Comment:
**`isSilentReplyStream` guard removed from `else if` fallback**
The old code checked `!isSilentReplyStream(state.chatStream)` in the `else if` branch (when `finalMessage` is absent or is itself a silent reply). The new code drops that guard and relies entirely on `isAssistantSilentReply(mergedMessage)` inside `appendStreamMessageToHistory`.
In practice these two predicates should agree, but the functions operate on different types (raw serialized string vs. normalized `StreamingAssistantMessage`). If a client stream contained purely silent-reply text that somehow survived without being captured in `chatStreamMessage` (e.g. due to a bug in a future delta path), the check would miss it. Consider keeping the explicit `!isSilentReplyStream(state.chatStream)` guard or adding a comment explaining why it is safe to drop.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: ui/src/ui/controllers/chat.ts
Line: 229-256
Comment:
**`mergeTerminalAssistantMessage` loses interleaved text when prepending thinking**
When the final terminal message has no thinking blocks and the previous streaming state had interleaved `[thinking1, text1, thinking2, text2]`, the merge collects _all_ previous thinking blocks and prepends them to the terminal content, discarding the intermediate `text1`/`text2` segments:
```ts
content: [...previousThinking, ...terminal.content]
// → [thinking1, thinking2, text_from_terminal]
```
In practice the terminal's text supersedes the streamed text, so the data loss is cosmetic. However, if the model produced genuinely distinct reasoning phases interleaved with partial answers, the final rendered message will collapse them into a single reasoning block followed by the terminal reply. A comment explaining this intended trade-off would help future readers.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "Chat: stream reasoning and split tool re..." | Re-trigger Greptile |
| return ""; | ||
| } | ||
| const singleWrappedUnderscore = | ||
| trimmed.length >= 2 && trimmed.startsWith("_") && trimmed.endsWith("_"); | ||
| const singleWrappedAsterisk = | ||
| trimmed.length >= 2 && trimmed.startsWith("*") && trimmed.endsWith("*"); | ||
| if (singleWrappedUnderscore || singleWrappedAsterisk) { | ||
| return trimmed.slice(1, -1).trim(); | ||
| } |
There was a problem hiding this comment.
Single-character strip applied to double-marker patterns
singleWrappedUnderscore / singleWrappedAsterisk only checks that the line starts and ends with the marker character — it does not verify that they are truly single markers. This means **bold** becomes *bold* (stripped of one * on each side) and __text__ becomes _text_ (stripped of one _ each side). Both are then re-wrapped by formatReasoningMarkdown and can render with unintended markdown styling.
For reasoning text these are edge cases, but the guard should exclude double-marker sequences to avoid corrupting deliberately-formatted content:
| return ""; | |
| } | |
| const singleWrappedUnderscore = | |
| trimmed.length >= 2 && trimmed.startsWith("_") && trimmed.endsWith("_"); | |
| const singleWrappedAsterisk = | |
| trimmed.length >= 2 && trimmed.startsWith("*") && trimmed.endsWith("*"); | |
| if (singleWrappedUnderscore || singleWrappedAsterisk) { | |
| return trimmed.slice(1, -1).trim(); | |
| } | |
| const singleWrappedUnderscore = | |
| trimmed.length >= 2 && | |
| trimmed.startsWith("_") && | |
| trimmed.endsWith("_") && | |
| !trimmed.startsWith("__") && | |
| !trimmed.endsWith("__"); | |
| const singleWrappedAsterisk = | |
| trimmed.length >= 2 && | |
| trimmed.startsWith("*") && | |
| trimmed.endsWith("*") && | |
| !trimmed.startsWith("**") && | |
| !trimmed.endsWith("**"); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: ui/src/ui/chat/message-extract.ts
Line: 125-133
Comment:
**Single-character strip applied to double-marker patterns**
`singleWrappedUnderscore` / `singleWrappedAsterisk` only checks that the line _starts and ends_ with the marker character — it does not verify that they are truly single markers. This means `**bold**` becomes `*bold*` (stripped of one `*` on each side) and `__text__` becomes `_text_` (stripped of one `_` each side). Both are then re-wrapped by `formatReasoningMarkdown` and can render with unintended markdown styling.
For reasoning text these are edge cases, but the guard should exclude double-marker sequences to avoid corrupting deliberately-formatted content:
```suggestion
const singleWrappedUnderscore =
trimmed.length >= 2 &&
trimmed.startsWith("_") &&
trimmed.endsWith("_") &&
!trimmed.startsWith("__") &&
!trimmed.endsWith("__");
const singleWrappedAsterisk =
trimmed.length >= 2 &&
trimmed.startsWith("*") &&
trimmed.endsWith("*") &&
!trimmed.startsWith("**") &&
!trimmed.endsWith("**");
```
How can I resolve this? If you propose a fix, please make it concise.| const nextValue = block.thinking.trim(); | ||
| last.thinking = nextValue.length >= previousValue.length ? block.thinking : last.thinking; | ||
| } else { | ||
| const previousValue = last.text.trim(); | ||
| const nextValue = block.text.trim(); | ||
| last.text = nextValue.length >= previousValue.length ? block.text : last.text; | ||
| } | ||
| continue; | ||
| } | ||
| mergedContent.push({ ...block }); | ||
| } | ||
|
|
||
| return { |
There was a problem hiding this comment.
isSilentReplyStream guard removed from else if fallback
The old code checked !isSilentReplyStream(state.chatStream) in the else if branch (when finalMessage is absent or is itself a silent reply). The new code drops that guard and relies entirely on isAssistantSilentReply(mergedMessage) inside appendStreamMessageToHistory.
In practice these two predicates should agree, but the functions operate on different types (raw serialized string vs. normalized StreamingAssistantMessage). If a client stream contained purely silent-reply text that somehow survived without being captured in chatStreamMessage (e.g. due to a bug in a future delta path), the check would miss it. Consider keeping the explicit !isSilentReplyStream(state.chatStream) guard or adding a comment explaining why it is safe to drop.
Prompt To Fix With AI
This is a comment left during a code review.
Path: ui/src/ui/controllers/chat.ts
Line: 286-298
Comment:
**`isSilentReplyStream` guard removed from `else if` fallback**
The old code checked `!isSilentReplyStream(state.chatStream)` in the `else if` branch (when `finalMessage` is absent or is itself a silent reply). The new code drops that guard and relies entirely on `isAssistantSilentReply(mergedMessage)` inside `appendStreamMessageToHistory`.
In practice these two predicates should agree, but the functions operate on different types (raw serialized string vs. normalized `StreamingAssistantMessage`). If a client stream contained purely silent-reply text that somehow survived without being captured in `chatStreamMessage` (e.g. due to a bug in a future delta path), the check would miss it. Consider keeping the explicit `!isSilentReplyStream(state.chatStream)` guard or adding a comment explaining why it is safe to drop.
How can I resolve this? If you propose a fix, please make it concise.| return null; | ||
| } | ||
| const timestamp = | ||
| source && | ||
| typeof source === "object" && | ||
| typeof (source as Record<string, unknown>).timestamp === "number" | ||
| ? ((source as Record<string, unknown>).timestamp as number) | ||
| : Date.now(); | ||
| return { | ||
| role: "assistant", | ||
| content, | ||
| timestamp, | ||
| }; | ||
| } | ||
|
|
||
| function serializeStreamingAssistantMessage(message: unknown): string { | ||
| const normalized = normalizeStreamingAssistantMessage(message); | ||
| if (!normalized) { | ||
| return ""; | ||
| } | ||
| return normalized.content | ||
| .map((block) => | ||
| block.type === "thinking" | ||
| ? `<thinking>\n${block.thinking.trim()}\n</thinking>` | ||
| : block.text.trim(), | ||
| ) | ||
| .filter(Boolean) | ||
| .join("\n\n"); |
There was a problem hiding this comment.
mergeTerminalAssistantMessage loses interleaved text when prepending thinking
When the final terminal message has no thinking blocks and the previous streaming state had interleaved [thinking1, text1, thinking2, text2], the merge collects all previous thinking blocks and prepends them to the terminal content, discarding the intermediate text1/text2 segments:
content: [...previousThinking, ...terminal.content]
// → [thinking1, thinking2, text_from_terminal]In practice the terminal's text supersedes the streamed text, so the data loss is cosmetic. However, if the model produced genuinely distinct reasoning phases interleaved with partial answers, the final rendered message will collapse them into a single reasoning block followed by the terminal reply. A comment explaining this intended trade-off would help future readers.
Prompt To Fix With AI
This is a comment left during a code review.
Path: ui/src/ui/controllers/chat.ts
Line: 229-256
Comment:
**`mergeTerminalAssistantMessage` loses interleaved text when prepending thinking**
When the final terminal message has no thinking blocks and the previous streaming state had interleaved `[thinking1, text1, thinking2, text2]`, the merge collects _all_ previous thinking blocks and prepends them to the terminal content, discarding the intermediate `text1`/`text2` segments:
```ts
content: [...previousThinking, ...terminal.content]
// → [thinking1, thinking2, text_from_terminal]
```
In practice the terminal's text supersedes the streamed text, so the data loss is cosmetic. However, if the model produced genuinely distinct reasoning phases interleaved with partial answers, the final rendered message will collapse them into a single reasoning block followed by the terminal reply. A comment explaining this intended trade-off would help future readers.
How can I resolve this? If you propose a fix, please make it concise.|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Keep this PR open for maintainer review: current main still does not fully solve live reasoning streaming/rendering, but this branch is not merge-ready because it is dirty against main, lacks real behavior proof, and changes the reasoning visibility/security boundary. Canonical path: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review. So I’m closing this here because the remaining work is already tracked in the canonical issue. Review detailsBest possible solution: Close this stale PR. The latest review rated it F, the branch still lacks merge-ready proof, and there has been no human follow-up after the durable review. Do we have a high-confidence way to reproduce the issue? No high-confidence live reproduction is present in the PR. The risky paths are source-reproducible from the diff and current-main contracts, especially the no-callback and hidden-reasoning delivery boundaries. Is this the best way to solve the issue? No, not as submitted. The branch is a plausible broad implementation, but the best fix should first preserve the current visibility/capability boundary and then layer UI rendering on the settled event contract. Security review: Security review needs attention: The diff changes delivery of potentially sensitive reasoning content and needs explicit visibility/capability gates before merge.
AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 52bc2a12bc8c. |
|
ClawSweeper PR egg 🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat. Where did the egg go?
|
|
This pull request has been automatically marked as stale due to inactivity. |
|
ClawSweeper applied the proposed close for this PR.
|
Summary
Testing