modusbrain serve ↔ modusbrain sync concurrency (PGLite)
Short version: on a PGLite brain, stop modusbrain serve before a large sync.
Why
PGLite is a single-writer embedded Postgres (WASM). A runningmodusbrain serve
(stdio or HTTP MCP) holds an open PGLite connection on the brain’s data
directory. modusbrain sync needs to write to that same data directory. The two
contend for PGLite’s single-writer connection / write-lock — this is NOT the
modusbrain-sync advisory lock (that’s a separate, DB-row coordination lock for
two concurrent syncs). Confusing the two sends you debugging the wrong surface.
Symptoms of serve↔sync contention on PGLite:
modusbrain syncblocks acquiring the PGLite write lock, or makes very slow progress, while amodusbrain serveprocess is alive on the same brain.- Killing stale
modusbrain serveMCP processes frees the lock and sync proceeds.
What to do
- Stop any
modusbrain serveprocess for this brain before a large sync: - Restart
modusbrain serveafter the sync completes.
serve and sync can run simultaneously there.
Diagnosing a sync hang
If a sync wedges (no progress, high CPU), re-run with the per-file begin trace so the stalling file is named:[sync] begin import: <path> line with no following completion is the
file being processed when the hang occurred. Under --workers >1 / --all,
the stuck file is in the set of begin-lines without a matching completion.
If you suspect a schema-pack regex is the cause (a pack with a
catastrophic-backtracking inference.regex), complete the sync with the pack
disabled and re-run extraction afterward:
modusbrain schema lint flags the classic nested-quantifier ReDoS shapes
((a+)+, (a*)*, …) in pack regexes as warnings.