Skip to content

test(tests): pin answered-decision terminal-stale regressions for the watcher - #3

Merged
saucetech merged 5 commits into
mainfrom
fm/fm-stale-terminal-reads-stale-log
Aug 10, 2026
Merged

saucetech merged 5 commits into
mainfrom
fm/fm-stale-terminal-reads-stale-log

Conversation

@saucetech

Copy link
Copy Markdown
Owner

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

  • Added two regression tests to tests/fm-watch-triage.test.sh pinning the live re-surfaced-decision sequence: an already-answered needs-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-fire stale:), and the fail-safe counterpart — parked gate, no readable run, and an unreadable run-step verdict — must still surface and queue the terminal stale.
  • Added a wait_log_count helper 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.
  • Updated the test file's header comment to describe the new answered-decision and fail-safe coverage.

No production code changed on this branch — bin/fm-watch.sh already 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_count not observing the watcher pid; the tests' dependence on triage-line write ordering inside bin/fm-watch.sh). Test step also notes a pre-existing intermittent failure in test_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.sh through 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 surfaces stale: 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:axi

watcher under test: /Users/sauce/.no-mistakes/worktrees/5bce7ea8fce8/01KZN5KA85SHHD7AW3XZSGHJQH/bin/fm-watch.sh
===================================================================
SCENARIO 1  answered decision, run resumed - must NOT re-surface
  (captain answered 'migration A'; the crew fed it to its gate and the
   no-mistakes run went back to validating. The status LOG is append-only,
   so its last line still reads needs-decision:.)
===================================================================

-- 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
  pane (quiet, unchanged since last poll):
    | no-mistakes axi respond: decision fed, validating...
  >> 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 --
  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
  pane (quiet, unchanged since last poll):
    | no-mistakes axi run: tests passing, ci next...
  >> 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
  (the decision is genuinely unanswered: the run is parked at its gate)
===================================================================

-- quiet pane, no run has moved past the decision --
  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: parked · source: run-step · parked at plan-approval: 1 finding(s)
  pane (quiet, unchanged since last poll):
    | gate prompt idle, awaiting the captain
  >> WATCHER WAKE (firstmate is woken, one LLM supervision turn burned):
    $ stale: fm:axi
  triage log:
    | (empty)
  durable wake queue (bin/fm-wake-drain.sh):
    | 1786344630	1	stale	fm:axi	stale: fm:axi
Evidence: 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:axi

watcher under test: /Users/sauce/.no-mistakes/worktrees/5bce7ea8fce8/01KZN5KA85SHHD7AW3XZSGHJQH/bin/.fm-watch-pre233.sh
===================================================================
SCENARIO 1  answered decision, run resumed - must NOT re-surface
  (captain answered 'migration A'; the crew fed it to its gate and the
   no-mistakes run went back to validating. The status LOG is append-only,
   so its last line still reads needs-decision:.)
===================================================================

-- 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
  pane (quiet, unchanged since last poll):
    | no-mistakes axi respond: decision fed, validating...
  >> WATCHER WAKE (firstmate is woken, one LLM supervision turn burned):
    $ stale: fm:axi
  triage log:
    | (empty)
  durable wake queue (bin/fm-wake-drain.sh):
    | 1786344637	1	stale	fm:axi	stale: fm:axi

-- pane changed, then re-quieted at a NEW 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
  pane (quiet, unchanged since last poll):
    | no-mistakes axi run: tests passing, ci next...
  >> WATCHER WAKE (firstmate is woken, one LLM supervision turn burned):
    $ stale: fm:axi
  triage log:
    | (empty)
  durable wake queue (bin/fm-wake-drain.sh):
    | 1786344642	2	stale	fm:axi	stale: fm:axi

===================================================================
SCENARIO 2  same leftover log line, NO active run - MUST still surface
  (the decision is genuinely unanswered: the run is parked at its gate)
===================================================================

-- quiet pane, no run has moved past the decision --
  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: parked · source: run-step · parked at plan-approval: 1 finding(s)
  pane (quiet, unchanged since last poll):
    | gate prompt idle, awaiting the captain
  >> WATCHER WAKE (firstmate is woken, one LLM supervision turn burned):
    $ stale: fm:axi
  triage log:
    | (empty)
  durable wake queue (bin/fm-wake-drain.sh):
    | 1786344650	1	stale	fm:axi	stale: fm:axi
Evidence: 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.

