Skip to content

fix(bin): bound lock steals and stop false watcher-down alarms - #13

Merged
Hozzy02 merged 2 commits into
mainfrom
fm/fm-watch-lock-steal-runaway
Sep 25, 2026
Merged

Hozzy02 merged 2 commits into
mainfrom
fm/fm-watch-lock-steal-runaway

Conversation

@Hozzy02

@Hozzy02 Hozzy02 commented Sep 25, 2026

Copy link
Copy Markdown
Owner

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_acquire in bin/fm-wake-lib.sh no longer nests steal mutexes, so a create that keeps failing (for example, when mktemp fails) now returns rc=1 instead of recursing into an ever-longer .steal.steal... lock name.
  • Under the Claude auto-arm model, the pull guard now counts a pending Stop-owned hand-off as healthy: an epoch rewake outcome, or arming with no live hook owner, within FM_AUTOARM_HANDOFF_HOLD (default 28800s). Failed, expired, and live-hook-with-stale-beacon states still raise WATCHER DOWN.
  • bin/fm-claude-stop-autoarm.sh turns 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 in docs/watcher-continuity.md and docs/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 rewake or arming records 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 with mktemp forced 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's state/ 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 remains

### BASE 41e6101
(still running after 5s — killed)
longest lock name under state/:
23 .watch-cycle-exits.lock
lock entries: 1

### FIX b5fedee
   1 fm_lock_try_acquire rc=1
longest lock name under state/:
23 .watch-cycle-exits.lock
lock entries: 1

