Repository navigation
fix(bin): read an exited opencode on Herdr as agent-free so relaunch proceeds - #14
Merged
Merged
Conversation
…free on Herdr A hook-authority idle/done opencode whose pane is a lone idle shell now reads dead so exit and relaunch can proceed. Working, blocked, live-foreground, and non-opencode agents keep their verdict.
…se subshell remains The idle-shell proof now also accepts a lone idle shell reached only through shells and the treehouse launcher. Verified read-only against a stuck live pane.
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
Fix: after an opencode worker exits on the Herdr backend, relaunch refuses because the pane still reads as a live agent. Evidence: after fm-control relaunch delivers opencode's exit the pane returns to its shell and herdr pane process-info shows only a shell in the foreground, but herdr agent explain still says opencode idle with screen_detection_skip_reason full_lifecycle_hook_authority, so the stop step reports agent-state=alive exit=unconfirmed and fm-spawn --relaunch refuses. Required: fix the liveness read in the Herdr backend (bin/backends/herdr.sh, fm_backend_herdr_agent_state, the recovery-grade classifier) so a hook-authority idle/done opencode agent whose pane foreground is only a shell with no harness process counts as agent-free (dead). Captain follow-up from a live stuck pane: the foreground may be the treehouse subshell (a recognized idle shell that is a descendant of the pane shell reached only through shells and the treehouse launcher, no children), not the pane shell itself, and that must also read agent-free. Keep working/blocked/busy cases, live opencode in the foreground, and non-opencode harnesses unchanged. Deliberate decisions: only fm_backend_herdr_agent_state is refined; fm_backend_herdr_pane_agent_state and fm_backend_herdr_pane_idle_shell_pid are intentionally left unchanged because pane-closing paths depend on them; the new subshell proof never prints a pid. Did not emit an exit event from a plugin because the opencode Herdr plugin is a Herdr-managed file overwritten on reinstall. Regression tests in tests/fm-backend-herdr.test.sh cover stale idle/done after exit, genuinely live idle opencode (stays alive), the treehouse-subshell layout, harness-parented and busy-subshell refusals, and non-opencode harnesses. Shellcheck clean via bin/fm-lint.sh; docs/agent-control.md notes the behavior. Caveat: could not reproduce the stale read in an isolated lab on Herdr 0.9.1; verified against the live stuck pane read-only.
What Changed
fm_backend_herdr_agent_stateinbin/backends/herdr.shnow returns dead (agent-free) for an opencode agent that Herdr still reports as idle/done under hook authority when the pane's foreground is only a shell with no harness process. That shell can be the pane shell or the treehouse subshell: an idle shell with no children that descends from the pane shell only through shells and the treehouse launcher.fm-controlcan now confirm the exit, andfm-spawn --relaunchno longer refuses. Working/blocked states, busy shells, opencode that is still running in the foreground, and non-opencode harnesses read the same as before.fm_backend_herdr_pane_agent_stateandfm_backend_herdr_pane_idle_shell_pidare unchanged, and the new subshell check never prints a pid.tests/fm-backend-herdr.test.shcover:docs/herdr-backend.mddocuments the exited-opencode liveness rule, anddocs/agent-control.mdgains a one-line pointer to it.Review left three info-level notes, none blocking:
agent getcall to each "live" verdict.🤖 Generated with Claude Code
Risk Assessment
✅ Low: The change is limited to fm_backend_herdr_agent_state and only reclassifies idle or done opencode registrations to agent-free after strict proofs (a lone idle shell, or an idle treehouse subshell reached only through shells and treehouse). Pane-closing paths still use the unchanged pane_agent_state and idle_shell_pid, and the regression tests cover the required cases from the intent.
Testing
I ran
tests/fm-backend-herdr.test.shand it passed, including the new agent_state regression tests. I then ran the same fake-herdr/ps scenarios against the base commit and the target commit. On the base, every case readalive, which is the reported refusal. On the target, only an exited opencode with a stale idle/done registration readsdead, whether the foreground is the pane's own shell or the treehouse subshell. Live opencode, harness-parented shells, busy subshells, working/blocked agents and claude stayalive. I did not run a real Herdr pane or the full fm-control relaunch flow; the author notes the stale read could not be reproduced in a lab, so the fake harness plus the dispatch trace from fm-control's exit wait is the evidence. This is a CLI/backend change with no UI surface, so there are no screenshots.Evidence: Verdict before vs after the fix (12 cases)
BASE 4159b40: all 12 cases -> alive TARGET 9431ebc: opencode idle/done zsh own -> dead opencode idle/done zsh treehouse -> dead opencode idle opencode own/treehouse -> alive opencode idle zsh harness-tree -> alive opencode idle zsh busy-tree -> alive opencode working/blocked zsh own -> alive claude idle zsh own/treehouse -> aliveEvidence: Script that builds the verdict comparison
Evidence: fm-backend-herdr test run log
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/backends/herdr.sh:1935- The treehouse-subshell proof (fm_backend_herdr_pane_idle_subshell_sample) is checked in a single sample, with no settle retry. The pane-shell proof retries for up to FM_BACKEND_HERDR_IDLE_SHELL_PROOF_POLLS samples because prompt helpers such as starship briefly appear as a second foreground process. fm-spawn --relaunch makes one fm_backend_agent_state read, so a prompt redraw during that read makes the subshell layout read 'alive' and the relaunch refuses. fm-control's wait loop re-polls and recovers, so the impact is limited to that one-shot read. Optional follow-up: reuse the same bounded retry.bin/backends/herdr.sh:1974- The subshell proof checks that the foreground shell has no children and that its ancestors are shells or treehouse. It does not check that those ancestors (the pane shell or the treehouse launcher) have no other children. A backgrounded or sibling opencode job under the pane shell would therefore still read agent-free. Normal launches run opencode as a child of the treehouse subshell (fm-spawn.sh:2254), so this needs an unusual manual layout. It is noted for completeness and does not block the change.bin/backends/herdr.sh:2005- Every 'live' verdict now costs an extraagent getcall. When a genuinely live opencode is registered idle or done, fm_backend_herdr_pane_idle_shell_pid also runs its full retry loop (about 10 × 0.1s plus a CLI call and ps calls on each attempt) before the subshell sample fails. That adds roughly 1s or more to each agent_state read for idle opencode workers in the fm-watch paused rechecks, fleet snapshots, and the post-launch alive wait. The verdict stays correct. If this becomes noticeable, the fix is to run the single-sample shell check before the retrying one.✅ **Test** - passed
✅ No issues found.
bash tests/fm-backend-herdr.test.sh: passed (rc=0), including the four new agent_state regression tests (stale idle/done reads dead, live idle opencode stays alive, the treehouse-subshell layout plus harness-parented/busy/non-opencode refusals, working/blocked never reclassified)Before/after comparison:verdict-matrix.shruns the test file's fake herdr CLI and fake ps harness against base 4159b40'sbin/backends/herdr.shand target 9431ebc'sbin/backends/herdr.shacross 12 casesChecked thatbin/fm-backend.sh:894sends Herdragent_statetofm_backend_herdr_agent_state, the state thatdo_exitinbin/fm-control.shwaits on before it reportsexit=unconfirmedRead the diff to confirmfm_backend_herdr_pane_agent_stateandfm_backend_herdr_pane_idle_shell_pidare unchanged and the new subshell proof prints no pid✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.