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

feat: add experimental Herdr session backend - #71

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

JTInventory merged 11 commits into
mainfrom
fm/herdr-backend-p2-0718

Conversation

@JTInventory

Copy link
Copy Markdown
Owner

Intent

Add the experimental Herdr session backend for JTInventory/firstmate on top of the merged PR1 runtime-backend abstraction. Preserve tmux as the default and production path; allow Herdr only through explicit --backend/FM_BACKEND/config/backend or appropriate auto-detection where /tmp/tmux-0/default,16107,3 wins nested sessions and HERDR_ENV=1 can select Herdr. Adapt owner comparison files without wholesale owner-main merging, require Herdr 0.7.x protocol 14+, keep Treehouse as the worktree provider, use per-home workspaces labeled firstmate and 2ndmate-, record backend=herdr and session:pane metadata, and provide guarded fm-lab-* lifecycle tooling that can never stop or delete the captain's default session. Include JT-adapted docs, unit tests without a live Herdr server, and opt-in smoke that skips cleanly; leave native event-stream and AFK/supervisor injection paths for P3. Keep JTInventory/firstmate as the PR target and preserve existing identity/no-mistakes guards.

What Changed

  • Added an experimental Herdr session backend with explicit/auto backend selection, strict Herdr 0.7.x/protocol 14+ validation, per-home workspace isolation, and backend=herdr session:pane metadata while retaining tmux as the default path.
  • Hardened Herdr workspace locking, legacy-lock recovery, session health checks, submission acknowledgements, teardown, spawn cleanup, and guarded fm-lab-* lifecycle operations that protect the captain's default session.
  • Updated JT-adapted documentation and added unit, safety, and opt-in smoke coverage; the referenced intent, review, test, document, lint, and push pipeline checks passed.

Risk Assessment

⚠️ Medium: The reviewed backend is a broad experimental process/lifecycle integration, but no additional material defects were substantiated after the latest lock-safety fix.

Testing

Reran the configured behavior command through its normal-clone harness, exercised focused Herdr/backend and supervision tests, captured direct CLI evidence, and verified no transient worktree residue. Overall result: pass; live Herdr validation was intentionally skipped because the smoke test is opt-in and no live server was available.

Evidence: Full behavior suite
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 58 behavior tests with 1 parallel job(s)
START: tests/fm-afk-inject-e2e.test.sh (TMPDIR=/tmp/fm-behavior-tests.bFg9zZ/fm-afk-inject-e2e/tmp GOTMPDIR=/tmp/fm-behavior-tests.bFg9zZ/fm-afk-inject-e2e/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
START: tests/fm-afk-launch.test.sh (TMPDIR=/tmp/fm-behavior-tests.bFg9zZ/fm-afk-launch/tmp GOTMPDIR=/tmp/fm-behavior-tests.bFg9zZ/fm-afk-launch/gotmp)
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 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
START: tests/fm-backend-herdr-smoke.test.sh (TMPDIR=/tmp/fm-behavior-tests.bFg9zZ/fm-backend-herdr-smoke/tmp GOTMPDIR=/tmp/fm-behavior-tests.bFg9zZ/fm-backend-herdr-smoke/gotmp)
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.bFg9zZ/fm-backend-herdr/tmp GOTMPDIR=/tmp/fm-behavior-tests.bFg9zZ/fm-backend-herdr/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
START: tests/fm-backend.test.sh (TMPDIR=/tmp/fm-behavior-tests.bFg9zZ/fm-backend/tmp GOTMPDIR=/tmp/fm-behavior-tests.bFg9zZ/fm-backend/gotmp)
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
START: tests/fm-backlog-audit.test.sh (TMPDIR=/tmp/fm-behavior-tests.bFg9zZ/fm-backlog-audit/tmp GOTMPDIR=/tmp/fm-behavior-tests.bFg9zZ/fm-backlog-audit/gotmp)
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
START: tests/fm-bearings-snapshot.test.sh (TMPDIR=/tmp/fm-behavior-tests.bFg9zZ/fm-bearings-snapshot/tmp GOTMPDIR=/tmp/fm-behavior-tests.bFg9zZ/fm-bearings-snapshot/gotmp)
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.bFg9zZ/fm-bootstrap/tmp GOTMPDIR=/tmp/fm-behavior-tests.bFg9zZ/fm-bootstrap/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
START: tests/fm-cbm.test.sh (TMPDIR=/tmp/fm-behavior-tests.bFg9zZ/fm-cbm/tmp GOTMPDIR=/tmp/fm-behavior-tests.bFg9zZ/fm-cbm/gotmp)
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
START: tests/fm-cd-pretool-check.test.sh (TMPDIR=/tmp/fm-behavior-tests.bFg9zZ/fm-cd-pretool-check/tmp GOTMPDIR=/tmp/fm-behavior-tests.bFg9zZ/fm-cd-pretool-check/gotmp)
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
START: tests/fm-cognee-brief-rules.test.sh (TMPDIR=/tmp/fm-behavior-tests.bFg9zZ/fm-cognee-brief-rules/tmp GOTMPDIR=/tmp/fm-behavior-tests.bFg9zZ/fm-cognee-brief-rules/gotmp)
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.bFg9zZ/fm-cognee-lookup-gate/tmp GOTMPDIR=/tmp/fm-behavior-tests.bFg9zZ/fm-cognee-lookup-gate/gotmp)
PASS: tests/fm-cognee-lookup-gate.test.sh
ok - default automatic lookup is disabled
ok - missing benchmark blocks automatic enablement
ok - missing telemetry rollup blocks automatic enablement
ok - missing or unknown cost evidence blocks automatic enablement
ok - missing cost evidence blocks automatic enablement
ok - session-window-only cost evidence is trial-only and bloc

... [46462 bytes truncated] ...

 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)
START: tests/fm-watcher-lock.test.sh (TMPDIR=/tmp/fm-behavior-tests.bFg9zZ/fm-watcher-lock/tmp GOTMPDIR=/tmp/fm-behavior-tests.bFg9zZ/fm-watcher-lock/gotmp)
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.bFg9zZ/fm-x-mode/tmp GOTMPDIR=/tmp/fm-behavior-tests.bFg9zZ/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 58 behavior tests passed
exit=0
Evidence: CLI contract transcript
$ backend selector / metadata transcript
default=tmux
config=herdr
herdr-env=herdr
nested-tmux=tmux
meta-backend=herdr
meta-target=fmtest:p42
notice=NOTICE: auto-detected herdr runtime (HERDR_ENV=1) - spawning into the EXPERIMENTAL herdr backend. Set config/backend or pass --backend tmux to opt out.
$ guarded lab command surface
$ fm-herdr-lab.sh name smoke
fm-lab-smoke-3802756-12312
$ fm-herdr-lab.sh teardown default
fm-herdr-lab: refusing session name 'default'
guarded refusal observed
Evidence: Herdr unit tests
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
exit=0
Evidence: Herdr lab tests
ok - Herdr lab names are scoped to fm-lab-* and reject default
ok - Herdr lab lifecycle uses trailing session scoping and guarded teardown
ok - Herdr lab refuses destructive operations without ownership evidence
ok - Herdr lab never stops or deletes the default session
exit=0
Evidence: Optional Herdr smoke
skip: set FM_HERDR_SMOKE=1 to opt into the real Herdr smoke
exit=0

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 12 issues found → auto-fixed (8) ✅
  • 🚨 bin/backends/herdr.sh:245 - Herdr kill returns success when target validation or pane close fails, so teardown can delete metadata and return the worktree while the pane remains live. Propagate failures and positively verify absence before reporting success.
  • 🚨 bin/fm-spawn.sh:856 - After creating a Herdr tab, later failures in treehouse get, endpoint access, or worktree validation exit without closing the new tab. This leaves orphaned tabs and can make retries fail on duplicate labels; add a post-create cleanup trap.
  • 🚨 bin/backends/herdr.sh:142 - When workspace creation returns a seeded tab, CONTAINER contains workspace<TAB>tab, but fm_backend_create_task only strips that suffix when its separate seeded argument is empty. The subsequent tab-list call receives an invalid workspace ID and the first spawn in a new workspace fails.
  • 🚨 bin/backends/herdr.sh:64 - Required criterion: “require Herdr 0.7.x protocol 14+.” The gate checks only numeric protocol at this line; it never rejects non-0.7.x versions, and existing targets bypass the gate because target_ready only ensures a server. A protocol-14 Herdr 0.6.x or 0.8.x client would be accepted.
  • 🚨 bin/backends/herdr.sh:94 - Required criterion: “use per-home workspaces labeled firstmate and 2ndmate-<id>.” Workspace lookup matches only the label and takes the first result, while primary homes default to the shared default session. Two homes can therefore adopt the same workspace, breaking the claimed per-home isolation.
  • 🚨 bin/fm-herdr-lab.sh:223 - Required criterion: preserve existing identity/no-mistakes guards. The new fm-lab-* entrypoint never sources or invokes fm_refuse_if_gate_agent, so a gate agent can directly run its mutating provision/stop/teardown paths outside the repository-wide guard.
  • 🚨 bin/fm-herdr-lab.sh:172 - Required criterion: “guarded fm-lab-* lifecycle tooling that can never stop or delete the captain's default session.” stop checks only that a tripwire file exists, and teardown verifies the tripwire only after destructive calls; a stale ownership snapshot can pass the precondition, and the default relationship can change before the raw stop/delete command.
  • ⚠️ bin/fm-spawn.sh:1041 - Herdr metadata is now emitted, but fm_supervision_window_live still calls tmux display-message unconditionally. Live Herdr tasks will be classified as dead/missing by supervision instead of using their recorded session:pane endpoint; adapt polling liveness to the recorded backend.
  • ⚠️ bin/backends/herdr.sh:174 - Every Herdr read/send operation calls target_ready, which calls server_ensure. Peeking, watching, or checking crew state can therefore start a stopped Herdr server as a side effect; reserve server creation for spawn and use a non-mutating availability check for existing targets.
  • ⚠️ bin/backends/herdr.sh:239 - Submit acknowledgement treats any change in the last six pane lines after Enter as proof that the composer cleared. Concurrent agent output can produce that change while the instruction remains unsent, causing fm-send to report success incorrectly; use a composer/submission-specific acknowledgement.
  • ⚠️ bin/fm-herdr-lab.sh:186 - Lab teardown ignores a failed session stop and proceeds to delete the session. If stop failed because the server is unavailable or the session remains active, deletion is attempted without verified shutdown; abort before delete unless stop succeeds or absence is positively confirmed.
  • ⚠️ tests/fm-herdr-lab.test.sh:100 - This safety test compares the log line count only after teardown has completed, so before and after are always identical. It would pass even if teardown made a forbidden Herdr call; capture the count before invoking teardown.

🔧 Fix: Harden Herdr teardown, isolation, guards, and supervision
5 issues (2 errors, 3 warnings) still open:

  • 🚨 bin/backends/herdr.sh:305 - The absence checks treat malformed JSON, missing .result.panes, and a valid empty list the same. If pane get or the post-close pane list response is malformed, this falls through as success, allowing teardown or spawn cleanup to delete metadata while the pane may still be live. Validate the response shape and fail closed unless absence is positively proven.
  • 🚨 bin/backends/herdr.sh:195 - tab create has already created the tab before this parse failure, but the spawn cleanup trap is installed only after both IDs are parsed. A malformed or unexpected successful response therefore leaves an orphaned fm-* tab that can block retries on the duplicate label. Clean up the created tab by label/listing or arm cleanup before parsing.
  • ⚠️ bin/backends/herdr.sh:121 - Workspace lookup fails open on workspace list errors and the find-then-create sequence has no per-home lock. Concurrent spawns, or a transient list failure, can create multiple workspaces with the same label/home identity, violating the one-workspace-per-home invariant and splitting later tasks across them. Propagate list errors and serialize ensure.
  • ⚠️ bin/backends/herdr.sh:274 - Submit acknowledgement is based only on an unrelated agent-state transition. A concurrent/pre-existing transition to working, blocked, or done can report the message as submitted even when Enter was swallowed, while a real submission that remains idle can report pending and cause callers to retry the instruction. Use a composer or submission-specific acknowledgement.
  • ⚠️ bin/fm-supervision-model.sh:784 - Supervision always marks the tmux source unavailable when tmux is absent, even if the fleet is entirely Herdr-backed and Herdr is the selected supported backend. This produces a false unhealthy source in the read-only supervision output; track health for the backends actually present in task metadata and report Herdr availability separately.

🔧 Fix: Harden Herdr cleanup, locking, submission, and supervision health
5 issues (2 errors, 3 warnings) still open:

  • 🚨 bin/backends/herdr.sh:62 - Required criterion: “require Herdr 0.7.x protocol 14+.” fm_backend_herdr_version_check is used for arbitrary session:pane targets, but this line calls bare herdr status --json instead of querying the selected session. With multiple Herdr sessions, an acceptable default session can mask an unsupported or unavailable target session; use the explicit session-aware status path.
  • ⚠️ bin/backends/herdr.sh:102 - A crash or SIGKILL after acquiring this workspace lock leaves .fm-herdr-workspace.lock permanently present. Future spawns wait ten seconds and fail because the recorded PID is never checked. Add safe stale-lock detection/recovery.
  • ⚠️ bin/backends/herdr.sh:254 - Malformed tab-create cleanup looks up the tab by label and discards both lookup and close failures. A concurrent tab change can close the wrong replacement, while a failed list/close leaves the newly created tab orphaned. Serialize task creation and fail/report when cleanup cannot be verified.
  • 🚨 bin/backends/herdr.sh:352 - Submission acknowledgement checks whether the entire message appears on only the final visible line. Wrapped or multiline text will not match there, so a swallowed Enter can be reported as empty and fm-send claims success without submitting the instruction. Inspect the complete composer region or use a backend submission acknowledgement.
  • ⚠️ bin/backends/herdr.sh:249 - The duplicate-tab preflight treats a successful but malformed tab list response as an empty list because the jq failure is hidden by head. A transient invalid response can therefore create a duplicate fm-* tab. Validate the response shape and propagate parse failures before creating.

🔧 Fix: Harden Herdr validation, locks, cleanup, and submission
5 issues (3 errors, 2 warnings) still open:

  • 🚨 bin/backends/herdr.sh:471 - The acknowledgement uses an unescaped shell glob with user text. A message such as * always matches the visible output, so a successfully cleared composer is reported as pending and fm-send fails or retries Enter. Use literal matching such as grep -F over a composer-specific region.
  • 🚨 bin/backends/herdr.sh:467 - Reading the last 40 visible pane lines does not isolate the composer. If Herdr or the agent echoes the submitted message in normal output after the composer clears, this substring check still reports pending, causing false Enter-swallowed errors and possible duplicate retries. Use a real composer boundary or backend submission acknowledgement.
  • ⚠️ bin/fm-supervision-model.sh:910 - Herdr source health is checked with bare herdr status, which targets the default session rather than the sessions recorded in task metadata. A healthy custom session can therefore be reported unhealthy, while an acceptable default session can mask an unavailable or unsupported task session.
  • ⚠️ bin/backends/herdr.sh:176 - The lock is considered stale after two seconds even while its owner is between mkdir &#34;$lock&#34; and writing pid/pid-start. If that process is suspended or delayed during initialization, another spawn can quarantine the live lock and perform workspace operations concurrently, breaking per-home serialization. Publish ownership atomically or make incomplete-owner locks fail closed until safely aged.
  • 🚨 bin/backends/herdr.sh:77 - Required criterion: “require Herdr 0.7.x protocol 14+.” The version pattern 0.7.[0-9]* treats [0-9]* as one digit followed by any characters, so values such as 0.7.4foo are accepted even though they are not an exact 0.7.x client version. Parse a strict semantic version or explicitly confirm that suffixed versions are intentional.

🔧 Fix: Harden Herdr acknowledgements, session health, locks, and version gating
2 warnings still open:

  • ⚠️ bin/backends/herdr.sh:153 - Legacy lock directories with an empty or malformed PID are now treated as live forever. A crash before the old implementation wrote ownership metadata leaves .fm-herdr-workspace.lock permanently blocking future Herdr spawns after the retry window; retain safe stale recovery for invalid legacy locks.
  • ⚠️ bin/fm-supervision-model.sh:924 - Per-session supervision now validates only client version/protocol. It does not check .server.running, so a stopped Herdr session can produce a healthy sources.herdr result even while active panes are unavailable and task liveness reports them missing. Include a non-mutating server-availability check for each recorded session.

🔧 Fix: Recover legacy locks and validate Herdr session health
1 warning still open:

  • ⚠️ bin/backends/herdr.sh:189 - Legacy lock recovery handles only empty or non-numeric PIDs. An older lock can contain a valid PID but no pid-start; if that PID was later reused, kill -0 succeeds and this branch treats the stale lock as live forever. Apply the legacy age/lsof recovery path whenever legacy ownership lacks a start identity.

🔧 Fix: Harden legacy lock recovery without PID start identity
1 error still open:

  • 🚨 bin/backends/herdr.sh:175 - Required isolation criterion: “use per-home workspaces labeled firstmate and 2ndmate-<id>.” For legacy locks without pid-start, this stale check runs before kill -0 and deletes any lock whose directory is old and has no open lsof descriptor. A live legacy owner does not need to keep the lock directory open while performing Herdr operations, so a second spawn can quarantine its lock and mutate the same workspace concurrently. Preserve fail-closed behavior by proving owner death/reuse or retaining ambiguous live-PID locks.

🔧 Fix: Preserve live legacy locks lacking start identity
1 error still open:

  • 🚨 bin/backends/herdr.sh:178 - Required isolation criterion: “use per-home workspaces labeled firstmate and 2ndmate-<id>.” This branch still treats a legacy lock with no pid-start and a malformed/empty PID as stale solely because lsof shows no open descriptor and the lock is old. That does not prove the owner is dead; a concurrent spawn can quarantine the lock and mutate the same workspace. Fail closed on ambiguous legacy locks or require stronger owner-death proof.

🔧 Fix: Fail closed on ambiguous legacy workspace locks
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • bash bin/fm-run-behavior-tests.sh
  • FM_TEST_JOBS=1 bash bin/fm-run-behavior-tests.sh
  • bash tests/fm-backend-herdr.test.sh
  • bash tests/fm-herdr-lab.test.sh
  • bash tests/fm-supervision-model.test.sh
  • bash tests/fm-backend-herdr-smoke.test.sh
  • Direct selector, metadata, and guarded lab CLI transcript capture
  • git status --short --branch
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@JTInventory
JTInventory merged commit f14c5a1 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