Repository navigation
perf(ui-react): parse a streaming answer block by block (#2588) - #4240
Conversation
Each animation frame gave the streaming text part a new string, and BrainMarkdownInner handed the whole of it to react-markdown: a full remark-gfm parse, highlight and React conversion of the part, every frame. The processed text is now split into top-level blocks, each parsed by a memoized block component with a stable index key, so a finished block is skipped while the answer grows; only the growing last block re-parses, and its re-parse is deferred behind input. Rendered HTML is unchanged: blocks rejoin with react-markdown's own newline, and the split is conservative (never inside a fence, before a list, blockquote, table or indented continuation, nor in a text holding a definition or a long HTML block). A projected range still parses whole. Two browser tests read a streamed fence right after a synchronous render; they now wait for the deferred render of the growing block. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No uploads on this PR yet This PR changes UI files (
Tips for agentsLabel each shot so reviewers know what they're seeing. Labels apply to every file in a call, so run one uploads put after.png --pr 4240 --meta path=/settings --state after --caption "Saved settings toast"
uploads put chat.png --pr 4240 --app ios --screen "Chat" --state afterNo CLI? With the Uploads MCP, call This comment updates with each upload, so you don't need to post the images yourself. A shot or two in the PR description is still welcome. Check what's attached with Workspace admins can turn this comment off in Settings → GitHub · docs |
Independent reviewReviewed head bbe6025 against base d84fca3. Reviewer: agent. 3 findings: 0 fixed, 0 filed, 0 rejected, 3 without a disposition. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4240,
"head": "bbe60253b8e7aad9dce7129e9e87e64c9aaf48cd",
"base": "d84fca3e08dfa7c5b65973f931ab08d740537d02",
"reviewer": "agent",
"outcome": "findings",
"findings": [
{
"summary": "packages/ui-react/src/components/chat/markdown-blocks.ts:23 — DEFINITION only matches definitions at column 0-3, so text still splits around definitions CommonMark resolves document-wide: in a blockquote ('> [l]: url', '> [^1]: note'), in a list item ('- [l]: url'), or with an escaped bracket ('[a\\\\]b]: url'). Whole parse renders the link or footnote; split renders '[the log][l]' and '[^1]' as literal text. The corpus has only column-0 definitions."
},
{
"summary": "packages/ui-react/src/components/chat/brain-markdown.tsx:183,213-216 — When a definition ('[^1]: …') or '<!--'/'<pre>' line streams in, the split collapses to [text]; block 0 becomes last and useDeferredValue returns its old text, so the urgent commit shows only the first block (three paragraphs citing [^1], then '\\n\\n[^1]: Source.' appended, paints 'First para.[^1]'). Blocks 1..n remount: a later Mermaid diagram loses its SVG state and a scrolled-up reader's position is clamped."
},
{
"summary": "packages/ui-react/tests/browser/renderer-dispatch.layout.tsx:45-46 (and code-fences-plain.layout.tsx:38-39) — The criterion says the existing renderer-dispatch tests pass unchanged. The PR edits them to poll, because the deferred tail no longer commits synchronously under flushSync. That is a behaviour change for any caller that reads the DOM straight after rendering new content, and the criterion is not met as written."
}
]
} |
…on collapse (#2588) - A link reference or footnote definition inside a blockquote or a list item, or with an escaped bracket in its label, resolves document-wide like any other; the splitter now finds those too and parses whole. - When a definition arrives mid-stream the text collapses to one block, so block 0 becomes the last. Its deferred value was block 0's old text, and the urgent commit painted that block alone. A block now defers only once it was already last, so it shows its current text on the render where it becomes last. Later blocks still remount once on that collapse, which a whole parse implies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Independent reviewReviewed head bbe6025 against base d84fca3. Reviewer: agent. 3 findings: 2 fixed, 0 filed, 1 rejected, 0 without a disposition. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4240,
"head": "bbe60253b8e7aad9dce7129e9e87e64c9aaf48cd",
"base": "d84fca3e08dfa7c5b65973f931ab08d740537d02",
"reviewer": "agent",
"outcome": "findings",
"findings": [
{
"summary": "packages/ui-react/src/components/chat/markdown-blocks.ts:23 — DEFINITION only matches definitions at column 0-3, so text still splits around definitions CommonMark resolves document-wide: in a blockquote ('> [l]: url', '> [^1]: note'), in a list item ('- [l]: url'), or with an escaped bracket ('[a\\\\]b]: url'). Whole parse renders the link or footnote; split renders '[the log][l]' and '[^1]' as literal text. The corpus has only column-0 definitions.",
"disposition": "fixed",
"commit": "af3773b4933cc370e7f0a4fca8280072ab2d6fb8"
},
{
"summary": "packages/ui-react/src/components/chat/brain-markdown.tsx:183,213-216 — When a definition ('[^1]: …') or '<!--'/'<pre>' line streams in, the split collapses to [text]; block 0 becomes last and useDeferredValue returns its old text, so the urgent commit shows only the first block (three paragraphs citing [^1], then '\\n\\n[^1]: Source.' appended, paints 'First para.[^1]'). Blocks 1..n remount: a later Mermaid diagram loses its SVG state and a scrolled-up reader's position is clamped.",
"disposition": "fixed",
"commit": "af3773b4933cc370e7f0a4fca8280072ab2d6fb8"
},
{
"summary": "packages/ui-react/tests/browser/renderer-dispatch.layout.tsx:45-46 (and code-fences-plain.layout.tsx:38-39) — The criterion says the existing renderer-dispatch tests pass unchanged. The PR edits them to poll, because the deferred tail no longer commits synchronously under flushSync. That is a behaviour change for any caller that reads the DOM straight after rendering new content, and the criterion is not met as written.",
"disposition": "rejected",
"reason": "The issue's own scope requires wrapping the last block in useDeferredValue, and a deferred update cannot commit synchronously inside flushSync, so the criterion's 'unchanged' cannot hold together with that scope item. Only the two synchronous reads were changed, to wait for the deferred render; every identity and content assertion is unchanged, and the finished-message equivalence tests show the rendered output is identical."
}
]
} |
Independent reviewReviewed head af3773b against base d84fca3. Reviewer: agent. 3 findings: 0 fixed, 0 filed, 0 rejected, 3 without a disposition. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4240,
"head": "af3773b4933cc370e7f0a4fca8280072ab2d6fb8",
"base": "d84fca3e08dfa7c5b65973f931ab08d740537d02",
"reviewer": "agent",
"outcome": "findings",
"findings": [
{
"summary": "packages/ui-react/src/components/chat/markdown-blocks.ts:29: DEFINITION excludes \\n from the label, so a reference definition whose label wraps across lines (`[long\\nlabel]: https://x.example/`) is missed and the text is split. Whole renders the link; split leaves `[the raft][long\\nlabel]` as literal text. The issue's pattern `^ {0,3}\\[[^\\]]+\\]:` matches across newlines, and no corpus fixture covers it."
},
{
"summary": "packages/ui-react/tests/browser/renderer-dispatch.layout.tsx:46 (and tests/browser/code-fences-plain.layout.tsx:39): the issue requires the existing renderer-dispatch tests to pass unchanged, but the PR rewrites a synchronous assertion into expect.poll because the deferred tail no longer shows the new text on the first commit. The criterion is missed by changing the test instead of the behaviour."
},
{
"summary": "packages/ui-react/src/components/chat/brain-markdown.tsx:218: the last block's useDeferredValue applies to every content change in every BrainMarkdown caller (file-viewer-markdown.tsx:11, ask-user-card.tsx:417, whatsup-modal.tsx:92, share-block.tsx:60, message-rich-text.tsx), not only streaming growth. Replacing content commits the new earlier blocks with the old document's last block (or all the old text if it is one block) for a render; before, it rendered synchronously."
}
]
} |
…els (#2588) - The last block's deferred text is used only when the new text extends it. Replaced content (another file, a new briefing, a renderer test swapping its content) renders at once again, as before, instead of committing the previous document's last block for a render. The renderer-dispatch layout test passes unchanged again; only a fence that genuinely grows (code-fences-plain) still waits for its deferred render. - A reference definition whose label wraps across lines resolves document-wide too; the splitter now finds it and parses whole. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Independent reviewReviewed head af3773b against base d84fca3. Reviewer: agent. 3 findings: 3 fixed, 0 filed, 0 rejected, 0 without a disposition. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4240,
"head": "af3773b4933cc370e7f0a4fca8280072ab2d6fb8",
"base": "d84fca3e08dfa7c5b65973f931ab08d740537d02",
"reviewer": "agent",
"outcome": "findings",
"findings": [
{
"summary": "packages/ui-react/src/components/chat/markdown-blocks.ts:29: DEFINITION excludes \\n from the label, so a reference definition whose label wraps across lines (`[long\\nlabel]: https://x.example/`) is missed and the text is split. Whole renders the link; split leaves `[the raft][long\\nlabel]` as literal text. The issue's pattern `^ {0,3}\\[[^\\]]+\\]:` matches across newlines, and no corpus fixture covers it.",
"disposition": "fixed",
"commit": "63229df1b8389d3e473e3591d0330ec91cfa13e3"
},
{
"summary": "packages/ui-react/tests/browser/renderer-dispatch.layout.tsx:46 (and tests/browser/code-fences-plain.layout.tsx:39): the issue requires the existing renderer-dispatch tests to pass unchanged, but the PR rewrites a synchronous assertion into expect.poll because the deferred tail no longer shows the new text on the first commit. The criterion is missed by changing the test instead of the behaviour.",
"disposition": "fixed",
"commit": "63229df1b8389d3e473e3591d0330ec91cfa13e3"
},
{
"summary": "packages/ui-react/src/components/chat/brain-markdown.tsx:218: the last block's useDeferredValue applies to every content change in every BrainMarkdown caller (file-viewer-markdown.tsx:11, ask-user-card.tsx:417, whatsup-modal.tsx:92, share-block.tsx:60, message-rich-text.tsx), not only streaming growth. Replacing content commits the new earlier blocks with the old document's last block (or all the old text if it is one block) for a render; before, it rendered synchronously.",
"disposition": "fixed",
"commit": "63229df1b8389d3e473e3591d0330ec91cfa13e3"
}
]
} |
String trim() also strips NBSP, U+3000, U+FEFF and \v, but CommonMark counts a line as blank only when it holds spaces and tabs alone, and lets a closing fence be followed by those alone. The splitter split inside a paragraph at a line of Unicode space and closed a fence whose closer was followed by one, so split and whole rendered differently. It also missed a definition label wrapped after a backslash. Each case is now in the equivalence corpus. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Independent reviewReviewed head 63229df against base d84fca3. Reviewer: agent. 3 findings: 0 fixed, 0 filed, 0 rejected, 3 without a disposition. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4240,
"head": "63229df1b8389d3e473e3591d0330ec91cfa13e3",
"base": "d84fca3e08dfa7c5b65973f931ab08d740537d02",
"reviewer": "agent",
"outcome": "findings",
"findings": [
{
"summary": "packages/ui-react/src/components/chat/markdown-blocks.ts:55 (and :60): String.prototype.trim() treats NBSP, U+3000, U+FEFF and \\v as whitespace, but CommonMark counts only space/tab lines as blank, so the splitter splits inside a paragraph. Whole 'Para\\n\\u00a0\\nmore' renders one <p>Para\\n\\u00a0\\nmore</p>; split renders <p>Para</p>\\n<p>more</p> (U+3000, U+FEFF, \\v reproduced too). Misses the identical-HTML criterion; no corpus fixture covers it."
},
{
"summary": "packages/ui-react/src/components/chat/markdown-blocks.ts:51: the closing-fence check uses .trim() on the rest of the line, so a closer followed by NBSP ('```\\u00a0') is taken as closing the fence. CommonMark allows only spaces or tabs after a closer, so the fence is still open. Whole parse of '```\\ncode\\n```\\u00a0\\n\\nmore' keeps 'more' inside the <pre><code>; split ends the code block and renders <p>more</p>. The split changes the rendered output."
},
{
"summary": "packages/ui-react/src/components/chat/markdown-blocks.ts:29: in DEFINITION's label pattern, `\\\\.` cannot match a backslash before a newline, so a definition whose label wraps after a backslash ('[a\\\\\\nb]: /u') is missed and the text is split. Whole parse renders <a href=\"/u\">a<br/>b</a>; split renders the literal '[a<br/>b]'. This is the same class of bug as the wrapped-label finding fixed in 63229df, but this variant is not covered."
}
]
} |
Independent reviewReviewed head 63229df against base d84fca3. Reviewer: agent. 3 findings: 3 fixed, 0 filed, 0 rejected, 0 without a disposition. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4240,
"head": "63229df1b8389d3e473e3591d0330ec91cfa13e3",
"base": "d84fca3e08dfa7c5b65973f931ab08d740537d02",
"reviewer": "agent",
"outcome": "findings",
"findings": [
{
"summary": "packages/ui-react/src/components/chat/markdown-blocks.ts:55 (and :60): String.prototype.trim() treats NBSP, U+3000, U+FEFF and \\v as whitespace, but CommonMark counts only space/tab lines as blank, so the splitter splits inside a paragraph. Whole 'Para\\n\\u00a0\\nmore' renders one <p>Para\\n\\u00a0\\nmore</p>; split renders <p>Para</p>\\n<p>more</p> (U+3000, U+FEFF, \\v reproduced too). Misses the identical-HTML criterion; no corpus fixture covers it.",
"disposition": "fixed",
"commit": "8b588033d1e4bf3705e1a586741186b34f339c6e"
},
{
"summary": "packages/ui-react/src/components/chat/markdown-blocks.ts:51: the closing-fence check uses .trim() on the rest of the line, so a closer followed by NBSP ('```\\u00a0') is taken as closing the fence. CommonMark allows only spaces or tabs after a closer, so the fence is still open. Whole parse of '```\\ncode\\n```\\u00a0\\n\\nmore' keeps 'more' inside the <pre><code>; split ends the code block and renders <p>more</p>. The split changes the rendered output.",
"disposition": "fixed",
"commit": "8b588033d1e4bf3705e1a586741186b34f339c6e"
},
{
"summary": "packages/ui-react/src/components/chat/markdown-blocks.ts:29: in DEFINITION's label pattern, `\\\\.` cannot match a backslash before a newline, so a definition whose label wraps after a backslash ('[a\\\\\\nb]: /u') is missed and the text is split. Whole parse renders <a href=\"/u\">a<br/>b</a>; split renders the literal '[a<br/>b]'. This is the same class of bug as the wrapped-label finding fixed in 63229df, but this variant is not covered.",
"disposition": "fixed",
"commit": "8b588033d1e4bf3705e1a586741186b34f339c6e"
}
]
} |
Independent reviewReviewed head 8b58803 against base d84fca3. Reviewer: agent. 2 findings: 0 fixed, 0 filed, 0 rejected, 2 without a disposition. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4240,
"head": "8b588033d1e4bf3705e1a586741186b34f339c6e",
"base": "d84fca3e08dfa7c5b65973f931ab08d740537d02",
"reviewer": "agent",
"outcome": "findings",
"findings": [
{
"summary": "packages/ui-react/src/components/chat/markdown-blocks.ts:51-55: a fence opened indented in a list item and closed at column 0 counts as closed, but CommonMark ends the item there and the column-0 line opens a new top-level fence, so the splitter splits inside it. For \"1. Install:\\n\\n ```bash\\n npm i\\n```\\n\\n2. Run it\\n\\nDone.\" whole puts \"Done.\" in <pre><code>, split gives <p>Done.</p>. Misses the identical-HTML and finished-message criteria; no corpus case covers it."
},
{
"summary": "packages/ui-react/src/components/chat/markdown-blocks.ts:31 (LONG_HTML): unlike DEFINITION, the HTML block types 1-5 guard is anchored at ^ {0,3}< and does not allow list-item or blockquote prefixes. A <pre> or <!-- block inside a list item is split: for \"- <pre>\\n\\n x\\n\\ny\" (or \"- <!--\\n\\n x\\n\\ny\") the whole parse keeps the blank-line text inside the <li> and the split drops it, so the HTML differs despite the file comment's claim that such texts are never split."
}
]
} |
…ainer (#2588) A fence opened inside a list item can be closed, or a new top-level one opened, at column 0 in ways only a full parse resolves; and a long HTML block after a list-item or blockquote prefix keeps its blank lines in the item. The splitter tracked fences up to three spaces in and checked HTML blocks at the top level only, so split and whole rendered differently. It now tracks only column-0 fences and parses whole any text holding an indented or contained fence, or a long HTML block behind a container prefix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Independent reviewReviewed head 8b58803 against base d84fca3. Reviewer: agent. 2 findings: 2 fixed, 0 filed, 0 rejected, 0 without a disposition. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4240,
"head": "8b588033d1e4bf3705e1a586741186b34f339c6e",
"base": "d84fca3e08dfa7c5b65973f931ab08d740537d02",
"reviewer": "agent",
"outcome": "findings",
"findings": [
{
"summary": "packages/ui-react/src/components/chat/markdown-blocks.ts:51-55: a fence opened indented in a list item and closed at column 0 counts as closed, but CommonMark ends the item there and the column-0 line opens a new top-level fence, so the splitter splits inside it. For \"1. Install:\\n\\n ```bash\\n npm i\\n```\\n\\n2. Run it\\n\\nDone.\" whole puts \"Done.\" in <pre><code>, split gives <p>Done.</p>. Misses the identical-HTML and finished-message criteria; no corpus case covers it.",
"disposition": "fixed",
"commit": "6148259f4b64a002ac2cc019c564fa3d6b1f0359"
},
{
"summary": "packages/ui-react/src/components/chat/markdown-blocks.ts:31 (LONG_HTML): unlike DEFINITION, the HTML block types 1-5 guard is anchored at ^ {0,3}< and does not allow list-item or blockquote prefixes. A <pre> or <!-- block inside a list item is split: for \"- <pre>\\n\\n x\\n\\ny\" (or \"- <!--\\n\\n x\\n\\ny\") the whole parse keeps the blank-line text inside the <li> and the split drops it, so the HTML differs despite the file comment's claim that such texts are never split.",
"disposition": "fixed",
"commit": "6148259f4b64a002ac2cc019c564fa3d6b1f0359"
}
]
} |
…#2588) A column-0 fence marker inside an HTML block of type 6 or 7 (<details>, <div>) is part of the HTML block, not a fence, until a blank line ends the block. The splitter took it as a fence, paired fences wrongly and split inside the real one. A fence marker in a run of lines that began with an HTML tag now makes the text parse whole. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Independent reviewReviewed head 6148259 against base d84fca3. Reviewer: agent. 2 findings: 0 fixed, 0 filed, 0 rejected, 2 without a disposition. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4240,
"head": "6148259f4b64a002ac2cc019c564fa3d6b1f0359",
"base": "d84fca3e08dfa7c5b65973f931ab08d740537d02",
"reviewer": "agent",
"outcome": "findings",
"findings": [
{
"summary": "packages/ui-react/src/components/chat/markdown-blocks.ts:57-79: a column-0 fence marker inside an HTML block (type 6/7, e.g. <details>) is taken as a fence opener, but CommonMark keeps that line in the HTML block, so fences pair wrongly and the text splits inside the real fence. Whole parse of '<details>\\n```js\\na\\n\\nb\\n```\\n</details>\\n\\nAfter.' puts 'After.' in <pre><code>; split gives <p>After.</p>. Misses the identical-HTML and finished-message criteria; no corpus case."
},
{
"summary": "packages/ui-react/src/components/chat/brain-markdown.tsx:183-188: when a definition, a '<pre'/'<!--' line or an indented fence arrives mid-stream (footnote definitions usually come last), the split collapses to [text] and StreamedBlock keys 1..n unmount, so a Mermaid diagram after block 0 remounts and loses its rendered SVG state, which the whole parse kept before. Misses the criterion that an earlier block's Mermaid keeps its state while later text streams; the PR calls it a limitation."
}
]
} |
Independent reviewReviewed head 6148259 against base d84fca3. Reviewer: agent. 2 findings: 1 fixed, 0 filed, 1 rejected, 0 without a disposition. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4240,
"head": "6148259f4b64a002ac2cc019c564fa3d6b1f0359",
"base": "d84fca3e08dfa7c5b65973f931ab08d740537d02",
"reviewer": "agent",
"outcome": "findings",
"findings": [
{
"summary": "packages/ui-react/src/components/chat/markdown-blocks.ts:57-79: a column-0 fence marker inside an HTML block (type 6/7, e.g. <details>) is taken as a fence opener, but CommonMark keeps that line in the HTML block, so fences pair wrongly and the text splits inside the real fence. Whole parse of '<details>\\n```js\\na\\n\\nb\\n```\\n</details>\\n\\nAfter.' puts 'After.' in <pre><code>; split gives <p>After.</p>. Misses the identical-HTML and finished-message criteria; no corpus case.",
"disposition": "fixed",
"commit": "2e48399f6a063d0a231a93e897814debecf17411"
},
{
"summary": "packages/ui-react/src/components/chat/brain-markdown.tsx:183-188: when a definition, a '<pre'/'<!--' line or an indented fence arrives mid-stream (footnote definitions usually come last), the split collapses to [text] and StreamedBlock keys 1..n unmount, so a Mermaid diagram after block 0 remounts and loses its rendered SVG state, which the whole parse kept before. Misses the criterion that an earlier block's Mermaid keeps its state while later text streams; the PR calls it a limitation.",
"disposition": "rejected",
"reason": "The rendered SVG is not lost: MermaidBlock initialises its svg state from the module-wide cache keyed by source (peekMermaidSvg, mermaid-block.tsx:20-31), so the remounted diagram paints its rendered SVG on its first render. Only transient UI state (source toggle, zoom) resets, once, at the collapse. A collapse is required for correctness (the text must parse whole once a definition exists), and the PR states it."
}
]
} |
…es in blocks (#2588) A generated-document test (fixed seeds, lines drawn from every construct the split must respect) found two more ways split and whole differed: - an HTML-looking line continuing a list item ends differently when the block stands alone; any line that starts with HTML (after container prefixes) now makes the text parse whole, which subsumes the long-HTML and HTML-run guards; - dropping the blank lines between blocks changed how a tab-indented code block ended. The blank lines now stay with the block before, exactly as the whole text has them. The generated test stays in the suite: 15,000 documents, over a thousand of which split, each parsed split and whole. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CommonMark ends a line at a bare \r as well as \n, while the splitter reads lines at \n alone, so a fence opened after a carriage return went unseen and the text split inside it. A text holding a carriage return now parses whole. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Independent reviewReviewed head b4696f9 against base d84fca3. Reviewer: agent. 1 finding: 0 fixed, 0 filed, 0 rejected, 1 without a disposition. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4240,
"head": "b4696f951e9a3d356dd499d992e8046dd7f9634e",
"base": "d84fca3e08dfa7c5b65973f931ab08d740537d02",
"reviewer": "agent",
"outcome": "findings",
"findings": [
{
"summary": "packages/ui-react/src/components/chat/markdown-blocks.ts:51: fences are tracked on lines split at \"\\n\" only, but CommonMark also ends a line at a bare \"\\r\", so a fence opened after a CR is missed and the text splits inside it. Repro: \"Para\\r```\\ncode\\n\\nmore code\\n```\\n\\nAfter.\" splits after \"code\". The split HTML ends the code block there and opens a stray fence; the whole parse keeps one block. Fix: normalise CRs or never split a text holding \"\\r\"."
}
]
} |
Independent reviewReviewed head b4696f9 against base d84fca3. Reviewer: agent. 1 finding: 1 fixed, 0 filed, 0 rejected, 0 without a disposition. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4240,
"head": "b4696f951e9a3d356dd499d992e8046dd7f9634e",
"base": "d84fca3e08dfa7c5b65973f931ab08d740537d02",
"reviewer": "agent",
"outcome": "findings",
"findings": [
{
"summary": "packages/ui-react/src/components/chat/markdown-blocks.ts:51: fences are tracked on lines split at \"\\n\" only, but CommonMark also ends a line at a bare \"\\r\", so a fence opened after a CR is missed and the text splits inside it. Repro: \"Para\\r```\\ncode\\n\\nmore code\\n```\\n\\nAfter.\" splits after \"code\". The split HTML ends the code block there and opens a stray fence; the whole parse keeps one block. Fix: normalise CRs or never split a text holding \"\\r\".",
"disposition": "fixed",
"commit": "bcc54acbd0bc6581a16a6722abfc0d3eeaa7ca80"
}
]
} |
Independent reviewReviewed head bcc54ac against base d84fca3. Reviewer: agent. 2 findings: 0 fixed, 0 filed, 0 rejected, 2 without a disposition. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4240,
"head": "bcc54acbd0bc6581a16a6722abfc0d3eeaa7ca80",
"base": "d84fca3e08dfa7c5b65973f931ab08d740537d02",
"reviewer": "agent",
"outcome": "findings",
"findings": [
{
"summary": "packages/ui-react/src/components/chat/brain-markdown.tsx:219-220 (StreamedBlock): the last block re-parses only in a deferred render, and each new delta interrupts and restarts it (React 19.3 transition lanes expire after 5 s). If the tail's parse outlasts the gap between deltas (a long highlighted fence, a phone, a 24 KB text left whole, ~40 ms on desktop), the tail freezes for up to 5 s or until the stream pauses; before, it updated every frame. Tests flush with act; none covers it."
},
{
"summary": "packages/ui-react/src/components/chat/brain-markdown.tsx:183-188: when a definition, HTML line or indented fence arrives mid-stream (closing footnotes, a line-start '<https://…>' autolink), the split collapses to [text]; StreamedBlock keys 1..n unmount and remount under block 0. A later block's Mermaid diagram loses its open zoom viewer and source toggle (mermaid-block.tsx:28-35) and later DOM nodes are replaced; the whole parse kept them, as an appended definition shifts no earlier key."
}
]
} |
…#2588) - React restarts a deferred render on every new delta, so a tail whose parse outlasts the gap between deltas (a long highlighted fence, a slow device, a text left whole) could stop updating until the stream paused. Past MAX_TAIL_LAG_MS (200 ms) of lag, the current tail now renders urgently (tailText), and the lag starts again from there. - A line-start autolink (<https://...>) no longer counts as an HTML line, so it no longer makes the text parse whole; only a tag name, a comment, a declaration or a processing instruction does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Independent reviewReviewed head bcc54ac against base d84fca3. Reviewer: agent. 2 findings: 1 fixed, 0 filed, 1 rejected, 0 without a disposition. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4240,
"head": "bcc54acbd0bc6581a16a6722abfc0d3eeaa7ca80",
"base": "d84fca3e08dfa7c5b65973f931ab08d740537d02",
"reviewer": "agent",
"outcome": "findings",
"findings": [
{
"summary": "packages/ui-react/src/components/chat/brain-markdown.tsx:219-220 (StreamedBlock): the last block re-parses only in a deferred render, and each new delta interrupts and restarts it (React 19.3 transition lanes expire after 5 s). If the tail's parse outlasts the gap between deltas (a long highlighted fence, a phone, a 24 KB text left whole, ~40 ms on desktop), the tail freezes for up to 5 s or until the stream pauses; before, it updated every frame. Tests flush with act; none covers it.",
"disposition": "fixed",
"commit": "8336e0238056e498098a21c0ce24769819facc6c"
},
{
"summary": "packages/ui-react/src/components/chat/brain-markdown.tsx:183-188: when a definition, HTML line or indented fence arrives mid-stream (closing footnotes, a line-start '<https://…>' autolink), the split collapses to [text]; StreamedBlock keys 1..n unmount and remount under block 0. A later block's Mermaid diagram loses its open zoom viewer and source toggle (mermaid-block.tsx:28-35) and later DOM nodes are replaced; the whole parse kept them, as an appended definition shifts no earlier key.",
"disposition": "rejected",
"reason": "The collapse is required for correctness: once a definition exists the text must parse whole, so the earlier blocks' elements cannot be kept. It happens at most once per message. The rendered SVG survives it (MermaidBlock initialises from its module-wide cache, mermaid-block.tsx:20-31); only transient UI state resets. The autolink trigger the finding names is removed in this commit: an autolink no longer counts as an HTML line."
}
]
} |
Independent reviewReviewed head 8336e02 against base d84fca3. Reviewer: agent. 2 findings: 0 fixed, 0 filed, 0 rejected, 2 without a disposition. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4240,
"head": "8336e0238056e498098a21c0ce24769819facc6c",
"base": "d84fca3e08dfa7c5b65973f931ab08d740537d02",
"reviewer": "agent",
"outcome": "findings",
"findings": [
{
"summary": "packages/ui-react/src/components/chat/brain-markdown.tsx:221-224: the 200 ms tail-lag bound does not hold. StreamedBlock writes lagSince.current during render, and React keeps ref writes from discarded renders. Each background deferred render sets lagSince to null (deferred===text); when a delta interrupts it, the next urgent render restarts the lag from now. Under fast deltas with a slow parse the tail never updates until the stream pauses. The pure tailText tests cannot catch this."
},
{
"summary": "packages/ui-react/tests/markdown-blocks.test.tsx:67: the corpus fixture meant to cover entity tags uses <person> and <place>. Those are not entity tags (renderEntityTags only converts co|p|proj|ev|d|st|f), so its catch-all strip deletes both before parsing and no entity marker is ever rendered or compared. The issue's first criterion requires entity tags in the split-vs-whole corpus, and this fixture leaves it unproven."
}
]
} |
) The lag start was a ref written during render, and React keeps ref writes from renders it discards: each background deferred render reset it, so under fast deltas the bound restarted and never fired. The tail now records when a commit last showed its current text, in an effect, and tailText compares now against that; a discarded render cannot move it. The entity-tag corpus fixture now uses real entity tags (<p>, <co>, <proj>, <d>) and asserts they render as entities. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Independent reviewReviewed head c4ee76a against base d84fca3. Reviewer: agent. 2 findings: 0 fixed, 0 filed, 0 rejected, 2 without a disposition. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4240,
"head": "c4ee76a90c9958e6af267b03523a58b672e66855",
"base": "d84fca3e08dfa7c5b65973f931ab08d740537d02",
"reviewer": "agent",
"outcome": "findings",
"findings": [
{
"summary": "packages/ui-react/src/components/chat/brain-markdown.tsx:221-230 (tailText, markdown-blocks.ts:106-109): after the 200 ms bound forces an urgent render of the current text, useDeferredValue still holds the old value D0, since its background render keeps being interrupted, and that commit clears behindSince. The next delta gets D0 back from tailText, so the tail goes back from text_n to old text for 200 ms, then forward. Before, it only grew. No test covers it."
},
{
"summary": "packages/ui-react/tests/render/streaming-markdown.test.tsx:58: the issue requires the 24 KB render-count test to fail on the tree before the change. On that tree it fails on the precondition `blocks > 100`, because a whole parse is one parse per render. It never reaches the 'only the grown tail block re-parses' assertion, so its failing-first receipt is not for the reason claimed (AGENTS.md testing rules). The PR admits this and relies on a memo mutation instead."
}
]
} |
Independent reviewReviewed head c4ee76a against base d84fca3. Reviewer: agent. 2 findings: 2 fixed, 0 filed, 0 rejected, 0 without a disposition. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4240,
"head": "c4ee76a90c9958e6af267b03523a58b672e66855",
"base": "d84fca3e08dfa7c5b65973f931ab08d740537d02",
"reviewer": "agent",
"outcome": "findings",
"findings": [
{
"summary": "packages/ui-react/src/components/chat/brain-markdown.tsx:221-230 (tailText, markdown-blocks.ts:106-109): after the 200 ms bound forces an urgent render of the current text, useDeferredValue still holds the old value D0, since its background render keeps being interrupted, and that commit clears behindSince. The next delta gets D0 back from tailText, so the tail goes back from text_n to old text for 200 ms, then forward. Before, it only grew. No test covers it.",
"disposition": "fixed",
"commit": "c2268a6338bd2cef5dcd97b6c3f5bdcf542de1bf"
},
{
"summary": "packages/ui-react/tests/render/streaming-markdown.test.tsx:58: the issue requires the 24 KB render-count test to fail on the tree before the change. On that tree it fails on the precondition `blocks > 100`, because a whole parse is one parse per render. It never reaches the 'only the grown tail block re-parses' assertion, so its failing-first receipt is not for the reason claimed (AGENTS.md testing rules). The PR admits this and relies on a memo mutation instead.",
"disposition": "fixed",
"commit": "c2268a6338bd2cef5dcd97b6c3f5bdcf542de1bf"
}
]
} |
A line-start '<h' or '<co' at the very end of a streaming text matched HTML_LINE through its end-of-text lookahead, so the split collapsed to the whole text and split again on the next delta, remounting every earlier block. A tag name now counts only once whitespace, '/' or '>' follows it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Independent reviewReviewed head c2268a6 against base d84fca3. Reviewer: agent. 1 finding: 0 fixed, 0 filed, 0 rejected, 1 without a disposition. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4240,
"head": "c2268a6338bd2cef5dcd97b6c3f5bdcf542de1bf",
"base": "d84fca3e08dfa7c5b65973f931ab08d740537d02",
"reviewer": "agent",
"outcome": "findings",
"findings": [
{
"summary": "packages/ui-react/src/components/chat/markdown-blocks.ts:42 (with brain-markdown.tsx:183): HTML_LINE's lookahead `(?=[\\s/>]|$)` lets `$` match a partial tag name at the end of a streaming text. While a line-start autolink or tag streams in ('<h'..'<https', '<co'), the split collapses to [text] and then splits again. StreamedBlock keys 1..n unmount and remount, an earlier block's Mermaid loses its zoom and source state, and the whole text parses. No test covers it."
}
]
} |
Independent reviewReviewed head c2268a6 against base d84fca3. Reviewer: agent. 1 finding: 1 fixed, 0 filed, 0 rejected, 0 without a disposition. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4240,
"head": "c2268a6338bd2cef5dcd97b6c3f5bdcf542de1bf",
"base": "d84fca3e08dfa7c5b65973f931ab08d740537d02",
"reviewer": "agent",
"outcome": "findings",
"findings": [
{
"summary": "packages/ui-react/src/components/chat/markdown-blocks.ts:42 (with brain-markdown.tsx:183): HTML_LINE's lookahead `(?=[\\s/>]|$)` lets `$` match a partial tag name at the end of a streaming text. While a line-start autolink or tag streams in ('<h'..'<https', '<co'), the split collapses to [text] and then splits again. StreamedBlock keys 1..n unmount and remount, an earlier block's Mermaid loses its zoom and source state, and the whole text parses. No test covers it.",
"disposition": "fixed",
"commit": "c8b5ac626b90288275e2a8deb5a95ab52aa4944f"
}
]
} |
Independent reviewReviewed head c8b5ac6 against base d84fca3. Reviewer: agent. 1 finding: 0 fixed, 0 filed, 0 rejected, 1 without a disposition. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4240,
"head": "c8b5ac626b90288275e2a8deb5a95ab52aa4944f",
"base": "d84fca3e08dfa7c5b65973f931ab08d740537d02",
"reviewer": "agent",
"outcome": "findings",
"findings": [
{
"summary": "packages/ui-react/src/components/chat/markdown-blocks.ts:54: CONTINUES matches an ordered-list marker at end of line through `$`, so a paragraph starting with a number flips the split back and forth. Verified with a Mermaid fence plus a blank line: `3` gives 2 blocks, `3.` gives 1, `3.14` gives 2. The earlier block re-parses twice at urgent priority and block 1 remounts. This is the defect class c8b5ac6 fixed for `<h`, and it hits versions and decimals (`2.0`)."
}
]
} |
…list
Every list marker kept the split from starting a new block, so a
paragraph being typed that starts with a number ('3', '3.', '3.14')
split, collapsed and split again as it grew. A list item now continues
the block above only when that block holds a list item (it would join
the list and make it loose) or ends in an indented line (micromark then
reads an empty item or '10. ten' as a paragraph).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Independent reviewReviewed head c8b5ac6 against base d84fca3. Reviewer: agent. 1 finding: 1 fixed, 0 filed, 0 rejected, 0 without a disposition. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4240,
"head": "c8b5ac626b90288275e2a8deb5a95ab52aa4944f",
"base": "d84fca3e08dfa7c5b65973f931ab08d740537d02",
"reviewer": "agent",
"outcome": "findings",
"findings": [
{
"summary": "packages/ui-react/src/components/chat/markdown-blocks.ts:54: CONTINUES matches an ordered-list marker at end of line through `$`, so a paragraph starting with a number flips the split back and forth. Verified with a Mermaid fence plus a blank line: `3` gives 2 blocks, `3.` gives 1, `3.14` gives 2. The earlier block re-parses twice at urgent priority and block 1 remounts. This is the defect class c8b5ac6 fixed for `<h`, and it hits versions and decimals (`2.0`).",
"disposition": "fixed",
"commit": "9a58d817f014a8e7531df2c0c922609df76c0f34"
}
]
} |
Independent reviewReviewed head 9a58d81 against base d84fca3. Reviewer: agent. No findings. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4240,
"head": "9a58d817f014a8e7531df2c0c922609df76c0f34",
"base": "d84fca3e08dfa7c5b65973f931ab08d740537d02",
"reviewer": "agent",
"outcome": "no-findings",
"findings": []
} |
|
Candidate run 44198693229 at 5905bf3 failed |
|
Candidate run 44207608156 at 3e08638 failed |
…4250) (#4251) #4240 re-parses the growing last markdown block at deferred priority, so the delta appended inside flushSync shows on the next commit. The frame-refusals visual case read the reply straight after it; it now polls for the appended text. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Closes #2588.
What this does
Each animation frame gives a streaming text part a new string.
BrainMarkdownInnerhanded the whole of it to react-markdown on every one of those frames: a full remark-gfm parse, rehype-highlight once it has loaded, and a React conversion of the entire part.splitMarkdownBlocks(packages/ui-react/src/components/chat/markdown-blocks.ts) splits the entity-processed text into top-level blocks.BrainMarkdownInnerrenders each through a memoizedMarkdownBlockkeyed by index. A finished block keeps its text, somemoskips it, and only the growing last block re-parses.StreamedBlock, which defers its text withuseDeferredValueonly while it grows as the last block: the deferred text is used only when the new text extends it. A block that has just become the last, and content that is replaced rather than extended (another file, a new briefing), show their current text at once, as before. React restarts a deferred render on every new delta, so a deferred tail renders its current text urgently once it has been behind its text for more thanMAX_TAIL_LAG_MS(200 ms) (tailText, unit-tested). The moment it fell behind is recorded in an effect, from committed renders only, and cleared once a commit shows it caught up. A render React discards cannot move it, a pause in the stream does not count as lag, and a slow parse under fast deltas still updates at least every 200 ms. The tail never shows less than its last commit did: after a forced render, the older deferred value is not shown again. Input and scrolling outrank re-parsing the tail. When a new block starts below, no element type changes, so nothing remounts.StreamedBlockdraws that newline between blocks, so the joined output equals the whole parse.>,|or indented. A list item (-,*,+,1.,1)) does not split when the block above holds one (it would join that list and make it loose) or ends in an indented line (micromark then reads an empty item or10. tenas a paragraph). Elsewhere it splits, so a paragraph being typed that starts with a number (3,3.,3.14) does not split, collapse and split again. The text is never split when it holds a link reference or footnote definition, including one inside a blockquote or a list item, with an escaped bracket in its label or with a label that wraps across lines, or any line that starts with HTML (a finished tag name, followed by whitespace,/or>, so a tag or an autolink still being typed at the end of the text is not one; a comment, processing instruction, declaration or CDATA; an autolink like<https://…>is not HTML), at the top level or after a list-item or blockquote prefix: an HTML block can hold blank lines and fence markers, and how it ends depends on what follows. Only column-0 fences are tracked, and a text holding a fence that is indented or inside a list item or blockquote is never split: a full parse alone knows how a column-0 line closes or reopens it. A text holding a carriage return is never split either: CommonMark ends a line there too, and the scan reads lines at\nalone.MarkdownRangeContext, the transcript window) maps offsets into the whole text, so it still parses whole. Ordinary streaming passes no range and is split.holdOpenLink, the share-block cut and the classified-block cuts still run on the full text before the split. They sit upstream inMarkdownContentandBrainMarkdown.Limitations, as the issue scopes them:
MermaidBlockinitialises from its module-wide SVG cache keyed by source (mermaid-block.tsx:20-31); only its transient source toggle and zoom reset.Behaviour change for tests: the growing block's re-parse is deferred, so a test that extends the text with
flushSyncand reads it straight away sees the previous text for one render.code-fences-plain.layout.tsxstreams a growing fence that way; it now polls for the deferred render, and its identity assertions are unchanged.renderer-dispatch.layout.tsxreplaces its content rather than extending it, so it passes unchanged.Acceptance criteria
renderToStaticMarkup) for the corpustests/markdown-blocks.test.tsx"split and whole render the same HTML". The corpus covers reference links and footnotes; loose and tight lists, including an ordered list from 3; backtick and tilde fences with blank lines and an unclosed fence; blockquotes, GFM tables, setext headings and an HTML block; entity tags; share blocks; inline links, code and emphasis. Each fixture also asserts whether it splits, so a match can't come from both sides being whole. The whole render is the same component with the splitter mocked to never split Also "generated documents parse the same split and whole": 15,000 documents from three fixed seeds, built from lines of every construct the split must respect (lists, quotes, fences top-level and nested, HTML, tables, definitions, setext lines, tab and Unicode blanks, images, hard breaks). More than 1,000 of them split, and each is parsed split and whole. React's static renderer hoists an image preload link to the start of its segment, and a DOM render has none, so that one tag is stripped before comparing. This test found the last two cases fixed here.tests/render/streaming-markdown.test.tsxwraps react-markdown to record every parse. For each of three appends to a 25 KB answer, every parse is the grown tail (at most two: deferred, then current)prose-links,scratch-links-render,expired-scratch-linksandrenderer-dispatchpass unchanged;renderer-dispatch.layout.tsxhas no diff in this PRProof
brain-markdown.tsxon their own assertions. The 24 KB test fails on "only the grown tail block re-parses: 24948" (the whole text re-parsed), since its precondition now asks the splitter, not the renderer. The Mermaid test fails on "the diagram's block is not parsed again".memoonMarkdownBlock: fails both render-count tests ("at most the tail's two parses").blocks.length - i, which shifts keys when a block is added: fails "the diagram's block is not parsed again".trim()-blank lines as blank, and allow a newline-free label only: fails the Unicode-space paragraph, the Unicode-space fence closer and the backslash-wrapped label cases.bun run test packages/ui-react: 2704 pass, 7 fail. The 7 areapi-client-sync.test.ts's "published sync helper" cases, which fail the same on an unmodified checkout on this host.ui-react-layout):renderer-dispatch6/6,code-fences4/4,code-fences-plain1/1,expired-scratch-links4/4, anddiagrams-renderer16/16 (indiagrams-chromium).ui-react-layoutproject on this host, compared with an unmodified checkout:discovery-expansion(12) andbrand-placements(8) fail on both.discovery-bands(4) andhygiene-loop(2) fail on both when run on their own. Main's one full run happened to pass them.mermaid-content-rendererfailed in a full run with Chromium's "Unable to capture screenshot" protocol error.transcript-qualifiersfailed once, in a dialog it opened, not in streamed text. Both pass when run alone with this change.check:prpass.Collisions
bun scripts/collisions.ts --json --pr 4240at head 7182edb: closure reports with #3054, #3056, #3059, #3069, #3581, #3622, #4151, #4198, #4234, #4238.{"version":1,"kind":"brain-check-pr-receipt","head":"3e08638bd85d091be6f7484f7c0fdac9c3f9fe3f","base":"origin/main","mode":"focused","startedAt":"2026-11-18T00:22:30.002Z","finishedAt":"2026-11-18T00:23:10.113Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":13555.968267},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":107.84190200000012},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":69.87111100000038},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":18.659303999997064},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":26341.276041999998}]}🤖 Generated with Claude Code