Skip to content

fix(bin): absorb unchanged declared-pause rechecks instead of waking hourly - #37

Merged
alandomio merged 3 commits into
mainfrom
fm/fm-pause-recheck-quiet
Sep 26, 2026
Merged

alandomio merged 3 commits into
mainfrom
fm/fm-pause-recheck-quiet

Conversation

@alandomio

Copy link
Copy Markdown
Owner

Intent

Stop the firstmate watcher (bin/fm-watch.sh) from repeatedly waking firstmate for a declared pause whose situation has not changed. This changes shared tracked material (bin/), so firstmate-coding-guidelines applies (one sentence per Markdown line, shellcheck-clean via bin/fm-lint.sh, colocated behavioral tests, no agent co-author).

Problem measured in one session (22-24/09/2026): firstmate spent over 80 handling turns on wakes that required nothing: stale: <window> (paused Ns, awaiting external - declared pause, rechecked on a long cadence not a wedge; confirm the wait still holds) for workers that had declared paused: (an MR awaiting merge, a captain decision pending), each fired roughly every hour (FM_PAUSE_RESURFACE_SECS) per paused worker, forever, plus plain stale: wakes for idle workers around the pause declaration. With four paused workers that is a wake every ~15 minutes, each a full drain/inspect/ack turn with nothing to do; the captain can no longer tell service messages from ones that need him.

