Skip to content

fix(dashboard): render LaTeX-native math delimiters via KaTeX - #7806

Merged
bolichen97 merged 1 commit into
kirodotdev:mainfrom
jeeshofone:fix/7803-latex-delimiters
Sep 17, 2026
Merged

bolichen97 merged 1 commit into
kirodotdev:mainfrom
jeeshofone:fix/7803-latex-delimiters

Conversation

@jeeshofone

@jeeshofone jeeshofone commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Assistant responses containing valid LaTeX display math (\[ ... \]) or inline math (\( ... \)) render as raw source text in the dashboard chat instead of formatted equations (#7803).

Why it matters

These are the delimiters LaTeX itself uses, and exactly what models tend to emit. Any technical or mathematical conversation degrades to unreadable markup, even though the dashboard already ships a full KaTeX pipeline.

What changed (motivation → approach → change)

Symptom: valid math shows as raw text. Root cause: the markdown pipeline runs remark-math with singleDollarTextMath: false — a deliberate guard so currency strings ($9.99 … $19.95) don't get parsed as one giant math span — which leaves $$…$$ as the only recognized math form. remark-math never tokenizes \[…\]/\(…\), so they fall through as text. KaTeX itself (rehype-katex + stylesheet) is fully wired; the gap is purely delimiter recognition.

Change: a remark transform, remarkLatexDelimiters (website/src/utils/remarkLatexDelimiters.ts), registered in REMARK_PLUGINS right after remark-math. It emits remark-math's own mdast nodes (inlineMath / math, identical data.hName/hProperties/hChildren) from eligible text nodes only, so rehype-katex renders them exactly like $$ math. Because remark has already consumed CommonMark escapes when it builds a text node, the transform reads the node's RAW source slice through its position (so \[ is still visible) and re-applies escape + character-reference decoding to the prose it hands back. Display math found inside a paragraph splits the paragraph so the math block is valid flow content.

What is protected, and why it is structural rather than enumerated: code, inlineCode, html, link, linkReference, image, imageReference, definition, footnotes and frontmatter are other node types and are never visited. So fenced code (including inside blockquotes), indented code, inline code spans, link destinations, reference-link definitions and raw HTML attributes are untouched by construction — not by a scanner that has to recognise each one in source. Eligibility rules, each with a regression test:

  • The delimiter backslash must be unescaped (\\( is an escaped backslash followed by a plain paren; \\\( is an escaped backslash then a real opener).
  • Inline \( … \) needs its closer in the same text node. Accepted residual: inline has no line-shape guard, so a producer that escapes parens in prose (the ADF/Jira class the display rule is hardened against) now renders \(x\) as KaTeX where it used to show (x); the display rule's line-shape test has no inline analogue because inline math legitimately sits mid-sentence, and the escape-parity rule still keeps \\(x\\) literal.
  • Display \[ … \] needs whitespace-shaped delimiters that own their line ends within the node (\[ x \], \[\n…\n\]); a hugging escaped bracket (\[a\], \[REDACTED: …\], see \[ x \] here — the Jira/ADF converter's shapes) stays a literal escape.
  • A closer immediately followed by ( is link/image syntax and never converts.
  • Single forward pass (openers remembered, paired when the closer arrives), so pathological unmatched-opener or ]( junk input stays linear. The timing guards assert ratios of medians over three interleaved samples per shape (a medianRatio helper in the test file), never a single performance.now() pair, so a GC pause or a shared runner's noise cannot fail them; the 900 KB flood test's timeout is raised to cover six renders.

This is the shape arbitrated in round 6: review rounds 1–6 each surfaced one more non-prose context a source scanner had to enumerate (ADF brackets, link destinations, definitions, escape parity, indented code, and finally raw HTML attributes), a list that can never be shown complete by inspection. The plugin costs no extra parse — it runs inside the parse the renderer already performs — and follows the file's existing "read it off remark's own parse" pattern (AUTOLINK_PARSER, remarkAutolinkRules).

Also in this change, because the plugin exposed it: the renderer's verbatim-unknown-tags pass and the plugin's verbatim context now share one tag grammar (website/src/utils/htmlTagGrammar.ts — the quote-aware single-tag regex, singleTagName, isOpeningTag, and a single-pass pairedCloseIndices), replacing two private copies that had already diverged on a quoted > inside an attribute. The shared pairing is one linear pass with a stack per tag name; the per-opener suffix scan it replaces was quadratic on unclosed openers in both consumers (measured 8.0 s for 6000 unclosed <customblock> before one math delimiter; ~0.3 s now, guarded by a timing test). The plugin's verbatimTag predicate is required — the renderer supplies the same predicate its own pass uses, so there is no second list of verbatim tags.

Alternatives considered: enabling singleDollarTextMath (reintroduces the currency-crash class the guard exists for); a standalone pre-parse mask (measured: the parse itself is super-linear on this PR's own ]( junk input, ~6.9s at 100kB — acceptable inside the render parse that already pays it, not as an additional pass).

Tests

Twenty render-level cases in MarkdownRenderer.test.tsx (144/144 in the file; 547/547 across the 35 renderer test files): display and inline math render through KaTeX (.katex-display / .katex); literal \[ survives inside fenced code, blockquoted fenced code, indented code and inline code; unmatched openers are left alone; ADF/Jira hugging and mid-sentence escaped brackets stay literal; whitespace-padded display converts; link destinations and reference-link definitions keep their escaped parens; escape parity (\\( literal, \\\( converts); the two linear-time guards against pathological unmatched-opener and ]( junk input; a raw HTML href with escaped parens survives intact while prose math beside it converts (the round-7 finding — fails on the scanner head); a paragraph is split around display math with no <pre> under a <p>; character references in prose next to converted math decode correctly.

Note: the new describe block is appended at the end of the test file — inserting it mid-file surfaced a pre-existing order-sensitivity in a neighboring test (reproducible at base with only test insertion, no source change); left for a separate report rather than folded into this fix.

Manual verification

N/A — unit coverage exercises the full render path (ReactMarkdown → remark-math → rehype-katex) through the real component in jsdom, including the exact payload from the issue.

Screenshots / video

Same markdown through the renderer on main and on this branch (Storybook story rendering the real MarkdownRenderer; the escaped-literal cases -- Jira key in a code span, **bold** \[ x \] mid-sentence, \[escape\] in code -- render identically in both, which is the point).

Before (main): raw \[ \sum_{i=1}^{n} ... \] and \(e^{i\pi} + 1 = 0\) shown as source text.

before: raw LaTeX delimiters shown as source text

After (this PR): inline and display KaTeX; the display block owns its line; blockquote math renders.

after: inline and display math rendered via KaTeX

Related Issues

Fixes #7803

Pattern harvest

Rule candidate: review-prompt
Pattern: "renderer feature enabled for only one delimiter dialect — check what producers actually emit (LLMs emit LaTeX-native \[ \]/\( \), not $$) before concluding a rendering feature works"

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

@jeeshofone
jeeshofone requested review from a team and pepmach September 2, 2026 05:33
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 2, 2026
@jeeshofone
jeeshofone force-pushed the fix/7803-latex-delimiters branch from 02225e0 to 3c7ee2a Compare September 2, 2026 05:56
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 2, 2026
@github-actions

github-actions Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Fable 5, fork) — ✅ PASS

UX-level review of fe8ae99eef61789093b7c042ddc4d9fc0629405e via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

UX-Verdict: PASS

Verify the PR's stated residual with real connector content: Jira/ADF-escaped \(x\) in prose now renders as inline math instead of literal (x).

[UX-REVIEWED] fe8ae99

@github-actions

github-actions Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — ✅ PASS

Design-level review of fe8ae99eef61789093b7c042ddc4d9fc0629405e via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Verify the timing-guard tests' wall-clock on CI — six 900 KB renders under one 5-minute timeout is a permanent cost every frontend run now pays.

Suggestions

  • Move the megabyte-scale linearity guards (the 150k \[ \] flood, the ampersand flood) into a separately-tagged perf suite so the default renderer test file stays fast; the small pathological cases already pin correctness.

[DESIGN-REVIEWED] fe8ae99

@github-actions

github-actions Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — 🟡 CONCERNS

Premise-level review of fe8ae99eef61789093b7c042ddc4d9fc0629405e via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

VERBATIM_CONTENT_TAGS is a second verbatim-tag list the description says doesn't exist — undeclared, and two of its nine entries are dead.

Not justified as shipped

  • Item 7 — undeclared: the description says "the renderer supplies the same predicate its own pass uses, so there is no second list of verbatim tags", but the diff ships a new nine-tag list (VERBATIM_CONTENT_TAGS) OR-ed into a predicate that differs from the pass's own (!ALLOWED_TAGS.has(tag) && divertibleTag(tag)) — a tag-policy list that can now diverge from the renderer's, the exact failure the shared grammar module was built to prevent at the syntax level.
    Subtraction: delete 'tt' and 'textarea' from VERBATIM_CONTENT_TAGS — I read ALLOWED_TAGS (MarkdownRenderer.tsx:2248-2277): neither is in it, so the !ALLOWED_TAGS.has(tag) half already makes them verbatim; 2 of 9 entries are dead, leaving the 7 tags the allowlist actually renders live.
    Clears when: the two dead entries are deleted, shrinking the list to exactly the allowlisted-verbatim-content overlap the shared half cannot cover.

What this change ships

Inventory (9 items) — 7 justified

Intent: make LaTeX-native \[…\]/\(…\) math render as KaTeX in dashboard chat (fixes #7803) — a FIX.

  1. \[…\] display math renders as a KaTeX block — justified
  2. \(…\) inline math renders as inline KaTeX — justified
  3. A paragraph is split so display math stands as its own block — justified
  4. Escaped \(x\) mid-sentence prose now renders as math instead of literal (x) — justified
  5. Chat with thousands of unclosed unknown tags renders ~25x faster (measured 8.0s→0.3s) — rides along
  6. Tag recognition/pairing moved to shared htmlTagGrammar.ts — justified (counted: singleTagName and pairedCloseIndices each have 2 consumers, renderer + plugin)
  7. New VERBATIM_CONTENT_TAGS list deciding where math never converts — undeclared, and 2 of 9 entries dead
  8. Prose entities beside converted math decode through a new in-repo table — justified (grepped: no in-repo decoder exists; decode-named-character-reference is lock-file-transitive only)
  9. Math never converts inside code, links, definitions, raw HTML, or verbatim containers — justified

[FIRST-PRINCIPLES-REVIEWED] fe8ae99

@github-actions

github-actions Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — ✅ no blocking findings

Reviewed fe8ae99eef61789093b7c042ddc4d9fc0629405e via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] fe8ae99

@github-actions

github-actions Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review (fork) — ✅ no blocking findings

Reviewed fe8ae99eef61789093b7c042ddc4d9fc0629405e via the fork AI-review pipeline; updated in place on each push.

Review details

The PR branch isn't checked out locally, so I'm validating against the pre-fetched diff, which contains the full new-file contents. I've traced both candidates through that code.

Candidate 1 (alignRawToValue, remarkLatexDelimiters.ts:269): confirmed real. A multi-code-point HTML5 named entity not in NAMED_ENTITIES (e.g. &fjlig; → fj, &nvlt; → two code points) hits the fallback branch, which assumes width 1 (or 2 only for a high surrogate). It advances j by 1 while the value consumed 2 UTF-16 units → raw/value desync → next non-whitespace mismatch returns null → any valid \(…\) in the same text node is suppressed. Errs literal, no corruption. Narrow but real false negative. → FINDING.

Candidate 2 (findMathSpans inline branch, :171): the raw[close+2] !== '(' guard does over-suppress \(f\)(3), but this errs conservatively toward literal and is a marginal completeness gap, not a clear defect. Below the 80 bar — dropped.

No new groundable defects surfaced during falsification.

No blocking issues; one advisory false-negative in entity alignment.

FINDING — website/src/utils/remarkLatexDelimiters.ts:269 — const width = vc >= '\ud800' && vc <= '\udbff' ? 2 : 1 assumes an unlisted named entity decodes to one code point, so a multi-code-point HTML5 entity (e.g. &fjlig;, &nvlt;) in the same text node desyncs raw↔value, makes alignRawToValue return null, and silently leaves valid \(…\) math unrendered → Fix: instead of guessing width, measure the code points remark actually consumed by scanning value forward from j for the token's decoded length, or return null for unknown multi-unit references rather than committing width 1.

[OPUS-REVIEWED] fe8ae99

@jeeshofone
jeeshofone force-pushed the fix/7803-latex-delimiters branch from 3c7ee2a to 5f51fca Compare September 2, 2026 06:41
@jeeshofone

Copy link
Copy Markdown
Contributor Author

Review round 1 — GPT blockings addressed in 5f51fca32630205c28c66b8879e1aa577d08232e

Blocking #1 (Jira/ADF padded escaped brackets converted to math): FIXED, without dropping display math. The suggested fix (normalize only \(…\)) would remove the issue's headline case — models emit \[…\] display math constantly. Instead, display conversion is now LINE-ANCHORED: \[ must be preceded on its line only by whitespace and \] followed only by whitespace. Mid-sentence Jira/ADF shapes (see \[ x \] here) stay literal — new regression test. Residual, stated honestly: a Jira paragraph consisting of NOTHING but a padded bracketed expression still converts; the full fix is provenance-gating (a renderer prop set only by LLM-output surfaces), which touches 46 call sites and is proposed as a follow-up rather than smuggled into this diff.

Blocking #2 (unmatched opener's closer search enters inline code): FIXED. closerIndex now skips balanced backtick spans while scanning, so a \) inside inline code can never be selected as a math closer; an unterminated span aborts the search. Regression test: a lone \( followed by code containing \) leaves the code span intact.

Blocking #3 (fence-like content line ends code protection): FIXED. A closing fence now requires the marker be followed only by whitespace (CommonMark: closing fences carry no info string), so ~~~not-close inside a tilde fence stays content. Regression test keeps \[ … \] inside such a fence literal.

Verified: 125/125 across MarkdownRenderer.test.tsx + MarkdownRenderer.adfSafety.test.tsx, tsc, eslint — green.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Sep 2, 2026
@jeeshofone
jeeshofone force-pushed the fix/7803-latex-delimiters branch from 5f51fca to b290b4d Compare September 2, 2026 09:19
@jeeshofone

Copy link
Copy Markdown
Contributor Author

Review round 2 — both lanes' blockings addressed in b290b4d51f5a48b90f2ceff292116dff9cef492b

Quadratic scan over untrusted content (GPT + Opus, convergent): FIXED by restructuring, not patching. The scanner is now a SINGLE FORWARD PASS with pending-opener state: an opener is remembered and paired when its closer arrives, so an unmatched opener costs only its own visit — no per-opener suffix rescan. Every position is visited once; the display-shape checks at pair time are bounded by their own line. Semantics preserved: fences kill pending openers (math cannot cross a fence, as before), code spans never contribute closers, and an ineligible pair consumes both ends rather than lying in wait. Regression guard: a new test feeds 50k unmatched openers (100k chars) through the function — at the old complexity that's ~1.25e9 steps and trips vitest's 5s timeout, so a quadratic reintroduction fails the suite by construction; the current pass completes in milliseconds (whole suite: 314ms of test time).

Escaped parens inside link destinations rewritten (GPT): FIXED. The scanner now recognizes ]( and skips the destination to its matching unescaped ) (escape-aware, depth-tracked, aborting at EOL), so \(/\) inside a URL are never rewritten. A pending inline opener survives the skip, preserving prior pairing behavior everywhere outside the destination. Regression test uses a disambiguation-style URL and asserts both the transform output and the rendered href are intact.

Verified: 127/127 across both renderer suites + tsc + eslint, green.

Round ledger: r1 = escape-collision family (three findings, fixed); r2 = complexity + link-destination (new families, fixed). No repeats.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 2, 2026
@jeeshofone

Copy link
Copy Markdown
Contributor Author

Review disposition (head 1bcd27707)

Both upheld findings accepted (GPT F1/F2; Opus's single blocking finding is the same as GPT F1).

F1 (unbounded indexOf(';', i) before the 33-char cap — quadratic on an &-flood) — accepted, fixed. The reference scan is now a bounded forward loop over at most 33 characters from the &, so each & costs O(1) and alignRawToValue is linear in the node. Honest note on the test: a CI-sized input cannot distinguish the two by timing — V8's vectorised indexOf hides the old quadratic below roughly a million characters (I measured 955 ms vs 325 ms at 250k, both under any sane bound). The added test is therefore a gross-regression guard at 100k with a comment saying exactly that; the bound itself is what the diff shows.

F2 (remarkLatexDelimiters runs before remarkVerbatimUnknownTags, and its verbatim set omitted the containers that pass diverts to literal source) — accepted, fixed. The plugin now takes a verbatimTag predicate; the renderer passes "verbatim-content tags (code, pre, kbd, samp, var, tt, textarea, svg, math) OR any tag not in ALLOWED_TAGS" — i.e. exactly the set the verbatim pass will show as source. A context opens only when the closing sibling exists (same-tag nesting tracked, the same matchingCloseIndex rule the verbatim pass uses); an unclosed tag is a lone tag and what follows it stays prose. The predicate is injected rather than imported because the util importing ALLOWED_TAGS from the component would be a module cycle. Tests: <customBlock>\(x\)</customBlock> then \(y\) → one KaTeX node and the literal <customBlock> text (fails on the previous head); <b>bold \(x\) here</b> still converts; <customBlock> lone tag then \(x\) converts (unclosed = prose).

556/556 across the 35 renderer files; tsc, eslint clean.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 11, 2026
@jeeshofone
jeeshofone force-pushed the fix/7803-latex-delimiters branch from 1bcd277 to d52066b Compare September 11, 2026 07:31
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 11, 2026
@jeeshofone

Copy link
Copy Markdown
Contributor Author

Round on 1bcd27707 → d52066bcf. Both findings addressed; Design/First-Principles' shared-grammar request done in the same push since it is the root of F2.

F1 — inline math strips the surrounding soft breaks (UPHELD → fixed). Exactly as described: pushText's newline trim ran unconditionally, so first\n\(x\)\nsecond lost both soft breaks and glued prose to the span. The trim is now keyed on which side faces a display block (afterDisplay / beforeDisplay from the neighbouring span kinds); inline spans leave the break in place as prose whitespace. Regression test asserts the three text nodes keep first\n, \nsecond and , \nthird around two inline spans, and that the display-block trim is unchanged; fails on the previous head.

F2 — quoted > in a verbatim tag's attribute bypasses the verbatim context (FLAGGED by the adjudicator → fixed anyway). I agree with the FLAG on impact, but Design and First-Principles both named the actual defect class — the plugin carried its own OPEN_TAG_RE/CLOSE_TAG_RE/matchingCloseIndex next to the renderer's SINGLE_TAG_RE/singleTagName/matchingCloseIndex, and two copies of one load-bearing grammar will keep drifting. Fixed structurally: one module, website/src/utils/htmlTagGrammar.ts, exports the quote-aware SINGLE_TAG_RE, singleTagName, isOpeningTag, matchingCloseIndex; the renderer's verbatim pass and the plugin both import it and their private copies are deleted. New test: <customBlock title="a>b">\(x\)</customBlock> then \(y\) renders exactly one KaTeX span with the tag shown as source — on the previous head it renders two (the inner math converts), which is the finding.

155/155 in the renderer suite, 1060 across the 62 renderer-related files, tsc -b, lint, i18n:check green.

@jeeshofone
jeeshofone force-pushed the fix/7803-latex-delimiters branch from d52066b to 4191a1f Compare September 11, 2026 08:33
@jeeshofone

Copy link
Copy Markdown
Contributor Author

Round on d52066bcf → 4191a1fc2.

F1 — unclosed verbatim openers make pairing quadratic (UPHELD-FENCED → fixed, in both consumers). Correct, and measurable: 6000 unclosed <customblock> openers before one \(x\) took 8.0 s on the previous head (1.1 s at 2000 — 3x input, 7.5x time). The cause is the per-opener matchingCloseIndex suffix scan, and it was not only in the plugin: the renderer's own verbatim-unknown-tags pass had the identical shape, which last round's shared-grammar extraction made visible.

Fix in the shared module: matchingCloseIndex is replaced by pairedCloseIndices(kids) — one linear pass with a stack per tag name that maps every closed opener to its close, with the same semantics (a close pairs with the nearest unpaired same-tag opener, nesting tracked, self-closing tags pair with nothing, unclosed openers absent). Both the plugin's verbatim context and the renderer's verbatim pass compute it once per sibling list (lazily, only when an html child is met) and look openers up in it. The suffix-scan function is deleted, so the pattern cannot come back through either consumer.

Test: the 6000-opener input under a 3 s bound — fails the previous head at 8.0 s, passes now at ~0.3 s (9x headroom, so it will not flake on a slow runner), and asserts the semantics (one KaTeX span for the trailing math, the lone openers shown as source). 156/156 renderer suite, 1061 across the 62 renderer-related files, tsc/lint clean.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 11, 2026
@jeeshofone

Copy link
Copy Markdown
Contributor Author

Round on 4191a1fc2 → bf349ca27.

F1 — text-node boundaries misclassify mid-sentence brackets as display math (UPHELD-FENCED → fixed). Correct: lineStartBefore/lineEndAfter tested the text node's own raw slice, so **bold** \[ x \] — where the strong sibling makes the text node begin at \[ — read as owning its line and became a centered block; and in a heading or table cell a math flow node could be nested where splitParagraphs never lifts it.

I did not take the suggested absolute-offset check: it would reject > \[ x \] and - \[ x \], where the blockquote/list marker precedes the node on the source line but the block is legitimately display. The mdast already has the answer, so findMathSpans now takes a SpanContext from the parent and neighbours: display is false unless the parent is a paragraph (the only place a flow math node can be lifted out), and a delimiter on the node's first (last) line is not owned when the previous (next) sibling ends (starts) on that same source line. Container markers are not siblings, so they are unaffected.

Tests: **bold** \[ x \] more and \[ x \] **bold** stay a single paragraph with no display block; ## \[ x \] and a \[ x \] table cell render the escaped literal [ x ] (the ADF/Jira shape the escape-safety test relies on) with no block; and **bold**\n\[\nx\n\]\nafter still lifts a display block — the guard against over-tightening. The first two fail on the previous head. 159/159 renderer suite, 1064 across the 62 renderer-related files, tsc/lint clean.

@jeeshofone

Copy link
Copy Markdown
Contributor Author

Round on a22259dab → e0c2d1575.

GPT F1 — cached tag indices go stale after a text-node splice (UPHELD-FENCED → fixed). Real, and mine from last round: the pairing map was built lazily on the sibling list and then consulted after splice had shifted every later index. transformChildren now makes every decision against one frozen snapshot of the siblings (pairing, verbatim window, neighbour-line checks all speak original indices) and rebuilds the children array once at the end; nothing is spliced mid-walk. Test: <code>\(a\)</code> then \(x\) then <customBlock>\(z\)</customBlock> — the first container builds the map, the rewrite between shifts the second by two, and on the previous head z converts (2 KaTeX spans instead of 1). Fails on the previous head.

First Principles BLOCK — committed screenshots (fixed). You are right and I should have read .gitignore:100-106 before force-adding: evidence is never committed to the code tree. The two PNGs are out of the diff (4 files, no binaries). A fork contributor cannot use gh pr edit --attach (needs write on the upstream), so the images now live on a dedicated pr-evidence orphan branch on the fork and the body's ## Screenshots / video links point there — outside every PR diff, still a plain markdown image the Screenshot Evidence check accepts.

Subtractions taken: verbatimTag is required (its one caller always supplies the renderer's own predicate; the dead VERBATIM_HTML default is gone), and SINGLE_TAG_RE is no longer exported. The shared-grammar / linear-pairing rewrite is now declared in the description (it was undeclared, as noted).

160/160 renderer suite, 1065 across the 62 renderer-related files, tsc/lint clean.

@jeeshofone

Copy link
Copy Markdown
Contributor Author

Round on e0c2d1575 → 4be7bf4b3.

Opus F1 — per-closer slicing makes a \[ \] flood quadratic (BLOCKING → fixed). Correct, and it is exactly the class this file's other guards exist for: the two raw.slice(...).includes('\n') calls ran for every display closer before the eligibility gate short-circuited. Both are answered now from raw.indexOf('\n') / raw.lastIndexOf('\n') computed once per slice — each closer is O(1). (lineStartBefore/lineEndAfter were already bounded: they stop at the first non-space, so a flood pays two steps per closer.)

Measured on '\[ \] '.repeat(150000) (900 KB): 9.4 s on the previous head, 3.6 s now — and the remainder is remark's own parse of that paragraph, which this plugin runs inside of rather than adding to. The new test asserts < 6 s at that size and fails the previous head; it is labelled honestly as a gross-regression guard, because V8's SIMD includes hides the quadratic term below ~100k chars (same caveat I gave on the ; scan in an earlier round).

161/161 renderer suite, 1066 across the 62 renderer-related files, tsc/lint clean.

@jeeshofone

Copy link
Copy Markdown
Contributor Author

4be7bf4b3 → 5e28c8a43 (test-only). Both review lanes were green on 4be7bf4b3; Frontend Tests shard 1 went red. The job's step log is not retrievable from the API right now (404 on the logs endpoint), so I could not read the failure directly; the only plausible candidate in shard 1 is the wall-clock bound I added last round (< 6 s for the 900 KB flood — 3.6 s on a fast workstation, which a 2-core runner can exceed on remark's parse alone).

Fix: both timing guards now assert a ratio, not a wall-clock bound, so they read the same on any runner:

  • the display-pair flood is measured against an equal-size flood of unmatched openers (known-linear, same remark parse): ratio 1.01 now vs 2.55 on the head Opus blocked;
  • the unclosed-opener guard measures 6000 vs 2000 openers after a warm-up render: ~2.5x now vs 7.5x on the quadratic shape; bound 5x.

Neither test's semantics changed (one KaTeX span / no conversion assertions kept). 161/161 x3 locally, tsc/lint clean. If the shard-1 red turns out to be something else once the log is readable, I'll address it next round rather than guess further here.

@jeeshofone

Copy link
Copy Markdown
Contributor Author

5e28c8a43 → d9e4250e3 — rebase onto main (372 commits), no code change. Readiness has read action required — 1 blocking readiness item since 11 Sep 12:02 UTC while every review lane and CI job was green: the one item was Code Review (cancelled) — attempt 2 of the Semgrep run was cancelled by the workflow's per-PR cancel-in-progress and nothing re-triggered it on an unchanged head (a rerun needs admin rights). This push gives it a fresh head. MarkdownRenderer suite 163 green plus the renderer family, tsc -b and lint green, no .github/ diff. Runs need the usual maintainer approval click.

@jeeshofone

Copy link
Copy Markdown
Contributor Author

d9e4250e3 → d4cd8924e — rebase onto main at a828bf834, no code change. The Backend Tests (3.12, 1) / Coverage Gate reds on the previous head were main's frontend-only-PR breakage (httpx missing when the aws-control container suite is collected), fixed on main by #10709 at 06:26 UTC — 45 minutes after my previous rebase. MarkdownRenderer suite 163 green, tsc -b green, no .github/ diff. UX Review's remaining item is the screenshot attachment format; being handled separately.

@jeeshofone

Copy link
Copy Markdown
Contributor Author

d4cd8924e → b0a4a91a3 — identical tree; re-push only. The before/after screenshots in the description are now GitHub-hosted user-attachments assets (the two raw.githubusercontent.com links are gone), which is the form the UX Review lane's blind read downloads. The lane triggers on synchronize, not on a description edit, hence the same-tree push. No code change since the last green run.

@iamwhatever

Copy link
Copy Markdown
Contributor

Reviewed on the current head for approval. readiness: passed is green because whole-design CONCERNS are advisory server-side; they still need an answer before a human approval lands. Fork-risk scan (CI, install, deps, network, subprocess, eval): clean. Holding on the items below.

  • Design Review CONCERNS on head 4090b4c6 with no disposition: three single-sample performance.now() guards (flood/base < 1.8, big/small < 5, elapsed < 2000) in the shared 547-test renderer suite, one rendering 900 KB twice under a 120s timeout. Clears when: median-of-N or several stable consecutive shard runs.
  • Residual worth a sentence in the body: inline \( ... \) converts with no line-shape guard, so a producer that escapes parens in prose (the ADF/Jira class the display rule was hardened against) now renders KaTeX where it used to show (x).
  • Security side verified clean: rehypeKatex still has no options (trust stays false), rehypeSanitize runs first, singleDollarTextMath: false unchanged.

@jeeshofone

Copy link
Copy Markdown
Contributor Author

4090b4c62 -> 6872876f6, rebased onto main (+197).

  • fixed the three single-sample timing guards in MarkdownRenderer.test.tsx: each now compares medians over three interleaved samples per shape through a medianRatio helper, and the ampersand-flood test is a ratio against the same flood with plain parens (about 1.1 here, bound 3) instead of a 2000 ms wall clock. The 900 KB flood test's timeout is raised to 300 s because it renders six times rather than twice. Locally: flood 22.8 s, verbatim-openers 1.6 s, ampersand 2.2 s.
  • fixed the body: the inline \( ... \) rule now records the residual you named (no line-shape guard, so an escaped-paren producer renders KaTeX where it used to show (x)), with why inline has no line-shape analogue and what escape parity still keeps literal.
  • Security paragraph unchanged; you verified it.

Models emit \[ ... \] (display) and \( ... \) (inline) — LaTeX's own
delimiters — but remark-math only tokenizes dollar math, and the renderer
deliberately runs singleDollarTextMath: false (the currency guard), so
valid math displayed as raw source text (kirodotdev#7803).

normalizeMathDelimiters rewrites both forms to $$ before remark-math,
skipping fenced code blocks and inline code spans, leaving unmatched
openers alone, and preserving string length exactly (2 chars -> 2 chars)
so sourcePos coordinates stay valid.

Fixes kirodotdev#7803

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the full diff on head fe8ae99 as part of the 2026-09-17 readiness audit (evidence: pr-ready-audit-20260917-0835). Verified before approving: readiness: passed in place, required status PR Readiness success on this head, no CHANGES_REQUESTED, no unresolved human hold, main-drift checked against files this PR touches, last push by jeeshofone. Merge follows through the normal protected path (no bypass).

@bolichen97 bolichen97 mentioned this pull request Sep 25, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dashboard displays valid LaTeX as raw text instead of rendering equations

3 participants