Peer-writer lock (#1818/#1823) is incompatible with the multi-session daemon topology (#1270) + external hook/manual mines
Summary
The new peer-writer guard shipped in 3.5.0 (#1818 / #1823) acquires mine_palace_lock and holds it for the entire process lifetime. For users running the multi-session daemon model — i.e. the topology that the still-open PR #1270 is meant to enable — this guard is, as far as I can tell from reading the code, not usable: it locks out hook-driven and manual mempalace mine runs, and it doesn't fit a daemon that services many sessions on different threads. The result is that the one 3.5.0 feature that would actually fix our root cause (concurrent writers corrupting the HNSW index) is the feature we can't adopt.
I'm filing this as a friendly heads-up: #1270 (open) and #1818 (merged) are on a collision course. If the guard stays as-is, daemon-topology users can't move to 3.5.0.
My setup (a concrete instance of #1270)
- MemPalace via
pipx, palace~/.mempalace, embedderembeddinggemma(CPU). - A single long-lived daemon (a LaunchAgent) that
importsmempalace.mcp_server.handle_requestand serves every editor session (Claude Code, Claude Desktop, WARP) through a tiny stdio↔unix-socket bridge. This is byte-for-byte the design in PR #1270. It exists precisely to avoid the concurrent-stdio-writer HNSW corruption that #1818 also targets. - Auto-save hooks that shell out to
mempalace mine --mode convos, plus periodic manualmempalace mineof docs. These are separate processes from the daemon.
I just hit an HNSW divergence (index held 21 elements vs 16,551 in sqlite; vector search fell back to BM25) — exactly the corruption class #1818 wants to prevent — so I very much want this protection. I just can't enable it without breaking the rest.
The incompatibility (code references, v3.5.0 / develop)
The guard holds the per-palace mine lock for the whole process lifetime.
_acquire_mcp_writer_lock()entersmine_palace_lock(_config.palace_path)and registers anatexitto release it — so it's held until the process exits.mempalace/mcp_server.py:299.It's the same lock external mines use. Both
miner.py:1649andconvo_miner.py:582wrap the mine pipeline inwith mine_palace_lock(palace_path). So once the daemon holds it for life, every hook-driven or manualmempalace mineraisesMineAlreadyRunningand skips — auto-capture silently stops ingesting.Re-entrancy is per-thread, but a daemon serves clients on many threads.
mine_palace_lock's re-entrancy is tracked inthreading.local()(palace.py:963,_held_by_this_thread). A daemon that holds the writer lease on the thread that first calledstatus, then services anadd_draweron a different client thread, would (as far as I can tell from the code) have that thread's innerChromaCollectionwrite fail to re-acquire the lock, since the re-entrancy credit is keyed to the original thread. The guard appears designed for the "one stdio process per client" model, not a shared multi-threaded daemon.
(Reads are fine — search/traverse aren't in _MUTATING_TOOLS, mcp_server.py:278 — and handle_request still exists, so the daemon import itself is unaffected.)
The only way I can run 3.5.0 today is MEMPALACE_MCP_ALLOW_PEER_WRITER=1 (mcp_server.py:276), which turns the guard off entirely — so I keep my workflow but lose the protection I actually want.
Why this matters beyond me
The real fix for the concurrent-writer corruption is a single writer that everything (MCP calls, hook mines, manual mines) funnels through. #1826's opt-in queued-writes daemon looks like a big step toward that — but it's unclear how it's meant to coexist with hook-spawned mempalace mine and manual CLI mines, which still take the same lock independently. Without that story, #1270-style users are stuck between "guard on → mines blocked" and "guard off → no protection."
Suggestions (any one would unblock us)
- Make the writer-lease re-entrancy process-wide, not thread-local (or have the guard mark the lease such that the owning process's own write paths recognize it across handler threads). This alone makes a multi-threaded single-daemon hold the lease and serve its own writes.
- Document/support how #1826's daemon is meant to absorb hook + manual mines (e.g. route
mempalace minethrough the daemon when one is running, instead ofMineAlreadyRunning). That would make "single writer" real end-to-end. - At minimum, document the daemon-topology trade-off — that #1270-style users should set
MEMPALACE_MCP_ALLOW_PEER_WRITER=1, and what they give up — so this isn't a silent surprise on upgrade.
Happy to test patches against my setup (Apple Silicon, Python 3.14, pipx, embeddinggemma, the #1270 daemon + bridge). Thanks for all the work on this — the project is genuinely useful and the concurrency hardening is going in the right direction; I just want the daemon path to ride along.
Source: MemPalace/mempalace