# Regression value of the new tests: run them against a pre-#233 watcher
# (bin/fm-watch.sh with the run-step override disabled - the code the live
#  watcher at 7af373e was running when the incidents were observed).

$ 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>   # the fail above aborts the run, so run it separately
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
#!/usr/bin/env bash
# End-to-end demo of the answered-needs-decision stale incident, driving the REAL
# bin/fm-watch.sh the way firstmate's supervision loop drives it.
#
# Usage: watcher-decision-demo.sh <repo-root> <workdir> [watcher-path]
#
# Prints the transcript a captain would actually see: the watcher's printed wake
# reason (or silence), the triage log line it recorded, and the durable wake
# queue drained by bin/fm-wake-drain.sh.
set -u

ROOT=$1
WORK=$2
WATCH=${3:-$ROOT/bin/fm-watch.sh}
DRAIN="$ROOT/bin/fm-wake-drain.sh"

rm -rf "$WORK"; mkdir -p "$WORK"

# Keep fm-guard's worktree-tangle banner and the wedge desktop alarm inert.
export FM_ROOT_OVERRIDE="$WORK/inert-root"; mkdir -p "$FM_ROOT_OVERRIDE"
printf '#!/usr/bin/env bash\nexit 0\n' > "$WORK/no-alarm"; chmod +x "$WORK/no-alarm"
export FM_WEDGE_ALARM_EXEC="$WORK/no-alarm"

hash_text() { printf '%s' "$1" | md5 -q 2>/dev/null || printf '%s' "$1" | md5sum | cut -d' ' -f1; }
seen_sig() {
  if [ "$(uname)" = Darwin ]; then stat -f '%z:%Fm' "$1"; else stat -c '%s:%Y' "$1"; fi
}

# --- a hermetic crew: one tmux window, one status log, one crew-state reader ---
setup_case() {  # <case> <window> <task> <status-log> <pane-text> <crew-state-verdict>
  local name=$1 window=$2 task=$3 log=$4 pane=$5 verdict=$6 dir key
  dir="$WORK/$name"; key=$(printf '%s' "$window" | tr ':/.' '___')
  mkdir -p "$dir/state" "$dir/fakebin"
  cat > "$dir/fakebin/tmux" <<'SH'
#!/usr/bin/env bash
set -u
case "${1:-}" in
  display-message)
    for a in "$@"; do case "$a" in *cursor_y*) printf '0\n'; exit 0 ;; esac; done
    printf 'fakepane\n'; exit 0 ;;
  list-windows) printf '%s\n' "$FM_FAKE_TMUX_WINDOW"; exit 0 ;;
  capture-pane) cat "$FM_FAKE_TMUX_CAPTURE"; exit 0 ;;
esac
exit 1
SH
  # Stands in for bin/fm-crew-state.sh, returning the verdict the real reader
  # emits for this situation (same "state: ... · source: ... · ..." shape).
  cat > "$dir/fakebin/fm-crew-state.sh" <<'SH'
#!/usr/bin/env bash
printf '%s\n' "$FM_FAKE_CREW_STATE"
SH
  chmod +x "$dir/fakebin/tmux" "$dir/fakebin/fm-crew-state.sh"
  printf '%s' "$pane" > "$dir/pane.txt"
  printf 'window=%s\nkind=ship\n' "$window" > "$dir/state/$task.meta"
  printf '%s' "$log" > "$dir/state/$task.status"
  printf '%s' "$(seen_sig "$dir/state/$task.status")" > "$dir/state/.seen-${task}_status"
  # Pane already seen once and unchanged => this poll classifies it as stale.
  printf '%s' "$(hash_text "$pane")" > "$dir/state/.hash-$key"
  printf '1\n' > "$dir/state/.count-$key"
  printf '%s' "$verdict" > "$dir/verdict"
  printf '%s' "$window" > "$dir/window"
  printf '%s' "$task" > "$dir/task"
}

# Run the watcher for one triage decision: it either prints a wake reason and
# exits (surfaced -> costs firstmate a full supervision turn), or stays blocked
# and silent (absorbed).
triage_lines() { # <case-dir>
  if [ -f "$1/state/.watch-triage.log" ]; then wc -l < "$1/state/.watch-triage.log" | tr -d " "; else printf 0; fi
}

run_watcher() {  # <case> [seconds]
  local name=$1 budget=${2:-25} dir window pid i base now
  dir="$WORK/$name"; window=$(cat "$dir/window")
  : > "$dir/watch.out"
  base=$(triage_lines "$dir")
  PATH="$dir/fakebin:$PATH" FM_FAKE_TMUX_WINDOW="$window" FM_FAKE_TMUX_CAPTURE="$dir/pane.txt" \
    FM_FAKE_CREW_STATE="$(cat "$dir/verdict")" \
    FM_STATE_OVERRIDE="$dir/state" FM_CREW_STATE_BIN="$dir/fakebin/fm-crew-state.sh" \
    FM_STALE_ESCALATE_SECS=999 FM_POLL=1 FM_SIGNAL_GRACE=1 \
    FM_CHECK_INTERVAL=999999 FM_HEARTBEAT=999999 "$WATCH" > "$dir/watch.out" 2>"$dir/watch.err" &
  pid=$!
  i=0
  while [ "$i" -lt "$((budget * 10))" ]; do
    kill -0 "$pid" 2>/dev/null || return 0          # exited => surfaced
    now=$(triage_lines "$dir")
    if [ "$((now))" -gt "$((base))" ]; then
      # A NEW triage line landed; give the loop a beat, then stop it: absorbed.
      sleep 0.3; kill -TERM "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; return 0
    fi
    sleep 0.1; i=$((i + 1))
  done
  kill -TERM "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; return 0
}

report() {  # <case> <headline>
  local name=$1 head=$2 dir out
  dir="$WORK/$name"
  printf '\n%s\n' "$head"
  printf '  status log (append-only, last line is what the old code trusted):\n'
  sed 's/^/    | /' "$dir/state/$(cat "$dir/task").status"
  printf '  crew-state verdict (authoritative run-step read):\n    | %s\n' "$(cat "$dir/verdict")"
  printf '  pane (quiet, unchanged since last poll):\n    | %s\n' "$(cat "$dir/pane.txt")"
  out=$(cat "$dir/watch.out")
  if [ -n "$out" ]; then
    printf '  >> WATCHER WAKE (firstmate is woken, one LLM supervision turn burned):\n'
    printf '%s\n' "$out" | sed 's/^/    $ /'
  else
    printf '  >> WATCHER WAKE: (none - watcher stayed blocked, no supervision turn burned)\n'
  fi
  printf '  triage log:\n'
  if [ -s "$dir/state/.watch-triage.log" ]; then sed 's/^/    | /' "$dir/state/.watch-triage.log"
  else printf '    | (empty)\n'; fi
  printf '  durable wake queue (bin/fm-wake-drain.sh):\n'
  if [ -s "$dir/state/.wake-queue" ]; then
    FM_STATE_OVERRIDE="$dir/state" "$DRAIN" 2>/dev/null | sed 's/^/    | /'
  else printf '    | (empty - nothing queued for the captain)\n'; fi
}

LOG='working: implementing the schema migration
needs-decision: pick migration A or B
'
ACTIVE='state: working · source: run-step · validating (running) · status-log superseded by active run'
PARKED='state: parked · source: run-step · parked at plan-approval: 1 finding(s)'

echo "watcher under test: $WATCH"
echo "==================================================================="
echo "SCENARIO 1  answered decision, run resumed - must NOT re-surface"
echo "  (captain answered 'migration A'; the crew fed it to its gate and the"
echo "   no-mistakes run went back to validating. The status LOG is append-only,"
echo "   so its last line still reads needs-decision:.)"
echo "==================================================================="

setup_case answered-1 'fm:axi' axi "$LOG" 'no-mistakes axi respond: decision fed, validating...' "$ACTIVE"
run_watcher answered-1
report answered-1 "-- first quiet pane hash --"

# The live re-fire shape: the run streams new output, then the pane re-quiets at
# a NEW hash. Each new hash is a fresh terminal-stale decision.
printf 'no-mistakes axi run: tests passing, ci next...' > "$WORK/answered-1/pane.txt"
printf '%s' "$(hash_text 'no-mistakes axi run: tests passing, ci next...')" \
  > "$WORK/answered-1/state/.hash-fm_axi"
printf '1\n' > "$WORK/answered-1/state/.count-fm_axi"
run_watcher answered-1
report answered-1 "-- pane changed, then re-quieted at a NEW hash --"

echo
echo "==================================================================="
echo "SCENARIO 2  same leftover log line, NO active run - MUST still surface"
echo "  (the decision is genuinely unanswered: the run is parked at its gate)"
echo "==================================================================="
setup_case unanswered 'fm:axi' axi "$LOG" 'gate prompt idle, awaiting the captain' "$PARKED"
run_watcher unanswered
report unanswered "-- quiet pane, no run has moved past the decision --"
echo
Evidence: tests/fm-watch-triage.test.sh — full suite, 48/48 ok
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 - signal_crew_provably_working: benign only when every referenced crew is provably working
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 - 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 - 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
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 - 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 - a process-event wake is delivered once: no duplicate wake while queued, and none once handled
ok - complete process-event queue keys map to distinct seen markers
ok - queue revalidation, proactive output, and marker commit serialize with drain
/Users/sauce/.no-mistakes/worktrees/5bce7ea8fce8/01KZN5KA85SHHD7AW3XZSGHJQH/bin/fm-push-transition-lib.sh: line 92: echo: write error: Broken pipe
tests/wake-helpers.sh: line 260: 39142 Killed: 9               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 260: 40337 Killed: 9               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 before marker commit and suppress only after delivered output
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
Evidence: tests/fm-crew-state.test.sh — authoritative run-step reader, 49/49 ok
ok - active run-step is authoritative
ok - stale needs-decision over active run is superseded
ok - stale blocked over active run is superseded
ok - genuine parked run is not flagged superseded
ok - scalar gate parked run is not flagged superseded
ok - gate block parked run is not flagged superseded
ok - ci-ready status log beats monitoring run
ok - ci-monitoring run with checks already green surfaces done
ok - top-level ci status uses ci log green marker
ok - terminal no-checks ci-monitor marker surfaces done
ok - base-advance rearm after green stays working
ok - pending no-checks ci-monitor marker stays working
ok - ci-monitoring run with checks not yet green stays working
ok - a fresh issue after an earlier green reading is not masked
ok - stale checks-green status log does not mask CI relapse
ok - ci fixing is not overridden by an earlier green marker
ok - top-level fixing is not overridden by a stale ci running row
ok - top-level fixing is not overridden by a stale done log
ok - terminal passed run is authoritative
ok - terminal failed run is authoritative
ok - cross-branch run is attributed via the real runs list
ok - cross-branch attribution picks the branch's most recent row
ok - coarse run does not probe another branch's ci log
ok - another branch's run is ignored, falls back
ok - no run + a busy semantic record reads working, attributed to its source
ok - a converted adapter never reads working from rendered footer text
ok - grok still reads working through its isolated rendered-tail fallback
ok - herdr's native busy verdict reads working with no record present
ok - a mid-tool-call crew stays working because its record outranks herdr's generation state
ok - an idle record with idle agent_status stays not-busy (no regression for a human-blocked agent)
ok - no run + idle pane uses the status-log verb
ok - no run + idle pane parses keyed status syntax
ok - no run + idle pane on a paused: status reports state: paused with its reason
ok - no run + idle pane honors the configured paused verb
ok - a trailing resolved: event does not corrupt state render (idle stays idle)
ok - dead window ignores stale status log
ok - closed pane still reports a terminal run-step
ok - closed pane still reports an active run-step
ok - no timeout command uses perl bound
ok - scout skips the run lookup
ok - torn-down worktree is handled gracefully
ok - missing meta is handled gracefully
ok - crew_is_provably_working absorbs a validating crew found only via the runs-list fallback
ok - crew_is_provably_working still surfaces a genuinely stopped crew (safety property preserved)
ok - usage error exits 2
ok - historical same-branch rewritten head is not attributed as current
ok - active run with valid descendant fix head remains current
ok - local work advanced past run head invalidates attribution
ok - missing run head falls back instead of matching by branch
all fm-crew-state tests passed
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)

$ git diff --stat 477ad93..6cb22d4
 tests/fm-watch-triage.test.sh | 232 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 222 insertions(+), 10 deletions(-)

# branch constraint: production code untouched (test-only branch)
$ git diff --name-only 477ad93..6cb22d4 -- bin/ skills/ docs/
  (no files)
Evidence: Evidence index
# Evidence — answered needs-decision must not re-surface as a terminal stale