### BASE bash -x trace (3s, mktemp failing)
longest lockdir argument: 807 chars: <state>/.watch-cycle-exits.lock.steal.steal.steal... (unbounded)
### FIX: returns rc=1 immediately, only .watch-cycle-exits.lock remains
Evidence: Base-code bash -x trace of unbounded steal recursion
+ . /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/no-mistakes-evidence/01M3B97TD0GPXDVRJ17GBZ9HZR/base-fm-wake-lib.sh
++++ dirname /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/no-mistakes-evidence/01M3B97TD0GPXDVRJ17GBZ9HZR/base-fm-wake-lib.sh
+++ cd /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/no-mistakes-evidence/01M3B97TD0GPXDVRJ17GBZ9HZR
+++ pwd
++ FM_WAKE_LIB_DIR=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/no-mistakes-evidence/01M3B97TD0GPXDVRJ17GBZ9HZR
+++ cd /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/no-mistakes-evidence/01M3B97TD0GPXDVRJ17GBZ9HZR/..
+++ pwd
++ FM_WAKE_DEFAULT_ROOT=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/no-mistakes-evidence
++ FM_ROOT=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/no-mistakes-evidence
++ FM_HOME=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/no-mistakes-evidence
++ STATE=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH
++ FM_WAKE_QUEUE=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.wake-queue
++ FM_WAKE_QUEUE_LOCK=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.wake-queue.lock
++ FM_LOCK_STALE_AFTER=0
+++ uname
++ _FM_UNAME=Darwin
++ mkdir -p /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH
++ FM_WATCHER_MATCHED_IDENTITY=
++ FM_WATCHER_HEALTHY_PID=
++ FM_WATCHER_HEALTHY_IDENTITY=
++ FM_WATCHER_VERDICT_OK=false
++ FM_WATCHER_VERDICT_REASON=stale-beacon
++ FM_RECOVERY_MARKER_TOKEN=
++ FM_RECOVERY_MARKER_ACTION=none
++ FM_WAKE_STATUS_KEY=
++ FM_WAKE_STATUS_HISTORICAL=false
++ FM_WAKE_EVENT_LINE=
++ FM_WAKE_UNREAD_LINES=
+ fm_lock_try_acquire /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock
+ local lockdir=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock pid steal cur rc steal_owner primary_owner
+ FM_LOCK_HELD_PID=
+ FM_LOCK_OWNER_DIR=
+ FM_LOCK_RECOVERED_PID=
+ fm_lock_try_create /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock
+ local lockdir=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock allowed_steal_owner= ownerdir
+ FM_LOCK_OWNER_DIR=
++ fm_lock_owner_dir /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock
++ local lockdir=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock lock_abs
+++ fm_lock_abs_path /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock
+++ local path=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock dir base
++++ dirname /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock
+++ dir=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH
++++ basename /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock
+++ base=.watch-cycle-exits.lock
++++ cd /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH
++++ pwd -P
+++ dir=/private/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH
+++ printf '%s/%s\n' /private/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH .watch-cycle-exits.lock
++ lock_abs=/private/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock
++ mktemp -d /private/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.owner.XXXXXX
+ ownerdir=
+ return 1
++ cat /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock/pid
+ pid=999999
+ '[' -n 999999 ']'
+ '[' 999999 = 86303 ']'
+ fm_pid_alive 999999
+ local pid=999999
+ case "$pid" in
+ kill -0 999999
+ fm_lock_mid_acquire_is_fresh /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock 999999
+ local lockdir=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock pid=999999 mid_acquire_stale
+ case "$pid" in
+ return 1
+ steal=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal
+ fm_lock_try_acquire /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal
+ local lockdir=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal pid steal cur rc steal_owner primary_owner
+ FM_LOCK_HELD_PID=
+ FM_LOCK_OWNER_DIR=
+ FM_LOCK_RECOVERED_PID=
+ fm_lock_try_create /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal
+ local lockdir=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal allowed_steal_owner= ownerdir
+ FM_LOCK_OWNER_DIR=
++ fm_lock_owner_dir /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal
++ local lockdir=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal lock_abs
+++ fm_lock_abs_path /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal
+++ local path=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal dir base
++++ dirname /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal
+++ dir=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH
++++ basename /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal
+++ base=.watch-cycle-exits.lock.steal
++++ cd /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH
++++ pwd -P
+++ dir=/private/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH
+++ printf '%s/%s\n' /private/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH .watch-cycle-exits.lock.steal
++ lock_abs=/private/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal
++ mktemp -d /private/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal.owner.XXXXXX
+ ownerdir=
+ return 1
++ cat /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal/pid
++ true
+ pid=
+ '[' -n '' ']'
+ fm_pid_alive ''
+ local pid=
+ case "$pid" in
+ return 1
+ fm_lock_mid_acquire_is_fresh /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal ''
+ local lockdir=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal pid= mid_acquire_stale
+ case "$pid" in
+ mid_acquire_stale=0
+ '[' 0 -lt 2 ']'
+ mid_acquire_stale=2
++ fm_path_age /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal
++ local path=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal m
+++ fm_path_mtime /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal
+++ '[' Darwin = Darwin ']'
+++ stat -f %m /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal
++ m=
++ echo 999999
++ return
+ '[' 999999 -lt 2 ']'
+ return
+ steal=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal.steal
+ fm_lock_try_acquire /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal.steal
+ local lockdir=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal.steal pid steal cur rc steal_owner primary_owner
+ FM_LOCK_HELD_PID=
+ FM_LOCK_OWNER_DIR=
+ FM_LOCK_RECOVERED_PID=
+ fm_lock_try_create /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal.steal
+ local lockdir=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal.steal allowed_steal_owner= ownerdir
+ FM_LOCK_OWNER_DIR=
++ fm_lock_owner_dir /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal.steal
++ local lockdir=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal.steal lock_abs
+++ fm_lock_abs_path /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exit

... [1298984 bytes truncated] ...

steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal
++ local lockdir=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal lock_abs
+++ fm_lock_abs_path /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal
+++ local path=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal dir base
++++ dirname /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal
+++ dir=/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH
++++ basename /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal
+++ base=.watch-cycle-exits.lock.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal
++++ cd /var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH
++++ pwd -P
+++ dir=/private/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH
+++ printf '%s/%s\n' /private/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH .watch-cycle-exits.lock.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal
++ lock_abs=/private/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal
++ mktemp -d /private/var/folders/t1/8htjz3j91cqcfslff4w76zqc0000gn/T/tmp.FPEzfSuSfH/.watch-cycle-exits.lock.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.steal.owner.XXXXXX
Evidence: New regression tests failing against base code
fm-watcher-lock (base bin): not ok - a failing steal create recursed instead of returning
fm-guard-stale-banner (base bin): not ok - auto-arm hand-off (rewake) with a stale beacon must stay silent, got: WATCHER DOWN banner
fm-claude-stop-autoarm (base bin): Terminated: 15 ... not ok - a signalled hook leaked the arm's captured output
Evidence: Watcher lock tests (change)
ok - simultaneous watcher starts leave exactly one live process
ok - fm_pid_identity real ps fallback is locale-invariant
ok - fm_pid_identity is locale-invariant across LC_ALL/LC_TIME
ok - /proc process identity ignores simulated btime changes
ok - /proc process identity detects pid reuse
ok - MSYS /proc process identity regression skipped on non-Windows host
ok - killed watcher stale lock is reclaimed
tests/fm-watcher-lock.test.sh: line 1109: 67979 Killed: 9               FM_STATE_OVERRIDE="$state" bash -c '
    . "$1"
    fm_lock_remove_path() {
      if [ "$1" = "$STATE/.watch.lock" ]; then
        kill -KILL "${BASHPID:-$$}"
      fi
      return 1
    }
    fm_lock_try_acquire "$2"
  ' _ "$LIB" "$lockdir" > /dev/null 2>&1
