Skip to content

fix(afk): support herdr away-mode injection - #251

Merged
kunchenguid merged 5 commits into
mainfrom
fm/afk-herdr-inject-h6
Jul 4, 2026
Merged

kunchenguid merged 5 commits into
mainfrom
fm/afk-herdr-inject-h6

Conversation

@kunchenguid

Copy link
Copy Markdown
Owner

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):

  • Extended supervisor-target/backend discovery: FM_SUPERVISOR_TARGET stays the explicit override (now also accepting a herdr ':' target), and a NEW FM_SUPERVISOR_BACKEND override resolves independently, mirroring bin/fm-backend.sh's own fm_backend_detect precedence (TMUX_PANE wins over HERDR_ENV=1, matching the innermost-first tmux-nested-in-herdr rule; falls back to tmux/firstmate:0 byte-identical to before when nothing is configured or detected).
  • zellij and orca are explicitly out of scope for this daemon and refuse loudly at startup with a clear message (FM_SUPERVISOR_SUPPORTED_BACKENDS) rather than being silently misapplied to tmux primitives - this is a deliberate scope decision, not an oversight.
  • inject_msg's pane-exists probe, busy-guard (pane_is_busy), composer-guard (pane_input_pending), and verified submit now take an optional backend argument (default tmux, so every existing caller/test is unaffected) and dispatch through bin/fm-backend.sh's generic primitives (fm_backend_target_exists, fm_backend_busy_state, fm_backend_capture, fm_backend_send_text_submit) instead of raw tmux calls. Added a new generic fm_backend_composer_state dispatcher to bin/fm-backend.sh (tmux/herdr/orca arms; zellij/unknown fall back to 'unknown') since no such generic dispatcher existed before, mirroring the existing fm_backend_busy_state pattern.
  • For backend=tmux every dispatch resolves to the EXACT same underlying call as before (verified: the full pre-existing test suite, including a real-tmux private-socket e2e test, passes unchanged) - this is intentionally byte-identical, not a behavior change.
  • Found and fixed a PRE-EXISTING, unrelated bug while doing empirical real-herdr verification: fm_backend_target_exists's herdr arm called WITHOUT the required --session flag, which docs/herdr-backend.md already documented as unreliable once more than one herdr server is running (it silently falls back to whichever server IS running). This is a real bug affecting bin/fm-session-start.sh's endpoint-liveness digest too, not something I introduced, but it directly blocked the daemon's own herdr startup validation and I fixed it in passing (route through fm_backend_herdr_cli, which appends --session). This is a deliberate fix, not scope creep - it was empirically reproduced (an isolated test session was misrouted to the ambient default session) before being fixed.
  • Empirical verification against THIS machine's real herdr, in strict isolation (never the live default session or any live pane): read-only discovery check against my own real pane first (confirmed target/backend resolution), then a full new e2e test file tests/fm-afk-inject-herdr-e2e.test.sh (mirroring tests/fm-afk-inject-e2e.test.sh's tmux e2e) on a throwaway, never-default HERDR_SESSION with guarded teardown (herdr_safe_stop_and_delete), covering: partial-input deferral, swallowed-Enter retry (via a thin herdr CLI shim that swallows exactly one Enter, since herdr's real CLI has no built-in way to drop a keystroke), a normal single digest, and a NEW max-defer scenario (a persistently pending composer must alarm via state/.subsuper-inject-wedged, preserve the buffer, and never crash the daemon).
  • Along the way, discovered and documented (docs/herdr-backend.md) that 80 is unreliable when called from within a script launched into a herdr pane (reports a stale default width instead of the pane's real width) - worked around in the test's own composer-drawing script with a hardcoded conservative width; this is a test-harness-only finding, not a change to the herdr adapter itself.
  • Also added an FM_SUPERVISOR_BACKEND=tmux pin to the existing tests/fm-afk-inject-e2e.test.sh's daemon-subprocess launch, because that e2e spawns the real daemon process and, without an explicit pin, would inherit whatever HERDR_ENV the invoking shell happens to carry (e.g. running this validation itself from inside a herdr pane) and misdetect backend=herdr against what is actually a tmux pane on a private socket - this is a necessary correctness fix given the new auto-detection behavior, not incidental to the task.
  • Documentation: docs/herdr-backend.md gets a new 'Away-mode daemon: herdr supervisor-pane support' section; .agents/skills/afk/SKILL.md's tmux-specific mechanics (busy-guard/composer-guard, submit model, auto-discovered supervisor pane) are updated to describe both backends. AGENTS.md's own afk stub was deliberately NOT touched - its inline facts (marker contract, watcher ownership, approval semantics) are backend-independent and did not change.
  • Out of scope, left alone: multi-harness (codex/opencode/pi) pane-mechanics verification, the primary turn-end guard, and any watcher-policy change.

Full local test suite (tests/*.test.sh) and shellcheck both pass clean.

What Changed

  • Captain, made fm-supervise-daemon.sh backend-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.
  • Fixed Herdr backend helpers used by daemon startup and session liveness by adding generic composer-state dispatch and using session-scoped Herdr target existence checks.
  • Updated AFK/Herdr documentation and added tmux/Herdr daemon coverage for startup, pending input deferral, swallowed-submit retry, and wedged max-defer behavior.

Risk Assessment

⚠️ Medium: Captain, the review found no material defects, but the change touches the daemon's live injection transport and backend discovery path, so residual integration risk is moderate.

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
Manual herdr AFK evidence session: fm-afk-herdr-evidence-54136
Supervisor target: fm-afk-herdr-evidence-54136:w1:p2

[Scenario A raw submitted lines]
68756d616e2064726166742074657874	human draft text	user
1f53757065727669736f7220657363616c61746520282020202020202031206576656e74287329293a2066616b652d63312e7374617475733a20646f6e653a2050522068747470733a2f2f6578616d706c652e746573742f70722f6d616e75616c2d61202863617463682d616c6c207363616e2920287072652d726561643b2072652d61726d206e6f74206e656564656420e280942077617463686572206461656d6f6e2d6d616e6167656429	�Supervisor escalate (       1 event(s)): fake-c1.status: done: PR https://example.test/pr/manual-a (catch-all scan) (pre-read; re-arm not needed — watcher daemon-managed)	injection

[Scenario C raw submitted lines]
1f53757065727669736f7220657363616c61746520282020202020202031206576656e74287329293a2066616b652d63312e7374617475733a20646f6e653a2050522068747470733a2f2f6578616d706c652e746573742f70722f6d616e75616c2d63202863617463682d616c6c207363616e2920287072652d726561643b2072652d61726d206e6f74206e656564656420e280942077617463686572206461656d6f6e2d6d616e6167656429	�Supervisor escalate (       1 event(s)): fake-c1.status: done: PR https://example.test/pr/manual-c (catch-all scan) (pre-read; re-arm not needed — watcher daemon-managed)	injection

[Scenario D wedge marker]
fm away-mode inject WEDGED: 11s undelivered as of 2026-07-04T12:52:24-0700
The supervisor pane could not accept an escalation. Buffered items:
fake-c1.status: needs-decision: pick A or B (catch-all scan)

[Scenario D buffered escalations]
fake-c1.status: needs-decision: pick A or B (catch-all scan)
Manual evidence passed
Evidence: Manual herdr submitted lines, readable
line 1: hex_prefix=68756d616e206472 classification=user text=human draft text
line 2: hex_prefix=1f53757065727669 classification=injection text=�Supervisor escalate (       1 event(s)): fake-c1.status: done: PR https://example.test/pr/manual-a (catch-all scan) (pre-read; re-arm not needed — watcher daemon-managed)
line 3: hex_prefix=1f53757065727669 classification=injection text=�Supervisor escalate (       1 event(s)): fake-c1.status: done: PR https://example.test/pr/manual-c (catch-all scan) (pre-read; re-arm not needed — watcher daemon-managed)
Evidence: Manual herdr daemon log
[2026-07-04T12:51:43-0700] daemon starting (pid 54511); target=fm-afk-herdr-evidence-54136:w1:p2; target_source=FM_SUPERVISOR_TARGET; backend=herdr; backend_source=FM_SUPERVISOR_BACKEND; afk=on; inject_skip='heartbeat'; stale_escalate=999999s; batch=0s
[2026-07-04T12:51:45-0700] inject deferred: supervisor pane has pending input (non-empty composer)
[2026-07-04T12:51:47-0700] inject deferred: supervisor pane has pending input (non-empty composer)
[2026-07-04T12:51:47-0700] wake: signal: /var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/no-mistakes-evidence/01KWQ882JBBTJ3F3S9J5SJ75VV/manual-herdr-state/fake-c1.status
[2026-07-04T12:51:47-0700] self-handle: signal: /var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/no-mistakes-evidence/01KWQ882JBBTJ3F3S9J5SJ75VV/manual-herdr-state/fake-c1.status -> signal already escalated (catch-all scan): fake-c1.status: done: PR https://example.test/pr/manual-a
[2026-07-04T12:51:48-0700] inject deferred: supervisor pane has pending input (non-empty composer)
[2026-07-04T12:51:49-0700] inject deferred: supervisor pane has pending input (non-empty composer)
[2026-07-04T12:51:50-0700] inject deferred: supervisor pane has pending input (non-empty composer)
[2026-07-04T12:51:51-0700] inject deferred: supervisor pane has pending input (non-empty composer)
[2026-07-04T12:52:00-0700] daemon shutting down
[2026-07-04T12:52:01-0700] daemon starting (pid 57322); target=fm-afk-herdr-evidence-54136:w1:p2; target_source=FM_SUPERVISOR_TARGET; backend=herdr; backend_source=FM_SUPERVISOR_BACKEND; afk=on; inject_skip='heartbeat'; stale_escalate=999999s; batch=0s
[2026-07-04T12:52:05-0700] wake: signal: /var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/no-mistakes-evidence/01KWQ882JBBTJ3F3S9J5SJ75VV/manual-herdr-state/fake-c1.status
[2026-07-04T12:52:05-0700] self-handle: signal: /var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/no-mistakes-evidence/01KWQ882JBBTJ3F3S9J5SJ75VV/manual-herdr-state/fake-c1.status -> signal already escalated (catch-all scan): fake-c1.status: done: PR https://example.test/pr/manual-c
[2026-07-04T12:52:10-0700] daemon shutting down
[2026-07-04T12:52:12-0700] daemon starting (pid 58656); target=fm-afk-herdr-evidence-54136:w1:p2; target_source=FM_SUPERVISOR_TARGET; backend=herdr; backend_source=FM_SUPERVISOR_BACKEND; afk=on; inject_skip='heartbeat'; stale_escalate=999999s; batch=99999s
[2026-07-04T12:52:15-0700] wake: signal: /var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/no-mistakes-evidence/01KWQ882JBBTJ3F3S9J5SJ75VV/manual-herdr-state/fake-c1.status
[2026-07-04T12:52:15-0700] self-handle: signal: /var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/no-mistakes-evidence/01KWQ882JBBTJ3F3S9J5SJ75VV/manual-herdr-state/fake-c1.status -> signal already escalated (catch-all scan): fake-c1.status: needs-decision: pick A or B
[2026-07-04T12:52:17-0700] inject deferred: supervisor pane has pending input (non-empty composer)
[2026-07-04T12:52:17-0700] ERROR: away-mode escalation undelivered 4s; inject could not confirm a submit (supervisor pane busy or wedged). Buffer + wake-queue preserved; alarm marker written.
[2026-07-04T12:52:20-0700] inject deferred: supervisor pane has pending input (non-empty composer)
[2026-07-04T12:52:20-0700] ERROR: away-mode escalation undelivered 7s; inject could not confirm a submit (supervisor pane busy or wedged). Buffer + wake-queue preserved; alarm marker written.
[2026-07-04T12:52:24-0700] inject deferred: supervisor pane has pending input (non-empty composer)
[2026-07-04T12:52:24-0700] ERROR: away-mode escalation undelivered 11s; inject could not confirm a submit (supervisor pane busy or wedged). Buffer + wake-queue preserved; alarm marker written.
[2026-07-04T12:52:25-0700] inject deferred: afk inactive
[2026-07-04T12:52:25-0700] daemon shutting down
Evidence: Manual herdr wedge marker
fm away-mode inject WEDGED: 11s undelivered as of 2026-07-04T12:52:24-0700
The supervisor pane could not accept an escalation. Buffered items:
fake-c1.status: needs-decision: pick A or B (catch-all scan)
Evidence: Real herdr AFK injection E2E transcript
ok - real herdr Scenario A: partial input defers injection; digest arrives clean after idle
ok - real herdr Scenario B: swallowed Enter (via the herdr shim) produces exactly one clean digest
ok - real herdr Scenario C: a normal captain status injects exactly one clean single-line sentinel digest
ok - real herdr Scenario D: a persistently pending composer raises the max-defer wedge alarm, preserves the buffer, and never crashes the daemon
all real-herdr afk injection e2e tests passed
Evidence: Tmux AFK injection regression E2E transcript
ok - Scenario A: partial input defers injection; digest arrives clean after idle
ok - Scenario B: swallowed Enter produces exactly one clean digest
ok - Scenario C: a normal captain status injects exactly one clean single-line sentinel digest
all e2e injection tests passed
Evidence: Daemon unit test transcript
ok - supervise daemon state root is scoped by FM_HOME
ok - routine signal self-handles
ok - captain-relevant status verbs escalate
ok - check + unknown escalate; heartbeat self-handles
ok - transient stale self-handles and records a persistence marker
ok - stale + terminal status escalates immediately
ok - persistent stale escalates after threshold and clears its marker
ok - resumed (busy) stale clears its marker without escalating
ok - persistent herdr stale resolves the target from metadata and escalates
ok - herdr idle busy-footer stale clears through capture corroboration
ok - resumed herdr stale clears through backend-aware busy state
ok - persistent Orca stale resolves the terminal from metadata
ok - multiple escalations flush as a single batched digest
ok - batch flush measures max-delay from the first append, not the last
ok - catch-all scan escalates a missed terminal once, not twice
ok - handle_wake routes routine->self and captain->escalate
ok - INJECT_SKIP forces self-handle, bypassing captain-relevant classification
ok - is_wake_reason distinguishes watcher wake reasons from singleton-status stdout
ok - terminal-stale escalate removes its marker so housekeeping does not re-escalate
ok - captain signal escalate marks seen so the catch-all scan does not re-fire
ok - _collapse_newlines replaces newlines with literal separator
ok - afk flag absent: daemon does not inject, buffer preserved
ok - busy-guard defers injection when supervisor pane is busy
ok - marker detection: marker -> stay afk, no marker -> exit afk
ok - /afk invocation is exempt from afk exit (no self-cancel)
ok - should_exit_afk returns false when afk is not active
ok - strip_injection_marker removes the sentinel marker cleanly
ok - pane_input_pending detects partial input on the cursor line
ok - pane_input_pending: blank cursor line is not pending
ok - pane_input_pending: bare prompts are not pending (idle)
ok - pane_input_pending honors FM_COMPOSER_IDLE_RE after border stripping
ok - classify_signal dedupes against the catch-all scan seen marker
ok - classify_stale dedupes against the signal path seen marker
ok - pane_input_pending: an idle bordered composer is NOT pending (afk-invx-i5)
ok - pane_input_pending: text inside a bordered composer is still pending
ok - submit-ACK confirms a submit when the composer returns to a bordered-empty box
ok - submit-ACK reports pending on a persistently swallowed Enter (type-once)
ok - max-defer on an empty stuck pane types once, alarms, and preserves the buffer
ok - max-defer flushes and clears the buffer on an empty bordered pane
ok - max-defer on a pending composer alarms without typing
ok - normal flush clears a stale wedge marker
ok - below MAX_DEFER: no inject, no alarm, buffer preserved
ok - max-defer does not flush or alarm while afk is inactive
ok - fm-send exits non-zero on a confirmed swallow, zero on a clean submit
ok - fm-send exits non-zero when initial text send fails
ok - discover_supervisor_backend: override > TMUX_PANE > HERDR_ENV+HERDR_PANE_ID > tmux fallback
ok - discover_supervisor_target: override > TMUX_PANE > herdr '<session>:<pane-id>' composition > firstmate:0 fallback
ok - pane_is_busy: herdr native busy_state='busy' short-circuits without a capture fallback
ok - pane_is_busy: herdr falls back to the shared regex-over-capture reader when native busy_state is unknown
ok - pane_is_busy: herdr corroborates native idle with the shared regex-over-capture reader
ok - pane_is_busy: omitted backend arg defaults to tmux (pre-existing callers unaffected)
ok - pane_input_pending: dispatches through fm_backend_composer_state for backend=herdr
ok - inject_msg: herdr busy-guard defers before ever attempting a submit
ok - inject_msg: herdr composer-guard defers before ever attempting a submit
ok - inject_msg: herdr pane-gone check defers before any busy/composer/submit call
ok - inject_msg: dispatches busy-guard/composer-guard/submit through the herdr backend and succeeds on a confirmed empty composer
Evidence: Herdr backend unit test transcript
ok - fm_backend_herdr_version_check: accepts the current protocol (14)
ok - fm_backend_herdr_version_check: refuses an old protocol loudly
ok - fm_backend_herdr_version_check: refuses loudly when herdr is not installed
ok - fm_backend_herdr_workspace_label: a primary home (no marker) resolves to 'firstmate'
ok - fm_backend_herdr_workspace_label: a secondmate home (.fm-secondmate-home) resolves to '2ndmate-<id>'
ok - fm_backend_herdr_workspace_label: trims whitespace around the marker's secondmate id
ok - fm_backend_herdr_workspace_label: an empty marker file falls back to the primary label 'firstmate'
ok - fm_backend_herdr_workspace_label: two different secondmate homes get two different, non-colliding labels
ok - fm_backend_herdr_cli: sets HERDR_SESSION AND appends a trailing --session flag on every call
ok - fm_backend_herdr_container_ensure: version-gates, starts the server, ensures the firstmate workspace, echoes session:workspace_id + the seeded default tab id
ok - fm_backend_herdr_container_ensure: reuses an existing firstmate workspace without recreating it, and reports no seeded default tab (adopted, not created)
ok - fm_backend_herdr_container_ensure: workspace create passes --no-focus
ok - fm_backend_herdr_container_ensure: creates the workspace under the SECONDMATE home's own label, not 'firstmate'
ok - fm_backend_herdr_create_task: prunes exactly the seeded default tab container_ensure identified, once the first real task tab exists
ok - herdr repeated spawn/teardown: one persistent firstmate workspace reused, zero orphans, default tab pruned, create ran once
ok - fm_backend_herdr_create_task: an ADOPTED workspace's pre-existing tab is never pruned (the created-vs-adopted gate)
ok - fm_backend_herdr_create_task: the label-collision startup-workspace scenario (2026-07-02 incident) leaves the captain's live tab untouched
ok - fm_backend_herdr_workspace_prune_seeded_default_tab: refuses to close the seeded default tab when its pane reports a working agent (defense in depth)
ok - no bin/ jq filter names a --arg/--argjson variable after a jq reserved keyword
ok - fm_backend_herdr_create_task: refuses a duplicate tab label (herdr's own tab create has no uniqueness check)
ok - fm_backend_herdr_create_task: a same-labeled tab with a live (even idle) registered agent still refuses exactly as before
ok - fm_backend_herdr_create_task: scans every same-labeled tab and refuses if any duplicate is live
ok - fm_backend_herdr_create_task: closes and replaces a same-labeled tab whose pane is dead (pane_not_found)
ok - fm_backend_herdr_create_task: closes and replaces a same-labeled tab whose pane is alive but hosts no registered agent (a restored plain shell)
ok - fm_backend_herdr_create_task: closes every confirmed same-labeled husk only after creating the replacement
ok - fm_backend_herdr_create_task: refuses success when a preexisting husk tab remains after replacement
ok - fm_backend_herdr_create_task: refuses (fail-safe) rather than guessing when the duplicate's agent state cannot be classified confidently
ok - fm_backend_herdr_create_task: creates the replacement tab BEFORE closing the husk tab, never the reverse
ok - fm_backend_herdr_create_task: creates a tab and parses tab_id/pane_id from the JSON response, prunes nothing when no seeded tab id is given
ok - fm_backend_herdr_create_task: tab create passes --no-focus
ok - fm_backend_herdr_workspace_find: matches only THIS home's own label among several coexisting workspaces
ok - fm_backend_herdr_list_live: scoped to this home's own workspace, never a sibling home's
ok - fm_backend_herdr_parse_target: splits '<session>:<pane_id>' on the FIRST colon (pane_id itself contains one)
ok - fm_backend_herdr_normalize_key: Enter/Escape/C-c map to herdr's verified enter/escape/ctrl+c
ok - fm_backend_herdr_capture: calls 'pane read <pane> --source recent --lines N' with the session set
ok - fm_backend_herdr_capture: works around the verified small-N '--lines' bug by over-fetching and trimming locally
ok - fm_backend_herdr_capture: ensures the session and preserves pane read failure
ok - fm_backend_herdr_send_key: normalizes the key and targets the right pane
ok - fm_backend_herdr_kill: calls pane close and stays best-effort on failure
ok - fm_backend_herdr_current_path: reads pane foreground_cwd (the live running process), not the frozen creation-time cwd
ok - fm_backend_herdr_busy_state: working -> busy
ok - fm_backend_herdr_busy_state: done -> idle, blocked -> idle (surfaced like a stale pane, not suppressed as busy)
ok - fm_backend_herdr_busy_state: unparseable/absent agent state reports unknown, the regex-fallback cue
ok - fm_backend_herdr_composer_state: a bare '❯' composer row reads empty
ok - fm_backend_herdr_composer_state: the ghost placeholder text reads empty, not pending
ok - fm_backend_herdr_composer_state: real composer text reads pending
ok - fm_backend_herdr_composer_state: a slash-command popup's argument-hint placeholder still reads pending (the incident fix)
ok - fm_backend_herdr_composer_state: reports unknown when the pane cannot be captured
ok - fm_backend_herdr_composer_state: reports unknown when no border-delimited composer row is found
ok - fm_backend_herdr_send_text_submit: reports 'empty' once the composer row reads empty after one Enter
ok - fm_backend_herdr_send_text_submit: reports 'pending' when the composer never clears after retried Enters (swallowed)
ok - fm_backend_herdr_send_text_submit: a slash-command popup's placeholder fill on Enter #1 does not short-circuit as submitted; Enter #2 is retried and lands it
ok - fm_backend_herdr_send_text_submit: reports 'send-failed' when the literal send-text call itself errors
ok - fm_backend_herdr_send_text_submit: reports 'unknown' when the post-Enter capture fails (never retries past an unreadable pane)
ok - fm_backend_validate: herdr is a known backend (P2)
ok - fm_backend_busy_state: tmux (no native primitive) always reports unknown, preserving the P1 regex-only path
error: unknown backend 'bogus' (known: tmux herdr zellij orca cmux)
ok - fm_backend_composer_state dispatches tmux/herdr/orca to their named classifiers, unknown for zellij/unrecognized backends
ok - fm-peek/fm-send: explicit stale targets matching metadata use the recorded backend
Evidence: Unsupported backend refusal transcript
error: away-mode daemon does not support supervisor backend 'zellij' yet (supported: tmux herdr); set FM_SUPERVISOR_BACKEND=tmux|herdr and FM_SUPERVISOR_TARGET to run firstmate's own pane under a supported backend
exit_code=1

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 native idle verdict as not busy and skips the regex capture fallback. That conflicts with the existing crew_pane_is_busy invariant: 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 only busy as conclusive and let both idle and unknown fall through to the capture/FM_BUSY_REGEX check.

🔧 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 immediate grep can race on slower Herdr/CI startup and fail even though the daemon would log backend=herdr moments 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 routes cmux, even though bin/backends/cmux.sh already has fm_backend_cmux_composer_state; any caller using this shared API for cmux will get unknown and skip pending-input protection.
  • ℹ️ .agents/skills/afk/SKILL.md:87 - This still documents the Herdr busy fallback as unknown-only, but the fixed daemon now corroborates every non-busy verdict, including idle; update this and the matching docs/herdr-backend.md wording 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 &gt;/dev/null || { echo &#34;tmux is required for e2e tests&#34; &gt;&amp;2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo &#34;== $t ==&#34;; bash &#34;$t&#34; || rc=1; done; exit &#34;$rc&#34;
  • command -v herdr
  • command -v jq
  • command -v tmux
  • bash tests/fm-daemon.test.sh > /var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/no-mistakes-evidence/01KWQ882JBBTJ3F3S9J5SJ75VV/fm-daemon-test.log 2>&1
  • bash tests/fm-backend-herdr.test.sh > /var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/no-mistakes-evidence/01KWQ882JBBTJ3F3S9J5SJ75VV/fm-backend-herdr-test.log 2>&1
  • bash tests/fm-afk-inject-e2e.test.sh > /var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/no-mistakes-evidence/01KWQ882JBBTJ3F3S9J5SJ75VV/fm-afk-inject-tmux-e2e.log 2>&1
  • bash 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>&1
  • FM_STATE_OVERRIDE=/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/no-mistakes-evidence/01KWQ882JBBTJ3F3S9J5SJ75VV/unsupported-backend-state FM_SUPERVISOR_BACKEND=zellij bash bin/fm-supervise-daemon.sh captured to unsupported-backend-refusal.log
  • git status --short
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

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.
@kunchenguid
kunchenguid merged commit 74a6973 into main Jul 4, 2026
4 checks passed
@kunchenguid
kunchenguid deleted the fm/afk-herdr-inject-h6 branch July 4, 2026 20:08
mielyemitchell added a commit to mielyemitchell/firstmate that referenced this pull request Jul 6, 2026