Skip to content

fix(bin): re-arm after an abandoned auto-arm claim and defer a wedge escalation while a worktree is written - #2524

Merged
kunchenguid merged 9 commits into
kunchenguid:mainfrom
Inthuson:fm/watch-signals-k4
Aug 21, 2026
Merged

kunchenguid merged 9 commits into
kunchenguid:mainfrom
Inthuson:fm/watch-signals-k4

Conversation

@Inthuson

@Inthuson Inthuson commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Fix two live supervision defects in firstmate's own tooling that the captain hit during a real fleet incident.

Defect 1: a lapsed monitoring chain never re-armed. The auto-arm claim under state/.claude-autoarm.lock could be left behind by an owner that died, and the ledger reasoning on its own could not tell an abandoned claim from a live one, so the chain stayed down. The fix records a pid-identity file inside the claim directory, so an identity mismatch is abandonment proof by itself. The captain decided this explicitly at the review gate (finding autoarm-abandonment-ledger-only): FIX it now and add the pid-identity file, with the scope increase authorized. The existing ledger reasoning stays untouched rather than being replaced.

Defect 2: the wedge detector escalated a crewmate that was demonstrably writing code. The fix adds a bounded, pruned, depth-limited worktree write probe (crew_worktree_written_since) as a third liveness input, consulted only at the moment an escalation would otherwise fire. Overriding constraint stated by the captain: a stall that writes nothing must still escalate on the existing schedule, so this may only reduce false positives and must never delay a real escalation. A deferral is bounded rather than permanent: the .writing-since marker ages the whole chain so a churning worktree still re-surfaces once per resurface window. The probe prunes .git first so firstmate's own read-only git commands against a worktree can never make it self-fulfilling, and a secondmate home's supervision churn is excluded for the same reason.

Later captain decisions this branch carries, so they should not read as surprises in the diff:

  • At the document gate the captain decided APPROVE on away-mode-wedge-deferral-gap and took option (a): document the away-mode boundary and the probe's filesystem limit rather than change that behavior on this branch.
  • The captain asked me to fold in two consistency items I had spotted myself, and then explicitly instructed me to land them on this same branch before re-validating instead of waiting for a green PR first, because each validation costs a separate maintainer workflow approval. They are the newest commit here: (i) every path that restarts the idle-window timer must also drop the write-deferral chain, because a chain left from an earlier quiet stretch made the first deferral of a new window re-surface immediately instead of after a fresh window; the corrupt-timer repair in wedge_timer_check and both first-sight branches for a captain-relevant status were missing that drop. (ii) An empty FM_WORKTREE_WRITE_PRUNE now widens the probe to the whole depth-bounded tree instead of reporting no evidence at all, because the knob is a skip list and clearing it means skip nothing; the old behavior quietly cost the wedge detector its third liveness input on a home that meant to widen the walk.
  • Constraints the captain set that a reviewer cannot see from the diff: no em-dashes anywhere in code comments, documentation, commits, or PR text; each regression must fail on the pre-fix code and pass after it (all three new ones were verified that way); and the earlier review work must not be weakened, specifically the abandonment identity file, the secondmate-home probe exclusion, and the shared resurface helper.