Goal: a declared pause whose situation has not changed must stop waking firstmate repeatedly. Requirements: after the first surfaced recheck of a given pause (same pause line identity, agent alive), absorb further rechecks while nothing changed (no new status line, agent still alive, still the same pause), with a much longer configurable ceiling (a daily reminder) instead of the hourly cadence; still wake when the agent dies, the pane shows a blocking dialog, a new status line appears, or the pause is replaced; log absorbed rechecks in the existing absorbed-wake debug log (state/.watch-triage.log). Pick the smallest design that meets this. Do not weaken detection for non-paused workers. Preserve commit 21c3d3f (#31)'s intent: a live agent's declared pause must not fall back to wedge detection, and a genuinely stuck or dead worker must still surface.

Design chosen: at each paused surface (the one-time live-agent surface in surface_nonterminal_stale, and each recheck surface in handle_paused_stale) the watcher records the pause's "situation" in state/.paused-surfaced-: the status log's size:mtime signature, the agent's liveness via fm_backend_agent_alive (not read for a secondmate, matching pause_state_class), and an md5 of the pane tail with digits and blanks removed (so ticking clocks/token counters are not a change, while a dialog or any new text is). At each due recheck (existing PAUSE_RESURFACE_SECS cadence) the current situation is compared with the record: unchanged and younger than FM_PAUSE_REMIND_SECS (new knob, default 86400) -> absorbed, logged "absorbed paused recheck", throttle re-stamped; unchanged but past the ceiling -> surfaces as a reminder with "unchanged since the last recheck Ns ago"; changed -> surfaces with the change named (status log updated / agent now dead / pane text changed). The record is written after the wake is queued and before it is reported. Additionally, because a busy turn (e.g. a steer) clears .paused-, pause_state_class now treats a pause as already past its one-time live-agent surface when the current status line is the one recorded in .paused-surfaced-, so the same pause line does not take a second plain "stale: " surface after every busy turn; a genuinely new pause line still takes it. Busy crew_absorb_class=working still lifts the pause.

Deliberate tradeoffs (not mistakes): agent death and a blocking dialog are detected at the next due recheck (at most FM_PAUSE_RESURFACE_SECS), the same latency as before this change, rather than per poll - per-poll pane comparison could wake constantly on panes whose non-digit text rotates, and this adds zero per-poll cost; new status lines and replaced pauses still wake immediately through the existing signal path. The away-mode daemon (fm-supervise-daemon.sh) is intentionally untouched and does not read FM_PAUSE_REMIND_SECS. The one-time live-agent plain stale surface for a new pause line is kept because an existing tested contract requires it. A busy pane past FM_BUSY_TURN_MAX_SECS under a declared pause usually changes pane text, so it keeps surfacing on the hourly recheck as before. The #31 churn regression test was adjusted so its odd rounds are due reminders (its intent - churn never produces a bare stale wake, the cadence decides - is unchanged). The .paused-surfaced- marker survives clear_pause_tracking on purpose (so a busy flicker does not reset it) and is removed only when the last status line is no longer a declared wait.

Tests: colocated in tests/fm-watch-triage.test.sh, reproducing the repeated wake (failed before the fix, pass after) plus death, blocking dialog, digits-only churn, replaced pause, reminder ceiling, and the same-pause-line-after-busy-turn cases. Docs: docs/configuration.md (FM_PAUSE_REMIND_SECS) and docs/architecture.md. PR title and description in English.

What Changed

  • bin/fm-watch.sh now saves a declared pause's situation in state/.paused-surfaced-<key> each time the pause surfaces. The situation is the status log's size:mtime, the agent's liveness (not read for a secondmate), and a hash of the pane tail with digits and blanks removed. At each due FM_PAUSE_RESURFACE_SECS recheck, the watcher compares the current situation with that record:
    • If nothing changed, the recheck is absorbed and logged as absorbed paused recheck in the triage log.
    • An unchanged pause surfaces again as a reminder once the new FM_PAUSE_REMIND_SECS has passed (default 86400).
    • A changed situation surfaces with the change named (status log updated, agent now dead, or pane text changed).
    • A dead agent is never absorbed, so it keeps surfacing at every recheck.
  • pause_state_class treats a pause as already past its one-time live-agent surface when the current status line matches the recorded one. The same pause line no longer gets a second plain stale: <window> wake after a busy turn, while a new pause line still does. The record is removed once the last status line is no longer a declared wait.
  • Colocated tests in tests/fm-watch-triage.test.sh cover the repeated wake, agent death, a blocking dialog, digits-only pane churn, a replaced pause, the reminder ceiling, and the same pause line after a busy turn. The fix(bin): keep a live agent's declared pause on the bounded recheck cadence #31 churn test was adjusted so its odd rounds are due reminders. docs/configuration.md documents FM_PAUSE_REMIND_SECS and docs/architecture.md describes the new recheck behavior.

Risk Assessment

✅ Low: The fix round adds one narrow guard: a recheck whose situation string contains ' agent=dead ' (paused_situation always prints 'status=… agent=… pane=…', and fm_backend_agent_alive emits exactly 'dead') is never absorbed. It matches the authorized option B. The test now expects a dead worker to surface on every recheck, and the replaced-pause and reminder rounds still each assert their own case.

Testing

I ran the colocated tests/fm-watch-triage.test.sh suite on the target commit and all tests passed. I ran the two new regression tests against the base commit's watcher, and both failed with the original repeated-wake symptoms, so they reproduce the bug. I also captured a per-round CLI transcript of the watcher's wake output plus the absorbed-wake debug log. It shows unchanged rechecks and digit-only pane churn absorbed and logged. It shows surfaces for the dialog, agent death, the dead agent on its next recheck, the replaced pause and the reminder ceiling, each naming the change or "unchanged since". This is a CLI/daemon change with no UI, so there is no visual evidence. The transient driver file was removed and the worktree is clean.

Evidence: Per-round watcher wake transcript and absorbed-wake log (after fix)

Source: Per-round watcher wake transcript and absorbed-wake log (after fix)

[first recheck] pane=claude -> stale: test:fm-quiet (paused 500s, ... confirm the wait still holds) [unchanged second recheck] pane=claude -> (absorbed: no wake) [digits-only pane churn] pane=claude -> (absorbed: no wake) [blocking dialog] pane=claude -> stale: ... changed since the last recheck: pane text changed [dialog already surfaced] pane=claude -> (absorbed: no wake) [agent exited] pane=zsh -> stale: ... changed since the last recheck: agent now dead [exit already surfaced] pane=zsh -> stale: ... unchanged since the last recheck 2s ago [replaced pause] pane=claude -> stale: ... changed since the last recheck: status log updated, agent now alive [replaced pause already surfaced] pane=claude -> (absorbed: no wake) [reminder ceiling] pane=claude -> stale: ... unchanged since the last recheck 500s ago --- state/.watch-triage.log --- absorbed paused recheck (paused, awaiting external, unchanged since its last surface 1s ago): test:fm-quiet (x3)

[first recheck]                    pane=claude -> stale: test:fm-quiet (paused 500s, awaiting external - declared pause, rechecked on a long cadence not a wedge; confirm the wait still holds)
[unchanged second recheck]         pane=claude -> (absorbed: no wake)
[digits-only pane churn]           pane=claude -> (absorbed: no wake)
[blocking dialog]                  pane=claude -> stale: test:fm-quiet (paused 506s, awaiting external - declared pause, rechecked on a long cadence not a wedge; confirm the wait still holds; changed since the last recheck: pane text changed)
[dialog already surfaced]          pane=claude -> (absorbed: no wake)
[agent exited]                     pane=zsh   -> stale: test:fm-quiet (paused 509s, awaiting external - declared pause, rechecked on a long cadence not a wedge; confirm the wait still holds; changed since the last recheck: agent now dead)
[exit already surfaced]            pane=zsh   -> stale: test:fm-quiet (paused 511s, awaiting external - declared pause, rechecked on a long cadence not a wedge; confirm the wait still holds; unchanged since the last recheck 2s ago)
[replaced pause]                   pane=claude -> stale: test:fm-quiet (paused 500s, awaiting external - declared pause, rechecked on a long cadence not a wedge; confirm the wait still holds; changed since the last recheck: status log updated, agent now alive)
[replaced pause already surfaced]  pane=claude -> (absorbed: no wake)
[reminder ceiling]                 pane=claude -> stale: test:fm-quiet (paused 503s, awaiting external - declared pause, rechecked on a long cadence not a wedge; confirm the wait still holds; unchanged since the last recheck 500s ago)
ok - an unchanged declared pause is rechecked once, then absorbed until the reminder ceiling or a change in status, liveness, or pane text

--- state/.watch-triage.log (absorbed-wake debug log) ---
[2026-09-24T17:06:33+0200] absorbed paused recheck (paused, awaiting external, unchanged since its last surface 1s ago): test:fm-quiet
[2026-09-24T17:06:35+0200] absorbed paused recheck (paused, awaiting external, unchanged since its last surface 3s ago): test:fm-quiet
[2026-09-24T17:06:44+0200] absorbed paused recheck (paused, awaiting external, unchanged since its last surface 1s ago): test:fm-quiet
Evidence: New regression tests fail on base commit (bug reproduced)

Source: New regression tests fail on base commit (bug reproduced)

not ok - unchanged second recheck: an unchanged declared pause surfaced again: stale: test:fm-quiet (paused 502s, awaiting external - declared pause, ...; confirm the wait still holds) not ok - the same pause line took a second live-agent surface after a busy turn: stale: test:fm-once

not ok - unchanged second recheck: an unchanged declared pause surfaced again: stale: test:fm-quiet (paused 502s, awaiting external - declared pause, rechecked on a long cadence not a wedge; confirm the wait still holds)
RESULT: quiet-recheck test FAILED on base
not ok - the same pause line took a second live-agent surface after a busy turn: stale: test:fm-once
RESULT: live-surface-once test FAILED on base
Evidence: fm-watch-triage suite output on target commit

Source: fm-watch-triage suite output on target commit

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 - status_is_nonterminal_progress_verb is the single shared predicate for all three call sites
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, paused is not captain-relevant, and the two declared-wait verbs stay separable
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 busy pane under a declared pause is rechecked on the long cadence, and lifting the pause restores the wedge escalation
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 live agent's declared pause with a churning pane hash uses the bounded recheck cadence, never a bare stale wake
ok - an unchanged declared pause is rechecked once, then absorbed until the reminder ceiling or a change in status, liveness, or pane text
ok - a live agent's pause line takes its one-time surface once, not again after every busy turn
ok - a declared paused secondmate re-surfaces on the bounded normal-mode cadence
ok - a captain-held 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 a pane recording that home 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 2635473.1790262345.yuPoLW
ok - queue revalidation, proactive output, and marker commit serialize with drain
~/.no-mistakes/worktrees/34c874d3722d/01M39YQK57440HQ5H3C6DK1RDG/bin/fm-push-transition-lib.sh: line 96: echo: write error: Broken pipe
tests/wake-helpers.sh: line 282: 2639692 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 282: 2641224 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

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 1 issue found → auto-fixed ✅
  • ⚠️ bin/fm-watch.sh:471 - The absorb condition only compares the recorded situation with the current one. It never checks that the agent is alive. The intent says further rechecks are absorbed only "while nothing changed (no new status line, agent still alive, still the same pause)", and fix(bin): keep a live agent's declared pause on the bounded recheck cadence #31 requires that "a genuinely stuck or dead worker must still surface". Here is how the current code behaves. A dead agent recorded as agent=dead (after the 'agent now dead' recheck, or when the first recheck of an already-exited crew records it) matches now_sit on every later hourly recheck. Those rechecks are absorbed for up to FM_PAUSE_REMIND_SECS, which defaults to a day. The new test enshrines this with its 'exit already surfaced' absorb round. Before this change, a dead paused worker surfaced every hour. Now it surfaces once and then stays quiet for 24h. Please confirm whether surfacing a dead worker once is enough. The alternative is to exclude agent=dead from absorption, for example by adding &amp;&amp; ! case $now_sit in *agent=dead*) ;; esac to the absorb predicate, so a dead worker keeps the hourly recheck.

🔧 Fix: Keep surfacing dead paused workers on every recheck
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-watch-triage.test.sh: the colocated watcher-triage suite, including the 2 new tests and the adjusted #31 churn test. All 64 pass.
  • New tests test_unchanged_declared_pause_recheck_is_absorbed_until_something_changes and test_same_pause_line_takes_the_live_surface_only_once run against the base commit 76891cd's bin/fm-watch.sh, in an extracted copy under a temp dir. Both fail, reproducing the hourly repeat wake and the second plain stale: surface after a busy turn.
  • A driver around paused_recheck_round that prints each round's real fm-watch.sh stdout (the wake reason firstmate would see) and then dumps state/.watch-triage.log. It covers: unchanged, digits-only churn, blocking dialog, agent exit, dead-agent recheck, replaced pause, and reminder ceiling.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Alan Domio added 3 commits September 24, 2026 16:56
…changed

A declared pause re-surfaced "confirm the wait still holds" every
FM_PAUSE_RESURFACE_SECS forever, although nothing about the worker had
changed, and a busy turn on a paused worker re-fired its one-time
live-agent surface for the same pause line.

The watcher now records the pause's situation at each surface - the
status log's size:mtime, the agent's liveness (never read for a
secondmate), and a digest of the pane tail with digits and blanks
removed - and compares it at each due recheck. An unchanged situation is
absorbed into the triage log until FM_PAUSE_REMIND_SECS (default one
day) has passed since the last surface; an exited agent, new pane text
such as a dialog, or a new status line surfaces at that recheck with the
change named. The same pause line no longer takes a second one-time
surface after a busy turn. #31's guarantee is kept: a live agent's
declared pause never falls back to wedge detection.
@alandomio
alandomio merged commit 859afa0 into main Sep 26, 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