Branch `fm/fm-stale-terminal-reads-stale-log` (477ad93 → 6cb22d4) is deliberately
test-only: the production fix (#233 terminal-stale run-step override) is already in
`bin/fm-watch.sh`. So the thing to demonstrate is (a) the end-user behavior the
intent claims, and (b) that the new tests actually pin it.

| file | what it shows |
| --- | --- |
| `fixed-watcher-transcript.txt` | Real `bin/fm-watch.sh` driven end-to-end: an answered needs-decision with a resumed run is absorbed silently on two successive quiet pane hashes, and the unanswered/parked case still surfaces `stale: fm:axi` into the durable wake queue. |
| `pre233-watcher-transcript.txt` | Same scenarios against a pre-#233 watcher (run-step override disabled) — the live defect: `stale: fm:axi` printed and queued on *both* quiet hashes for an already-answered decision. |
| `regression-test-catches-defect.txt` | The new regression test fails against the pre-#233 watcher with the exact incident symptom, passes on current code; the fail-safe surfacing test passes on both. |
| `full-suite-final.txt` | `tests/fm-watch-triage.test.sh` — 48/48 ok, exit 0. |
| `crew-state-suite.txt` | `tests/fm-crew-state.test.sh` — 49/49 ok (the authoritative run-step reader the fix consults). |
| `branch-scope.txt` | Confirms no production file changed on the branch. |
| `watcher-decision-demo.sh` | The reproducible harness that produced the two transcripts. |
| `full-suite-run2.txt` | Earlier suite run that caught the pre-existing phase-A race in `test_stale_terminal_status_overridden_by_active_run` (since hardened). |

## How to reproduce the transcripts

`` `
bash watcher-decision-demo.sh <repo-root> <workdir>            # current code
bash watcher-decision-demo.sh <repo-root> <workdir> <watcher>  # any watcher build
`` `

The pre-#233 watcher used above was a throwaway copy of `bin/fm-watch.sh` with the
single override line replaced by `if false; then`; it was deleted after the run and
the worktree left clean of it.
- Outcome: ⚠️ 2 issues (1 warning, 1 info) across 1 run (45m14s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 3 infos
  • ℹ️ tests/fm-watch-triage.test.sh:57 - wait_log_count polls 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 3s wait_live that precedes it. If a regression surfaces after that 3s window (the loaded-machine case these waits exist for), the watcher is already dead and wait_log_count still spins its full 20s budget before failing — at 4 call sites. Conversely, the fixed wait_live &#34;$pid&#34; 30 is now an unconditional 3s sleep on every happy path. Threading the pid into wait_log_count and breaking on kill -0 failure would make both the pass and fail paths fast and let the redundant wait_live go.
  • ℹ️ 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-$key to disappear), joining four existing copies of the same shape at :1100, :1120, :1623, :1660. A single helper (e.g. wait_state &#34;$pid&#34; &lt;file&gt; &lt;expected-or-absent&gt; &lt;limit&gt;) alongside wait_log_count would 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: that triage_log is 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 that clear_pause_tracking's single rm -f deletes .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.
⚠️ **Test** - 2 issues (1 warning, 1 info)
  • ⚠️ 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_surfaces fails 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 flat wait_live &#34;$pid&#34; 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 via wait_log_count for 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 0
  • bash tests/fm-crew-state.test.sh — 49/49 ok (authoritative run-step reader the fix consults)
  • test_stale_answered_needs_decision_superseded_by_resumed_run and test_stale_needs_decision_without_active_run_still_surfaces run in isolation 3x each — consistently green
  • Mutation check: same two tests run against a throwaway pre-#233 bin/fm-watch.sh (run-step override replaced with if false; then) — the absorb regression fails with stale: test:fm-answered, the fail-safe surfacing test still passes; mutant deleted afterwards
  • Manual end-to-end: bash watcher-decision-demo.sh &lt;repo&gt; &lt;workdir&gt; drives the real bin/fm-watch.sh with a fake tmux pane and a fm-crew-state.sh stub returning the real status-log superseded by active run verdict; captured watcher stdout, .watch-triage.log, and bin/fm-wake-drain.sh output for both the answered (two distinct quiet hashes) and parked cases
  • Manual end-to-end against the pre-#233 watcher: bash watcher-decision-demo.sh &lt;repo&gt; &lt;workdir&gt; bin/.fm-watch-pre233.sh — reproduces stale: fm:axi re-firing on every quiet hash
  • test_stale_terminal_status_overridden_by_active_run and test_exited_declared_pause_is_bounded_but_live_gate_surfaces each run in isolation 7x to characterize flakiness before and after hardening
  • git diff --name-only 477ad93..6cb22d4 -- bin/ skills/ docs/ — confirms the no-production-change constraint
  • bash -n tests/fm-watch-triage.test.sh; verified no stray watcher processes and a clean worktree apart from the intentional test fix
⚠️ **Document** - 1 info
  • ℹ️ bin/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.

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.
@saucetech
saucetech merged commit cce3e75 into main Aug 10, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant