This repository was archived by the owner on Aug 25, 2026. It is now read-only.
Repository navigation
feat: add experimental Herdr session backend - #71
Merged
Merged
Conversation
…upervision health
…ocks, and version gating
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
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
backend=herdrsession:pane metadata while retaining tmux as the default path.fm-lab-*lifecycle operations that protect the captain's default session.Risk Assessment
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
Evidence: CLI contract transcript
Evidence: Herdr unit tests
Evidence: Herdr lab tests
Evidence: Optional Herdr smoke
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 intreehouse 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,CONTAINERcontainsworkspace<TAB>tab, butfm_backend_create_taskonly 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 becausetarget_readyonly 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 shareddefaultsession. 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 newfm-lab-*entrypoint never sources or invokesfm_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.”stopchecks only that a tripwire file exists, andteardownverifies 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, butfm_supervision_window_livestill callstmux display-messageunconditionally. 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 callstarget_ready, which callsserver_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, causingfm-sendto report success incorrectly; use a composer/submission-specific acknowledgement.bin/fm-herdr-lab.sh:186- Lab teardown ignores a failedsession stopand 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, sobeforeandafterare 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. Ifpane getor the post-closepane listresponse 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 createhas 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 orphanedfm-*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 onworkspace listerrors 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 toworking,blocked, ordonecan report the message as submitted even when Enter was swallowed, while a real submission that remainsidlecan reportpendingand 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 whentmuxis 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_checkis used for arbitrarysession:panetargets, but this line calls bareherdr status --jsoninstead 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.lockpermanently 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 asemptyandfm-sendclaims 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 malformedtab listresponse as an empty list because thejqfailure is hidden byhead. A transient invalid response can therefore create a duplicatefm-*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 aspendingandfm-sendfails or retries Enter. Use literal matching such asgrep -Fover 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 reportspending, 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 bareherdr 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 betweenmkdir "$lock"and writingpid/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 pattern0.7.[0-9]*treats[0-9]*as one digit followed by any characters, so values such as0.7.4fooare 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.lockpermanently 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 healthysources.herdrresult 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 nopid-start; if that PID was later reused,kill -0succeeds 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 withoutpid-start, this stale check runs beforekill -0and deletes any lock whose directory is old and has no openlsofdescriptor. 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.shFM_TEST_JOBS=1 bash bin/fm-run-behavior-tests.shbash tests/fm-backend-herdr.test.shbash tests/fm-herdr-lab.test.shbash tests/fm-supervision-model.test.shbash tests/fm-backend-herdr-smoke.test.shDirect selector, metadata, and guarded lab CLI transcript capturegit status --short --branch✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.