Repository navigation
feat(android): render Mermaid diagrams in chat - #135342
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: found issues before merge. Reviewed September 1, 2026, 12:53 PM ET / 16:53 UTC. ClawSweeper reviewWhat this changesThis PR adds offline Mermaid diagram rendering to Android chat and moves the existing web renderer into a shared package used by both clients. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readinessKeep open: the Android feature remains absent from fetched current main, but the new shared queue permanently downgrades existing math blocks to source text when it reaches capacity. Priority: P2 Review scores
Verification
How this fits togetherAndroid chat detects completed Mermaid Markdown fences and sends them to a bounded local WebView renderer. The renderer returns a sanitized SVG and bitmap for inline chat display and a full-screen preview. flowchart LR
A[Chat transcript] --> B[Markdown fence parser]
B --> C{Completed Mermaid fence}
C -->|Yes| D[Bounded local renderer]
C -->|No| E[Code block display]
D --> F[Sanitized SVG and bitmap]
F --> G[Chat preview and full-screen viewer]
Decision needed
Why: This draft creates a shared renderer and an ongoing native presentation surface; technical repair alone does not establish the intended rollout scope. Before merge
Findings
Agent review detailsSecurityNone. PR surfacePR surface statistics unavailable: the file list is incomplete. Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the queue bound, but distinguish temporary admission loss from a permanent render failure and automatically re-admit visible math work when capacity frees. Do we have a high-confidence way to reproduce the issue? Yes, from source: submit more than 33 distinct rich blocks in one composed message, including a later math block. The coordinator reports TransientFailure and the math caller immediately commits the code fallback; execution was not possible because pnpm is unavailable in this review environment. Is this the best way to solve the issue? No. Sharing the renderer is a coherent direction, but treating temporary queue admission failure as permanent math-render failure is not the maintainable solution. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 520f6f7d22af. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
Dependency GuardThis PR changes dependency-related files. Maintainers should confirm these changes are intentional. Changed files:
Maintainer follow-up:
|
Dependency graph changes notedThis PR includes dependency graph changes. The dependency guard is informational because the PR author is a repository admin, a member of
Security review is still recommended before merge when the dependency graph change is intentional. |
72692bf to
9dcc084
Compare
|
The review findings are addressed in the final native artifact, built from Math and Mermaid have separate renderer instances and queues. The 32-queued-diagram bound remains; math preserves its prior admission behavior. The same persisted 40-formula message that previously left seven permanent source blocks now renders 40/40 without retry or edits. A 5,000-pending-job regression also proves synchronous host loss drains without stack overflow. Activity destruction now retires the old document before completion and replacement. Live font-scale changes The PR body now contains the final before/after diagram and math screenshots, 66 focused Android tests, seven generated protocol tests, browser proof, exact APK digest, and CI follow-through. The rollout order is the maintainer's explicit Android → iOS → macOS request. All renderer caches are in memory; no database/schema or persistent-state change is present. |
ec42739 to
597af72
Compare
57e3137 to
3a2fff5
Compare
3a2fff5 to
e016723
Compare
|
Merged via squash.
|
* feat(android): render Mermaid diagrams in chat * fix(android): finish diagram preview and retry feedback * fix(android): preserve rich renderer recovery and lifecycle * test(mermaid): type browser fixture receivers * fix(android): gate rich renderer WebView allocation
Related: #135293
What Problem This Solves
Android chat displays Mermaid diagrams as code even when the same message renders as a diagram in the Control UI. Completed
mermaidfences now render inline with corner copy/options buttons and a full-screen vector viewer.Why This Change Was Made
The Control UI and native apps share one pinned Mermaid engine, sandbox, and SVG sanitizer through a private workspace package. Android bundles the renderer for offline use. Math and diagrams share the native lifecycle implementation, with separate warm documents, queues, caches, and resource limits.
Incomplete streaming fences remain code. Failed diagrams retain readable source; temporary failures offer Retry. Android builds generate the assets and required dependency notices from pinned dependencies, including clean CI and release checkouts. This is the first of the requested Android, iOS, then macOS PRs.
User Impact
Users can read diagrams inline, copy or inspect their source, and expand a vector preview with zoom and pan. Rendering needs no network service, Gateway configuration, or additional device permissions. Caches are in-memory only; there is no persistent cache, database schema, migration, or serialized user-state change.
The lifecycle refactor preserves existing math admission. Mermaid alone has the new 32-item queue limit. Synchronous failures drain iteratively, and Activity teardown retires the old WebView before completing interrupted work or admitting its replacement.
Evidence
The final signed APK was built from
e016723640697d40398219815f67171b268f5f82and connected to an isolated real Gateway. Synthetic transcripts were read through the normal native chat flow, without model-provider calls or operator Gateway state. All 2,220 Android/shared/tooling input hashes were verified.Final APK expanded vector preview
Final APK SHA-256:
2fd62bb764d39b2e2868901045f0f79bcad3aa864a209f9a728c166b3aa1ad52; the installedbase.apkhas the same hash. Physical Android hardware was unavailable, so native proof used a task-owned emulator. Memory samples are observations, not whole-app memory limits.The broad 40-item stress and zoom/pan/rotation runs are attributed to APK7, source
9dcc084cb5785a0ff07a4d1eb71ede6cb3940653, SHA-256c0c6ad12a585acb3e700cc0a5d4cba8e7af8f632a4540ae474ca92e6599b61f1. APK8, source57e3137809c652c6144149d835f7e04cbdd2a75b, only relocates AndroidX's required method-local WebView feature checks and repeats cold rendering/lifecycle proof. All five feature commits remain patch-identical across the final rebase; the fresh APK9 build and live run above verify the newer upstream native inputs.40-formula admission regression: before and after repair
The initial candidate rendered 33 formulas and left seven permanently as source. The repaired owner renders all 40 without Retry, message edits, or clearing app data. The after picture is from APK7.
Production LOC, excluding moves: +1,191/-651 (net +540), for native presentation, vector viewing, the shared native boundary, and the rendering owner replacing the old math-only implementation. Tests/support: +894/-238 (net +656). Build/CI: +101; docs: +72; source inventory: +12; lockfile: +16; upstream notices: +1,909.
Review Follow-through
The math-admission and Activity-retirement findings are fixed and covered by failing-before/passing-after tests plus native runs. Mermaid retains its 32-item bound. Math preserves its preexisting admission policy, avoiding a new retry/re-admission state machine. The requested mixed-block coverage is the real 40-diagram transcript with following math, the 40-formula regression, and independent per-kind queues; a synthetic cross-kind queue would not represent production ownership. The persistent-data-model warning does not apply to transient renderer caches and bridge envelopes.
The final local test selection first encountered a Robolectric native-font initialization
FileSystemAlreadyExistsExceptionbefore the test body. A repeat and a repeat in the exact original suite order both passed all 406 tests. No assertion, timeout, graphics mode, or dependency override was changed. The shared state-directory CI failure was repaired at its test owner in #135495 and is included here. The earlier supplemental Gateway abort-fixtureENOTEMPTYcleanup failure did not reproduce in two complete six-case runs; current-head CI is green.Named follow-ups: the existing Android landscape chat header/composer can consume the transcript viewport (also reproduced on baseline; expanded diagram landscape works); native localization extraction broadly excludes
Previewfilenames (this productionPreviewViewand all 12 strings are in inventory); the two non-reproducing test-initialization/cleanup failures above remain recorded for investigation if they recur. iOS and macOS follow separately under #135293.