Repository navigation
fix: bound stale wakes for live decision holds - #36
Merged
Merged
Conversation
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.
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
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
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 escalationEvidence: Complete watcher triage test transcript
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.
Inspectedgit diff 9a589a99e9bbf9bdc6e2c21c715680832085727c..11c54982c01a06f673c2f34e1a59414c98d4a8d8 -- bin/fm-watch.sh tests/fm-watch-triage.test.sh docs/architecture.mdRanbash tests/fm-watch-triage.test.shagainst realfm-watch.shsubprocessesExtracted the relevant behavioral transcript withrg '^ok - (declared-pause and captain-held|a live captain-held park|a paused status overridden)' .../fm-watch-triage.logVerifiedgit status --shortremained clean after testing✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.