Repository navigation
fix(watch): require agent presence before trusting a busy frame - #7
Merged
Merged
Conversation
An agent process that exits leaves its last rendered frame painted in the pane, and that residual frame keeps matching the harness busy signature on every poll. Stale detection therefore classified the dead, agent-less endpoint as a busy worker forever: it never went stale, never woke supervision, and never reached recovery (reproduced 2026-07-27 on herdr - a crewmate died overnight and the task showed as working for ~16h with the pane's own `agent` field absent the whole time). Liveness now verifies agent PRESENCE, not just frame appearance. Where a backend can answer presence authoritatively, a confirmed agent-less endpoint overrides a busy-looking frame: - bin/fm-backend.sh gains fm_backend_has_agent_presence (the per-backend capability) and fm_backend_agent_confirmed_absent (two reads, so a transient status flap mid-repaint is not mistaken for an exit). - bin/fm-watch.sh's window_is_busy consults it only on the frame-matched branch, so the dead pane goes stale on the normal cadence while a live busy pane pays one presence read and an idle pane pays none. - bin/fm-crew-state.sh reports an agent-less endpoint as gone rather than reading `working` off its residual frame, so the resulting stale wake is not absorbed as provably working. Only herdr qualifies: `agent get` answers from herdr's own agent registry. tmux is deliberately excluded even though it has an agent-state classifier - its `dead` verdict reads the pane's foreground command, which a live harness running a shell tool call legitimately makes a bare shell, so trusting it in the per-poll busy path would mint false stales. zellij, orca, and cmux have no recovery classifier at all. All four keep their existing behavior.
This was referenced Aug 7, 2026
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.
Problem
When an agent process exits, its final rendered screen frame stays painted in the pane. That residual frame still matches the harness busy signature, so stale detection classified the dead, agent-less pane as a busy worker on every poll: it never went stale, never woke supervision, and never reached recovery.
Reproduced 2026-07-27 on the herdr backend. A claude crewmate's process died overnight in a host resource-pressure termination wave. Its pane kept the last frame, and the task sat "working" for ~16 hours with zero stale wakes until the captain noticed the abandoned tab. Ground truth was visible the whole time:
herdr pane listreturned noagentfield andagent_status: "unknown"for that pane, while live worker panes carryagent: claude|codexwithworking|idle|done. The task's uncommitted work was intact - only detection failed.Fix
Liveness classification now verifies agent presence, not just frame appearance.
bin/fm-backend.sh(backend dispatch owner) gains two primitives:fm_backend_has_agent_presence <backend>- does this backend answer "is an agent registered here right now" from a registration surface independent of both the rendered frame and the pane's foreground process?fm_backend_agent_confirmed_absent <backend> <target>- 0 only when the backend has that surface and two reads separated byFM_AGENT_ABSENT_CONFIRM_SECS(default 2) both report the endpoint agent-less. Any ambiguous or unreadable verdict returns 1, so an inconclusive read never overrides the caller's existing classification.bin/fm-watch.sh(stale-detection cadence owner):window_is_busyconsults it only on the frame-matched branch. A live busy pane pays one presence read; a plainly idle pane pays none; a dead pane loses to the frame and goes stale on the normal cadence.bin/fm-crew-state.sh(current-state reconciliation owner): an agent-less endpoint is reported gone (state: unknown · source: none) instead of readingworking · paneoff its residual frame, so the resulting stale wake is not absorbed as provably working.The two-read confirmation is what satisfies "no new false stales": a live agent already loses on the first read (costing nothing extra), while a momentary deregistration mid-frame-repaint re-reads alive and is rejected.
Backend compatibility review
Every supported backend was reviewed against its actual integration surface:
agent getanswers from herdr's own agent registry (agent_not_foundfor an agent-less pane, viafm_backend_herdr_pane_agent_state)fm_backend_tmux_agent_stateexists, but itsdeadverdict reads the pane's foreground command being a bare shellfm_backend_target_existsreporting a gone tmux window as alive) is not touched here and is not made worse - that function is untouched.fm_backend_agent_state->unverified)unverified)unverified)Other busy-state call sites reviewed and left alone:
bin/fm-composer-lib.shclassifies composer/pending-input, not liveness - not applicable.fm_pending_reply_backend_observation(bin/fm-pending-reply-lib.sh) uses a busy observation to mark a secondmate turn as seen; a residual frame there shortens the grace and escalates earlier rather than masking, so it is not the same defect.stale_window_is_busyinbin/fm-supervise-daemon.sh(away-mode supervision) does carry the same hole, but that file was deliberately reset to match upstream byte-for-byte in c4ec3b2 ("match upstream exactly in fm-supervise-daemon"). Closing it there means a fork-only edit to that file, so it is left out of this PR as a captain decision rather than taken silently. Consequence: while away mode is active, the dead-agent pane can still stay suppressed.Docs
docs/herdr-backend.md"Restart and liveness behavior" gains two sentences: the liveness probe now also backs stale detection and current-state reconciliation, and absence must survive a confirming re-read. One-owner rule respected - the probe's state vocabulary is still stated once, in that section.Tests
New regression coverage, colocated in the existing suites:
tests/fm-backend-herdr.test.shtests/fm-watch-triage.test.sh-window_is_busy: live+busy -> busy, live+idle -> idle, dead+busy-frame -> not busy, missing+busy-frame -> not busy, unreadable -> frame still wins, tmux -> frame-only behavior preservedtests/fm-crew-state.test.sh- dead agent with a residual busy frame reads gone (notworking · pane) and is notcrew_is_provably_working; the herdr fake now modelspane getand the realagent_not_founderror shape so pane presence and agent presence are separableLocal verification
GitHub Actions is billing-disabled fleet-wide, so local runs are the gate.
An earlier full canonical
bin/fm-lint.shrun over the whole file set also passed (exit 0); a later full re-run hit my own 900s wrapper timeout because of host load, so the changed-file run above is the clean current evidence at the same pinned version and config.One suite could not be run green on this host, and it is not green on
origin/maineithertests/fm-watch-triage.test.shdrives realfm-watch.shsubprocesses with 3-second liveness budgets. This host is at load average ~80 on 6 cores (sibling worktrees running their own lint/test sweeps), and those subprocess-timing tests fail there.stale suppressor not advanced on absorb.origin/main, two runs:stale suppressor not advanced on absorb, thenprovably-working signal did not advance its .seen-* suppressor.Different failure points across runs, and present without my changes, so this is host-load flakiness rather than a regression. The failing cases are all tmux-backend/no-backend paths where
fm_backend_has_agent_presencereturns false and the new code is inert. My new test in that suite,window_is_busy: a residual busy frame needs a present agent on a presence-capable backend, passed in every run. Worth a green re-run on a quiet host before merge.Pre-existing failure spotted, not fixed here
tests/fm-daemon.test.shfails atpane_is_busy must trust Herdr native idle over historical busy text. Cause: commit c4ec3b2 dropped the fork-onlyidle) return 1short-circuit frompane_is_busyto match upstream byte-for-byte, but the fork-only test asserting that behavior stayed. Fixing it means either re-diverging from upstream or removing the test - a captain call, so it is reported rather than decided here.