fix(lock): wait before failing palace writer lock - #1978
Conversation
|
@fatkobra the acquired path never releases the flock or closes the file: the old outer finally did LOCK_UN plus lf.close(), the new one only closes when The dead-PID remove is racy too: a dead holder's flock is already released by the OS, so the file can be locked as-is and the stale identity just gets overwritten by the next Most of the CI failures are existing tests pinning the documented fail-fast contract ("exit cleanly instead of piling up as a waiting worker"), so default-on waiting is a behavior change for every caller, including hook-spawned mines. That trade-off is an open discussion in #1888, and #1826 added the opt-in queued-writes daemon for it. This also rewrites the same lines as #1971 and your #1977, so these can't land independently. (The 3.9 collection errors: |
|
Thanks @mvalentsev — I agree with this review. I’m going to stop pushing fixes to this PR in its current form. The patch changes I also agree that removing the lock file by pathname is unsafe because it can split contenders across different inodes. And the acquired-path release bug means this PR can create the same starvation/self-deadlock symptom it is trying to fix. I’ll close this rather than keep patching around CI. The safer direction for #1920 seems to be queueing through the existing opt-in daemon path, not changing the global lock semantics for every caller. |
What does this PR do?
Closes and Fixes #1920 by making
mine_palace_lock()bounded-wait instead of immediate fail-fast.The previous behavior raised
MineAlreadyRunningimmediately whenever a transient mine/hook/MCP holder had the palace lock. That turns ordinary overlap into lost writes and retry storms.This PR changes the lock behavior to:
MEMPALACE_MINE_PALACE_LOCK_WAIT_SECONDS, default 30s;MEMPALACE_MINE_PALACE_LOCK_POLL_SECONDS, default 250ms;MineAlreadyRunningmessage after the bounded wait expires.Why this shape
The issue proposed bounded wait plus liveness checking. This implements the safe part of liveness recovery: dead-PID cleanup. It deliberately does not steal an alive-but-idle process because local Chroma/HNSW writes remain unsafe under concurrent multi-process access.
How to test
Added
tests/test_palace_lock_wait.pycovering:Run:
Checklist
python -m pytest tests/ -v)ruff check .)