Repository navigation
feat(android): render LaTeX display math in chat via bundled KaTeX - #101435
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed July 7, 2026, 6:03 AM ET / 10:03 UTC. Summary PR surface: Docs +37, Other +1330. Total +1367 across 33 files. Reproducibility: yes. for the blockers: source inspection shows renderer.js still uses throwOnError:false and the live current-head Android build log reproduces the WebView JavaScript lint failure. The visible Android rendering behavior itself remains unproven because no emulator/device proof was provided. Review metrics: 3 noteworthy metrics.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Maintainer decision needed
Security Review findings
Review detailsBest possible solution: Fix malformed-math fallback and the Android WebView JavaScript lint gate, then land only after redacted Android emulator or device proof shows both rendered display math and fallback behavior. Do we have a high-confidence way to reproduce the issue? Yes for the blockers: source inspection shows renderer.js still uses throwOnError:false and the live current-head Android build log reproduces the WebView JavaScript lint failure. The visible Android rendering behavior itself remains unproven because no emulator/device proof was provided. Is this the best way to solve the issue? No, not merge-ready yet: the Android-owned renderer shape is a plausible follow-up to the iOS implementation, but it must preserve the raw fallback contract, clear the WebView lint/security gate, and prove the UI path in a real Android setup. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 2394a0a55963. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Docs +37, Other +1330. Total +1367 across 33 files. View PR surface stats
Security concerns:
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
Review history (1 earlier review cycle)
|
ee50ac5 to
d054e41
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d054e41827
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| maxExpand: 1000, | ||
| maxSize: 10, | ||
| strict: "ignore", | ||
| throwOnError: false, |
There was a problem hiding this comment.
Render malformed math via fallback
For malformed display math, this option prevents the catch path from running: KaTeX's bundled renderer handles throwOnError: false by returning a .katex-error node instead of throwing, so ChatMathBridge.onRenderComplete(..., true) is reached and the chat shows a red KaTeX error image. That breaks the stated/plain-text fallback behavior for inputs like $$\notARealCommand{$$ and differs from the iOS sibling path, which falls back when parsing fails.
Useful? React with 👍 / 👎.
d054e41 to
65748a4
Compare
|
Coordination note from the sibling session that authored this branch (now standing down — your head supersedes my local lint fixes, which you made independently and named better):
|
|
@clawsweeper re-review Both prior findings are fixed on the current head: malformed KaTeX now reports failure into the raw-text fallback, and the Android WebView lint/security surface is explicitly documented, lifecycle-bounded, and lint-clean. The PR body now includes full Testbox and local API 36 emulator proof; screenshots were inspected locally but not uploaded because image-upload approval was not provided. |
|
🦞🧹 I asked ClawSweeper to review this item again. |
This reverts commit 4035628.
|
Land-ready.
|
|
Merged via squash.
|
…penclaw#101435) * feat(android): render LaTeX display math in chat via bundled KaTeX * fix(android): preserve fallback for invalid math * docs(changelog): note Android display math * Revert "docs(changelog): note Android display math" This reverts commit 4035628.
Related: #100699
What Problem This Solves
Delivers the declared Android math follow-up:
$$…$$and\[…\]blocks in assistant responses rendered as typeset math instead of raw TeX, matching the iOS display-math behavior from #100829.Why This Change Was Made
Dependency decision first: jlatexmath-android (the only native Android LaTeX library lineage) is GPL-2.0 and archived since 2023 — unusable for store distribution. Instead, KaTeX v0.17.0 (MIT) ships as bundled assets (minified js/css + required woff2 fonts only; no Gradle dependency): the release archive's SHA-256 matches GitHub's published digest, per-file hashes are recorded in an assets README, and the licenses screen gains a KaTeX entry (MIT + SIL OFL font note) per the Android licenses policy.
Rendering keeps WebViews out of the transcript entirely: one process-singleton offscreen WebView (attached as a transparent 1px view per Android's visible-state contract, lifecycle-detached) renders queued math jobs into bitmaps that transcript rows display as plain
Images, cached in a byte-bounded LRU keyed by latex/width/dark-mode, with negative caching and a 3s per-job timeout falling back to code-style raw text. The WebView is locked down: an asset-allowlist request interceptor returns empty responses for anything not underfile:///android_asset/katex/, LaTeX reaches KaTeX only as a JSON-encodedevaluateJavascriptargument (never HTML concatenation) withtrust:false,throwOnError:true,maxExpand:1000, and the only JS bridge is a render-completion callback. The process singleton retains only an Application-backed WebView and a weak activity host that detaches on destruction. Segmentation mirrors the iOS contract exactly: top-level blocks only, never inside code, unclosed math stays plain while streaming, 5000-byte cap falls back.User Impact
Android users see typeset display math in finished assistant messages; streaming, code blocks, and oversized/invalid math keep today's plain-text behavior. Android's licenses screen credits KaTeX.
Evidence
tbx_01kwy132f27yajdr0494ge03j7: Play + ThirdParty unit suites, both debug APK assemblies, both lint lanes, benchmark assembly, app and benchmark ktlint all passed after rebase.f77cf2…4b88matches GitHub's published release digest (independently re-verified via the releases API); per-file sha256s inassets/katex/README.md.\frac{stayed raw in the code-style fallback; chat remained responsive after background/foreground. Screenshots were inspected locally and not uploaded because image-upload approval was not provided.trust:false, bounded expansion/bitmap/cache, Application-only process lifetime, weak/detached activity host.