Repository navigation
fix(afk): support herdr away-mode injection - #251
Merged
Merged
Conversation
bin/fm-supervise-daemon.sh discovered its supervisor pane and injected via raw tmux calls only, so /afk failed outright on a herdr-based fleet (TMUX_PANE unset, firstmate:0 fallback unresolvable). Discovery now resolves backend (tmux|herdr) and target independently, mirroring fm-backend.sh's own runtime auto-detection, with an explicit FM_SUPERVISOR_BACKEND override alongside the existing FM_SUPERVISOR_TARGET. zellij/orca refuse loudly at startup instead of misapplying tmux primitives. Injection (pane-exists probe, busy-guard, composer-guard, verified submit) now dispatches through bin/fm-backend.sh's generic primitives, adding a new fm_backend_composer_state dispatcher; the tmux path is byte-identical to before. Also fixes a pre-existing bug in fm_backend_target_exists's herdr arm (missing --session, so it silently misrouted once more than one herdr server was running) found while verifying this end to end against a real isolated herdr session. Classification, batching, max-defer, the marker contract, locks, and wake-queue handling are unchanged - this is a transport-layer fix.
mielyemitchell
added a commit
to mielyemitchell/firstmate
that referenced
this pull request
Jul 6, 2026
Intent
Make the away-mode supervise-daemon (bin/fm-supervise-daemon.sh) work on the herdr runtime backend, not just tmux. Live failure: on a herdr-based fleet (firstmate itself running with HERDR_ENV=1, no TMUX_PANE), /afk's daemon errored out at startup because supervisor-pane discovery and every injection primitive (busy-guard, composer-guard, verified submit) were tmux-only raw calls.
Scope, deliberately kept to a transport-layer fix (classification policy, batching, max-defer, the FM_INJECT_MARK contract, locks, and wake-queue handling are explicitly NOT touched):
Full local test suite (tests/*.test.sh) and shellcheck both pass clean.
What Changed
fm-supervise-daemon.shbackend-aware so away-mode injection can discover tmux or Herdr supervisor targets, refuse unsupported supervisor backends, and route target, busy, composer, and submit checks through backend primitives.Risk Assessment
Testing
Captain, the already-successful baseline was accounted for; I reran focused daemon, herdr backend, tmux E2E, and real-herdr E2E coverage, then performed a preserved manual real-herdr run showing pending-input deferral, sentinel-prefixed injection after idle, max-defer wedge alarm with buffer preservation, and loud unsupported-backend refusal. No tests failed, no source files were modified, and no UI surface changed, so no screenshot was applicable.
Evidence: Manual herdr observed behavior
Evidence: Manual herdr submitted lines, readable
Evidence: Manual herdr daemon log
Evidence: Manual herdr wedge marker
Evidence: Real herdr AFK injection E2E transcript
Evidence: Tmux AFK injection regression E2E transcript
Evidence: Daemon unit test transcript
Evidence: Herdr backend unit test transcript
Evidence: Unsupported backend refusal transcript
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 1 issue found → auto-fixed (3) ✅
bin/fm-supervise-daemon.sh:495- The Herdr busy guard trusts a nativeidleverdict as not busy and skips the regex capture fallback. That conflicts with the existingcrew_pane_is_busyinvariant: Herdr can report idle while the pane is still blocked in a foreground tool call and rendering the busy footer, so the AFK daemon can inject into firstmate's active turn. Treat onlybusyas conclusive and let bothidleandunknownfall through to the capture/FM_BUSY_REGEXcheck.🔧 Fix: Corroborate Herdr idle busy state
1 warning still open:
tests/fm-afk-inject-herdr-e2e.test.sh:214- The test waits only for.supervise-daemon.pid, but the daemon writes that pidfile before backend discovery, target validation, and the startup log line. The immediategrepcan race on slower Herdr/CI startup and fail even though the daemon would logbackend=herdrmoments later; fold this assertion into the wait loop and also fail early if the daemon exits.🔧 Fix: Stabilize Herdr daemon startup wait
2 issues (1 warning, 1 info) still open:
bin/fm-backend.sh:440- The new generic composer dispatcher never routescmux, even thoughbin/backends/cmux.shalready hasfm_backend_cmux_composer_state; any caller using this shared API for cmux will getunknownand skip pending-input protection..agents/skills/afk/SKILL.md:87- This still documents the Herdr busy fallback asunknown-only, but the fixed daemon now corroborates every non-busyverdict, includingidle; update this and the matchingdocs/herdr-backend.mdwording so future AFK work does not reintroduce the unsafe idle shortcut.🔧 Fix: Captain, route cmux composer and update AFK docs
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"Pre-existing baseline reported successful before this validation:command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"command -v herdrcommand -v jqcommand -v tmuxbash tests/fm-daemon.test.sh > /var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/no-mistakes-evidence/01KWQ882JBBTJ3F3S9J5SJ75VV/fm-daemon-test.log 2>&1bash tests/fm-backend-herdr.test.sh > /var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/no-mistakes-evidence/01KWQ882JBBTJ3F3S9J5SJ75VV/fm-backend-herdr-test.log 2>&1bash tests/fm-afk-inject-e2e.test.sh > /var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/no-mistakes-evidence/01KWQ882JBBTJ3F3S9J5SJ75VV/fm-afk-inject-tmux-e2e.log 2>&1bash tests/fm-afk-inject-herdr-e2e.test.sh > /var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/no-mistakes-evidence/01KWQ882JBBTJ3F3S9J5SJ75VV/fm-afk-inject-herdr-e2e.log 2>&1/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/no-mistakes-evidence/01KWQ882JBBTJ3F3S9J5SJ75VV/manual-herdr-afk-evidence.sh > /var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/no-mistakes-evidence/01KWQ882JBBTJ3F3S9J5SJ75VV/manual-herdr-afk-evidence.log 2>&1FM_STATE_OVERRIDE=/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/no-mistakes-evidence/01KWQ882JBBTJ3F3S9J5SJ75VV/unsupported-backend-state FM_SUPERVISOR_BACKEND=zellij bash bin/fm-supervise-daemon.shcaptured tounsupported-backend-refusal.loggit status --short✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.