Skip to content

fix: recover stale directory locks during session startup - #8381

Merged
kunchenguid merged 4 commits into
kunchenguid:mainfrom
WTF-KRP:fm/up-fm-8275
Nov 12, 2026
Merged

kunchenguid merged 4 commits into
kunchenguid:mainfrom
WTF-KRP:fm/up-fm-8275

Conversation

@WTF-Am-ID

@WTF-Am-ID WTF-Am-ID commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

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 c6bd3c191c985c8cd9fc0f40b89fd9bede6342f8 at 5/5.
The only failing check waits for a maintainer to add the full-ci label.
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 use pwd, not pwd -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.

  • Live validation: ✅ go - 7 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Acquire session and Stop-hook locks after synthetic dead-directory residue on local macOS ✅ pass live live-lock-results.json: recover-nested, recover-top-level, stop-hook-lock-recovery; baseline-repro.jsonl
Attempt reclamation with a live nested owner and preserve its lock despite old timestamps ✅ pass live live-lock-results.json: live-nested, live-nested.steal
Acquire an unreapable session claim and receive a prompt refusal naming the exact path ✅ pass live live-lock-results.json: refuse-primary, refuse-steal, own-refuse
Use ordinary acquisition waiting and acquire only after blocking residue is removed ✅ pass live live-lock-results.json: ordinary-wait-before-release, ordinary-wait-after-release
Repeatedly attempt publication onto an existing directory without leaking owner directories ✅ pass live live-lock-results.json: failed-create-cleanup
Recover a stale watcher identity through a symlinked home while protecting matching and unrecorded live identities ✅ pass live live-lock-results.json: logical-home-identity-mismatched, matching, unrecorded
Race concurrent reclaimers without deleting the winning successor lock ✅ pass live live-lock-results.json: concurrent-reapers-0 through concurrent-reapers-2
  • TMPDIR="$PWD/.test-8275/tmp" bash bin/fm-test-run.sh tests/fm-watcher-lock.test.sh
  • bash tests/fm-watcher-lock.test.sh with seven focused directory, cleanup, race, and identity selectors
  • Verified 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

@greptile-apps

greptile-apps Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[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

Comment thread bin/fm-wake-lib.sh Resolved
…lock directories while keeping replacements retriable. Non-root permission, both session paths, recovery/race regressions, and pinned lint pass. Scratch files cleaned
@kunchenguid kunchenguid added the full-ci Maintainer go-ahead: run the full CI suite on this outside pull request label Nov 12, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @WTF-Am-ID. I read the full diff on c6bd3c19 against main a02b0898. Stale real-directory locks are reaped only when the top-level holder and every nested owner record are dead. Unknown contents and successor links are never touched. Failed creates no longer leak owner directories. The new named refusal is opt-in, and only fm-lock.sh's two claim waits use it. This is a restore for #8275: the default lock path already recovers dead holders, and this leftover shape broke that recovery.

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 (full-ci). Nothing is waiting on you right now.

@kunchenguid kunchenguid added full-ci Maintainer go-ahead: run the full CI suite on this outside pull request and removed full-ci Maintainer go-ahead: run the full CI suite on this outside pull request labels Nov 12, 2026
@kunchenguid
kunchenguid merged commit 42ec97f into kunchenguid:main Nov 12, 2026
94 of 102 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @WTF-Am-ID — really appreciate you taking the time on this.

ironerumi added a commit to ironerumi/firstmate that referenced this pull request Nov 15, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-ci Maintainer go-ahead: run the full CI suite on this outside pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lock acquisition spins forever when a lock path is a real directory instead of a symlink

2 participants