Skip to content

Fix Mermaid diagrams that stay on error after replies finish - #26480

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/mermaid-streaming-error
Oct 8, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/mermaid-streaming-error

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

A valid diagram in a chat reply could stay on “Diagram error” after the reply finished. An incomplete diagram failed while the reply was arriving, and the error display removed the container that later successful renders needed.

What Changed

Chat now shows a Mermaid fence in the existing code block while the reply is streaming, then renders the diagram when that reply finishes. A real syntax error in a finished reply still shows the existing error and source.

The shared diagram component stores the sanitized SVG or error in React state, so a successful render can replace an error in chat, markdown previews, and expanded comments. Cancelled renders cannot replace newer results, and the serialized render queue resets only after its last waiting render completes.

Why

Intended choice: follow the common pattern of keeping source visible until a reply settles. This avoids parsing half-arrived diagrams and avoids transient error banners; progressively rendering diagrams would require additional recovery and display policy without improving the requested outcome. Keeping the result in React state fixes the shared component’s missing-container failure instead of adding another guard around it.

Linked Issue

Reported while testing native chat on October 7; no separate issue. Kept separate from #26380.

Visual Proof

Hidden macOS Electron check through Playwright CDP, using a private profile, synthetic chat transcript, hooks off, and absolute agent stand-ins. The app used the real Mermaid renderer and DOMPurify; no real provider stream was used. No QA host was allocated within 20 minutes, so this ran hidden on the laptop.

While the reply is streaming, the partial fence uses the existing code block:

Partial Mermaid source while streaming

Once the reply finishes, the full flowchart renders:

Finished chat reply with rendered flowchart

A finished reply with invalid source still shows the existing error and source:

Finished invalid diagram with error and source

Testing

  • Hidden Electron: streaming source, finished SVG, finished invalid source, and invalid-to-valid recovery.
  • 40 tests pass across six explicitly selected diagram, chat markdown, visual, comment, and theme suites.
  • The invalid-to-valid recovery and streaming-source regression tests both fail against the base implementation.
  • Renderer typecheck passes through the machine queue.
  • All 22 static checks from orca-ci-checks pass. Package scripts were expanded into their exact direct commands to avoid running pnpm through the shared node_modules symlink.

Unit tests control the asynchronous Mermaid renderer and sanitizer to test component state, cancellation, queuing, and use of sanitized output; the hidden Electron check exercised the real renderer and sanitizer. Windows, Linux, and SSH have not been exercised locally. The change is renderer-only, uses no host-specific operations, changes no remote protocol or saved data, and applies equally to folder workspaces and git worktrees.

Completed CI run 37742588327 on final head 3135d2424aa9c922bd8cfbafd13091a0393b7798: all 35 checks finished (16 passed, 17 skipped, 2 failed). The failed unit shard 9 is classified infrastructure: GitHub reports “The hosted runner lost communication with the server”; the job ended during its test step without a test result or log blob. The failed verification gate follows that failed unit job. Nine unit shards, static analysis/typecheck, both package jobs, relay integration, and the advisory evidence job passed. Skipped checks are not test passes; shard 9 remains a CI coverage gap. No code assertion failure was reported. Marking the PR ready queued a new automatic run, whose result is not yet verified.

Review

Self-reviewed the result state, cancellation, sanitization, queue serialization, and default behavior outside native chat. No independent review was run.

Agent skill upstream boundary

  • Not applicable: no upstream skill source or supporting files copied.

Notes

DOMPurify’s SVG pass remains in place. No dependency, localization, persistence, or remote wire changes.

Checklist

  • This PR is small and focused.
  • Explained the problem, user-facing change, mechanism, and approach.
  • Streaming and finished screenshots attached; a base-branch screenshot was not captured.
  • Self-reviewed for correctness, security, and performance.
  • Cross-platform, SSH, and folder workspace impact considered.
  • The completed final-head CI run is classified below; CI is not green, and the ready-event run is pending.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

A valid diagram could remain on “Diagram error” after a chat reply finished because the earlier error display removed the DOM container that later successful renders needed. This change stores the sanitized SVG or error in React state and keeps chat source in its existing code block until the reply stops streaming, so the finished diagram can appear and a later valid source can recover from an error.

Self-review covered stale render cancellation, use of sanitized output, serialization of diagram renders, and unchanged default rendering outside native chat. No independent review was run. Fixed: the shared component's stuck error, mid-stream chat parsing, and premature queue reset; deferred: live provider timing and in-app checks of editor/comment surfaces.

Verified: 40 targeted tests, both requested regressions failing on the base implementation, renderer typecheck through the machine queue, and all 22 repository static checks before each push. Hidden macOS Electron with a fresh private profile, hooks off, absolute agent stand-ins, and synthetic transcript/status fixtures displayed partial source without an error, a complete real SVG, finished invalid source with the existing error, and invalid-to-valid recovery. Screenshots are embedded above. Not verified: a live provider stream, Linux/Windows, SSH, editor/comment UI, or a base-branch error screenshot.

Final head 3135d2424aa9c922bd8cfbafd13091a0393b7798: all 35 checks finished (16 passed, 17 skipped, 2 failed). The failed unit shard 9 is classified infrastructure: GitHub reports “The hosted runner lost communication with the server”; the job ended during its test step without a test result or log blob. The failed verification gate follows that failed unit job. Nine unit shards, static analysis/typecheck, both package jobs, relay integration, and the advisory evidence job passed. Skipped checks are not test passes; shard 9 remains a CI coverage gap. No code assertion failure was reported.

@brennanb2025
brennanb2025 marked this pull request as ready for review October 8, 2026 08:44
@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 74be23b0-eb25-43a4-b7a8-469de8b39c85
📥 Commits

Reviewing files that changed from the base of the PR and between a4854ac and 3135d24.

📒 Files selected for processing (6)
  • src/renderer/src/components/editor/MermaidBlock.test.tsx
  • src/renderer/src/components/editor/MermaidBlock.tsx
  • src/renderer/src/components/native-chat/NativeChatMarkdown.mermaid.test.tsx
  • src/renderer/src/components/native-chat/NativeChatMarkdown.tsx
  • src/renderer/src/components/sidebar/CommentMarkdown.tsx
  • src/renderer/src/components/sidebar/comment-markdown-element-renderers.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.


📝 Walkthrough

Walkthrough

MermaidBlock now stores sanitized SVG or an error in state and preserves queued renders when earlier tasks complete. CommentMarkdown adds a setting to enable or disable Mermaid rendering. NativeChatMarkdown disables rendering while a message is streaming. Tests cover editor rendering, sanitization, queueing, and streaming chat behavior.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 3135d

Mermaid diagrams stay as source while a reply streams and render once it finishes. A diagram that failed to parse can now recover into a valid render. No merge-blocking issues were found. Unit shard 9 did not complete in CI, so it should be re-run.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly describes the main change: fixing Mermaid diagrams that remain in an error state after replies finish.
Description check ✅ Passed The description is detailed and relevant. It explains the user impact, implementation, rationale, visual proof, testing, CI status, limitations, and checklist items. It does not provide an actual link…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@brennanb2025
brennanb2025 merged commit 79a8cff into main Oct 8, 2026
67 of 69 checks passed
@brennanb2025
brennanb2025 deleted the brennanb2025/mermaid-streaming-error branch October 12, 2026 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant