Skip to content
This repository was archived by the owner on Aug 25, 2026. It is now read-only.

feat: support Herdr AFK supervisor injection - #72

Merged
JTInventory merged 3 commits into
mainfrom
fm/herdr-backend-p3-0718
Jul 19, 2026
Merged

JTInventory merged 3 commits into
mainfrom
fm/herdr-backend-p3-0718

Conversation

@JTInventory

Copy link
Copy Markdown
Owner

Intent

Make AFK/supervisor injection and supervisor target resolution work when firstmate or its supervisor pane runs on Herdr, while keeping tmux as the default path unchanged. Adapt the Herdr owner patterns onto the JT HEAD without wholesale-merging owner main; support only tmux|herdr supervisor backends, use Herdr pane send primitives when selected, preserve the secondmate marker path, refuse unsupported backends, and include unit tests, a guarded fm-lab-* Herdr e2e, and brief configuration/Herdr/AFK documentation. Never touch the captain's default Herdr session.

What Changed

  • Added tmux|herdr supervisor backend selection with backend-aware target discovery, endpoint resolution, busy/composer checks, and Herdr-native send primitives while preserving tmux defaults.
  • Updated AFK launch and supervision rechecks to carry backend/target metadata, preserve secondmate markers, and refuse unsupported backends.
  • Added unit and guarded fm-lab-* Herdr end-to-end coverage, plus focused AFK, configuration, backend, architecture, and protocol documentation.

Risk Assessment

⚠️ Medium: The change adds a substantial experimental Herdr runtime path, but the previously identified target-resolution, idle-state, and backend-aware recheck issues are addressed in the current HEAD.

Testing

The supplied baseline and a fresh full behavior run passed; focused tmux/Herdr unit tests, backend refusal checks, marker coverage in the cloned harness, and the guarded real Herdr AFK injection all passed, with default-session safety verified and no UI screenshot applicable to this CLI/backend change.

Evidence: Herdr lab safety evidence

default_status_before_rc=0 herdr_afk_e2e_rc=0 default_status_after_rc=0 default_session_status_unchanged=true ok - Herdr AFK injection uses the selected lab supervisor pane and send primitives

default_status_before_rc=0
herdr_afk_e2e_rc=0
default_status_after_rc=0
default_session_status_unchanged=true
ok - Herdr AFK injection uses the selected lab supervisor pane and send primitives
Evidence: Full behavior test transcript
ok: PR target repo jtinventory/firstmate verified
tmux 3.4
ok - gate refusal helper covers marker, empty marker, path backstop, and normal session
ok - spawn, send, and teardown refuse both gate signals before lifecycle work
ok - tracked gate-refusal wiring and trusted no-mistakes config are present
# all fm-gate-refuse tests passed
Running 61 behavior tests with 4 parallel job(s)
START: tests/fm-afk-inject-e2e.test.sh (TMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-afk-inject-e2e/tmp GOTMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-afk-inject-e2e/gotmp)
START: tests/fm-afk-inject-herdr-e2e.test.sh (TMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-afk-inject-herdr-e2e/tmp GOTMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-afk-inject-herdr-e2e/gotmp)
START: tests/fm-afk-launch.test.sh (TMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-afk-launch/tmp GOTMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-afk-launch/gotmp)
START: tests/fm-backend-herdr-smoke.test.sh (TMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-backend-herdr-smoke/tmp GOTMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-backend-herdr-smoke/gotmp)
PASS: tests/fm-afk-inject-e2e.test.sh
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
PASS: tests/fm-afk-inject-herdr-e2e.test.sh
ok - Herdr AFK injection uses the selected lab supervisor pane and send primitives
PASS: tests/fm-afk-launch.test.sh
ok - AFK daemon survives harness process-group reap and stops on return
ok - AFK launch fails closed when the durable away flag cannot be created
ok - AFK launch is idempotent and return clears the away flag
ok - AFK launch forwards the resolved Herdr supervisor target and backend
ok - AFK refresh fails closed when the durable away flag cannot be written
ok - AFK return retains the away flag when identity verification fails
ok - AFK return retains the away flag when a live daemon record is missing
ok - AFK return retains the away flag when a stale daemon record remains live
ok - AFK status keeps a live unverified daemon visible
ok - AFK return fails closed when the durable away flag cannot be removed
ok - AFK transition lock rejects an invalid state path promptly
ok - AFK transition lock distinguishes I/O failure from contention
ok - AFK transition lock handoff preserves contention return code
ok - AFK transition lock bounds contention retries
ok - AFK transition lock preserves a replacement daemon and away flag
ok - AFK return clears the away flag after confirmed daemon absence
ok - AFK return retains the away flag when TERM does not stop the daemon
all fm-afk-launch tests passed
PASS: tests/fm-backend-herdr-smoke.test.sh
skip: set FM_HERDR_SMOKE=1 to opt into the real Herdr smoke
START: tests/fm-backend-herdr.test.sh (TMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-backend-herdr/tmp GOTMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-backend-herdr/gotmp)
START: tests/fm-backend.test.sh (TMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-backend/tmp GOTMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-backend/gotmp)
START: tests/fm-backlog-audit.test.sh (TMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-backlog-audit/tmp GOTMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-backlog-audit/gotmp)
START: tests/fm-bearings-snapshot.test.sh (TMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-bearings-snapshot/tmp GOTMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-bearings-snapshot/gotmp)
PASS: tests/fm-backend-herdr.test.sh
NOTICE: auto-detected herdr runtime (HERDR_ENV=1) - spawning into the EXPERIMENTAL herdr backend. Set config/backend or pass --backend tmux to opt out.
ok - Herdr selection honors explicit config/env and nested TMUX precedence
ok - bootstrap backend tool gating keeps Herdr dependencies opt-in
ok - Herdr version gate enforces 0.7.x and protocol 14+
ok - Herdr container ensure is version-gated and workspace-per-home
ok - Herdr task creation, duplicate protection, target parsing, and key mapping work
ok - Herdr kill propagates close failures and avoids server creation
ok - Herdr capture uses safe over-fetch and native busy state
ok - Herdr text submit confirms the composer cleared
ok - backend dispatch accepts Herdr and preserves opaque session:pane targets
PASS: tests/fm-backend.test.sh
ok - backend selection precedence, metadata default, and known/unknown validation
ok - fm-spawn refuses unknown backends from FM_BACKEND, config/backend, and --backend
ok - selector resolution and capture/key/readability/kill dispatch use tmux adapter
ok - tmux adapter propagates kill and container-creation failures
ok - teardown preserves task state when backend kill fails
PASS: tests/fm-backlog-audit.test.sh
ok - clean backlog/state audit passes
ok - required backlog/state drift cases are reported
ok - backlog audit is read-only
ok - registered secondmate meta is accepted outside main In flight
ok - ordinary and unregistered secondmate meta without In flight are reported
PASS: tests/fm-bearings-snapshot.test.sh
ok - bearings defaults to a compact local-only TOON view
ok - bearings soft-fails unavailable remote PR data
ok - bearings discovers gh-axi through HOME-local PATH normalization
START: tests/fm-bootstrap.test.sh (TMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-bootstrap/tmp GOTMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-bootstrap/gotmp)
START: tests/fm-cbm.test.sh (TMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-cbm/tmp GOTMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-cbm/gotmp)
START: tests/fm-cd-pretool-check.test.sh (TMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-cd-pretool-check/tmp GOTMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-cd-pretool-check/gotmp)
START: tests/fm-cognee-brief-rules.test.sh (TMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-cognee-brief-rules/tmp GOTMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-cognee-brief-rules/gotmp)
PASS: tests/fm-bootstrap.test.sh
ok - bootstrap reports treehouse lease + tasks-axi default/backend contracts
ok - bootstrap requires gh pr checks --json for no-mistakes CI monitoring
ok - bootstrap enforces no-mistakes minimum version
ok - bootstrap surfaces active crew-dispatch rules and default
ok - bootstrap validates crew-dispatch.json and reports malformed or unverified configs
ok - bootstrap validates secondmate-profile.json and reports malformed or invalid configs
ok - bootstrap discovers HOME NVM tasks-axi in a clean non-interactive PATH
PASS: tests/fm-cbm.test.sh
ok - fm-cbm-lib: FM_CBM_ENABLED=0 disables CBM even if binary exists
ok - fm-cbm-lib: auto enables with binary and builds launch prefix
ok - fm-cbm-lib: unsafe resource caps are rejected
ok - fm-cbm-lib: rejects relative explicit binary
ok - fm-cbm-lib: default project allowlist
ok - fm-cbm-lib: config/cbm-projects overrides defaults
ok - fm-cbm-lib: append brief policy is idempotent for eligible projects
ok - fm-cbm-lib: skips brief policy for ineligible projects
ok - fm-spawn: CBM integration contract lines present
ok - fm-cbm-index.sh: help works
ok - fm-cbm-index: escapes paths and surfaces index failures
ok - fm-cbm-index: rejects unallowlisted absolute paths
ok - fm-cbm-index: index all skips ineligible without hard abort mid-list
ok - fm-cbm-index: rejects the .openclaw monorepo root
ok - fm-cbm-index: list surfaces CLI failures
ok - fm-cbm-cli: appends durable usage.jsonl and summary works
ok - fm-cbm-lib: no-jq fallback writes valid escaped JSONL
ok - fm-cbm-lib: omitted detail is logged as null
ok - fm-cbm-lib: brief points at fm-cbm-cli.sh
PASS: tests/fm-cd-pretool-check.test.sh
ok - primary persistent cd into projects is denied
ok - dynamic primary project cd is denied
ok - subshell, unrelated, and linked-worktree commands are allowed
ok - PreToolUse JSON transport blocks the persistent project cd
ok - tracked Grok and Codex hook snippets point at the cd guard
PASS: tests/fm-cognee-brief-rules.test.sh
ok - fm-brief: ship briefs include Cognee attachment rules
ok - fm-brief: scout briefs include Cognee attachment rules
ok - fm-brief: secondmate briefs include Cognee attachment rules
START: tests/fm-cognee-lookup-gate.test.sh (TMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-cognee-lookup-gate/tmp GOTMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-cognee-lookup-gate/

... [48021 bytes truncated] ...

alated past the threshold
ok - a not-provably-working non-terminal stale is surfaced immediately (never left to wait out the timer)
ok - matching non-terminal stale suppressors repair missing or corrupt stale-since timers
ok - triage log capping handles wc byte counts with leading spaces
ok - a heartbeat with no captain-relevant change is absorbed and backs off the cadence
ok - heartbeat backstop fail-safe surfaces a captain-relevant status the per-wake path missed
ok - the liveness beacon stays fresh while the watcher absorbs benign wakes (fm-guard never false-alarms)
ok - with .afk present the watcher reverts to one-shot so the daemon owns triage (no double-triage)
PASS: tests/fm-watcher-lock.test.sh
ok - simultaneous watcher starts leave exactly one live process
ok - killed watcher stale lock is reclaimed
ok - live watcher lock with stale heartbeat is actionable
ok - guard banner leads when down with pending wakes (re-arm-after-drain) and stays silent when fresh+live
ok - guard requires a fresh beacon plus a live matching watcher lock
ok - concurrent fm_lock_try_acquire yields exactly one winner
ok - dead-pid stale lock is reclaimed by a single acquirer
ok - concurrent stale-lock steal yields exactly one winner
ok - live steal mutex is not reclaimed
ok - live-held lock is not stolen
ok - live-held lock with matching pid identity is not stolen
ok - live-held lock with mismatched pid identity is reclaimed
ok - live-held legacy identity remains protected during migration
ok - expired live-held legacy identity is reclaimed
ok - matching expired legacy watcher identity is migrated before expiry recovery
ok - live-held lock without pid identity remains live-held
ok - zombie follower lock is reclaimed using its stored process identity
ok - legacy zombie follower lock is reclaimed without new metadata
ok - fallback process identity includes stable process-group and command data
ok - fallback start identity accepts and distinguishes prior formats
ok - detach cleanup rejects legacy start tokens
ok - detached spawn waits for the target after exec
ok - detached spawn cleans the launcher after pid-file timeout
ok - detached spawn cleans the target after exec timeout
ok - arm reclaims a legacy follower lock whose pid was reused
ok - legacy follower locks without home scope fail closed
ok - watcher health rejects a zombie lock owner
ok - watcher health rejects an unpinned legacy lock
ok - Grok treats an existing follower as a live cycle
ok - empty mid-acquire lock keeps a minimum grace
ok - late original claimant cannot claim a recreated lock
ok - paused mid-acquire claimant backs off to active stealer
ok - watch restart refuses to signal a reused pid
ok - plain arm recovers from a reused-pid stale watcher lock
ok - watcher self-evicts when the lock pid no longer names it
ok - arm attaches to a live fresh watcher and exits only when that cycle ends
ok - arm migrates and attaches to a live legacy watcher lock
ok - arm rejects an unverified legacy watcher lock
ok - arm starts+confirms a fresh watcher on a clean lock and self-heals a dead-pid lock (never healthy off a dead pid)
ok - arm stands down on HUP while the detached watcher keeps its lock and beacon
Terminated
ok - watcher survives SIGTERM of the arm's entire process group
ok - a healthy cycle keeps one attach waiter and duplicate arms exit without stacking
ok - restart hands off the follower slot without stacking waiters
ok - process start identity distinguishes same-second processes
ok - arm propagates an immediate watcher wake before confirmation
ok - arm attaches to a peer watcher after child stands down and exits when peer dies
ok - arm reports FAILED and exits non-zero when no fresh watcher can be confirmed
START: tests/fm-x-mode.test.sh (TMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-x-mode/tmp GOTMPDIR=/tmp/fm-behavior-tests.efC0a7/fm-x-mode/gotmp)
PASS: tests/fm-x-mode.test.sh
ok - fm-x-poll is a hard no-op without a token (inert default)
ok - fm-x-poll treats an explicitly empty env token as configured
ok - fm-x-poll stays silent on HTTP 204 (the common case)
ok - fm-x-poll lets an explicitly empty relay env override .env
ok - fm-x-poll surfaces auth/config errors once and clears on recovery
ok - fm-x-poll stashes the question and prints the compact marker
ok - fm-x-poll preserves in_reply_to conversation context in the inbox
ok - fm-x-poll reports inbox commit failures without emitting a mention wake
ok - fm-x-poll requires a non-empty question before waking
ok - fm-x-poll rejects an unsafe request_id (path-traversal guard)
ok - fm-x-reply posts a request-bound answer and echoes only the request_id
ok - fm-x-reply accepts the reply via --text-file and stdin (safe, unexpanded)
ok - fm-x-reply exits non-zero on a non-2xx relay response
ok - fm-x-reply cleans up auth header temp files on interrupted posts
ok - fm-x-reply rejects missing arguments with a usage error
ok - fm-x-reply --help makes image support discoverable
ok - fm-x-reply rejects whitespace-only reply text
ok - fm-x-reply dry-run records the would-be reply and never posts
ok - fm-x-reply dry-run works without a token
ok - fm-x-reply honors FMX_DRY_RUN from .env
ok - fm-x-reply lets an explicitly empty dry-run env override .env
ok - fm-x-reply dry-run fails when it cannot record the preview
ok - fmx_split_thread: word-boundary, within-limit, numbered, lossless, capped
ok - fm-x-reply keeps a concise reply as a single unnumbered tweet
ok - fm-x-reply auto-splits a long reply into a numbered thread (texts[])
ok - fm-x-reply clamps a below-floor max to 50 characters
ok - fm-x-reply posts a thread payload (texts[]) to the relay
ok - fm-x-reply --image posts an image object on answer
ok - fm-x-reply streams large image payloads outside curl argv
ok - fm-x-reply dry-run records compact image metadata for threaded replies
ok - fm-x-reply cleans image and payload temp files
ok - fm-x-reply --image rejects missing and unsupported image paths clearly
ok - fm-x-reply --image rejects oversized files before encoding
ok - fm-x-reply --followup posts to /connector/followup with the same request-bound body
ok - fm-x-reply --followup --image posts an image object
ok - fm-x-reply --followup is accepted in any position and leaves the answer path default
ok - fm-x-reply --followup dry-run marks the endpoint without changing the answer path
ok - fm-x-reply --followup auto-splits a long follow-up into a marked thread
ok - fm-x-reply followup dry-run keeps endpoint marker and compact image metadata
ok - fm-x-dismiss posts a request-bound dismiss and echoes only the request_id
ok - fm-x-dismiss dry-run records the would-be body and never posts
ok - fm-x-dismiss dry-run works without a token
ok - fm-x-dismiss exits non-zero on a non-2xx relay response
ok - fm-x-dismiss exits non-zero on a transport failure
ok - fm-x-dismiss rejects an unsafe request_id (path-traversal guard)
ok - fm-x-dismiss rejects missing or extra arguments with a usage error
ok - fm-x-link records and refreshes the X-request link without disturbing meta
ok - meta rewrites are independent of TMPDIR
ok - fm-x-link rejects unsafe ids, missing meta, and missing arguments
ok - fm-x-followup --check reports postable / not-linked correctly
ok - fm-x-followup --check prunes a link past the 24h window
ok - fm-x-followup posts the follow-up and clears the link on success
ok - fm-x-followup --image forwards the attachment through fm-x-reply --followup
ok - fm-x-followup keeps the link when the post fails
ok - fm-x-followup skips silently and clears the link past the 24h window
ok - fm-x-followup is a no-op for a task with no X link
ok - fm-x-followup dry-run records the follow-up and clears the link
ok - fm-x-followup rejects malformed invocations
ok - bootstrap activates X mode from an .env token, idempotently
ok - bootstrap reports missing X-mode dependencies before arming
ok - bootstrap does not report X mode on when activation artifacts cannot be written
ok - bootstrap is inert without a non-empty .env token (non-X users unaffected)
ok - bootstrap cleans up X artifacts on opt-out and is silent once off
ok - bootstrap reports failed X artifact cleanup on opt-out
All 61 behavior tests passed

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 3 issues found → auto-fixed ✅
  • 🚨 bin/fm-supervisor-target-lib.sh:22 - Required: “Make AFK/supervisor injection and supervisor target resolution work when firstmate or its supervisor pane runs on Herdr.” With FM_SUPERVISOR_BACKEND=herdr and inherited TMUX_PANE, the resolver still selects the tmux target, producing an invalid Herdr target. Make target discovery backend-aware or fail clearly on the mismatch.
  • ⚠️ bin/fm-supervise-daemon.sh:472 - Herdr reports idle as a conclusive non-busy state, but this wrapper only returns early for busy and then scans captured output for stale busy-footer text. That can defer every AFK injection after a completed turn. Return immediately for idle; use capture fallback only for unknown.
  • 🚨 bin/fm-supervise-daemon.sh:136 - Required Herdr AFK supervision is incomplete: the new supported-backend path still uses tmux-only window_for_task/pane checks during stale and paused rechecks, so Herdr worker panes can have their persistence markers discarded without wedge or pause escalation. Resolve task endpoints through recorded backend metadata.

🔧 Fix: Fixed Herdr target resolution and backend-aware AFK rechecks
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • bash bin/fm-run-behavior-tests.sh
  • bash bin/fm-run-behavior-tests.sh
  • bash tests/fm-supervisor-target.test.sh
  • bash tests/fm-afk-launch.test.sh
  • bash tests/fm-daemon.test.sh
  • bash tests/fm-backend-herdr.test.sh
  • bash tests/fm-herdr-lab.test.sh
  • bash tests/fm-afk-inject-herdr-e2e.test.sh
  • herdr status --json --session default before and after the guarded e2e, with byte-for-byte comparison
  • git status --short --branch and untracked-file check
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@JTInventory
JTInventory merged commit 5e7e68b into main Jul 19, 2026
4 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant