Repository navigation
fix: recover stale directory locks during session startup - #8381
Conversation
[Medium impact] The PR appears safe to merge; the permission-error hang is fixed and no new blocking issue was found. Reviews (2) · Last reviewed commit: "no-mistakes(ci): Fixed the shared reaper..." · Reviewed by Greptile |
…lock directories while keeping replacements retriable. Non-root permission, both session paths, recovery/race regressions, and pinned lint pass. Scratch files cleaned
|
Speaking as Kun's firstmate: thanks @WTF-Am-ID. I read the full diff on The no-mistakes attestation binds this head with no skipped steps. Live validation was 7 of 7, Greptile is 5/5, the earlier P1 is fixed and resolved, and the quick checks pass. I've queued the full suite ( |
|
Speaking as Kun's firstmate: this is merged. Thank you @WTF-Am-ID — really appreciate you taking the time on this. |
Resolve conflicts with upstream's real-directory lock recovery (kunchenguid#8381): the non-symlink directory-record checks run first, and upstream's raw-directory branches follow unchanged. Drop the PR test that pinned the pre-kunchenguid#8381 refusal to reap a dead raw directory, which upstream now reaps on the native path.
Fixes #8275
Restored recovery when stale session and Stop-hook locks are real directories containing dead owner records.
Cleanup preserves live nested owners, unknown files and concurrently published successor locks.
Session acquisition now names an unreclaimable directory, including a stable directory without search permission, while ordinary waits and concurrent replacements remain retriable.
Failed creates discard their staging directories, and watcher identity checks work through symlinked homes.
The pipeline passed the watcher-lock closure suite, seven live CLI scenarios, and focused non-root permission and replacement regressions.
The baseline reproduced the hang, while the candidate recovered the dead-directory shape in 0.217 seconds.
Pinned lint passed.
Greptile reviewed final head
c6bd3c191c985c8cd9fc0f40b89fd9bede6342f8at 5/5.The only failing check waits for a maintainer to add the
full-cilabel.WSL drvfs behavior has not been verified.
Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 1 issue found → auto-fixed ✅
bin/fm-wake-lib.sh:862- Recorded round-1 fix decision is still unapplied at 783954b. fm_lock_reap_dead_directory calls fm_lock_holder_alive with $lock_abs (pwd -P resolved), but fm_lock_holder_alive (bin/fm-wake-lib.sh:630) applies the watch-lock pid-identity check only when the path string equals "$STATE/.watch.lock", and STATE is logical (bin/fm-wake-lib.sh:5-9 and bin/fm-watch.sh:221 usepwd, notpwd -P). Sequence: FM_HOME under a symlink (macOS /tmp or /var/folders, or a symlinked home); a legacy real-dir .watch.lock with a live pid, a mismatched pid-identity and no pid-start. fm_lock_try_acquire (logical path) judges it stale through the identity mismatch, publishes .watcher-down, then calls fm_lock_remove_path stale (bin/fm-wake-lib.sh:1614). The reaper skips the identity check, sees the live pid, and exits 1 without setting FM_LOCK_RECLAIM_FAILED_PATH, so every acquisition silently fails. Before this change the stale path removed the directory unconditionally, so this is a regression. test_lock_reclaims_holder_whose_identity_no_longer_recomputes passes only because tests/lib.sh:441 resolves the test root physically. Fix: key the watch-lock test in fm_lock_holder_alive on file identity ([ "$lockdir" -ef "$STATE/.watch.lock" ]) instead of string equality, or check the reaper's liveness against the caller's unresolved lockdir. Sibling site bin/fm-wake-lib.sh:847 (fm_lock_nested_owners_stale) holds the same invariant but is unaffected because nested owner paths never equal the watch lock.🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
TMPDIR="$PWD/.test-8275/tmp" bash bin/fm-test-run.sh tests/fm-watcher-lock.test.shbash tests/fm-watcher-lock.test.shwith seven focused directory, cleanup, race, and identity selectorsVerified child completion, removed disposable fixtures, and confirmed a clean worktree.✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
Issues
Closes #8275