Repository navigation
fix(bin): bound lock steals and stop false watcher-down alarms - #13
Merged
Merged
Conversation
Steal mutexes no longer nest, so a failed create cannot grow .steal.steal names; a signalled auto-arm hook now releases its lock and output. The pull guard treats a pending Stop-owned hand-off as healthy under the Claude auto-arm model. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01CBNsH4FtJ7oBS5wxLrRWac
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Fix three linked watcher-supervision defects in firstmate. (1) A lock steal must never re-suffix an already-stolen lock name: fm_lock_try_acquire recursed into $lock.steal.steal... on any persistent create failure (e.g. mktemp failing), growing the name without bound (observed as basename errors on state/.watch-cycle-exits.lock.steal.steal...); steal mutexes must not nest, with a regression test proving repeated steals keep a bounded name. (2) Identify who SIGTERMs freshly started watcher cycles: established it is the Claude harness signalling the Stop asyncRewake hook's process group (output 'watcher: started pid=N (beacon fresh)' then 'Terminated: 15', arm-interrupted ledger row), not firstmate code; this is intended, but the hook leaked its owner lock and .claude-autoarm-output.* files on TERM, so it now converts HUP/INT/TERM into an ordinary exit that cleans up; documented in docs/watcher-continuity.md. (3) The liveness beacon must reflect Stop-owned short cycles so the WATCHER DOWN banner is not raised falsely: under the Claude auto-arm model the pull guard treats a pending Stop-owned hand-off (epoch outcome rewake, or arming with no live hook owner, within FM_AUTOARM_HANDOFF_HOLD default 28800s) as healthy, while failed, expired, or live-hook-with-stale-beacon states still alarm; regression tests. Colocated tests pass and shellcheck (bin/fm-lint.sh) is clean. Known pre-existing unrelated failure: tests/fm-wake-queue.test.sh subshell check fails on macOS bash 3.2 (no BASHPID) on the base too. Do not touch the live home's state/. Brevity: commit subject plus at most 3 prose body lines; PR description at most 5 lines plus footer.
What Changed
fm_lock_try_acquireinbin/fm-wake-lib.shno longer nests steal mutexes, so a create that keeps failing (for example, whenmktempfails) now returns rc=1 instead of recursing into an ever-longer.steal.steal...lock name.rewakeoutcome, or arming with no live hook owner, withinFM_AUTOARM_HANDOFF_HOLD(default 28800s). Failed, expired, and live-hook-with-stale-beacon states still raise WATCHER DOWN.bin/fm-claude-stop-autoarm.shturns HUP/INT/TERM into a normal exit, so the harness's intended SIGTERM of the Stop hook's process group now releases the owner lock and removes the.claude-autoarm-output.*files. This is documented indocs/watcher-continuity.mdanddocs/turnend-guard.md, and each fix has a regression test.Risk Assessment
✅ Low: The three fixes are narrowly scoped and each has a regression test. Steal locks now return on a failed create instead of growing longer names, and the final claim still checks that the steal lock points to the claimer's owner directory, so two processes can't both take the main lock. The hook's signal traps route through the existing EXIT cleanup. The hand-off check only suppresses the alarm for recent
rewakeorarmingrecords with no live hook owner, and failed, expired, and wedged states still alarm.Testing
I ran the three test files that cover this change (watcher lock, guard stale banner, Claude Stop auto-arm), and all pass. To confirm the new tests catch the original bugs, I ran them against the base
bin/code, where each one fails on its regression case. I also ran a manual before/after demonstration of the lock-steal runaway withmktempforced to fail. The base code keeps recursing, reaching a lock name of 807 characters of.steal.steal...in 3 seconds, while the fixed code fails at once with a bounded name. There is no UI surface, so the evidence is CLI transcripts and test logs. All scratch state was temporary and the live home'sstate/was not touched.Evidence: Lock-steal runaway before/after transcript
BASE 41e6101: still running after 5s, killed; bash -x trace shows lockdir arg growing to 807 chars: <state>/.watch-cycle-exits.lock.steal.steal.steal... FIX b5fedee: fm_lock_try_acquire rc=1 immediately; only .watch-cycle-exits.lock remainsEvidence: Base-code bash -x trace of unbounded steal recursion
Evidence: New regression tests failing against base code
Evidence: Watcher lock tests (change)
Evidence: Guard stale-banner tests (change)
Evidence: Claude Stop auto-arm tests (change)
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
bash tests/fm-watcher-lock.test.sh(includes the new tests test_lock_repeated_steals_keep_bounded_name and test_lock_failed_create_does_not_recurse_into_steal_names): passesbash tests/fm-guard-stale-banner.test.sh(includes the new tests test_autoarm_stale_beacon_is_healthy_while_stop_handoff_pending and test_autoarm_handoff_does_not_mask_real_lapses): passesbash tests/fm-claude-stop-autoarm.test.sh(includes the new test test_signalled_hook_releases_owner_lock_and_output): passesSwapped in the base (41e6101)bin/fm-wake-lib.shandbin/fm-claude-stop-autoarm.shand ran all three test files. Each fails on its new regression test (steal recursion, false WATCHER DOWN banner on rewake, leaked autoarm output). Restored the change's files afterwards and the worktree is cleanManual before/after run:fm_lock_try_acquireon a stale.watch-cycle-exits.lockin a scratch state dir withmktempforced to fail. The base code never returns and, in abash -xtrace, its lockdir argument reaches 807 characters of.steal.steal...within 3 seconds. The fixed code returns rc=1 right away and leaves only the original lock✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.