Skip to content

fix(bin): stop the repeating watcher recovery wake and stop reading a busy watcher as hung - #7205

Open
Marsjohn-11 wants to merge 11 commits into
kunchenguid:mainfrom
Marsjohn-11:fm/watcher-recovery-wake-repeat
Open

Marsjohn-11 wants to merge 11 commits into
kunchenguid:mainfrom
Marsjohn-11:fm/watcher-recovery-wake-repeat

Conversation

@Marsjohn-11

@Marsjohn-11 Marsjohn-11 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What Changed

  • When a turn-boundary re-arm reopens an announced recovery episode, it now keeps the episode's current generation instead of minting a new one (_fm_recovery_marker_reopen_announced in bin/fm-wake-lib.sh). This lets an acknowledgement that was already handed out land. Separately, bin/fm-wake-drain.sh now retires the episode when an acknowledgement settled what was presented: it consumed rows, or it had none to consume and no presented row waits above its cutoff. Together these stop the loop of one firstmate turn per recovery round. A stale acknowledgement still leaves the episode open.
  • bin/fm-watch.sh now touches the liveness beacon at every progress point in a cycle (between reconciliation steps, before each check, at each scan phase, before each scanned window), not once per cycle. A large fleet's long cycle no longer looks like a wedged watcher. A new state/.last-cycle-turnover marker is touched once per cycle, just before the terminal wait. Only the tests read it, to wait for a cycle to finish.
  • Updated the comments in fm-claude-stop-autoarm.sh, fm-supervision-lib.sh and fm-wake-lib.sh, and the docs (watcher-continuity.md, turnend-guard.md, verification/supervision.md, the operational-home-layout skill), to describe the new beacon cadence and retirement rule. Added and adjusted tests: a recovery-loop re-arm between presentation and acknowledgement, a check sweep longer than the grace that keeps the beacon fresh, and new episode-retirement expectations in the wake-queue, arm, triage and watcher-lock tests.

Scope note

The late-append behaviour from the original #5421 was dropped to match main: a wake appended over an announced recovery episode still starts a fresh generation (#4819, #5489), so this PR does not make a row appended during handling leave the presented acknowledgement able to retire its episode. The same-generation reopen, the acknowledgement retirement rule and the per-progress-point beacon are kept. If you want the late-append behaviour too, the alternative is for an append over an announced downtime episode to reopen it pending on the same generation and rewrite main's characterization fixtures; say so and it can be added.

This PR and #7203 both add per-progress beacon touches in bin/fm-watch.sh; whichever lands second reconciles them.

Risk Assessment

⚠️ Medium: The change alters core recovery-marker transitions (same-generation reopen, broader ack retirement) and beacon semantics that guards and arms depend on. Tracing the append, reopen, arm-check and ack paths showed them consistent with main's append rule and the documented contract, but this is a central supervision state machine, so it deserves maintainer attention.

Testing

The Test agent exceeded its invocation budget before live validation completed; no evidence was gathered for this head.

  • Outcome: ⚠️ 1 warning across 1 run (30m1s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - medium risk

✅ No issues found.

⚠️ **Test** - 1 warning
  • ⚠️ The Test agent did not finish within its invocation budget. Reported: agent run tests timed out after 30m0s: agent last produced output 5m5s ago (90 observed); agent reported: claude exited: exit status 255:. This is a budget or provider-slowness cut, not a code failure. Re-running the same request costs another full budget, so no further attempt is made automatically. If this repository's targeted tests or evidence gathering routinely approach the default 30m0s, raise test_agent_timeout in global config. Respond with fix to spend another budget: a repair turn runs only for selected findings other than this budget cut, then validation re-runs. Or abort and retry after raising the budget.
✅ **Document** - passed

✅ No issues found.

⚠️ **Lint** - 1 warning
  • ⚠️ linter found issues (exit code 1)
✅ **Push** - passed

✅ No issues found.

…a busy watcher as hung

Two faults in the same area left a 38-task home with no live watcher for stretches of
hours while costing a supervision turn every few minutes.

A watcher start that found an announced but unacknowledged downtime episode minted a
fresh generation, which invalidated the acknowledgement the handling turn had already
been given. Every turn then announced recovery, exited on that wake, and left nothing
supervising in between. The reopen now keeps the episode's own generation, and an
acknowledgement retires an episode once it has settled what was presented rather than
waiting for an empty queue, which a busy home never reaches. A row appended during
handling stays queued and resurfaces through its own wake.

Separately, the liveness beacon was touched once per cycle while a cycle's work scales
with the fleet, so cycles ran 300-1000s against a 300s grace. Arms then refused to
attach to a live pid with a stale beacon, and the guard reported supervision as hung.
The watcher now beats at each proven-progress point, so beacon age bounds progress
rather than cycle turnover.

That split the beacon's meaning from cycle turnover, which tests/fm-watch-triage.test.sh
had been inferring from it: its cycle waits began returning inside the first fraction of
a cycle and two CI shards failed. Turnover now has its own signal,
state/.last-cycle-turnover, touched exactly once per cycle immediately before the
terminal wait. Nothing may infer turnover from the beacon.

Observable for consumers: state/.last-cycle-turnover is new durable state, documented in
AGENTS.md. The beacon's meaning changed from per-cycle to per-progress-point; every
existing reader uses it for freshness only, so no reader changed.

Tests cover the turn-boundary re-arm between presentation and acknowledgement, a cycle
whose beacon must keep advancing through a sweep longer than the grace, and the turnover
marker bounded to exactly one touch per cycle. docs/verification/supervision.md holds
the measurements. docs/watcher-continuity.md and docs/turnend-guard.md record the known
limitations, including the check-timeout gap tracked as arm-guard-poll-derived-grace.

This branch carries only this fix, nothing from PR 4488, which gets its own run.
The per-progress-point beat, the turnover marker, and the recovery-generation
reopen are exercised by five specific cases. Record them with their observed
output and why each one is the case that breaks if its contract regresses, so a
later change to those contracts knows what to run.

States the scoping rationale explicitly: targeted validation belongs to the
no-mistakes evidence path while CI owns broad regression coverage across its
nine sharded lanes, and running either enclosing suite whole here would
duplicate that serially.
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @Marsjohn-11. The base reproductions (28s stale beacon, generation churn at T3) and the lab beacon drive make this easy to follow.

  • Review: the no-mistakes attestation matches the tip (e69caf7e), and live validation is go (6 of 6). I found no safety concerns in the diff.
  • CI: parallel 1 fails on the same Pi type error that currently breaks main, so that one is not yours. Serial 2 hit the known 30-minute cancel, and I re-ran it once. All other shards are green.
  • Contract-class: new-default. This changes three behaviors that docs/watcher-continuity.md documents on main: a reopen now keeps the generation, an acknowledgement that consumed any row now retires the episode, and the beacon is touched many times per cycle (plus the new .last-cycle-turnover file). It is a good direction, but it changes the default, so Kun will make the merge call himself once main and this PR are green. That decision is not waiting on you.
  • Two optional notes:
    1. no-mistakes' review left one info-level point open: the sentence at docs/watcher-continuity.md ~224 ("If a durable row arrived after the announcement, the arm returns that episode to pending") no longer matches the code under main's append rule. The real trigger is presented-but-unacknowledged rows still queued.
    2. Your fix(bin): keep the watcher beacon fresh through long reply histories and scans #7203 also changes the watcher beacon in bin/fm-watch.sh. Whichever lands second will probably need a rebase.

@Marsjohn-11 Marsjohn-11 changed the title fix(bin): stop repeating watcher recovery wakes and stop reading a busy watcher as hung fix(bin): stop the repeating watcher recovery wake and stop reading a busy watcher as hung Oct 13, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @Marsjohn-11, the reworded docs/watcher-continuity.md passage now names the real trigger (presented rows still unacknowledged), and the turnend-guard beacon sentence matches the per-progress-point cadence. That closes the no-mistakes doc nit from last time.

Re-look at tip 3c0546b4:

  • Delta since e69caf7e: docs only (docs/watcher-continuity.md, docs/turnend-guard.md); no code changed.
  • No-mistakes attestation: matches the tip. This raise gathered no live evidence of its own (the Test agent ran out of budget). The code is byte-identical to e69caf7e, so the earlier 6/6 live go still covers the behavior, and I'm not asking you to re-run it.
  • CI: parallel 1 fails only on the Pi 1.2 BeforeAgentStartEvent.prompt type error that currently breaks main, so that one isn't yours. Serial 2 hit the known 30-minute cancel again, and I've re-run it once. Every other shard is green.
  • Contract-class: still new-default, for the same three changes to documented default paths as before. Once main and this PR are green, Kun makes the merge-or-leave call himself. That decision is not waiting on you.

The #7203 beacon overlap note still stands.

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.

2 participants