ok - stale watcher reclaim publishes durable recovery evidence before clear
ok - live watcher lock with stale heartbeat is actionable
ok - guard banner leads when down with pending wakes (repair-after-drain) and stays silent when live and fresh
ok - concurrent fm_lock_try_acquire yields exactly one winner
ok - dead-pid stale lock is reclaimed by a single acquirer
ok - concurrent stale-lock steal yields exactly one winner
ok - live steal mutex is not reclaimed
ok - repeated steals keep a bounded lock name
ok - a failing steal create returns instead of nesting steal names
ok - live-held lock is not stolen
ok - empty mid-acquire lock keeps a minimum grace
ok - late original claimant cannot claim a recreated lock
ok - paused mid-acquire claimant backs off to active stealer
ok - watch restart preserves recovery without signaling a reused pid
ok - watch restart attaches to a verified healthy peer and later surfaces a successor gap
ok - watcher self-evicts when the lock pid no longer names it
ok - arm turns clean self-eviction without a successor into a typed failure
ok - arm attaches to a live fresh watcher and fails loudly when that cycle has no successor
ok - attached arm signals record a classified lifecycle entry
ok - arm starts cleanly and resurfaces recovery after a dead-pid lock
ok - arm cleans child watcher and temp output on HUP
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 86640.1790306531.eKTl09
ok - arm propagates an immediate watcher wake before confirmation
ok - arm attaches to a peer watcher after child stands down and surfaces a missing successor
watcher: lock held by live pid 88590 but heartbeat is stale for 843603735s (>300s); inspect or stop that watcher before re-arming.
ok - arm reports FAILED and exits non-zero when no fresh watcher can be confirmed
ok - cycle-exit ledger links a verified successor and remains size-capped
ok - SIGSTOP distinguishes live PID from stale beacon and termination records the exit class
Evidence: Guard stale-banner tests (change)
ok - fm-guard stale banner: first stale call prints the full actionable banner
ok - fm-guard stale banner: repeated same-episode calls print a concise reminder only
ok - fm-guard stale banner: Pi and pi-signed primaries route themselves to the extension model
ok - fm-guard stale banner: extension-owned hand-off with a live session is healthy
ok - fm-guard stale banner: extension-owned empty lock is genuinely unheld
ok - fm-guard stale banner: held unhealthy extension locks stay loud
ok - fm-guard stale banner: extension model without ownership evidence stays loud
ok - fm-guard stale banner: every extension-ownership signal is load-bearing
ok - fm-guard stale banner: extension model still alarms on a genuinely stale beacon
ok - fm-guard stale banner: queued-wake warning survives the extension hand-off tolerance
ok - fm-guard stale banner: persistent primaries ignore Pi extension evidence
ok - fm-guard stale banner: extension model stays silent for a live watcher
ok - fm-guard stale banner: auto-arm fresh beacon without a live watcher is healthy
ok - fm-guard stale banner: auto-arm stale beacon alarms with the true reason
ok - fm-guard stale banner: auto-arm stale episode stays one episode across calls
ok - fm-guard stale banner: auto-arm stale beacon is healthy while a Stop-owned hand-off is pending
ok - fm-guard stale banner: a pending hand-off never masks failed, expired, or wedged auto-arm
ok - fm-guard stale banner: persistent no-watcher banner names the true reason
ok - fm-guard stale banner: a no-watcher episode survives a beacon mtime change
ok - fm-guard stale banner: a fresh beacon without a live watcher remains unhealthy
ok - fm-guard stale banner: X-mode polling without a live watcher remains unhealthy
ok - fm-guard stale banner: healthy recovery rearms the next stale episode
ok - fm-guard stale banner: concurrent same-episode calls claim exactly one full banner
ok - fm-guard stale banner: deduplication is isolated per FM_HOME
ok - fm-guard stale banner: queued-wake warning remains independent
ok - fm-guard stale banner: read-only before writable does not consume full banner
ok - fm-guard stale banner: read-only during episode observes without mutating marker
ok - fm-guard stale banner: healthy read-only does not clear marker
ok - fm-guard stale banner: read-only never mutates stale-banner state files
Evidence: Claude Stop auto-arm tests (change)
ok - auto-arm: inert in a linked child worktree even when in-flight
ok - auto-arm: inert with no session lock
ok - auto-arm: a demonstrably dead recorded session owner is reclaimed through fm-lock.sh before arming
ok - auto-arm: inert without arm, rewake, or lock replacement when another live harness owns the home
ok - auto-arm: inert while AFK owns supervision
ok - auto-arm: stale-owner recovery leaves the AFK and supervision-need gates unchanged
ok - auto-arm: resolves the outermost pid of a nested contiguous claude ancestry (bg-spare chain)
ok - auto-arm: inert with nothing in flight and no X-mode need
ok - auto-arm: actionable close translates to exactly one exit-2 rewake with reason
ok - auto-arm: actionable close survives a healthy successor without duplicate delivery
ok - auto-arm: bounded failure verification emits one automatic-mechanism alarm
ok - auto-arm: consecutive failures keep Stop-owned retry without repeating notice
ok - auto-arm: unverified clean close exhausts retries and fails closed
ok - auto-arm: post-alarm actionable outcomes cannot continue or reset failure state
ok - auto-arm: benign cycle end with a live watcher and fresh beacon stays silent across the next cycle
ok - auto-arm: budget contention preserves the episode and forces a reset retry
ok - auto-arm: X-mode poll need arms the cycle even with no tasks in flight
ok - auto-arm: concurrent firings admit one owner and one rewake translation
ok - auto-arm: a signalled hook releases its owner lock and output
ok - auto-arm: need vanishing mid-cycle closes without a rewake
ok - auto-arm: mid-cycle AFK hands triage to the daemon with no rewake
ok - auto-arm: active in a marked secondmate home
ok - fm-lock: shared session-lock lib preserves the status path

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): passes
  • bash 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): passes
  • bash tests/fm-claude-stop-autoarm.test.sh (includes the new test test_signalled_hook_releases_owner_lock_and_output): passes
  • Swapped in the base (41e6101) bin/fm-wake-lib.sh and bin/fm-claude-stop-autoarm.sh and 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 clean
  • Manual before/after run: fm_lock_try_acquire on a stale .watch-cycle-exits.lock in a scratch state dir with mktemp forced to fail. The base code never returns and, in a bash -x trace, 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.

Hozzy02 and others added 2 commits September 24, 2026 23:19
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
@Hozzy02
Hozzy02 merged commit 4159b40 into main Sep 25, 2026
13 checks passed
@Hozzy02
Hozzy02 deleted the fm/fm-watch-lock-steal-runaway branch September 26, 2026 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant