You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Malformed multiline $$ math is not closed by trailing $$: the parser consumes the rest of the message into one .katex-error #1778
A common multiline formula shape renders as one giant red .katex-error that swallows the rest of the assistant message. Headings, lists, tables, and links after the formula lose all Markdown structure; thousands of characters can be consumed.
Observed on bb 0.38.0.
Reproduction
Render the following assistant message:
Before the formula.
$$T_{\text{appearance}\rightarrow\text{chunk}}
\approx73\text{--}146\text{ ms}$$## Content after the formula- This should remain a list item.
-[This should remain a link](https://example.com).
The opening $$ is on the first line, the closing $$ is appended to the end of the second line. remark-math treats the $$ at the start of the first line as an opening delimiter but does not recognize the trailing $$ as a closing delimiter, so math consumes through the end of the message.
Actual behavior
The whole remainder of the message — the trailing $$, the heading, the list, the link — becomes the content of a single math node. rehype-katex emits one .katex-error (typically Can't use function '$' in math mode) and the entire suffix renders as red raw text. In the observed case the error node contained ~3,000 characters through the end of the message.
Why it matters
bb renders messages from many sources — arbitrary providers, historical messages, imports. One malformed formula currently makes everything after it unreadable. A local delimiter error should be localized: the formula may break, but the rest of the message must keep rendering.
Suggested fixes
Support this multiline shape — normalize $$-bounded spans regardless of trailing-newline placement, or
Localize the error — keep the malformed math literal/broken but ensure subsequent Markdown is parsed normally.
Regression guard: an invalid or unclosed formula must not consume content beyond its own block. Existing inline $$x$$, display $$\n...\n$$, and the invalid-TeX test (which only asserts a .katex-error exists, not that it stays local) must keep passing.
Root cause (short): micromark-extension-math (via remark-math in MarkdownPreview) treats $$<tex> at line start as a display-math opening fence with the TeX as dropped meta, and only accepts a closing fence that is $$ alone on its own line, so a trailing …$$ never closes the block and it swallows the rest of the message into one .katex-error; bb does no normalisation.
Proposed fix: Add a pure pre-parse normaliser (normalizeMathFences) applied to the markdown body in MarkdownPreview (and apps/mobile/src/markdown/parse.ts) that, outside code fences, rewrites LaTeX-style display spans — $$<tex> opener with meta and/or a content line ending in $$ — into canonical $$\n…\n$$ fences before remark-math sees them; prototype patch in 1778/repro/prototype-fix.patch makes the repro test pass, keeps all 17 existing markdown-preview tests green, and typechecks. Add regression tests for shapes A/B/C. Alternative: a custom micromark construct replacing mathFlow that accepts a trai…
Caveats: Worktree HEAD was c4a3dc5 (origin/main, 3 mobile-only commits after base c7c6642); no math-pipeline files differ, so findings apply to the base. Live repro used one real codex echo turn plus one "ok" turn. New finding beyond the issue: the first formula line is dropped as meta, and shape $$x\n$$ renders an empty formula. Prototype fix is not production-ready (no blockquote/list prefix hand…
The report has copy-paste repro steps, screenshots where the bug is visual, code permalinks at the base commit, and repro artifacts. It was independently re-run by a second agent (see its Verification section).
Activity
SawyerHood commentedon Aug 20, 2026
Reproduction & root-cause report: https://get-bb.github.io/reports/issues/1778.html
$$<tex>at line start as a display-math opening fence with the TeX as droppedmeta, and only accepts a closing fence that is$$alone on its own line, so a trailing…$$never closes the block and it swallows the rest of the message into one .katex-error; bb does no normalisation.$$<tex>opener with meta and/or a content line ending in$$— into canonical$$\n…\n$$fences before remark-math sees them; prototype patch in 1778/repro/prototype-fix.patch makes the repro test pass, keeps all 17 existing markdown-preview tests green, and typechecks. Add regression tests for shapes A/B/C. Alternative: a custom micromark construct replacing mathFlow that accepts a trai…meta, and shape$$x\n$$renders an empty formula. Prototype fix is not production-ready (no blockquote/list prefix hand…The report has copy-paste repro steps, screenshots where the bug is visual, code permalinks at the base commit, and repro artifacts. It was independently re-run by a second agent (see its Verification section).
Close display math whose $$ delimiters are glued to the TeX (get-bb#2151