Repository navigation
Conversation
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Reviews (3): Last reviewed commit: "merge(main): resolve lock-steal-recursio..." | Re-trigger Greptile |
Reviewer note: which lock the race regression test drives, and why it matters
The double-publish window opens between the primary reclaim's staleness re-proof and its publish. This is worth stating because the first version of this fix was validated with a 40-racer hammer on a plain lock and passed, while the hole was real. The test creates the stalls by copying the two real functions with |
|
Speaking as Kun's firstmate: Corrective for #2787: VISION (per rule):
Security: none. Workflows approved this pass after a clean diff review (CI 32573464807, Require no-mistakes 32573464806). Class: corrective. Overlap: CI: no structured Ahead 7, behind 0, mergeable, mergeStateStatus UNSTABLE. Not merge-eligible. Waiting on the author for a green no-mistakes raise whose body attestation matches this HEAD ( |
…lock fm_lock_try_acquire treated a lock it could not create as a stale lock to recover, then serialized that recovery by calling itself on "<lock>.steal". For a steal mutex that meant "<lock>.steal.steal", and so on with no base case, so a filesystem that refused every create walked the name down a chain of .steal suffixes until the path was rejected. Reproduced on a full filesystem and on an unwritable lock parent: over 1400 suffixes, 6.3 MB of stderr, and bash itself killed by SIGSEGV before the chain could stop. A steal mutex is now a leaf: it reclaims its own stale holder directly and never appends a second .steal, for internal callers and for fm_autoarm_release_abandoned alike. The mutex is kept, because it is what stops two processes both publishing the primary lock; the reclaim stays exclusive because a live holder is never evicted, and two racers on a dead holder are separated by the ownership rechecks the primary reclaim already performs before it touches the lock. Creation failure is also now separated from contention. A create that leaves no lock behind means the filesystem refused, not that a holder exists, so acquisition refuses there instead of entering recovery with nothing to recover. FM_LOCK_FAIL_REASON reports which of the two happened, and the refusal explains itself once to the operator rather than being silent until the path grows too long to print. fm_lock_acquire_wait keeps blocking rather than returning, so no caller can walk into its critical section believing it holds a lock it never got. Legacy .steal chains already on disk are swept when stale and left alone when a holder is still live, so a rolling update cannot evict one.
BSD wc -l pads its count with leading blanks, so comparing an unstripped "$(wc -l < ...)" against a bare 1 can never match on macOS and the three one-line report assertions failed there while passing on GNU coreutils in CI. One count in the same file already stripped; these three did not.
… steal-bound coverage
…e locks in three consumers
…ntion, cover last two consumers
…uisition regressions
14442f0 to
49011bd
Compare
main rewrote the Claude Stop auto-arm single-flight from a held owner
lock to the generation ledger (fm_autoarm_claim_open/fm_autoarm_claim_next)
while this branch was bounding the .steal recursion and giving a
filesystem-refused lock a voice. Both survive:
- bin/fm-claude-stop-autoarm.sh keeps main's generation claim and the
legacy shim, and reports FM_LOCK_FAIL_REASON=unavailable at each of the
three points that used to exit silently - the claim itself, the legacy
reclaim, and the retry after it.
- fm_autoarm_release_abandoned keeps main's grace argument, the TERM of a
live identity-verified legacy owner and the ledger graft, and re-proves
the steal mutex still points at this process immediately before removing
the lock. That re-proof moved after the TERM wait and the graft, which
are several forks wider than the window it originally guarded.
- fm_lock_try_acquire keeps its steal-mutex routing to the new leaf, and
both it and fm_lock_try_acquire_leaf read their own pid through main's
fm_current_pid rather than an inline ${BASHPID:-$$}, so the self-held
reclaim check survives stock Bash 3.2.
- docs/configuration.md keeps main's FM_LOCK_STALE_AFTER wording beside
this branch's two new lock tunables.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V8NBG3Uj6iwDBp7xJe9bSc
Keep both sides in every hunk. The two sides only collided because each added material at the same spot, so no lock behaviour had to be chosen over anything main does. - docs/configuration.md: keep this branch's FM_LOCK_UNAVAILABLE_REPORT_EVERY and FM_LOCK_LEGACY_STEAL_SCAN_MAX entries, and take main's newer FM_GUARD_GRACE wording. - tests/fm-claude-stop-autoarm.test.sh: keep the two uncreatable-lock refusal tests and main's long-poll grace and supervision-host tests, and call all of them. - tests/fm-watch-arm.test.sh: keep the two refused cycle-ledger tests and main's launch-confirm-window refusal test, and call all of them. - tests/fm-watcher-lock.test.sh: keep this branch's lock-refusal and steal-bound tests, and main's wait-deadline reap test call.
… eviction Keep both sides. - bin/fm-watch.sh: main turned the single watcher-lock acquire into a retry loop that can evict a holder whose beacon stalled past a hard bound. The branch's refusal for a lock the filesystem cannot create now runs first in that loop body, so an unavailable lock still exits 1 saying no watcher is running before any held-lock or eviction handling. Where the two could disagree, the lock-safety refusal wins: eviction only ever applies to a lock that is genuinely held. - docs/watcher-continuity.md: take main's bulleted coverage list and new section heading, keep the branch's acquisition-primitive coverage paragraph, and keep the branch's unavailable-lock limits after main's reworded opening sentence.
Intent
Fix the conflicts on #2796 so it can merge.
The PR is "fix(bin): bound lock stealing to one .steal level and refuse uncreatable locks" on branch fm/fm-lock-steal-recursion. It is open, not a draft, and GitHub reports it dirty against main.
What the PR does, because you must not change its behaviour while resolving:
fm_lock_try_acquire in bin/fm-wake-lib.sh serialized a stale-owner reclaim through a steal mutex by calling itself with "$lockdir.steal". When the steal lock itself looked stale it recursed on "$lockdir.steal.steal", with no depth bound and no base case, walking down a chain of .steal suffixes until the path exceeded the filesystem limit. It was hit for real on this machine while it was out of disk space, filed as issue #2787. The fix bounds the steal to exactly one level, and makes a lock that cannot be created refuse rather than proceed, because two sessions both believing they hold the home's session lock is the exact failure the mechanism exists to prevent.
Deliberate decisions already taken on this PR, which stand and must be preserved:
What Changed
fm_lock_try_acquireinbin/fm-wake-lib.shno longer calls itself on"$lockdir.steal". It now reclaims a stale owner through a single steal mutex using a new non-recursivefm_lock_try_acquire_leaf, which claims a stale lock by renaming it aside. The steal mutex still serializesfm_autoarm_release_abandoned, which now also checks that it still owns the steal mutex before going on. Chains of.stealdirectories left by the old recursive code are cleared one level at a time, stopping at the first live or fresh level.FM_LOCK_LEGACY_STEAL_SCAN_MAX(default 8) caps how many levels are walked. A leftover steal mutex next to a missing primary lock is now reclaimed instead of being read as a held lock.FM_LOCK_FAIL_REASONtellsunavailableapart fromheld, working from theln -serror and whether the path exists. If a creation race's winner releases the lock before the loser checks, the loser retries once instead of reporting a refusing filesystem. The explanation is printed on stderr, throttled byFM_LOCK_UNAVAILABLE_REPORT_EVERY(default 100).unavailabledistinctly.fm-watch.shexits nonzero saying no watcher is running and none was started. The Claude Stop auto-arm prints on stderr that supervision is not running for this home, and still exits 0. The turn-end guard (block budget), the cycle-ledger writes infm-watch-arm.sh, the watch-delivery record infm-push-transition-lib.shand herdr session cleanup each name the record or lock the filesystem refused, instead of passing silently or calling it busy.docs/configuration.mdanddocs/watcher-continuity.mddocument the new knobs and behaviour, and the lock, auto-arm, turn-end, watch-arm, herdr-cleanup and supervision-events test suites gain coverage for them.Risk Assessment
Testing
I ran every test file the PR touches on the merge commit. That includes the bounded-steal, unavailable-lock and live-holder tests, and main's test that evicts a watcher whose beacon stalled past the hard bound. All passed except one watch-arm test that fails intermittently; the same test fails at a similar rate on an untouched copy of base 1a814e4, so it is not caused by this merge. I also ran three manual CLI scenarios and saved a transcript. In the first, a lock whose
.stealmutex was also stale was acquired without creating a.steal.stealchain. In the second, a lock that couldn't be created was refused and reported asunavailable. In the third, the mergedfm-watch.shloop exits 1 with its 'no watcher is running' message when it can't create its lock. Overall result: the PR's behaviour is preserved. The temporary base copy and scratch directories were deleted and the worktree is clean.Evidence: Manual CLI transcript: bounded steal, unavailable refusal, watcher refusal in the merged loop
Scenario 1 (dead-pid lock + dead-pid .steal): acquire rc=0; paths: .contend.lock, .contend.lock.owner.* (no .steal.steal) Scenario 2 (lock parent not writable): fm_lock: … cannot create the lock and none exists to reclaim …; refusing to acquire acquire rc=1 reason=unavailable held_pid=none; steal paths created: 0 Scenario 3 (fm-watch.sh, state dir not writable): watcher: cannot create …/.watch.lock - the filesystem refused the operation …; no watcher is running and none was started. fm-watch.sh exit=1Evidence: Test-run log for the PR's test files
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-watch.sh:2372- The conflict-resolved hunk puts the unavailable-lock refusal at the top of main's new stalled-holder eviction retry loop, so it now runs before any held-lock or eviction handling. The ordering is correct: FM_LOCK_FAIL_REASON is reset on every fm_lock_try_acquire call, so acontinueafter an eviction cannot carry over a stale reason, and eviction only ever applies to a held lock. However, no test runs fm-watch.sh against an uncreatable .watch.lock and checks that it exits 1 with the 'no watcher is running and none was started' message. The only coverage is at the library level (fm-watcher-lock.test.sh reason=unavailable), so a later reordering of this loop could make it fall back to 'already running'/exit 0 without any test failing. Optional follow-up.tests/fm-watch-arm.test.sh:1143- The test 'watcher pid … outlived its deleted state directory' (added on main by fix(bin): refuse watchers from disposable checkouts and exit when the home is gone #5552) fails intermittently. It failed in 3 of 4 runs on the merge commit and in 2 of 4 runs on an untouched copy of the base commit 1a814e4 (main). So the flakiness is already on main and wasn't introduced by this merge. The PR's own watch-arm cases, including the watcher's refusal when it can't create its lock, passed in every run.bin/fm-test-run.sh tests/fm-watcher-lock.test.sh tests/fm-watch-arm.test.sh tests/fm-claude-stop-autoarm.test.sh tests/fm-herdr-session-cleanup.test.sh tests/fm-turnend-guard.test.sh tests/fm-supervision-events.test.shon the merge commit (every file the PR touches): all pass except the one watch-arm flakebin/fm-test-run.sh tests/fm-watch-arm.test.shrun 3 more times on the merge commit (1 pass, 2 hit the same flake)bin/fm-test-run.sh tests/fm-watch-arm.test.shrun 4 times on a clean copy of base 1a814e4 (2 pass, 2 hit the same flake, so it is pre-existing)Manual:fm_lock_try_acquireon a lock and.stealmutex both held by a dead pid (the #2787 setup): acquires, and no.steal.stealchain is createdManual:fm_lock_try_acquirewith a lock parent that isn't writable: rc=1, reason=unavailable, no held pid, no.stealpaths createdManual:bin/fm-watch.shwith a state directory that isn't writable: prints 'cannot create … no watcher is running and none was started.' and exits 1 through the merged retry and eviction loop✅ **Document** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.