You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is asymmetric with the XDG path (line 274-288) which treats EX contention as "another instance running — warn and continue." The legacy path was designed as a #412 B1 cross-version mutex against pre-0.1.25 servers (whose data model could corrupt WAL if run concurrently with a 0.1.26+ server). But because it uses exclusive locking, it also blocks two 0.1.26 instances from coexisting — a side effect, not the intent.
Intended: "0.1.26 ⊗ pre-0.1.25 (no concurrent run)."
Actual: "0.1.26 ⊗ pre-0.1.25" AND "0.1.26 ⊗ 0.1.26" — the second breaks multi-project usage.
Fix
Change the legacy flock to LOCK_SH (shared). Shared locks compose with other shared locks but still conflict with exclusive locks, so:
Multiple 0.1.26 instances each hold LOCK_SH → coexist fine.
Reverse case: 0.1.26 starts when pre-0.1.25 already holds LOCK_EX → 0.1.26's LOCK_SH fails → 0.1.26 exits. ✓ still safe.
Also soften the exit path on flock failure — log a warning and return None (skip), mirroring the XDG path's "proceed with a warning" behavior. The pre-0.1.25 exit side of the mutex is preserved by the pre-0.1.25 process's own LOCK_EX logic.
Test plan
New unit test: two in-process fcntl.flock(…, LOCK_SH) on the same legacy file both succeed.
New integration test: two memtomem-server subprocesses started back-to-back both reach the ready state, both write pid files, both exit cleanly on SIGTERM.
Existing test_server_refuses_when_legacy_lock_held must be updated: the "pre-0.1.25 holder" simulator must use LOCK_EX (which is what real pre-0.1.25 did), and the new server's LOCK_SH attempt must still fail (so the existing mutex test still pins cross-version protection).
Problem
Running
memtomem-serverin one Claude Code session blocks all other sessions from connecting. Observed on 0.1.26.Repro:
memtomemconnects ✓memtomem→ Failed to connectpkill -f memtomem-server; rm -f ~/.memtomem/.server.pidkills everythingOnly one session can hold the connection at a time.
Root cause
_try_hold_legacy_flockinserver/__init__.py:230-240usesLOCK_EX(exclusive) on~/.memtomem/.server.pid, and on failure callssys.exit(1):This is asymmetric with the XDG path (line 274-288) which treats
EXcontention as "another instance running — warn and continue." The legacy path was designed as a #412 B1 cross-version mutex against pre-0.1.25 servers (whose data model could corrupt WAL if run concurrently with a 0.1.26+ server). But because it uses exclusive locking, it also blocks two 0.1.26 instances from coexisting — a side effect, not the intent.Intended: "0.1.26 ⊗ pre-0.1.25 (no concurrent run)."
Actual: "0.1.26 ⊗ pre-0.1.25" AND "0.1.26 ⊗ 0.1.26" — the second breaks multi-project usage.
Fix
Change the legacy flock to
LOCK_SH(shared). Shared locks compose with other shared locks but still conflict with exclusive locks, so:LOCK_SH→ coexist fine.LOCK_EXon the same path, per server: relocate.server.pidto $XDG_RUNTIME_DIR so~/.memtomem/stays lazy #412 docstring line 186-187) tries to acquire → fails → pre-0.1.25 exits. ✓ cross-version mutex preserved.LOCK_EX→ 0.1.26'sLOCK_SHfails → 0.1.26 exits. ✓ still safe.Also soften the exit path on flock failure — log a warning and return
None(skip), mirroring the XDG path's "proceed with a warning" behavior. The pre-0.1.25 exit side of the mutex is preserved by the pre-0.1.25 process's ownLOCK_EXlogic.Test plan
fcntl.flock(…, LOCK_SH)on the same legacy file both succeed.memtomem-serversubprocesses started back-to-back both reach the ready state, both write pid files, both exit cleanly on SIGTERM.test_server_refuses_when_legacy_lock_heldmust be updated: the "pre-0.1.25 holder" simulator must useLOCK_EX(which is what real pre-0.1.25 did), and the new server'sLOCK_SHattempt must still fail (so the existing mutex test still pins cross-version protection).Scope
Small.
_try_hold_legacy_flockflags + exit-path change + docstring update + 2-3 tests. CHANGELOG entry. Target v0.1.27.