Repository navigation
fix(bin): absorb unchanged declared-pause rechecks instead of waking hourly - #37
Merged
Merged
Conversation
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.
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
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 declaredpaused:(an MR awaiting merge, a captain decision pending), each fired roughly every hour (FM_PAUSE_RESURFACE_SECS) per paused worker, forever, plus plainstale: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.shnow saves a declared pause's situation instate/.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 dueFM_PAUSE_RESURFACE_SECSrecheck, the watcher compares the current situation with that record:absorbed paused recheckin the triage log.FM_PAUSE_REMIND_SECShas passed (default 86400).pause_state_classtreats 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 plainstale: <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.tests/fm-watch-triage.test.shcover 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.mddocumentsFM_PAUSE_REMIND_SECSanddocs/architecture.mddescribes 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)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-onceEvidence: fm-watch-triage suite output on target commit
Source: fm-watch-triage suite output on target commit
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 asagent=dead(after the 'agent now dead' recheck, or when the first recheck of an already-exited crew records it) matchesnow_siton 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 excludeagent=deadfrom absorption, for example by adding&& ! case $now_sit in *agent=dead*) ;; esacto 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 teststest_unchanged_declared_pause_recheck_is_absorbed_until_something_changesandtest_same_pause_line_takes_the_live_surface_only_oncerun 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 plainstale:surface after a busy turn.A driver aroundpaused_recheck_roundthat 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.