Skip to content
This repository was archived by the owner on Oct 20, 2026. It is now read-only.

fix(watcher): stop per-poll stale runaway on a finished-and-parked crew - #1

Merged
psacc merged 3 commits into
mainfrom
fm/watcher-stale-rca-k2
Jul 17, 2026
Merged

psacc merged 3 commits into
mainfrom
fm/watcher-stale-rca-k2

Conversation

@psacc

@psacc psacc commented Jul 17, 2026 •

Copy link
Copy Markdown
Owner

Problem

The always-on supervision watcher entered a runaway false-alarm loop for a crew that had finished its pipeline but was parked awaiting a captain decision. Once such a crew reached authoritative state done (for example, a PR raised and being monitored for merge/close) and appended a paused: awaiting-captain-decision as its last status line, the watcher re-appended a stale: wake on every poll (roughly every 15-30s), burning a full supervisor turn each time, for the crew's entire parked life.

Root cause

In bin/fm-watch.sh's stale poll loop, the suppressor-equal (already-surfaced hash) branch re-classifies a paused-last-line pane via pause_state_class. For a done/parked crew, crew_absorb_class returns none, which fell through to surface_nonterminal_stale with no cadence gate. surface_nonterminal_stale also deletes the pause/wedge markers, so neither the wedge timer nor the pause-recheck throttle could ever engage - the loop re-entered the same none -> surface path every poll. The per-hash suppressor (.stale-<key> equal to the current hash) never suppressed, because the paused-last-line branch bypassed it.

The fault is exposed only by a done-and-parked crew in normal (non-away) supervision: an actively-working crew is absorbed on the working arm, a genuinely paused crew on the long pause cadence, and away mode uses a one-shot-per-hash branch.

Fix

  • Add crew_reached_terminal in bin/fm-classify-lib.sh, true only for authoritative state done or parked. This is deliberately narrower than crew_absorb_class's none, which also covers failed/unknown/torn-down crews that carry no positive terminal confirmation.
  • In the suppressor-equal paused-last-line branch, route a terminal crew to handle_paused_stale (re-check on the long FM_PAUSE_RESURFACE_SECS cadence, since it was already surfaced once), while a genuinely stopped or unknown crew keeps surfacing via surface_nonterminal_stale.
  • The first-sight arm is unchanged, so a crew's finish is still surfaced exactly once.
  • On the terminal route, refresh the .paused-rechecked-<key> marker so pause_state_class's fast path absorbs subsequent polls without re-reading the authoritative crew state every poll - the costly read runs only on first sight per FM_STALE_ESCALATE_SECS window, honoring the classifier's stated invariant.
  • A provably-working crew (the fix: absorb stale wakes during active validation kunchenguid/firstmate#233 "absorb stale wakes during active validation" protection) and a genuinely-paused crew (the feat(watcher): add paused external-wait supervision kunchenguid/firstmate#421 pause-transition reclassification) are unaffected.

Tests

Six regression cases in tests/fm-watch-triage.test.sh, driving the real fm-watch.sh poll loop through the existing harness:

Docs

docs/architecture.md and docs/configuration.md describe the new terminal-parked recheck behavior. Note: the pipeline's documentation step also added a couple of lines documenting the pre-existing FM_SPAWN_WORKTREE_POLL_TRIES knob (in docs/configuration.md and docs/herdr-backend.md); that knob landed earlier and was undocumented, so this only fills that gap - it is not part of the watcher change.

Validation

Validated end-to-end through the local no-mistakes pipeline on a quiet machine: review, tests (full suite, 0 findings), document, and lint all passed. This fork runs no GitHub CI, so the local pipeline is the validation gate.

psacc and others added 3 commits July 17, 2026 09:40
A crew that finished its pipeline (authoritative state done, e.g. a PR raised
and monitoring for merge/close) and then appended a `paused: awaiting-decision`
last line re-surfaced a stale wake on every poll. The suppressor-equal
paused-last-line branch re-classified via pause_state_class, whose `none` verdict
(crew_absorb_class maps done -> none) fell through to surface_nonterminal_stale
with no cadence gate; surface then deleted the pause/wedge markers, so nothing
could ever throttle it. Each wake exits the watcher and it re-arms, so a done and
parked pane burned a supervisor turn every 20-30s.

Add crew_reached_terminal (done or parked) and, on the already-surfaced
(suppressor-equal) hash, route a terminal crew to handle_paused_stale for a long
pause-cadence recheck while a genuinely stopped or unknown crew keeps surfacing.
The first-sight arm is untouched, so the finish is still surfaced once;
provably-working (kunchenguid#233) and declared-pause (kunchenguid#421) crews are unaffected.

Regression tests cover the five cases in tests/fm-watch-triage.test.sh.
The terminal -> long-cadence recheck route never wrote the
.paused-rechecked-<key> marker, so pause_state_class's zero-read fast
path never engaged and every poll re-ran two authoritative
fm-crew-state.sh reads (crew_absorb_class + crew_reached_terminal) for
the crew's entire parked lifetime. Record the marker when the terminal
route absorbs, restoring the first-sight-only read invariant; the read
re-verifies on the existing STALE_ESCALATE_SECS cadence. Adds a
call-counting regression test proving the read does not repeat per poll.
@psacc
psacc merged commit b2027d1 into main Jul 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant