feat(mcp): single-instance store guard to stop crypto-store races #17

Merged
jmz merged 1 commit from fix/mcp-single-instance-guard into main 2026-06-10 15:36:39 +00:00
Owner

Startup guard: exclusive flock on the crypto store; supersede any predecessor instance (kills the orphan-process Olm-store racing that silently broke inbound decryption). Complements fix/mcp-shutdown-zombie. Rebased on current main.

Startup guard: exclusive flock on the crypto store; supersede any predecessor instance (kills the orphan-process Olm-store racing that silently broke inbound decryption). Complements fix/mcp-shutdown-zombie. Rebased on current main.
feat(mcp): single-instance store guard to stop crypto-store races
All checks were successful
check / check (pull_request) Successful in 3m14s
check / check (push) Successful in 3m13s
bcfe7b73cf
Claude Code spawns a fresh matrix-bridge-mcp child on every MCP
connect/reconnect but does NOT close the old child's stdin, so abandoned
instances accumulate (5 found live in the wild, back weeks) and race the
single Olm crypto store as the same device — which silently breaks
*inbound* decryption (the bridge can only decrypt its own outbound).

On startup, before MatrixBridgeClient::restore opens the store, take an
exclusive fs2 flock on <store>/.bridge.lock. If a predecessor holds it,
read its pid from the lock file and SIGTERM (then SIGKILL) it, then take
over — newest connection wins. Orphans can no longer accumulate.

Note: exit-on-stdin-EOF is already implemented via rmcp .waiting(), but
the EOF trigger never arrives for children Claude Code abandons without
closing the pipe, hence a startup-side guard is required. Complements the
fix/mcp-shutdown-zombie work rather than replacing it.
jmz merged commit bcfe7b73cf into main 2026-06-10 15:36:39 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
public/matrix-bridge!17
No description provided.