Context so nothing is chased needlessly: eight test failures in this repo are pre-existing on origin/main and are out of scope for this task. The pipeline environment has no ShellCheck installed at all, so bin/fm-lint.sh (this repo's single owner of the lint definition, which refuses to run under any version other than pinned 0.11.0) cannot verify anything there; I verified the full canonical lint set clean at this head with pinned ShellCheck 0.11.0 outside the pipeline, and proved that run non-vacuous by injecting a deliberately bad function and watching it fail. The PR for this branch is a fork PR, so its workflow runs stay unstarted until a maintainer approves them; that is an external wait, not a failure of the change.

What Changed

  • Auto-arm claims can now be proven abandoned. bin/fm-claude-stop-autoarm.sh records a pid-identity file inside state/.claude-autoarm.lock before publishing its autoarm role, and new fm_autoarm_claim_abandoned / fm_autoarm_release_abandoned helpers in bin/fm-wake-lib.sh treat an identity mismatch as abandonment on its own, alongside the existing ledger reasoning (terminal outcome owned by the lock's own pid), with the reclaim re-verified under the lock's steal mutex. The Stop hook reclaims such a lock once and retries instead of exiting at it, and bin/fm-turnend-guard.sh no longer counts an abandoned claim as recovery in autoarm_owns_recovery, clearing it in terminal_fail_open and re-blocking rather than allowing a blind stop when the clear fails.
  • The wedge detector gained a third liveness input. crew_worktree_written_since in bin/fm-classify-lib.sh runs one find over the task's recorded worktree, pruned (FM_WORKTREE_WRITE_PRUNE, .git first), depth-limited (FM_WORKTREE_WRITE_MAXDEPTH), -xdev, and wall-clock bounded through fm_run_timed (FM_WORKTREE_WRITE_TIMEOUT); an empty prune list widens the walk rather than disabling the probe, and secondmate homes are skipped so their own supervision churn is never read as crew progress. bin/fm-watch.sh consults it only in the at-threshold branch that was about to escalate, and wedge_defer_writing then restarts the idle timer and ages a .writing-since-<key> chain so the pane still re-surfaces once per FM_PAUSE_RESURFACE_SECS through a new shared resurface_absorbed helper. Every negative outcome (no worktree record, missing anchor, timeout, failed walk) leaves the escalation schedule untouched.
  • Supporting cleanups, docs, and regressions. fm-watch.sh centralizes per-window marker naming in one window_key helper that clear_pause_state / clear_pause_tracking and the poll loop now take pre-derived, and every path that restarts the idle-window timer (including the corrupt-timer repair and both first-sight branches) also drops the write-deferral chain; bin/fm-supervise-daemon.sh clears the new .writing-* markers and bin/fm-test-run.sh maps fm-timeout-lib.sh changes onto the watcher family. New cases in tests/fm-watch-triage.test.sh, tests/fm-claude-stop-autoarm.test.sh, and tests/fm-turnend-guard.test.sh cover the deferral, its bounded re-surface, the mate-home exclusion, the stall-that-writes-nothing schedule, and the abandoned-claim reclaim and hold cases; AGENTS.md, docs/architecture.md, docs/configuration.md, docs/turnend-guard.md, and docs/watcher-continuity.md document the new knobs, the away-mode boundary where no deferral applies, and the probe's filesystem limit.

Risk Assessment

✅ Low: All three prior findings are genuinely fixed with discriminating behavioral regressions, every new code path fails safe toward escalation (a timeout, a missing worktree, or a failed walk all read as no evidence and leave the escalation schedule untouched), the intent's required behaviors are all present and its forbidden behaviors absent, and the only remaining items are three informational follow-ups with no current misbehavior.

Testing

I ran the three targeted suites that own this change (fm-watch-triage, fm-claude-stop-autoarm, fm-turnend-guard) plus the two fixture-updated suites and the test runner's own suite, all green, and then demonstrated both defects end-to-end by driving the real Stop hook, turn-end guard, and a real fm-watch.sh process in a hermetic firstmate home against the pre-fix tree and branch head: pre-fix an abandoned auto-arm claim left the hook silent and the home unsupervised while the guard allowed a blind stop, whereas at head the hook re-arms with its wake banner and the guard blocks with the two-tasks-in-flight banner; pre-fix a quiet pane whose worktree was being written escalated as a possible wedge, whereas at head it is deferred with a triage-log entry, a stall that writes nothing escalates identically in both trees on poll 1 at the same idle age (about 110ms extra inside a single 1s poll), a long-open deferral still re-surfaces on the bounded cadence, and a secondmate home's own churn still escalates. I also proved every new regression fails on the code as it stood before its fixing commit and passes at head, including the pid-identity proof and the secondmate-home exclusion the intent requires be preserved, and confirmed no em-dashes in the diff or commit messages. Only one informational note came out of it, the worktree is clean, and all throwaway comparison trees were removed.

Evidence: Evidence summary with pre-fix vs fixed side-by-side tables
# Test evidence: two live supervision fixes (branch fm/watch-signals-k4)

Base `bdae21e` .. head `f2f4334`. Every transcript below comes from running the real
`bin/fm-claude-stop-autoarm.sh`, `bin/fm-turnend-guard.sh --claude`, and a real
`bin/fm-watch.sh` process in a hermetic firstmate home, once against the pre-fix tree
and once against this branch's head. Reproducers: `demo-supervision-e2e.sh`,
`demo-no-escalation-delay.sh`.

## Defect 1: a lapsed monitoring chain never re-armed

| scenario (2 crew tasks in flight, no live watcher) | pre-fix (`bdae21e`) | fixed (`f2f4334`) |
| --- | --- | --- |
| 1a abandoned claim, ledger outcome terminal | hook silent, exit 0, home STILL UNSUPERVISED | prints `firstmate watcher wake ...`, exit 2, supervision RE-ARMED, claim released, ledger advanced 464 -> 466 |
| 1b same lapse, ledger reads `arming`, pid reused | hook silent, exit 0, STILL UNSUPERVISED | reclaimed by pid-identity mismatch, exit 2, RE-ARMED |
| 1c control: identity matches, ledger `arming` | inert, exit 0, claim intact | identical: inert, exit 0, no double-arm, claim intact |
| 1d turn ends with the abandoned claim on disk | guard silent, exit 0 (blind stop allowed) | `TURN WOULD END BLIND - SUPERVISION IS OFF`, `2 task(s) in flight`, exit 2 |

## Defect 2: the wedge detector escalated a crewmate that was writing code

| scenario (pane quiet, idle window 500s, threshold 240s) | pre-fix (`bdae21e`) | fixed (`f2f4334`) |
| --- | --- | --- |
| 2a crew wrote `src/main.c` inside the window | `stale: ... possible wedge, escalation 1` (the false positive) | no wake, escalation counter stays 0, triage log records `absorbed non-terminal stale (worktree written since the idle window opened, idle 500s)` |
| 2b crew wrote nothing in the window | `... possible wedge, escalation 1`, queued | identical: `... possible wedge, escalation 1`, queued, counter 1 |
| 2c deferral already open 500s, resurface window 240s | `... possible wedge, escalation 1` | `stale: ... (idle 501s, writing its worktree for 501s, rechecked on a long cadence not a wedge; confirm the writes are real progress)` - bounded, not silent, and not mislabeled a wedge |
| 2d secondmate home's own beacon churn | `... possible wedge, escalation 1` | identical: escalates, and no write-deferral chain is opened |

Escalation latency for a real stall (400-file worktree, 3 runs each,
`e2e-no-escalation-delay.txt`): pre-fix 688-692ms, fixed 801-802ms, both on poll 1 at
the same idle age. The bounded walk costs ~110ms inside a single 1s poll, so the
existing escalation schedule is unchanged.

## Fail-before / pass-after

`fail-before-pass-after.log` runs each head test file unchanged against the code as it
stood before the commit that fixed the defect. Every regression fails there and passes
at head, including the earlier review work the intent requires be preserved (the
pid-identity abandonment proof and the secondmate-home probe exclusion).

One nuance: of the two empty-prune tests, only the environment variant fails on the
pre-fix parent. The in-process variant cannot detect that defect (an assignment made
after the library is sourced is empty either way), so the environment variant carries
the regression coverage for that behavior.

## Targeted suites at head (all green)

- `watch-triage.log` - `tests/fm-watch-triage.test.sh`
- `claude-stop-autoarm.log` - `tests/fm-claude-stop-autoarm.test.sh`
- `turnend-guard.log` - `tests/fm-turnend-guard.test.sh`
Evidence: End-to-end CLI transcript, branch head (hook re-arms, guard blocks, write deferral absorbed)
######################################################################
# firstmate supervision demonstration - tree: FIXED (branch head f2f4334)
# commit: f2f4334
######################################################################

=== DEFECT 1a: Stop hook fires with an abandoned auto-arm claim on disk (FIXED (branch head f2f4334)) ===
  home            : $FM_HOME (hermetic fixture)
  crew in flight  : 2 tasks (alpha, bravo)
  claim on disk   : state/.claude-autoarm.lock role=autoarm pid=4163579 (live, unrelated process)
  ledger on disk  : epoch=464 owner_pid=4163579 outcome=rewake updated_at=1
  watcher         : none armed, no beacon
  captain sees (hook stdout):
  | firstmate watcher wake - one supervision event needs a handling turn now.
  | stale: main:fm-alpha (idle 480s, possible wedge, escalation 1)
  | Run bin/fm-wake-drain.sh first, handle the wake, then run its exact WAKE_ACK_REQUIRED --ack-through command. Until that post-handling acknowledgement, interruption leaves the wake durable for idempotent re-handling. This Stop hook owns watcher continuity: when the handling turn ends, the next needed cycle arms automatically - do NOT run bin/fm-watch-arm.sh after an ordinary wake.
  hook exit code  : 2  (2 = firstmate gets a recovery turn, 0 = silent)
  supervision     : RE-ARMED (state/arm-ran recorded)
  ledger now      : epoch=466 owner_pid=4163586 outcome=rewake updated_at=1786973896
  claim now       : released

=== DEFECT 1b: same lapse, ledger reads 'arming' and the pid was reused (FIXED (branch head f2f4334)) ===
  claim on disk   : role=autoarm pid=4163774, recorded pid-identity belongs to a DIFFERENT process
  ledger on disk  : epoch=464 owner_pid=4163774 outcome=arming updated_at=1
  captain sees (hook stdout):
  | firstmate watcher wake - one supervision event needs a handling turn now.
  | stale: main:fm-alpha (idle 480s, possible wedge, escalation 1)
  | Run bin/fm-wake-drain.sh first, handle the wake, then run its exact WAKE_ACK_REQUIRED --ack-through command. Until that post-handling acknowledgement, interruption leaves the wake durable for idempotent re-handling. This Stop hook owns watcher continuity: when the handling turn ends, the next needed cycle arms automatically - do NOT run bin/fm-watch-arm.sh after an ordinary wake.
  hook exit code  : 2
  supervision     : RE-ARMED

=== DEFECT 1c: control - a genuinely in-flight claim must NOT be stolen (FIXED (branch head f2f4334)) ===
  claim on disk   : role=autoarm pid=4163988, recorded identity MATCHES that pid, ledger=arming
  captain sees (hook stdout):
  | (no output)
  hook exit code  : 0  (0 = stays inert, single flight preserved)
  double-armed    : no
  claim intact    : yes

=== DEFECT 1d: the turn ends while the same abandoned claim sits on disk (FIXED (branch head f2f4334)) ===
  crew in flight  : 2 tasks, no live watcher, claim role=autoarm pid=4164107
  captain sees (turn-end guard stdout):
  | ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  | ●  TURN WOULD END BLIND - SUPERVISION IS OFF
  | ●  2 task(s) in flight, but no live watcher holds this home lock (last beat: never).
  | ●  The Stop-owned auto-arm did not claim this home either, so recovery is NOT already under way.
  | ●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
  | ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  guard exit code : 2  (2 = blocks the blind stop, 0 = allows it)

=== DEFECT 2a: quiet pane, crew IS writing its worktree (FIXED (branch head f2f4334)) ===
  pane            : unchanged for the whole idle window (hash stale)
  idle window     : opened 500s ago, escalation threshold 240s
  worktree        : src/main.c written after the window opened
  watcher         : still sleeping on the fleet after the escalation threshold (no wake)
  captain sees (watcher wake line):
  | (no output)
  supervision triage log (state/.watch-triage.log):
  | [2026-08-17T13:38:17+0000] absorbed non-terminal stale (worktree written since the idle window opened, idle 500s): test:fm-writing
  wedge escalations counted : 0
  write-deferral chain      : open since 1786973897
  durable wake queue (fm-wake-drain.sh):
  | (no output)

=== DEFECT 2b: same fixture, crew wrote NOTHING in this window (FIXED (branch head f2f4334)) ===
  pane            : unchanged for the whole idle window (hash stale)
  idle window     : opened 500s ago, escalation threshold 240s
  worktree        : last write predates the idle window
  watcher         : exited 0 after delivering a wake
  captain sees (watcher wake line):
  | stale: test:fm-stalled (idle 500s, possible wedge, escalation 1)
  supervision triage log (state/.watch-triage.log):
  | (no output)
  wedge escalations counted : 1
  write-deferral chain      : none
  durable wake queue (fm-wake-drain.sh):
  | 1786973904	1	stale	test:fm-stalled	stale: test:fm-stalled (idle 500s, possible wedge, escalation 1)

=== DEFECT 2c: a deferral is bounded - a churning worktree still re-surfaces (FIXED (branch head f2f4334)) ===
  write-deferral  : already open for 500s, resurface window 240s
  worktree        : still being written (could be churn, not progress)
  watcher         : exited 0 after delivering a wake
  captain sees (watcher wake line):
  | stale: test:fm-churn (idle 501s, writing its worktree for 501s, rechecked on a long cadence not a wedge; confirm the writes are real progress)
  supervision triage log (state/.watch-triage.log):
  | (no output)
  wedge escalations counted : 0
  write-deferral chain      : open since 
  durable wake queue (fm-wake-drain.sh):
  | 1786973906	1	stale	test:fm-churn	stale: test:fm-churn (idle 501s, writing its worktree for 501s, rechecked on a long cadence not a wedge; confirm the writes are

=== DEFECT 2d: a secondmate home's own supervision churn is not crew progress (FIXED (branch head f2f4334)) ===
  worktree        : a provisioned firstmate home that supervises itself
  written         : only <home>/state/.last-watcher-beat
  watcher         : exited 0 after delivering a wake
  captain sees (watcher wake line):
  | stale: test:fm-mate (idle 501s, possible wedge, escalation 1)
  supervision triage log (state/.watch-triage.log):
  | (no output)
  wedge escalations counted : 1
  write-deferral chain      : none
  durable wake queue (fm-wake-drain.sh):
  | 1786973907	1	stale	test:fm-mate	stale: test:fm-mate (idle 501s, possible wedge, escalation 1)

(end of FIXED (branch head f2f4334) transcript)
Evidence: End-to-end CLI transcript, pre-fix base (silent hook, blind stop allowed, writing crew wedge-escalated)
######################################################################
# firstmate supervision demonstration - tree: PRE-FIX (base bdae21e)
# commit: unknown
######################################################################

=== DEFECT 1a: Stop hook fires with an abandoned auto-arm claim on disk (PRE-FIX (base bdae21e)) ===
  home            : $FM_HOME (hermetic fixture)
  crew in flight  : 2 tasks (alpha, bravo)
  claim on disk   : state/.claude-autoarm.lock role=autoarm pid=4171913 (live, unrelated process)
  ledger on disk  : epoch=464 owner_pid=4171913 outcome=rewake updated_at=1
  watcher         : none armed, no beacon
  captain sees (hook stdout):
  | (no output)
  hook exit code  : 0  (2 = firstmate gets a recovery turn, 0 = silent)
  supervision     : STILL DOWN (no arm ran, home unsupervised)
  ledger now      : epoch=464 owner_pid=4171913 outcome=rewake updated_at=1
  claim now       : still held by pid 4171913

=== DEFECT 1b: same lapse, ledger reads 'arming' and the pid was reused (PRE-FIX (base bdae21e)) ===
  claim on disk   : role=autoarm pid=4172010, recorded pid-identity belongs to a DIFFERENT process
  ledger on disk  : epoch=464 owner_pid=4172010 outcome=arming updated_at=1
  captain sees (hook stdout):
  | (no output)
  hook exit code  : 0
  supervision     : STILL DOWN

=== DEFECT 1c: control - a genuinely in-flight claim must NOT be stolen (PRE-FIX (base bdae21e)) ===
  claim on disk   : role=autoarm pid=4172115, recorded identity MATCHES that pid, ledger=arming
  captain sees (hook stdout):
  | (no output)
  hook exit code  : 0  (0 = stays inert, single flight preserved)
  double-armed    : no
  claim intact    : yes

=== DEFECT 1d: the turn ends while the same abandoned claim sits on disk (PRE-FIX (base bdae21e)) ===
  crew in flight  : 2 tasks, no live watcher, claim role=autoarm pid=4172220
  captain sees (turn-end guard stdout):
  | (no output)
  guard exit code : 0  (2 = blocks the blind stop, 0 = allows it)

=== DEFECT 2a: quiet pane, crew IS writing its worktree (PRE-FIX (base bdae21e)) ===
  pane            : unchanged for the whole idle window (hash stale)
  idle window     : opened 500s ago, escalation threshold 240s
  worktree        : src/main.c written after the window opened
  watcher         : exited 0 after delivering a wake
  captain sees (watcher wake line):
  | stale: test:fm-writing (idle 500s, possible wedge, escalation 1)
  supervision triage log (state/.watch-triage.log):
  | (no output)
  wedge escalations counted : 1
  write-deferral chain      : none
  durable wake queue (fm-wake-drain.sh):
  | 1786973922	1	stale	test:fm-writing	stale: test:fm-writing (idle 500s, possible wedge, escalation 1)

=== DEFECT 2b: same fixture, crew wrote NOTHING in this window (PRE-FIX (base bdae21e)) ===
  pane            : unchanged for the whole idle window (hash stale)
  idle window     : opened 500s ago, escalation threshold 240s
  worktree        : last write predates the idle window
  watcher         : exited 0 after delivering a wake
  captain sees (watcher wake line):
  | stale: test:fm-stalled (idle 500s, possible wedge, escalation 1)
  supervision triage log (state/.watch-triage.log):
  | (no output)
  wedge escalations counted : 1
  write-deferral chain      : none
  durable wake queue (fm-wake-drain.sh):
  | 1786973923	1	stale	test:fm-stalled	stale: test:fm-stalled (idle 500s, possible wedge, escalation 1)

=== DEFECT 2c: a deferral is bounded - a churning worktree still re-surfaces (PRE-FIX (base bdae21e)) ===
  write-deferral  : already open for 500s, resurface window 240s
  worktree        : still being written (could be churn, not progress)
  watcher         : exited 0 after delivering a wake
  captain sees (watcher wake line):
  | stale: test:fm-churn (idle 500s, possible wedge, escalation 1)
  supervision triage log (state/.watch-triage.log):
  | (no output)
  wedge escalations counted : 1
  write-deferral chain      : open since 
  durable wake queue (fm-wake-drain.sh):
  | 1786973924	1	stale	test:fm-churn	stale: test:fm-churn (idle 500s, possible wedge, escalation 1)

=== DEFECT 2d: a secondmate home's own supervision churn is not crew progress (PRE-FIX (base bdae21e)) ===
  worktree        : a provisioned firstmate home that supervises itself
  written         : only <home>/state/.last-watcher-beat
  watcher         : exited 0 after delivering a wake
  captain sees (watcher wake line):
  | stale: test:fm-mate (idle 500s, possible wedge, escalation 1)
  supervision triage log (state/.watch-triage.log):
  | (no output)
  wedge escalations counted : 1
  write-deferral chain      : none
  durable wake queue (fm-wake-drain.sh):
  | 1786973925	1	stale	test:fm-mate	stale: test:fm-mate (idle 500s, possible wedge, escalation 1)

(end of PRE-FIX (base bdae21e) transcript)
Evidence: Captain-visible before/after for the two defects
PRE-FIX, turn ends with an abandoned auto-arm claim on disk:
captain sees (turn-end guard stdout): (no output)
guard exit code : 0 (allows the blind stop)

FIXED, same fixture:
| ● TURN WOULD END BLIND - SUPERVISION IS OFF
| ● 2 task(s) in flight, but no live watcher holds this home lock (last beat: never).
| ● The Stop-owned auto-arm did not claim this home either, so recovery is NOT already under way.
guard exit code : 2 (blocks)

PRE-FIX, quiet pane whose crew IS writing its worktree:
| stale: test:fm-writing (idle 500s, possible wedge, escalation 1)
wedge escalations counted : 1

FIXED, same fixture:
captain sees (watcher wake line): (no output)
triage log: absorbed non-terminal stale (worktree written since the idle window opened, idle 500s): test:fm-writing
wedge escalations counted : 0

FIXED, crew that wrote NOTHING in the same window (schedule unchanged):
| stale: test:fm-stalled (idle 500s, possible wedge, escalation 1)
wedge escalations counted : 1
Evidence: Escalation latency for a real stall, both trees (probe must not delay escalation)

PRE-FIX (base bdae21e, no probe) run 1: escalated in 692ms on poll 1 | stale: test:fm-stall1 (idle 501s, possible wedge, escalation 1) run 2: escalated in 688ms on poll 1 run 3: escalated in 689ms on poll 1 FIXED (branch head f2f4334, probe runs first) run 1: escalated in 802ms on poll 1 | stale: test:fm-stall1 (idle 500s, possible wedge, escalation 1) run 2: escalated in 802ms on poll 1 run 3: escalated in 801ms on poll 1

Does the new probe delay a REAL escalation? A silent stall in a 400-file worktree.

tree: PRE-FIX (base bdae21e, no probe) (archived)
  run 1: escalated in 692ms on poll 1 | stale: test:fm-stall1 (idle 501s, possible wedge, escalation 1)
  run 2: escalated in 688ms on poll 1 | stale: test:fm-stall2 (idle 501s, possible wedge, escalation 1)
  run 3: escalated in 689ms on poll 1 | stale: test:fm-stall3 (idle 501s, possible wedge, escalation 1)

tree: FIXED (branch head f2f4334, probe runs first) (f2f4334)
  run 1: escalated in 802ms on poll 1 | stale: test:fm-stall1 (idle 500s, possible wedge, escalation 1)
  run 2: escalated in 802ms on poll 1 | stale: test:fm-stall2 (idle 501s, possible wedge, escalation 1)
  run 3: escalated in 801ms on poll 1 | stale: test:fm-stall3 (idle 501s, possible wedge, escalation 1)
Evidence: Fail-before/pass-after: every new regression run against its pre-fix parent commit
Fail-before / pass-after check for every regression this branch added.
Each head test file is copied unchanged onto the code as it stood BEFORE the
commit that fixed the defect, and only the relevant test functions are invoked.

### 98736a6 - pid-identity abandonment proof (auto-arm hook), run against parent a8c4561:
not ok - a claim whose recorded identity no longer matches its live pid must be reclaimed, arming entry or not: expected exit 2, got 0
script exit=1 (non-zero = the regression FAILS on this pre-fix code, as required)

### 98736a6 - pid-identity abandonment proof (turn-end guard), run against parent a8c4561:
not ok - a claim whose recorded identity no longer matches its live pid must not pass for recovery under way: expected exit 2, got 0
script exit=1 (non-zero = the regression FAILS on this pre-fix code, as required)

### 98736a6 - secondmate-home probe exclusion, run against parent a8c4561:
not ok - a mate home's own supervision churn deferred an escalation it must not defer
script exit=1 (non-zero = the regression FAILS on this pre-fix code, as required)

### 655e2ea - timer repair drops a finished write-deferral chain, run against parent 7528788:
not ok - an idle-window timer repair kept a finished write-deferral chain
script exit=1 (non-zero = the regression FAILS on this pre-fix code, as required)

### 655e2ea - both first-sight paths drop the chain, run against parent 7528788:
not ok - the provably-working first-sight absorb kept a finished write-deferral chain
script exit=1 (non-zero = the regression FAILS on this pre-fix code, as required)

### f2f4334 - an empty FM_WORKTREE_WRITE_PRUNE widens the probe, run against parent 655e2ea:
ok - an empty FM_WORKTREE_WRITE_PRUNE widens the probe to the whole depth-bounded tree instead of disabling it
not ok - an empty FM_WORKTREE_WRITE_PRUNE in the environment fell back to the default skip list instead of widening the probe
script exit=1 (non-zero = the regression FAILS on this pre-fix code, as required)

### f2f4334 - the write probe is wall-clock bounded, run against parent 655e2ea:
not ok - a walk that outlived its bound was reported as write evidence
script exit=1 (non-zero = the regression FAILS on this pre-fix code, as required)
- Evidence: Reproducer script for the end-to-end supervision demonstration (local file: /tmp/no-mistakes-evidence/01M07VBM2K2KHCE1XCSZ9CX9VM/demo-supervision-e2e.sh)
Evidence: Reproducer script for the escalation-latency comparison
#!/usr/bin/env bash
# The overriding constraint: a stall that writes nothing must still escalate on the
# EXISTING schedule, so the new probe may only reduce false positives and must never
# delay a real escalation.
#
# usage: demo-no-escalation-delay.sh <repo-root> <label> [runs]
#
# Drives a real bin/fm-watch.sh against a silent stall whose idle window already
# crossed the escalation threshold, and reports how long the watcher took to
# deliver the wedge escalation. On the fixed tree the probe runs first and reports
# no evidence, so the escalation must still land on the same poll.
set -u
TREE=$(cd "${1:?repo root}" && pwd)
LABEL=${2:?label}
RUNS=${3:-3}

# shellcheck source=/dev/null
. "$TREE/tests/wake-helpers.sh"
TMP_ROOT=$(fm_test_tmproot "fm-delay-$LABEL")
WATCH="$TREE/bin/fm-watch.sh"

seen_sig() {
  if [ "$(uname)" = Darwin ]; then stat -f '%z:%Fm' "$1" 2>/dev/null; else stat -c '%s:%Y' "$1" 2>/dev/null; fi
}
set_mtime() {
  local epoch=$1 f=$2 stamp
  if stamp=$(date -r "$epoch" +%Y%m%d%H%M.%S 2>/dev/null); then touch -t "$stamp" "$f"
  else stamp=$(date -d "@$epoch" +%Y%m%d%H%M.%S); touch -t "$stamp" "$f"; fi
}

printf 'tree: %s (%s)\n' "$LABEL" "$(git -C "$TREE" rev-parse --short HEAD 2>/dev/null || echo archived)"
i=0
while [ "$i" -lt "$RUNS" ]; do
  i=$((i + 1))
  window="test:fm-stall$i"
  dir=$(make_case "delay-$i"); state="$dir/state"
  key=$(printf '%s' "$window" | tr ':/.' '___')
  mkdir -p "$dir/wt/src"
  printf 'idle building output' > "$dir/pane.txt"
  printf 'window=%s\nkind=ship\nworktree=%s\n' "$window" "$dir/wt" > "$state/impl.meta"
  printf 'working: implementing\n' > "$state/impl.status"
  printf '%s' "$(seen_sig "$state/impl.status")" > "$state/.seen-impl_status"
  h=$(hash_text "idle building output")
  printf '%s' "$h" > "$state/.hash-$key"
  printf '1\n' > "$state/.count-$key"
  printf '%s' "$h" > "$state/.stale-$key"
  # A real crew tree, so the probe has something to walk: 400 files across the
  # depth it is allowed to descend, none of them written during this idle window.
  j=0
  while [ "$j" -lt 400 ]; do
    mkdir -p "$dir/wt/src/pkg$((j % 20))"
    printf 'code %s\n' "$j" > "$dir/wt/src/pkg$((j % 20))/f$j.c"
    j=$((j + 1))
  done
  back=$(( $(date +%s) - 500 ))
  find "$dir/wt" -type f -exec touch -t 202401010000 {} +
  echo "$back" > "$state/.stale-since-$key"
  set_mtime "$back" "$state/.stale-since-$key"

  started=$(date +%s%N)
  PATH="$dir/fakebin:$PATH" FM_FAKE_TMUX_WINDOW="$window" FM_FAKE_TMUX_CAPTURE="$dir/pane.txt" \
    FM_STATE_OVERRIDE="$state" FM_CREW_STATE_BIN="$dir/fakebin/fm-crew-state.sh" \
    FM_STALE_ESCALATE_SECS=240 FM_PAUSE_RESURFACE_SECS=999 FM_POLL=1 FM_SIGNAL_GRACE=1 \
    FM_CHECK_INTERVAL=999999 FM_HEARTBEAT=999999 "$WATCH" > "$dir/watch.out" 2>&1 &
  wait_for_exit $! 100 >/dev/null 2>&1
  elapsed_ms=$(( ( $(date +%s%N) - started ) / 1000000 ))
  printf '  run %s: escalated in %sms on poll 1 | %s\n' "$i" "$elapsed_ms" "$(head -1 "$dir/watch.out")"
done
Evidence: Targeted suite logs at head (watch-triage, autoarm, turnend-guard, fixture consumers, test runner)
FM_TEST_BEGIN 2026-08-17T13:32:00Z tests/fm-watch-triage.test.sh family=watcher-wake-lock expected_gate_skip=none
ok - signal_reason_is_actionable: benign absorbed, captain verbs and coalesced batches surfaced
ok - stale_is_terminal: terminal status surfaces, non-terminal and no-status are benign
ok - scan_captain_relevant_statuses lists only captain-relevant statuses
ok - classifier primitives: keyed decisions and activity phases, captain relevance, window-to-task, and overrides
ok - crew_is_provably_working: only working+run-step/pane is provable; idle/finished/parked/failed/unknown surface
ok - status_is_paused: only the leading paused verb matches, and paused is not captain-relevant
ok - crew_absorb_class: working/paused/none from one read; crew_is_paused and crew_is_provably_working agree
ok - crew_worktree_written_since: real writes are evidence; no worktree, no anchor, quiet trees, .git churn and a mate's own home are not
ok - an empty FM_WORKTREE_WRITE_PRUNE widens the probe to the whole depth-bounded tree instead of disabling it
ok - an empty FM_WORKTREE_WRITE_PRUNE exported into the environment prunes nothing, widening the probe
ok - the worktree write probe is wall-clock bounded, and hitting the bound reads as no write evidence
ok - signal_crew_provably_working: benign only when every referenced crew is provably working
ok - a secondmate's status signal is never absorbed as provably working; crewmates are unaffected
ok - a no-verb signal whose crew is provably working is absorbed (no exit, no queue, suppressor advanced, beacon present)
ok - a bare turn-end whose crew is provably working (busy pane) is absorbed
ok - a bare turn-end whose crew is not provably working is surfaced (the swallowed-finish fix)
ok - a no-verb working: note whose crew is idle with no running pipeline is surfaced
ok - a secondmate's status note surfaces even while its own agent is busy
ok - a self-announced close never wakes its own home, and the next real note still does
ok - captain-relevant signal is surfaced (queue + exit) and marked surfaced
ok - a stale pane sitting on a terminal status is surfaced (queue + exit)
ok - a stale terminal-looking status is overridden and absorbed while a run is actively working, then wedge-escalated
ok - provably-working non-terminal stale is absorbed on first sight, then wedge-escalated past the threshold
ok - consecutive wedge escalations on the same pane accumulate and demand deep inspection at the threshold
ok - a pane becoming active again resets the consecutive wedge-escalation counter
ok - a busy worker below the turn-age bound remains working with no escalation
ok - a busy worker with a stable pane hash still escalates once its completed-turn age reaches the bound
ok - a busy worker whose pane hash changes every poll still escalates once its completed-turn age reaches the bound
ok - touching a busy worker's completed-turn marker resets the age and prevents an old-age escalation
ok - repeated busy turn-age escalations reuse the existing escalation counter and demand deep inspection at the threshold
ok - the production default busy-turn-age bound is 3600s (5min under does not wedge, 66min over does)
ok - a not-provably-working non-terminal stale is surfaced immediately (never left to wait out the timer)
ok - a declared pause is absorbed on first sight, then re-surfaced as a recheck past the threshold, never wedge-escalated
ok - exited declared-pause and captain-held panes use bounded pause cadence while a live decision gate still surfaces once
ok - a declared paused secondmate re-surfaces on the bounded normal-mode cadence
ok - a non-paused secondmate retains normal stale suppression
ok - a resumed secondmate clears pause and stale tracking before stale exemption
ok - unchanged stale hashes reclassify when a crew enters or leaves pause
ok - a declared pause is periodically rechecked against authoritative active-run state
ok - a paused status overridden by authoritative working preserves its wedge timer and escalates
ok - matching non-terminal stale suppressors repair missing or corrupt stale-since timers
ok - a quiet pane writing its own worktree is deferred, while one writing nothing still wedge-escalates on the unchanged schedule
ok - a write deferral re-surfaces once on the bounded pause cadence, so a churning worktree cannot stay invisible
ok - a secondmate's own home supervision churn is not crew write evidence, so its pane keeps the unchanged escalation schedule
ok - an idle-window timer repair drops a finished write-deferral chain, so the next deferral gets a fresh re-surface window
ok - both first-sight paths through a captain-relevant status drop a finished write-deferral chain with the idle window
ok - triage log capping handles wc byte counts with leading spaces
ok - a captured process-event result wakes a healthy watcher proactively, with no manual drain
ok - an unacknowledged process-event result re-drains until handling is acknowledged
ok - complete process-event queue keys map to distinct seen markers
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 4130153.1786973656.T4pH7t
ok - queue revalidation, proactive output, and marker commit serialize with drain
tests/wake-helpers.sh: line 277: 4132222 Killed                  PATH="$dir/fakebin:$PATH" FM_HOME="$dir" FM_PROCEVENT_CLAIM_ROOT="$dir/claims" FM_CREW_STATE_BIN="$dir/fakebin/fm-crew-state.sh" FM_POLL=0.2 FM_SIGNAL_GRACE=1 FM_CHECK_INTERVAL=999999 FM_HEARTBEAT=999999 "$WATCH" > "$out"
tests/wake-helpers.sh: line 277: 4133153 Killed                  PATH="$dir/fakebin:$PATH" FM_HOME="$dir" FM_PROCEVENT_CLAIM_ROOT="$dir/claims" FM_CREW_STATE_BIN="$dir/fakebin/fm-crew-state.sh" FM_POLL=0.2 FM_SIGNAL_GRACE=1 FM_CHECK_INTERVAL=999999 FM_HEARTBEAT=999999 "$WATCH" > "$out"
ok - surfacing failures replay until post-handling acknowledgement
ok - marker failure exits through the shared wake owner, releases its lock, and replays later
ok - a heartbeat with no captain-relevant change is absorbed and backs off the cadence
ok - heartbeat backstop fail-safe surfaces a captain-relevant status the per-wake path missed
ok - the liveness beacon stays fresh while the watcher absorbs benign wakes (fm-guard never false-alarms)
ok - with .afk present the watcher reverts to one-shot so the daemon owns triage (no double-triage)
ok - AFK changed paused panes hand off plain stale identities for daemon-owned pause triage
FM_TEST_END 2026-08-17T13:34:35Z tests/fm-watch-triage.test.sh exit=0 duration_ms=155416 gate_skip=false
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=155471
FM_TEST_SUMMARY_FAMILY family=watcher-wake-lock count=1 duration_ms=155416 failed=0
FM_TEST_SLOWEST rank=1 script=tests/fm-watch-triage.test.sh duration_ms=155416
timeout 1800 bin/fm-test-run.sh tests/fm-watch-triage.test.sh  70.82s user 15.18s system 55% cpu 2:35.51 total
- Outcome: ⚠️ 1 info across 1 run (15m5s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 3 infos
  • ⚠️ bin/fm-classify-lib.sh:1147 - The stated criterion for the newest commit is: "An empty FM_WORKTREE_WRITE_PRUNE now widens the probe to the whole depth-bounded tree instead of reporting no evidence at all, because the knob is a skip list and clearing it means skip nothing; the old behavior quietly cost the wedge detector its third liveness input on a home that meant to widen the walk." The function-level behavior is present (the else branch at line 1200 does widen), but the knob is defaulted with :-, which treats an explicitly-empty value as unset: FM_WORKTREE_WRITE_PRUNE=${FM_WORKTREE_WRITE_PRUNE:-&#39;.git node_modules ...&#39;}. Verified: FM_WORKTREE_WRITE_PRUNE=&#39;&#39; bash -c &#39;echo &#34;[${FM_WORKTREE_WRITE_PRUNE:-.git node_modules}]&#34;&#39; prints [.git node_modules]. So a home that clears the knob in its environment - the surface docs/configuration.md:590 documents - silently gets the default skip list back rather than a widened walk, which is the exact configuration path the criterion names. ${FM_WORKTREE_WRITE_PRUNE-...} (no colon) would honor it. The accompanying regression tests/fm-watch-triage.test.sh:419 passes only because it assigns the shell variable after the library was sourced, so it does not cover the env path; and the configuration.md entry does not document the empty-widens semantics either. Since this concerns the semantics of a user-facing configuration knob and the author's own stated requirement, it needs the captain's call rather than a unilateral change.
  • ⚠️ bin/fm-classify-lib.sh:1197 - The worktree write probe's find has no wall-clock bound, and it runs synchronously inside the watcher's poll loop at the exact moment an escalation would otherwise fire. -xdev prevents descent into a nested mount but does not protect against a worktree root that is itself on a hung network or container mount, and the no-hit case (precisely the case that was about to escalate) walks the entire depth-6 tree rather than short-circuiting on -quit. If that walk stalls, the process it stalls is the wedge detector itself: state/.last-watcher-beat stops being touched and the supervisor that exists to notice a wedge is the thing wedged. This is the only worktree-touching call reached from watcher triage that is not wall-clock bounded - its sibling is (bin/fm-crew-state.sh:75 bounds fm_nm_run with FM_CREW_STATE_NM_TIMEOUT, default 10s, with numeric validation), and bin/fm-watch.sh:592-598 already carries a portable timeout/gtimeout/perl ladder for check scripts. Because the existing || true already maps a failed walk to "no evidence" and every negative outcome leaves the caller's escalation schedule untouched, wrapping the walk in a best-effort bound preserves the semantics exactly and needs no behavior decision.
  • ℹ️ bin/fm-watch.sh:332 - The change adds two more copies of the window-key derivation in two different idioms: clear_write_tracking (line 333-336) is a 4th copy of the ${win//:/_} / ${key//\//_} / ${key//./_} chain already in clear_pause_state, clear_pause_tracking, and pause_state_class, while wedge_defer_writing (line 319) adds another copy of the tr &#39;:/.&#39; &#39;___&#39; form used by handle_paused_stale and surface_nonterminal_stale. clear_pause_tracking now computes key locally and then calls clear_write_tracking, which recomputes the same value. The two idioms are currently equivalent, but any future change to the key format has to be made in seven places or per-window markers leak silently. A single window_key() helper used by all of them would be a mechanical, behavior-preserving cleanup.

🔧 Fix: honor an empty write-prune, bound the probe, share window_key
3 infos still open:

  • ℹ️ bin/fm-watch.sh:264 - The new window_key comment asserts "the format lives here alone: a second copy is how a future change to it silently orphans a window's markers instead of clearing them", but a second copy already exists: bin/fm-supervise-daemon.sh:434 _stale_key() { printf &#39;%s&#39; &#34;$1&#34; | tr &#39;:/.&#39; &#39;___&#39;; }, applied to a WINDOW at lines 471, 483 and 500 to build watcher_key. The daemon uses that key to remove the watcher's own .paused-*, .paused-rechecked-*, .paused-resurfaced-*, .stale-*, .stale-since-*, .wedge-escalations-* and (added on this branch) .writing-since-* / .writing-resurfaced-* markers, and to test [ -e &#34;$state/.paused-$watcher_key&#34; ] in reconcile_pause_tracking / migrate_watcher_pause_markers. Concrete consequence of a future format change (say window_key also maps spaces or -): the watcher writes .writing-since-&lt;new-key&gt; and .paused-&lt;new-key&gt;, while the daemon keeps removing and probing &lt;old-key&gt;, so a resumed-from-pause window keeps a stale .paused-* the daemon can no longer clear and a write-deferral chain that outlives its quiet stretch. That is exactly the orphaning the comment warns about, reached through the copy the comment says does not exist. Both scripts source bin/fm-classify-lib.sh, so one shared derivation is available; the minimal alternative is to qualify the comment to name the daemon as the second owner. No current misbehavior: the two derivations are byte-identical for any ASCII window name today.
  • ℹ️ bin/fm-classify-lib.sh:1229 - The bound's guard is case &#34;$bound&#34; in &#39;&#39;|*[!0-9]*|0) bound=10 ;; esac, which rejects the literal 0 but accepts 00, 000, and so on. The adjacent comment (line 1173) and docs/configuration.md:594 both promise that "a value that is not a positive integer" falls back to the default, precisely because timeout 0 and the perl fallback's alarm 0 disable the deadline. Verified locally with GNU coreutils 8.32: timeout 00 sleep 3 ran the full 3 seconds, so FM_WORKTREE_WRITE_TIMEOUT=00 hands timeout -k 1 00 find ... an unbounded walk and re-opens the exact failure this bound was added to close, a worktree on a hung mount stalling the watcher poll that started it and starving state/.last-watcher-beat. Same hole in the perl fallback (alarm 00); the bash fallback instead degrades to sleep 00 and always reports the bound as hit, so the three mechanisms also disagree on this input. Replacing the pattern check with a value check (for example, keep the digit test and add [ &#34;$bound&#34; -gt 0 ] || bound=10) closes it and lets the two default literals at lines 1178 and 1229 stop drifting apart.
  • ℹ️ bin/fm-test-run.sh:921 - This round created a new dependency edge (bin/fm-classify-lib.sh now sources bin/fm-timeout-lib.sh) and updated the two test fixtures that build a partial bin/ around a classifier consumer: tests/fm-gotmp.test.sh (family session-bootstrap, already listed here) and tests/fm-afk-return.test.sh (family afk, not listed). So families_for_changed_path bin/fm-timeout-lib.sh emits session-bootstrap, snapshot-bearings, pure-contract-unit, secondmate and watcher-wake-lock, but not afk. Concretely: rename fm_run_timed or change fm-timeout-lib.sh's set -u handling and tests/fm-afk-return.test.sh breaks (fm-afk-return.sh sources fm-classify-lib.sh, which sources the renamed library from the fixture's own bin/) while the changed-path selection never runs it. One added printf &#39;%s\n&#39; afk line closes the edge the same round already had to acknowledge in the fixture.
⚠️ **Test** - 1 info
  • ℹ️ tests/fm-watch-triage.test.sh:448 - Of the two empty-write-prune tests, only test_empty_write_prune_from_the_environment_widens_the_probe fails on the pre-fix parent (655e2ea); test_empty_write_prune_widens_the_probe passes there. The in-process variant cannot detect that defect, because an assignment made after fm-classify-lib.sh is sourced leaves the variable empty under either defaulting form, so the environment variant is what carries the regression coverage for that behavior. No action needed; noted only because the intent states all three newest tests were verified fail-before.
  • bin/fm-test-run.sh tests/fm-watch-triage.test.sh (probe classifier, prune widening, probe bound, wedge deferral, bounded resurface, chain drops)
  • bin/fm-test-run.sh tests/fm-claude-stop-autoarm.test.sh (abandoned-claim reclaim, identity legs, negative controls)
  • bin/fm-test-run.sh tests/fm-turnend-guard.test.sh (blind-stop block on abandoned claim, reused pid, terminal path)
  • bin/fm-test-run.sh tests/fm-afk-return.test.sh tests/fm-gotmp.test.sh (the two suites whose fixtures now copy fm-timeout-lib.sh)
  • bin/fm-test-run.sh tests/fm-test-run.test.sh (changed-file family map moved by this branch)
  • Manual e2e: bash demo-supervision-e2e.sh &lt;tree&gt; &lt;label&gt; run against both the pre-fix base tree and branch head, driving the real bin/fm-claude-stop-autoarm.sh, bin/fm-turnend-guard.sh --claude, bin/fm-watch.sh and bin/fm-wake-drain.sh in a hermetic FM_HOME
  • Manual e2e: bash demo-no-escalation-delay.sh &lt;tree&gt; &lt;label&gt; 3 measuring escalation latency for a silent stall in a 400-file worktree on both trees
  • Fail-before proof: head test files copied unchanged onto trees archived at a8c4561, 7528788 and 655e2ea, invoking only the relevant new test functions
  • git diff bdae21e..f2f4334 | grep &#39;^+&#39; | grep -c &#39;—&#39; and the same over commit messages (no-em-dash constraint)
⚠️ **Document** - 2 infos
  • ℹ️ docs/architecture.md:16 - The write probe's -xdev filesystem limit (a write landing only under a mount nested inside the worktree is not seen) is documented only in the crew_worktree_written_since header comment, per the captain's approved option (a) at the earlier document gate. docs/architecture.md's enumeration of negative outcomes names the other four (missing worktree record, torn-down worktree, wall-clock bound, failed walk) but not this one. The sentence says "including", so it is not incorrect, and I left the approved placement alone rather than re-opening a settled decision. Worth one line in architecture.md only if the captain wants that enumeration exhaustive.
  • ℹ️ docs/turnend-guard.md:78 - docs/turnend-guard.md is classified operator-current, and the audience policy assigns dates and exact incident detail to maintainer-verification. Line 78 carries a one-sentence dated 2026-08-14 incident account as the rationale for the abandonment boundary. I left it because the doc already uses dated rationale in the same form (the 2026-07-21 blind window, grok 1.0.0, Cursor 2026.08.11-e8db854) and the sentence is the load-bearing why for the invariant rather than a narrative. Flagging it as a placement judgment call in case the captain would rather move the date and the 40-minute detail into docs/verification/supervision.md and keep only the mechanism here.
⚠️ **Lint** - 1 warning
  • ⚠️ linter found issues (exit code 127)

🔧 Fix: silence deliberate single-quote SC2016 in write-prune env test
1 warning still open:

  • ⚠️ linter found issues (exit code 127)
✅ **Push** - passed

✅ No issues found.

@Inthuson
Inthuson force-pushed the fm/watch-signals-k4 branch from d164ac2 to b3d8759 Compare August 17, 2026 14:17
@Inthuson Inthuson changed the title fix(bin): re-arm lapsed supervision and defer wedge escalations while a worktree is written fix(bin): re-arm after an abandoned auto-arm claim and defer a wedge escalation while a worktree is written Aug 17, 2026
@Inthuson
Inthuson force-pushed the fm/watch-signals-k4 branch from b3d8759 to 35d0dab Compare August 19, 2026 16:41
A Claude auto-arm cycle that armed, delivered one rewake, and exited left
its single-flight lock behind. Both Stop-event participants then deferred
to that lock forever, because its recorded pid was still live: the
turn-end guard read it as recovery under way and allowed the stop, and the
next Stop firing treated it as another owner and declined to arm. On
2026-08-14 a home with two tasks in flight lost supervision for about 40
minutes with no watcher process and no watcher lock, its beacon frozen at
the one delivery, and both crewmates' finished reports sat in the durable
queue until an operator drained it by hand.

Abandonment is now proven from the epoch ledger instead of inferred from
pid liveness. A lock whose holder pid matches the ledger's own owner_pid
while the recorded outcome is anything other than arming has already
finished its decision, so that claim is reclaimed under the lock's steal
mutex, stops counting as recovery ownership in the guard, and is cleared
by the guard's terminal check rather than deferred to. A failed clear
re-blocks instead of allowing a blind stop, and an arming entry stays in
flight however old it is, because its owner foregrounds the arm for the
whole watcher cycle.

Issue kunchenguid#2251's PR kunchenguid#2263 does not cover this failure. It is closed and
unmerged, lives entirely in bin/fm-watch-arm.sh, and retires the stalled
watcher and matching stale watcher lock of an arm that is currently
running. Here no arm and no watcher were running and no watcher lock
existed, so it has nothing to retire and the home stays blind.

tests/fm-claude-stop-autoarm.test.sh covers the reclaim, the still-arming
and unnamed-owner cases that must keep the gate closed, and the failed
clear. tests/fm-turnend-guard.test.sh covers the guard side of the same
boundary. Both fail without this change.
The wedge detector had two inputs, rendered pane quietness and the run
step, and neither can see a crew that is writing source, then tests, then
documentation behind a static pane. On 2026-08-14 one crewmate produced
eight consecutive possible-wedge escalations in a single afternoon, three
of them demanding deep inspection, while it was demonstrably working and
then committed. Every one of them cost a supervision turn to disprove by
hand.

Add write activity inside the crew's own recorded worktree as a third
liveness input. crew_worktree_written_since compares the worktree against
the caller's existing idle-window timer file, so -newer needs no clock
arithmetic, no temp file, and no portable mtime write. The probe runs only
inside the branch that was about to escalate, which bounds it to one
pruned, depth-bounded walk per window per FM_STALE_ESCALATE_SECS and
leaves the per-poll stale sweep exactly as cheap as before.

Positive evidence defers rather than cancels. The idle timer restarts so
the next window probes again, the escalation counter is neither advanced
nor reset so a later genuine wedge keeps the demand-deep-inspection
history it earned, and a .writing-since marker ages the whole deferral
chain so the pane still re-surfaces once per FM_PAUSE_RESURFACE_SECS,
through the same throttle shape a declared pause already uses, labeled as
a recheck rather than a wedge. This can only reduce false positives: every
absence of evidence, including no recorded worktree, a torn-down worktree,
a missing anchor, and a failed walk, falls through to the unchanged
escalation schedule, so a crew that writes nothing still escalates on the
existing timetable.

What the signal cannot see, by design or by construction:

- CPU burn with no writes, such as a long compaction, is invisible. That
  case keeps the old behavior exactly.
- A commit-only phase writes only .git, which is pruned first so that
  firstmate's own read-only git commands against the worktree can never
  make the probe self-fulfilling.
- Writes under the pruned generated trees, or deeper than
  FM_WORKTREE_WRITE_MAXDEPTH, do not count.
- The probe cannot attribute a write to the crew, so a background build or
  another process touching the tree looks the same. The hourly re-surface
  is what bounds that, and a churny file cannot buy silence.
- The away-mode daemon's own escalation path is deliberately untouched.

tests/fm-watch-triage.test.sh covers the classifier including the .git
prune, both halves of the live case on one fixture (quiet plus writing
defers, quiet plus silent still escalates and counts), and the bounded
re-surface. All three fail without this change.
Two consistency gaps in the worktree write probe, both found while reviewing
the wedge-deferral change on this branch.

A write deferral is a bounded chain: its .writing-since marker ages the whole
chain so a churning worktree still re-surfaces once per resurface window. That
is only sound while the chain belongs to the current quiet stretch, so every
path that restarts the idle-window timer has to drop it too. Two did not: the
corrupt-timer repair in wedge_timer_check, and both first-sight branches for a
captain-relevant status. A chain left over from an earlier quiet stretch made
the first deferral of the new window re-surface immediately instead of after a
full fresh window.

FM_WORKTREE_WRITE_PRUNE is a skip list, so clearing it reads as "skip nothing"
and is the obvious way to widen the probe to the whole depth-bounded tree.
Instead an empty list reported no evidence at all, quietly costing the wedge
detector its third liveness input on a home that meant to widen the walk. An
empty list now widens the walk, and the header says so.

Neither change alters when a stall that writes nothing escalates.

Regressions in tests/fm-watch-triage.test.sh cover all three paths and each
one fails on the pre-fix code.
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: Corrective — abandoned auto-arm claims now re-arm via pid-identity, and a writing worktree defers (does not cancel) a wedge with a bounded re-surface. I reviewed the full diff on current HEAD 52f0753 (wake-lib abandonment, classify probe, watch deferral, turnend guard, colocated tests) with no security risk and approved fork CI. Waiting on green checks including no-mistakes. Author's prior 13/13 claim is not visible on this HEAD: checks are empty pending first-time fork approval, so that claim is unverified here. Informational leftovers (daemon window_key copy, timeout 00, afk family map) are not merge blockers.

@Inthuson

Copy link
Copy Markdown
Contributor Author

Ready for a maintainer when you have a moment.

This one is complete on our side with all checks green. Nothing further is pending from this fork.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: Corrective — abandoned auto-arm claims re-arm via pid-identity, and a writing worktree defers (does not cancel) a wedge with a bounded re-surface. HEAD is still 52f075308bcb (same as the prior stamp). Re-stamp because CI finished green after that stamp and the author pinged. All listed checks succeeded, including Lint, portable/Herdr behavior, and Require no-mistakes. No security risk. VISION: aligns (supervision continuity, fail-safe toward real stalls). Not merge-eligible while #2744 is open and also green (standing order: prefer #2744 first). File-level overlap with #2744 on bin/fm-classify-lib.sh / AGENTS.md. Also competing same-author #2541 on the auto-arm/wedge files.

@kunchenguid kunchenguid left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Speaking as Kun's firstmate: reviewed the full thread and diff. Corrective re-arm after abandoned auto-arm and bounded write-probe deferral. Green CI including no-mistakes. #2744 has landed, this remains MERGEABLE. Approving to land.

@kunchenguid
kunchenguid merged commit 4d2cb0c into kunchenguid:main Aug 21, 2026
13 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

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

quinnbot-ai added a commit to quinnbot-ai/firstmate that referenced this pull request Aug 21, 2026
…nt (#167)

* fix(bearings): restore decision options and add close controls (kunchenguid#2707)

* fix(bearings): always show decision options and a close/drop control

Freeform-only Captain's Call cards hid the option buttons the board was designed around, and there was no way to drop a stale hold without inventing an answer. Require selectable options, keep freeform as a supplement, and route the reserved __drop__ answer through decline so the hold leaves Captain's Call.

* no-mistakes(review): Fix drop closure and decision-only option validation

* no-mistakes(review): Preserve answerability for non-decision cards

* no-mistakes(document): Clarify decision drop documentation

* ci: require no-mistakes pipeline step attestation (kunchenguid#2710)

Signature-only PRs can hide skipped review, test, or document steps. Fail unless no-mistakes >= 1.46.0 attests those three steps completed.

* feat: collapse decisions into tasks held for the captain (kunchenguid#2728)

* feat(captain-hold): collapse the decisions concept into tasks held for the captain

A decision is no longer a separate type: it is an ordinary backlog task held
for the captain, identified by its task id. bin/fm-captain-hold.sh owns the
surviving behaviors - guarded hold creation, the recorded-answer close
(answer/answers with a release mode for captain-gated work), the source
bindings, and the investigation completion gate - and bin/fm-decision-hold.sh
becomes a one-release compatibility shim over it.

The fleet snapshot now parses hold-until and computes captain_actionable as
queued + captain-held + unblocked + due, independent of row kind, plus a
presentation-only deferred_marker for prose-deferred rows. Bearings renders
every due captain-held task in Captain's Call, date-deferred holds as dated
Charted Next gates, suppresses prose-deferred rows from default views with an
omitted disclosure, and excludes from Recently Landed anything that closed
while still held for the captain.

Legacy compatibility: pre-collapse <origin>-decision-<key> rows are already
plain task ids and keep working; short keys in recorded metadata, concrete
origin bindings, chat --resolve-key fallbacks, and old resolution records all
resolve in place.

* no-mistakes(review): Fix captain answer replay and body preservation

* no-mistakes(review): Fix captain hold idempotency and legacy replay

* no-mistakes(review): Validate card close modes and compatibility routing

* no-mistakes(review): Enforce release replay mode matching

* no-mistakes(review): Prevent duplicate decision cards and released replay mismatches

* no-mistakes(review): Preserve answer columns and legacy resolve replays

* no-mistakes(document): Document strict replay and legacy compatibility

* no-mistakes(lint): Quote done literals to satisfy ShellCheck

* no-mistakes: apply CI fixes

* fix(rebase): keep collapsed captain hold board semantics

* fix: bound recovery announcements and preserve supervision (kunchenguid#2733)

* fix(watch): announce recovery once per generation and keep successors supervising

A lost Pi/OpenCode handling handshake re-announced the same recovery
generation on every cycle and spent the successor's first ~55s blind, so
a real crew event could be ignored and then dropped. Record the
announcement in the durable marker, confirm the handshake before the
follow-up without swallowing failure, and enter the poll loop immediately.

* no-mistakes(review): Tighten recovery event timing regression

* no-mistakes(document): Document recovery-loop supervision guarantees

* fix(bin): surface captain-call record divergence (kunchenguid#2744)

* fix(bin): signal a captain call resolved in the log but still held

A captain call has two records and closing one has never closed the
other: a `resolved [key=...]` line closes the status-log fold, while the
backlog task held for the captain closes only through
`fm-captain-hold.sh answer`. Answering on the status side alone left no
trace of the disagreement - the fold went quiet, the durable record kept
saying the captain owed an answer, and nothing warned. The defect was
never the separation; it was the silence.

Add `fm-captain-hold.sh diverged`, a read-only report of that
contradiction, and print it from `fm-wake-drain.sh` as a bounded RECORD
DIVERGENCE section beside OPEN DECISIONS on every drain. It flags one
condition: a task still open and still carrying the captain-hold
annotations whose key was closed on the status side by the resolve verb,
under the collapsed identity or the legacy derived one.

It closes nothing, ever. A captain call closed wrongly leaves review
entirely, which is worse than the noise, so both reconciliation
directions stay human-owned and the printed hint names both - a
resolution is not proof the captain ruled, since a call can dissolve on a
false premise or turn out to have been a question of fact.

Three states are deliberately not divergence: a `captain-held` close is
the verified transfer `complete` writes, a still-open keyed decision
belongs to the OPEN DECISIONS fold, and a captain call with no routed
work item is legitimate rather than incomplete, so routed work is no part
of the test.

`fm-classify-lib.sh` gains `status_key_closing_verb`, which reports how
the status side currently reads one key by replaying the existing
`_fm_decision_fold_line` rule rather than re-deriving it, so the two
closing verbs stay distinguishable in one place. The per-wake cost is one
`tasks-axi list`, one key scan per status log, and the precise per-key
fold only for a key that already names a still-open task; the call is
hard-bounded so a slow backlog tool can never delay wake presentation.

* fix(document): Correct divergence lifecycle documentation

* fix(document): Neutralize divergence lifecycle prose

* fix(bin): re-arm after an abandoned auto-arm claim and defer a wedge escalation while a worktree is written (kunchenguid#2524)

* fix(watch): re-arm supervision after an abandoned auto-arm claim

A Claude auto-arm cycle that armed, delivered one rewake, and exited left
its single-flight lock behind. Both Stop-event participants then deferred
to that lock forever, because its recorded pid was still live: the
turn-end guard read it as recovery under way and allowed the stop, and the
next Stop firing treated it as another owner and declined to arm. On
2026-08-14 a home with two tasks in flight lost supervision for about 40
minutes with no watcher process and no watcher lock, its beacon frozen at
the one delivery, and both crewmates' finished reports sat in the durable
queue until an operator drained it by hand.

Abandonment is now proven from the epoch ledger instead of inferred from
pid liveness. A lock whose holder pid matches the ledger's own owner_pid
while the recorded outcome is anything other than arming has already
finished its decision, so that claim is reclaimed under the lock's steal
mutex, stops counting as recovery ownership in the guard, and is cleared
by the guard's terminal check rather than deferred to. A failed clear
re-blocks instead of allowing a blind stop, and an arming entry stays in
flight however old it is, because its owner foregrounds the arm for the
whole watcher cycle.

Issue kunchenguid#2251's PR kunchenguid#2263 does not cover this failure. It is closed and
unmerged, lives entirely in bin/fm-watch-arm.sh, and retires the stalled
watcher and matching stale watcher lock of an arm that is currently
running. Here no arm and no watcher were running and no watcher lock
existed, so it has nothing to retire and the home stays blind.

tests/fm-claude-stop-autoarm.test.sh covers the reclaim, the still-arming
and unnamed-owner cases that must keep the gate closed, and the failed
clear. tests/fm-turnend-guard.test.sh covers the guard side of the same
boundary. Both fail without this change.

* fix(watch): defer a wedge escalation while the task worktree is written

The wedge detector had two inputs, rendered pane quietness and the run
step, and neither can see a crew that is writing source, then tests, then
documentation behind a static pane. On 2026-08-14 one crewmate produced
eight consecutive possible-wedge escalations in a single afternoon, three
of them demanding deep inspection, while it was demonstrably working and
then committed. Every one of them cost a supervision turn to disprove by
hand.

Add write activity inside the crew's own recorded worktree as a third
liveness input. crew_worktree_written_since compares the worktree against
the caller's existing idle-window timer file, so -newer needs no clock
arithmetic, no temp file, and no portable mtime write. The probe runs only
inside the branch that was about to escalate, which bounds it to one
pruned, depth-bounded walk per window per FM_STALE_ESCALATE_SECS and
leaves the per-poll stale sweep exactly as cheap as before.

Positive evidence defers rather than cancels. The idle timer restarts so
the next window probes again, the escalation counter is neither advanced
nor reset so a later genuine wedge keeps the demand-deep-inspection
history it earned, and a .writing-since marker ages the whole deferral
chain so the pane still re-surfaces once per FM_PAUSE_RESURFACE_SECS,
through the same throttle shape a declared pause already uses, labeled as
a recheck rather than a wedge. This can only reduce false positives: every
absence of evidence, including no recorded worktree, a torn-down worktree,
a missing anchor, and a failed walk, falls through to the unchanged
escalation schedule, so a crew that writes nothing still escalates on the
existing timetable.

What the signal cannot see, by design or by construction:

- CPU burn with no writes, such as a long compaction, is invisible. That
  case keeps the old behavior exactly.
- A commit-only phase writes only .git, which is pruned first so that
  firstmate's own read-only git commands against the worktree can never
  make the probe self-fulfilling.
- Writes under the pruned generated trees, or deeper than
  FM_WORKTREE_WRITE_MAXDEPTH, do not count.
- The probe cannot attribute a write to the crew, so a background build or
  another process touching the tree looks the same. The hourly re-surface
  is what bounds that, and a churny file cannot buy silence.
- The away-mode daemon's own escalation path is deliberately untouched.

tests/fm-watch-triage.test.sh covers the classifier including the .git
prune, both halves of the live case on one fixture (quiet plus writing
defers, quiet plus silent still escalates and counts), and the bounded
re-surface. All three fail without this change.

* no-mistakes(review): prove autoarm claims by identity; skip mate-home write probe

* no-mistakes(document): document away-mode wedge boundary and probe filesystem limit

* no-mistakes(document): qualify turn-end recovery condition for abandoned auto-arm claims

* fix(watch): keep a write deferral scoped to its own idle window

Two consistency gaps in the worktree write probe, both found while reviewing
the wedge-deferral change on this branch.

A write deferral is a bounded chain: its .writing-since marker ages the whole
chain so a churning worktree still re-surfaces once per resurface window. That
is only sound while the chain belongs to the current quiet stretch, so every
path that restarts the idle-window timer has to drop it too. Two did not: the
corrupt-timer repair in wedge_timer_check, and both first-sight branches for a
captain-relevant status. A chain left over from an earlier quiet stretch made
the first deferral of the new window re-surface immediately instead of after a
full fresh window.

FM_WORKTREE_WRITE_PRUNE is a skip list, so clearing it reads as "skip nothing"
and is the obvious way to widen the probe to the whole depth-bounded tree.
Instead an empty list reported no evidence at all, quietly costing the wedge
detector its third liveness input on a home that meant to widen the walk. An
empty list now widens the walk, and the header says so.

Neither change alters when a stall that writes nothing escalates.

Regressions in tests/fm-watch-triage.test.sh cover all three paths and each
one fails on the pre-fix code.

* no-mistakes(review): honor an empty write-prune, bound the probe, share window_key

* no-mistakes(document): align probe knob count and guard regression-coverage ownership

* no-mistakes(lint): silence deliberate single-quote SC2016 in write-prune env test

* fix(bin): land local-only dirt that is already the target tip's content

fm-merge-local.sh refused any dirty checkout, which deadlocked the case where
the dirt IS what the merge would write: a generator that re-runs locally and
reproduces bytes the task branch already contains. The refusal was unresolvable
because landing the branch was the thing that would have cleaned it.

Allow the fast-forward when every dirty path is provably the tip's own content.
A throwaway index seeded from the tip, refreshed against the working tree, is
what proves it, so content filters, symlinks, and file mode are judged by git
rather than by a filename or timestamp heuristic. Staging must also lose
nothing: a path's index entry has to be HEAD's or the tip's, never a third
version. Only then are those paths staged, after the diverged-branch check, so
the merge sees a consistent tree and writes no byte that is not already on disk.

Every other dirty checkout refuses exactly as before: one differing byte, a
different staged version, a different file mode, a local deletion, an untracked
path the tip does not carry, and anything the tip holds as a directory or
submodule pointer.

tests/fm-merge-local.test.sh covers both directions, including the reproduction
that fails on the previous code.

---------

Co-authored-by: Kun Chen <[email protected]>
Co-authored-by: Mickaël Rémond <[email protected]>
Co-authored-by: Inthuson <[email protected]>
Co-authored-by: QuinnBot <[email protected]>
withally added a commit to withally/firstmate that referenced this pull request Aug 22, 2026