Skip to content

Draw Mermaid diagrams with Pele, in a worker, as a message arrives - #140

Merged
lydakis merged 7 commits into
mainfrom
claude/project-thread-si1dw1
Oct 25, 2026
Merged

lydakis merged 7 commits into
mainfrom
claude/project-thread-si1dw1

Conversation

@lydakis

@lydakis lydakis commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

What

The app's ```mermaid blocks (and .mmd files beside) now draw with Pele 1.10.0, Obsidian's Mermaid renderer, in place of the vendored Mermaid.js 11.17.2. Mermaid.js is gone; nothing falls back to it.

Pele lays out in milliseconds and bounds its input, so a diagram no longer waits for a click on diagram: it draws as soon as its message is in, in a message as in a file. While a reply streams it stays code, as before.

  • Off the window's thread. Pele runs in a worker (app/ui/diagram-worker.js). One still laying out after 3 s ends the worker, and the next diagram starts another.
  • Bounded. Pele refuses over 50,000 characters, 5,000 flowchart edges, or 100,000 block-beta spaces. The worker also holds the SVG to a million characters, because inserting a 1.4M-character SVG took the window 183 ms.
  • Themed. Colors are --pele-* CSS variables set to the window's (app.css), with the series in the charts' order. Labels use the window's font, and the layout fits the block's width.
  • Safe. Links keep http/https/mailto and still go through the guarded opener. Images are off, so an img: node fetches nothing.
  • Failures. A diagram that fails shows Pele's message in its head. When its pane is drawn again it shows that message without trying again; a click on diagram tries again.

Size: 709 KB (264 KB gzipped), against 3.57 MB (980 KB gzipped) for Mermaid.js.

Measured

node app/bench/diagrams.cjs (new), headless Chrome 153, median of five warm runs, from post to answer:

diagram Pele in the worker
flowchart, 5 nodes 2.3 ms
sequence, 5 messages 4.8 ms
state, 80 states / 3,000 transitions 184 ms (866K chars of SVG)
block-beta space:99999 311 ms
block-beta space:500000 refused in 2 ms (Mermaid.js held the window past 110 s at space:1000)
flowchart, 4,999 edges refused for SVG over 1M chars

The page's longest frame gap while the worker ran was 22 ms. The numbers and what they mean are in docs/APP.md.

Screenshots

A reply's sequence diagram, drawn on arrival (demo mode, Chromium):

reply diagram

PLAN.md beside with its flowchart:

file beside

The real app (Linux build, WebKitGTK webview, playground model). The worker loads from the app's own scheme, and each reply's diagram drew as it came in:

webkit

Tests

node --test app/tests/state.test.cjs: 212 pass. The diagram tests now cover:

  • drawing on arrival in a stand-in worker
  • the window's font and the block's width
  • drawing again from the cache
  • the reader keeping their place
  • a timeout ending the worker
  • a failure not being retried until clicked

Not yet seen in macOS's WKWebView.

Replace the vendored Mermaid.js 11.17.2 (3.57 MB) with Pele 1.10.0
(709 KB), Obsidian's Mermaid renderer. Pele bounds its input and lays
out in milliseconds, so a diagram no longer waits for a click: it draws
once its message is in, in a message as in a file beside.

Pele runs in a worker (diagram-worker.js), so layout never holds the
window's thread; a diagram still laying out after 3 s ends the worker.
The SVG is held to a million characters, as inserting one that size
takes the window about 150 ms. Colors are CSS variables set to the
window's, links keep the schemes the window opens, and images are off.
A diagram that fails shows Pele's message and is tried again only on a
click. Adds app/bench/diagrams.cjs and its numbers in docs/APP.md.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Rze6PVuq7A1ENuxrAt6QEA
@lydakis lydakis self-assigned this Oct 25, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-25T22:18:21.781712Z 0941ef0 Manual request
🔒 Security Review ✅ Completed 2026-10-25T22:22:03.730743Z 0941ef0 Manual request

Security findings

Advisory findings (1)

ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 919bbfff84

ℹ️ 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".

Comment thread app/ui/rich.js Resolved
Comment thread app/ui/diagram-worker.js Resolved
A diagram draws on its own only while the blocks in the document hold
under 2 million characters of drawn SVG; past that it waits for a click.
Pele names its IDs from a fixed prefix that each mount renames, so two
diagrams' accessible titles never share an ID.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Rze6PVuq7A1ENuxrAt6QEA

lydakis commented Oct 25, 2026

Copy link
Copy Markdown
Owner Author

@codex review

Round 1 is addressed in 76f818f. Diagrams that draw on their own now stop once the blocks in the document hold 2 million characters of drawn SVG, and later ones wait for a click. Each mount also gets its own IDs. All 214 app tests pass.


Generated by Claude Code

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 76f818f861

ℹ️ 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".

Comment thread app/ui/rich.js Resolved
A diagram or chart still queued when its pane was drawn anew, or another
agent was opened, is not drawn and its result is not mounted, so the
blocks now on screen draw next.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Rze6PVuq7A1ENuxrAt6QEA

lydakis commented Oct 25, 2026

Copy link
Copy Markdown
Owner Author

@codex review

Round 2 is addressed in 660fb13. A queued drawing whose block has left the document is skipped and never mounted. All 215 app tests pass.


Generated by Claude Code

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 660fb13e3a

ℹ️ 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".

Comment thread app/ui/rich.js Resolved

lydakis commented Oct 25, 2026

Copy link
Copy Markdown
Owner Author

@codex review

Round 3 is addressed in 0231506 and 19b374e. Drawn blocks that have left the document are now let go on every drawing, clicked or automatic, and every time a pane is drawn. All 215 app tests pass.


Generated by Claude Code

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 19b374eb7d

ℹ️ 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".

Comment thread app/ui/rich.js Resolved
Comment thread app/ui/rich.js Resolved

lydakis commented Oct 25, 2026

Copy link
Copy Markdown
Owner Author

@codex review


Generated by Claude Code

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 0941ef0bd3

ℹ️ 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".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛡️ Codex Security Review · Automatically triggered

Here are some automated security review suggestions for this pull request.

Reviewed commit: 0941ef0bd3

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread app/ui/rich.js
const lang = (info ?? '').trim().split(/\s+/)[0].toLowerCase();
if (draft) return `<div class="rc" data-kind="code">${head(lang, '')}${pre(text, lang)}</div>`;
if (lang === 'mermaid' || lang === 'mmd') return `<div class="rc" data-kind="mermaid" data-lazy${lazy(page)} data-view="code">${head('mermaid', toggle)}<div class="view"></div>${pre(text, '')}</div>`;
if (lang === 'mermaid' || lang === 'mmd') return `<div class="rc" data-kind="mermaid" data-lazy data-page data-view="code">${head('mermaid', toggle)}<div class="view"></div>${pre(text, '')}</div>`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛡️ Codex Security Review · Automatically triggered

P2 Badge Security: Bound automatic diagram rendering

A malicious model, bot, or attached daemon can now make every Mermaid fence render without a click. A 329 KB message with 5,000 distinct block-beta … space:99999 fences passes the provider, Markdown, and transcript bounds; Pele took ~0.6 s per fence locally, below the 3 s timeout, and produced only ~1.2 KB SVG. hydrate() queues all fences while the 2 MiB SVG cap is empty and does not recheck it before worker dispatch, so one reply can burn a worker core for tens of minutes. Cap aggregate automatic render count/work and recheck before dispatch; leave excess diagrams click-to-render.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Not fixing this in this PR. It needs a crafted reply with thousands of distinct diagrams, each laid out just under the timeout. The layout runs in the worker, so the window stays responsive. Under the repo's merge rule, hostile-input findings without an ordinary-use bug are logged rather than fixed at merge. This one is in #97, along with the fix: cap the count or total worker time of automatic draws and leave the rest click-to-draw.


Generated by Claude Code

@lydakis
lydakis merged commit e0f003c into main Oct 25, 2026
1 check passed
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.

2 participants