Repository navigation
test(tests): pin answered-decision terminal-stale regressions for the watcher - #3
Merged
Merged
Conversation
The 2026-08-05/09 incidents re-surfaced an already-answered needs-decision as a terminal stale on every distinct quiet-pane hash, because the pre-kunchenguid#233 watcher trusted the append-only status log's last line without consulting the branch-matched run-step. The terminal-stale override that fixes this landed in kunchenguid#233; these tests pin the exact live sequence so it cannot regress: an answered decision with a resumed run is absorbed on every distinct quiet hash, while a parked gate and an unreadable run still surface (the reconciliation fails toward surfacing). Verified failing against the pre-kunchenguid#233 watcher (7af373e), which surfaces stale: <window> for the answered decision exactly as observed live.
…atch-triage header
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Fix the watcher defect where an ALREADY-ANSWERED needs-decision was re-surfaced as a terminal stale every time a crew pane went quiet: bin/fm-watch.sh's stale_is_terminal path read the append-only status LOG's last line instead of the authoritative no-mistakes run-step, so after firstmate answered a decision and the run went back to validating(running), every new quiet pane hash re-fired 'stale:' and burned a full LLM turn (observed live 2026-08-05 and 2026-08-09). Investigation established that current main ALREADY contains the code fix (the kunchenguid#233 terminal-stale run-step override: stale_is_terminal consults the branch-matched run-step first and treats a captain-relevant verb in the log as superseded when an active run has moved past it, failing safe to surfacing when the run-step cannot be read); the live re-fires happened because the running watcher's primary checkout (7af373e, 2026-07-03) predates kunchenguid#233. This branch therefore deliberately contains NO production code change - it pins the exact live sequence as regression tests in the watcher test suite: (1) needs-decision written to the log, decision answered, run active again, pane quiet -> must NOT surface as a terminal stale; (2) the safety case, same log last-line with NO active run -> MUST still surface; plus review-round hardening commits covering the unreadable-verdict fallback, pinning the terminal-override branch, stabilizing phase-2 timing, and reaping helper processes on phase-1 failure, and the pipeline's own test-step stabilization commit (wait for the absorb to land via the triage line before asserting, with bounded budgets for loaded machines). Constraints honored per the task brief: fail-safe direction preserved (unreadable run-step keeps today's surfacing behavior), no changes to the afk daemon classification or bin/fm-classify-lib.sh's captain-relevant verb set, and the run-step read stays on the stale path only so per-wake triage stays cheap. Known repo caveat: fm-teardown-test-red is a pre-existing failing teardown test on firstmate main (confirmed 2026-08-03 by base-compare) and is not introduced by this branch.
What Changed
tests/fm-watch-triage.test.shpinning the live re-surfaced-decision sequence: an already-answeredneeds-decision:left as the status log's last line while the branch-matched run is active again must be absorbed by the terminal-stale run-step override on every distinct quiet pane hash (never re-firestale:), and the fail-safe counterpart — parked gate, no readable run, and an unreadable run-step verdict — must still surface and queue the terminal stale.wait_log_counthelper and switched the terminal-override, provably-working, and declared-pause absorb tests from a fixed 3s liveness wait to waiting on the triage line each absorb branch appends last, so assertions read a completed absorb instead of racing it on a loaded machine; failure paths now reap the watcher before failing, and phase-B escalation budgets were widened.No production code changed on this branch —
bin/fm-watch.shalready contains the run-step override these tests pin. Pipeline: full watcher suite 48/48 green, plus a mutation check against a pre-override watcher where the absorb test fails as expected. Review flagged three non-blocking infos (helper consolidation for the hand-rolled poll loops;wait_log_countnot observing the watcher pid; the tests' dependence on triage-line write ordering insidebin/fm-watch.sh). Test step also notes a pre-existing intermittent failure intest_exited_declared_pause_is_bounded_but_live_gate_surfaces, byte-identical to base and unrelated to this branch, left for a separate fix.Risk Assessment
✅ Low: Test-only change that adds well-targeted regression coverage matching the stated intent, reuses established fixture patterns in the same file, reaps background watchers on every new failure path, and carries only bounded-latency and deduplication nits.
Testing
Ran the targeted watcher-triage suite (48/48 ok) plus the crew-state suite (49/49 ok), then demonstrated the intent end-to-end by driving the real
bin/fm-watch.shthrough the exact incident sequence: an answered needs-decision whose run resumed stays absorbed and silent across two distinct quiet pane hashes with nothing queued, while the same leftover log line with no active run still surfacesstale:and lands in the durable wake queue. A mutation run against a pre-kunchenguid#233 watcher reproduces the live re-fire and makes the new regression test fail with the incident's own symptom, confirming the tests pin the defect rather than passing vacuously; the fail-safe surfacing test passes on both builds. One pre-existing race in the sibling override test was hardened using the branch's own wait-for-triage pattern; one unrelated pre-existing flake in the dead-agent pause-cadence test remains and is reported for the author.Evidence: Real watcher transcript — answered decision absorbed, unanswered still surfaces
SCENARIO 1 answered decision, run resumed - must NOT re-surface -- first quiet pane hash -- status log (append-only, last line is what the old code trusted): | working: implementing the schema migration | needs-decision: pick migration A or B crew-state verdict (authoritative run-step read): | state: working · source: run-step · validating (running) · status-log superseded by active run >> WATCHER WAKE: (none - watcher stayed blocked, no supervision turn burned) triage log: | [2026-08-09T23:50:22-0700] absorbed stale (provably working, overriding a stale captain-relevant status): fm:axi durable wake queue (bin/fm-wake-drain.sh): | (empty - nothing queued for the captain) -- pane changed, then re-quieted at a NEW hash -- >> WATCHER WAKE: (none - watcher stayed blocked, no supervision turn burned) triage log: | [2026-08-09T23:50:22-0700] absorbed stale (provably working, overriding a stale captain-relevant status): fm:axi | [2026-08-09T23:50:25-0700] absorbed stale (provably working, overriding a stale captain-relevant status): fm:axi durable wake queue (bin/fm-wake-drain.sh): | (empty - nothing queued for the captain) SCENARIO 2 same leftover log line, NO active run - MUST still surface crew-state verdict: state: parked · source: run-step · parked at plan-approval: 1 finding(s) >> WATCHER WAKE (firstmate is woken, one LLM supervision turn burned): $ stale: fm:axi durable wake queue (bin/fm-wake-drain.sh): | 1786344630 1 stale fm:axi stale: fm:axiEvidence: Pre-kunchenguid#233 watcher — the live defect reproduced (re-fires on every quiet hash)
watcher under test: bin/.fm-watch-pre233.sh (override disabled; deleted after the run) -- first quiet pane hash -- (answered decision, run actively validating) >> WATCHER WAKE (firstmate is woken, one LLM supervision turn burned): $ stale: fm:axi durable wake queue: 1786344637 1 stale fm:axi stale: fm:axi -- pane changed, then re-quieted at a NEW hash -- >> WATCHER WAKE (firstmate is woken, one LLM supervision turn burned): $ stale: fm:axi durable wake queue: 1786344642 2 stale fm:axi stale: fm:axiEvidence: New regression tests catch the defect (mutation check)
$ FM_WATCH_OVERRIDE=<pre-233 watcher> <new regression tests> not ok - watcher exited for an answered needs-decision whose run resumed (should absorb): stale: test:fm-answered $ <same tests, unmodified bin/fm-watch.sh> ok - an answered needs-decision with a resumed run is absorbed on every distinct quiet hash, never re-surfaced ok - an unanswered needs-decision still surfaces: a parked gate, no readable run, and an unreadable verdict all fail toward surfacing $ FM_WATCH_OVERRIDE=<pre-233 watcher> <safety test alone> ok - an unanswered needs-decision still surfaces: a parked gate, no readable run, and an unreadable verdict all fail toward surfacing # => the pre-#233 watcher fails ONLY the absorb regression; the fail-safe # surfacing case is unchanged by the fix, exactly as the intent requires.Evidence: Reproducible harness used to produce both transcripts
Evidence: tests/fm-watch-triage.test.sh — full suite, 48/48 ok
Evidence: tests/fm-crew-state.test.sh — authoritative run-step reader, 49/49 ok
Evidence: Branch scope — no production file changed
$ git diff --stat 477ad93..6cb22d4 tests/fm-watch-triage.test.sh | 232 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 222 insertions(+), 10 deletions(-) $ git diff --name-only 477ad93..6cb22d4 -- bin/ skills/ docs/ (no files)Evidence: Evidence index
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
tests/fm-watch-triage.test.sh:57-wait_log_countpolls the triage log but never checks the watcher pid, so the comments at :588 and :718 ("a re-surface exits the watcher, which the wait detects at once") are only true for the fixed 3swait_livethat precedes it. If a regression surfaces after that 3s window (the loaded-machine case these waits exist for), the watcher is already dead andwait_log_countstill spins its full 20s budget before failing — at 4 call sites. Conversely, the fixedwait_live "$pid" 30is now an unconditional 3s sleep on every happy path. Threading the pid intowait_log_countand breaking onkill -0failure would make both the pass and fail paths fast and let the redundantwait_livego.tests/fm-watch-triage.test.sh:611- The branch adds two more hand-rolled "poll a state file until it matches, abort if the watcher dies" loops (:611 waiting for.stale-$key== hash2, :1064 waiting for.wedge-escalations-$keyto disappear), joining four existing copies of the same shape at :1100, :1120, :1623, :1660. A single helper (e.g.wait_state "$pid" <file> <expected-or-absent> <limit>) alongsidewait_log_countwould collapse all six and give uniform diagnostics on timeout.tests/fm-watch-triage.test.sh:585- The new synchronization depends on two ordering details inside bin/fm-watch.sh that nothing enforces: thattriage_logis the LAST side effect of each absorb branch (true today at fm-watch.sh:990-992, :1030-1032 and handle_paused_stale:330-345), and thatclear_pause_tracking's singlerm -fdeletes.wedge-escalations-after the other markers (fm-watch.sh:362). Both hold, and rm processes operands in order, but a future reorder of those writes would turn these tests flaky rather than failing loudly. Noted only — pinning it with a source comment would mean a production edit, which this branch deliberately excludes.tests/fm-watch-triage.test.sh:897- Pre-existing flaky test, not introduced by this branch:test_exited_declared_pause_is_bounded_but_live_gate_surfacesfails intermittently (~1 in 4 isolated runs on this machine), usually at the exited-captain-held sub-case ("captain-held dead-agent pane did not re-surface on the bounded cadence") and sometimes at the six-round loop ("dead-agent declared pause flooded stale wakes...", where awk also crashes on a missing .wake-queue and prints an empty count). The function body is byte-identical to base commit 477ad93, and it is unrelated to this branch's subject (dead-agent/captain-held pause cadence, not the terminal-stale run-step override). I trialled the same hardening the branch applies elsewhere (wait for the decision to land per round; 20s exit budgets instead of 4s) and it still failed once, so it is not purely a timing-budget issue - there is real nondeterminism in the pause-classification path worth a proper look. I reverted that trial rather than land a half-fix to an out-of-scope test; the author should decide whether to fix it here or file it separately.tests/fm-watch-triage.test.sh:512- Test-only fix I applied while validating:test_stale_terminal_status_overridden_by_active_run(the direct sibling of the new regression tests, guarding the same fix: absorb stale wakes during active validation kunchenguid/firstmate#233 override branch) asserted on state files after a flatwait_live "$pid" 30(3s), which loses the race on a loaded machine - it failed twice during this run ("stale suppressor not advanced on absorb" in phase A, "did not escalate an overridden stale terminal status past the threshold" in phase B). I applied the branch's own established pattern: wait viawait_log_countfor the triage line the override branch appends last, re-check liveness, reap before every failure, and widen phase B's exit budget from 40 to 200 ticks. 7 consecutive green runs afterwards; full suite 48/48.bash tests/fm-watch-triage.test.sh— full suite, 48/48 ok, exit 0bash tests/fm-crew-state.test.sh— 49/49 ok (authoritative run-step reader the fix consults)test_stale_answered_needs_decision_superseded_by_resumed_runandtest_stale_needs_decision_without_active_run_still_surfacesrun in isolation 3x each — consistently greenMutation check: same two tests run against a throwaway pre-#233bin/fm-watch.sh(run-step override replaced withif false; then) — the absorb regression fails withstale: test:fm-answered, the fail-safe surfacing test still passes; mutant deleted afterwardsManual end-to-end:bash watcher-decision-demo.sh <repo> <workdir>drives the realbin/fm-watch.shwith a fake tmux pane and afm-crew-state.shstub returning the realstatus-log superseded by active runverdict; captured watcher stdout,.watch-triage.log, andbin/fm-wake-drain.shoutput for both the answered (two distinct quiet hashes) and parked casesManual end-to-end against the pre-#233 watcher:bash watcher-decision-demo.sh <repo> <workdir> bin/.fm-watch-pre233.sh— reproducesstale: fm:axire-firing on every quiet hashtest_stale_terminal_status_overridden_by_active_runandtest_exited_declared_pause_is_bounded_but_live_gate_surfaceseach run in isolation 7x to characterize flakiness before and after hardeninggit diff --name-only 477ad93..6cb22d4 -- bin/ skills/ docs/— confirms the no-production-change constraintbash -n tests/fm-watch-triage.test.sh; verified no stray watcher processes and a clean worktree apart from the intentional test fixbin/fm-test-run.sh:430- bin/fm-test-run.sh's portable-serial weight hint for tests/fm-watch-triage.test.sh (113051 ms, line 430) predates the two watcher tests this branch adds, so it now understates the script's serial cost. I could not fix it here: it lives in an executable script, and this task is limited to documentation and doc comments. No documented fact is wrong — docs/fm-test-portable-shards.md dates the hints to the 2026-08-02 timing artifact and states explicitly that a stale hint costs shard balance rather than coverage — so this is a follow-up for whoever next refreshes the timing artifact, not a doc defect.✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.