Repository navigation
Mermaid validation: PythonMonkey on main thread, then system Node, never mermaid.ink - #1
Merged
Merged
Conversation
PythonMonkey crashes Python when it is imported on a non-main thread (segfault during validation, caw's FastMCP tool thread) or used from a non-main thread's loop (segfault at exit, the web app's worker thread). This happens with 1.2.0 and 1.4.1 on Linux and macOS, on every Python version tested; the old "3.12+ only" diagnosis was wrong, so the version skip just sent all validation to mermaid.ink. Now the parse, import included, always runs on the main thread: directly, or handed to the main loop via run_coroutine_threadsafe. Off the main thread with no main loop to hand off to, validation falls back to mermaid-py. Bump pythonmonkey to 1.4.1. The new test runs both thread layouts in a subprocess, so a segfault fails it instead of killing pytest. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…work The Node fallback ran codewiki/mermaid_node/validate.mjs, which was not in package-data (so missing from wheels) and npm-installed mermaid into site-packages at run time (network access, writable install dir, a second mermaid version). Node now runs mermaid-parser-py's own parser.bundle.js, the same file PythonMonkey loads: no npm, no lock file, same parse errors. Drop the mermaid.ink fallback (mermaid-py, MERMAID_VALIDATE). If neither PythonMonkey nor Node can run, log one warning and skip validation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011nNK4oKT17vZwKhUezJQ5z
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011nNK4oKT17vZwKhUezJQ5z
dandydarshan
force-pushed
the
fix/pythonmonkey-main-thread
branch
from
October 25, 2026 17:22
1f61dbe to
e8f5687
Compare
This was referenced Nov 7, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
_PYTHONMONKEY_BROKEN = sys.version_info >= (3, 12)skipped PythonMonkey on 3.12+, sending all Mermaid validation to mermaid.ink (diagram content leaves the machine). Testing on Linux and on GitHub's macOS runners (arm64 + Intel, py3.12–3.14, PythonMonkey 1.2.0 and 1.4.1; see theexperiment/pythonmonkey-macosbranch) shows the crash depends on the thread, not the Python version:Change
Mermaid validation now runs in this order and never calls a web service:
run_coroutine_threadsafe(caw backend). The 3.12+ skip is gone;pythonmonkeybumped to 1.4.1.mermaid_parser/js/parser.bundle.js, the bundlemermaid-parser-pyalready ships and PythonMonkey loads, so parse errors are identical. No npm install, no lock file, nothing extra in the wheel. Node comes fromPATH, orCODEWIKI_NODE_PATH.The mermaid.ink fallback (mermaid-py,
MERMAID_VALIDATE) is commented out incodewiki/src/be/utils.py, along with themermaid-pydependency, so it can be restored by uncommenting. An earlier version of this PR addedcodewiki/mermaid_node/with apackage.json/package-lock.jsonand installed mermaid via npm at run time; that's removed, since it wasn't in package-data (missing from wheels) and needed network access and a writable install dir.Tests
tests/test_compiled_wheel.pyruns both thread layouts in a subprocess (it segfaults without the fix). The main-thread case checks PythonMonkey is used; the worker-thread case checks PythonMonkey is never loaded and, whennodeis onPATH, that good/broken diagrams are reported correctly through Node.🤖 Generated with Claude Code
https://claude.ai/code/session_011nNK4oKT17vZwKhUezJQ5z