Skip to content

fix: bound stale wakes for live decision holds - #36

Merged
levelupself merged 2 commits into
mainfrom
fm/128-captain-held-stale-loop
Aug 10, 2026
Merged

levelupself merged 2 commits into
mainfrom
fm/128-captain-held-stale-loop

Conversation

@levelupself

Copy link
Copy Markdown
Owner

Intent

A worker parked on a captain decision re-surfaces as an ordinary stale wedge on every watcher cycle, because the absorption path built for it can only engage once its agent is DEAD. Fix that.

Context and evidence: observed on a live task (codex, tmux pane default:w5:p2S) which surfaced a bare 'stale: ' three times in ~30 minutes while correctly parked and idle. Each one costs a full supervision turn to inspect and dismiss. pause_state_class() in bin/fm-watch.sh guarded its absorption branch on agent_alive != dead for any non-secondmate window; the secondmate branch already skipped that requirement. The classifier in bin/fm-classify-lib.sh was verified correct against the live status line and is EXPLICITLY OUT OF SCOPE - do not change it.

The single most important constraint: the failure mode of a WRONG fix here is silent - a genuinely wedged worker gets absorbed and never reaches a supervisor, which is the exact class of defect this whole guard stack exists to prevent. Suppression must never be unbounded. A parked worker must still re-surface on a long cadence, and that cadence must be proven by a test, not asserted. 'It stopped being noisy' is an unacceptable acceptance criterion on its own. The required pair of properties is: quiet on consecutive cycles, AND still surfaces after the long interval.

Required investigation, which was carried out before changing anything: establish whether the agent_alive != dead guard is load-bearing for anything other than recovering a park claim from a crew that has actually exited (the case the comment near bin/fm-watch.sh:156 describes), reading the history on that guard rather than assuming the most recent nearby change explains it. If its only purpose is that dead-crew transfer, a live captain-held worker should absorb rather than surface, with the secondmate branch as precedent. If it turned out to be load-bearing for something else, the accepted outcome was to say so and propose the smallest alternative rather than removing it.

Finding from that investigation, which drove the chosen fix: the guard entered in commit ab8cea6 (PR kunchenguid#743, 'fix(watcher): bound stale wakes for parked crew') as a pipeline review fix commit titled 'Gate pause suppression on confirmed agent death'. Its own function comment states a narrower purpose than its placement achieves - 'Only a confidently dead ordinary crew may recover paused classification after fm-crew-state has fallen back to stopped or unknown' - which is served entirely by the later 'class = none && dead -> paused' recovery line. Sitting AHEAD of that recovery, the guard additionally suppressed the genuine 'paused' verdict that crew_absorb_class/fm-crew-state already returns for a declared external wait, so a live 'paused:' crew regressed the same way. That over-reach is collateral, not purpose. The one behaviour it did uniquely provide - a live declared park surfacing one bare stale wake - is redundant: a 'paused:'/'captain-held:' status append is a no-verb signal whose crew is not provably working, so the watcher's signal path already surfaces the declaration itself.

Implemented fix: a declared park (paused: or captain-held:) now classifies 'paused' regardless of agent liveness and regardless of window kind, matching the secondmate branch that never read liveness at all. Only authoritative crew state reporting an actively running pipeline ('working') outranks the declaration. Absorbed parks therefore route through handle_paused_stale and carry the declared-pause reason wording it already produces, instead of the bare 'stale: ' form, so a supervisor can tell a declared park from a wedge without opening the pane. The per-poll fm_backend_agent_alive backend calls inside pause_state_class are gone; the STALE_ESCALATE_SECS recheck window that avoids re-reading crew state on every poll is preserved. surface_nonterminal_stale is now only reachable for a window whose status declares no park, so its pause-marker branch was dropped and it returns to unconditionally clearing the pause cadence markers.

Why suppression stays bounded, which is the safety argument for the change: (1) the park declaration itself still surfaces once through the no-verb signal path; (2) handle_paused_stale re-surfaces the park on the PAUSE_RESURFACE_SECS cadence anchored on the park's OWN status-file mtime, so a park that has silently gone stale still reaches a supervisor and a churny idle pane cannot keep resetting the cadence; (3) any later non-park status line clears the pause tracking and restores ordinary wedge escalation; (4) a pane that becomes busy again leaves the park branch entirely.

Tests were written RED-FIRST, which is the point of this task. tests/fm-watch-triage.test.sh gains two behavioural tests driving a real fm-watch.sh subprocess. test_live_captain_held_park_stays_quiet_across_cycles runs four consecutive watcher cycles over a LIVE captain-held window whose idle footer changes each cycle (so each one re-enters the stale path as a first sighting, the exact live mechanism) and asserts zero stale wakes; it failed before the fix with 'a live captain-held park spent 4 supervision turns across four cycles' and four bare 'stale: test:fm-parked' lines. test_live_captain_held_park_resurfaces_on_the_long_cadence is the companion long-cadence bound: with the park's status file backdated past PAUSE_RESURFACE_SECS it must re-surface exactly once, carrying the declared-park wording and not the bare form and not wedge wording, then stay quiet for the rest of that window; it failed before the fix with 'the long-cadence recheck used bare wedge wording instead of the declared-park wording: stale: test:fm-parked'. A shared count_window_stale_wakes helper was added so an absorbed window is asserted the same way as a noisy one.

One pre-existing test codified the behaviour this change deliberately reverses and was updated on purpose, not to make the suite pass: test_exited_declared_pause_is_bounded_but_live_gate_surfaces asserted that a live external-decision gate surfaces exactly one BARE stale wake. It is renamed test_declared_pause_is_bounded_whether_or_not_the_agent_exited and its live-gate phase now asserts the gate is absorbed onto the pause cadence with zero supervision turns, while its dead-agent phases and its residual-wedge-timer assertions are unchanged. docs/architecture.md's two sentences describing the dead-agent-only cadence were rewritten to the new contract and its bounding argument.

This is firstmate's own shared tracked material, so the firstmate-coding-guidelines skill was loaded before editing: one sentence per line in tracked Markdown, plain dash never an em dash, bin/*.sh shellcheck-clean via bin/fm-lint.sh, tests colocated in tests/ extending the existing runner rather than a new one, no agent name as commit co-author, and one owner per contract with cross-references rather than restatements.

Artifact-style constraint: pipeline-authored risk rationales, fix summaries, and PR bodies must use role-neutral prose with no second person and no captain, user, firstmate, or crewmate role nouns; this constraint does not apply to product code, prompts, or user-facing copy.

What Changed

  • Classify declared pauses and decision holds on the bounded pause cadence regardless of agent liveness, eliminating repeated bare stale wakes and per-poll liveness probes.
  • Preserve finite suppression by resurfacing long-held parks from status-file age with declared-pause wording and clearing obsolete pause tracking when work resumes.
  • Add subprocess coverage proving consecutive parked cycles stay quiet while an expired park resurfaces exactly once, and document the updated cadence.

Risk Assessment

✅ Low: The change is narrowly scoped, preserves bounded resurfacing and active-pipeline precedence, and adds behavioral coverage for both consecutive-cycle suppression and long-cadence resurfacing.

Testing

The focused watcher suite passed end-to-end, demonstrating four quiet live-park cycles, one correctly worded long-cadence recheck followed by renewed suppression, dead/live parity, and preserved fail-safe wedge escalation. This is a CLI watcher change, so reviewer-visible command transcripts were captured instead of visual UI evidence.

Evidence: Focused behavioral evidence

ok - declared-pause and decision-held panes use the bounded pause cadence whether or not their agent exited ok - a live decision-held park is absorbed instead of re-surfacing every cycle ok - it still re-surfaces after the long cadence with declared-pause wording ok - authoritative working state preserves wedge escalation

ok - declared-pause and captain-held panes use the bounded pause cadence whether or not their agent exited
ok - a live captain-held park is absorbed on the bounded cadence instead of re-surfacing every cycle
ok - a live captain-held park still re-surfaces once past the long cadence, with declared-park wording
ok - a paused status overridden by authoritative working preserves its wedge timer and escalates
Evidence: Complete watcher triage test transcript
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 - 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 - declared-pause and captain-held panes use the bounded pause cadence whether or not their agent exited
ok - a live captain-held park is absorbed on the bounded cadence instead of re-surfacing every cycle
ok - a live captain-held park still re-surfaces once past the long cadence, with declared-park wording
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
/home/fungiman/.no-mistakes/worktrees/6be0eeed9e9c/01KZFRMW19XS152YY3XBD3CYTC/bin/fm-push-transition-lib.sh: line 92: echo: write error: Broken pipe
tests/wake-helpers.sh: line 260: 692240 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 260: 693510 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 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

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Inspected git diff 9a589a99e9bbf9bdc6e2c21c715680832085727c..11c54982c01a06f673c2f34e1a59414c98d4a8d8 -- bin/fm-watch.sh tests/fm-watch-triage.test.sh docs/architecture.md
  • Ran bash tests/fm-watch-triage.test.sh against real fm-watch.sh subprocesses
  • Extracted the relevant behavioral transcript with rg '^ok - (declared-pause and captain-held|a live captain-held park|a paused status overridden)' .../fm-watch-triage.log
  • Verified git status --short remained clean after testing
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

A crew that appended `captain-held:` and went idle re-surfaced as a bare
`stale: <window>` wedge again and again, spending a supervision turn each
time. `pause_state_class` gated the bounded pause cadence on the backend
reporting the agent DEAD for any non-secondmate window, and a crew parked
on a captain decision is by definition still running, so every fresh pane
hash re-entered the stale path as a first sighting.

The liveness gate arrived as a review fix inside kunchenguid#743, whose stated purpose
was narrower than its placement: recovering a park claim after fm-crew-state
falls back to stopped or unknown. Sitting ahead of that recovery, it also
suppressed the genuine `paused` verdict fm-crew-state already returns for a
declared external wait, so a live `paused:` crew surfaced the same way. A
declared park now classifies `paused` regardless of liveness, matching the
secondmate branch that never read liveness at all, and absorbed parks carry
the declared-pause reason wording instead of the bare stale form.

Suppression stays bounded three ways: the declaration itself still surfaces
through the no-verb signal path, handle_paused_stale re-surfaces the park on
the PAUSE_RESURFACE_SECS cadence anchored on its own status-file age, and any
later non-park status line restores ordinary wedge escalation.

`surface_nonterminal_stale` is now only reachable for a window whose status
declares no park, so its pause-marker branch is dropped.
@levelupself
levelupself merged commit 80a33df 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.

2 participants