Repository navigation
fix(bin): stop herdr server inheriting fm-crew-state snapshot overrides - #17
Merged
Merged
Conversation
…dr CLI environment A herdr server auto-started by the CLI from inside a fleet-snapshot child inherited that child's FM_CREW_STATE_META_OVERRIDE / FM_CREW_STATE_STATUS_OVERRIDE and passed them to every later pane, so fm-crew-state.sh read the snapshot's captured generation for every task. - bin/fm-crew-state.sh honours an override only when its basename is the asked task's own .meta/.status file name; anything else falls through to $STATE/$ID.*. - fm_backend_herdr_cli runs every client invocation (plain, retry, and the long-lived server launch) with both overrides and the session-start-scoped FM_SESSION_START_STAGE_FILE, FM_HOME_SUMMARY_IF_IDLE, and FM_HOME_SUMMARY_WORKER_BEST_EFFORT unset, so no CLI-started server ever inherits per-call state. - docs/herdr-backend.md documents the leak path under the server-start notes. - Regression tests: a mismatched override is ignored and a matched one honoured (tests/fm-crew-state.test.sh); the five variables are absent from a fake herdr's dumped environment on both the plain and server paths (tests/fm-backend-herdr.test.sh).
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Defect in the firstmate fork's own tooling, found 2026-09-16 in the main home: the Herdr headless server inherits fm-crew-state snapshot overrides, so every agent, watcher and worker launched through Herdr since then reads the wrong task's state. Fix the override guard and scrub the herdr CLI environment so it cannot recur.
Evidence:
herdr server --session default, pid 24246, started 2026-09-15 08:35:36) has parentbash bin/fm-crew-state.sh selfimprove(pid 24243, still alive). The herdr CLI auto-started the server from inside a session-start fleet snapshot child, because no server was bound after the host restart.FM_CREW_STATE_META_OVERRIDE=/tmp/fm-fleet-tasks.VPw7YU/selfimprove.metaandFM_CREW_STATE_STATUS_OVERRIDE=/tmp/fm-fleet-tasks.VPw7YU/selfimprove.status(set per child bybin/fm-fleet-snapshot.sharound line 323), plusFM_SESSION_START_STAGE_FILE,FM_HOME_SUMMARY_IF_IDLE=0,FM_HOME_SUMMARY_WORKER_BEST_EFFORT=1and the launching Claude session'sCLAUDE_*variables.bin/fm-crew-state.sh(line 128,META=${FM_CREW_STATE_META_OVERRIDE:-"$STATE/$ID.meta"}) honours the override unconditionally, so from any Herdr pane it reads selfimprove's snapshot copy for every task id (wrong task while the temp dir existed,unknown · no metadatafor every task now that it is gone). Verified:env -u FM_CREW_STATE_META_OVERRIDE -u FM_CREW_STATE_STATUS_OVERRIDE bin/fm-crew-state.sh <id>returns the correct state.Fix, smallest correct change at the shared points:
bin/fm-crew-state.sh: honourFM_CREW_STATE_META_OVERRIDE/FM_CREW_STATE_STATUS_OVERRIDEonly when the override's basename is exactly$ID.meta/$ID.status; otherwise ignore it and read$STATE/$ID.*. Add a regression test that a mismatched override is ignored and a matched one is honoured.bin/backends/herdr.shfm_backend_herdr_cli: run the herdr client with the twoFM_CREW_STATE_*_OVERRIDEvariables and the session-start-scopedFM_SESSION_START_STAGE_FILE,FM_HOME_SUMMARY_IF_IDLE,FM_HOME_SUMMARY_WORKER_BEST_EFFORTunset (env -u), so a server the CLI auto-starts never inherits per-call state. Test with a fake herdr binary that dumps its environment.Out of scope: restarting the live Herdr server (fleet-wide outage; the main firstmate schedules that separately), the host-up systemd unit for the Herdr server, any change under projects/.
What Changed
bin/fm-crew-state.shnow honoursFM_CREW_STATE_META_OVERRIDE/FM_CREW_STATE_STATUS_OVERRIDEonly when the override's basename is exactly$ID.meta/$ID.status; any other value falls through to$STATE/$ID.*, so an override inherited from another task's environment no longer redirects state reads.fm_backend_herdr_cliinbin/backends/herdr.shruns every herdr client invocation (including theserverlaunch and the protocol-mismatch retry) viaenv -uwith the twoFM_CREW_STATE_*_OVERRIDEvariables and the session-start-scopedFM_SESSION_START_STAGE_FILE,FM_HOME_SUMMARY_IF_IDLE,FM_HOME_SUMMARY_WORKER_BEST_EFFORTunset, so a server the CLI auto-starts never inherits per-call state.tests/fm-crew-state.test.sh), and a fake herdr binary that dumps its environment to confirm the scrub (tests/fm-backend-herdr.test.sh);docs/herdr-backend.mddocuments the leak path and both guards under the server-start notes.Risk Assessment
✅ Low: Two small guards at the shared points named by the intent (basename-matched override in fm-crew-state.sh, env -u scrub on every fm_backend_herdr_cli invocation including the server launch and the protocol-mismatch retry); the snapshot's own captured paths ($SNAPSHOT_TASK_DIR/$id.meta|status) still match the guard, all server-starting paths route through the scrubbed helper, and the regression tests exercise the real interfaces with observable output.
Testing
Ran the two new regression tests in both suites (pass on target, fail on base code with the exact leak assertions), drove bin/fm-crew-state.sh live with test fakes across incident-shaped and adversarial override values, drove fm_backend_herdr_cli and fm_backend_herdr_server_ensure live with env-dumping fake herdr clients covering plain, server and protocol_mismatch reselection paths, and ran the real fm-fleet-snapshot.sh captured-status test to confirm matched overrides still steer reads. All seven runtime scenarios passed live; the doc paragraph was checked by diff only and is recorded as untested.
git diff dd80265..5233b30 -- docs/herdr-backend.md, which does not establish a live result. The parag…Evidence: fm-crew-state.sh live transcript: leaked/adversarial overrides ignored, matched overrides honoured
Source: fm-crew-state.sh live transcript: leaked/adversarial overrides ignored, matched overrides honoured
Evidence: herdr CLI env scrub transcript (plain, server, protocol_mismatch reselection)
Source: herdr CLI env scrub transcript (plain, server, protocol_mismatch reselection)
Evidence: Environment inherited by a server auto-started via fm_backend_herdr_server_ensure
Source: Environment inherited by a server auto-started via fm_backend_herdr_server_ensure
declare -x FM_UNRELATED="keep" declare -x HERDR_SESSION="default" (no FM_CREW_STATE_OVERRIDE, FM_SESSION_START_STAGE_FILE, FM_HOME_SUMMARY, FM_HOME or CLAUDECODE present)Evidence: New regression tests fail on base commit dd80265
Source: New regression tests fail on base commit dd80265
not ok - a mismatched override must be ignored: the task's own working log line wins (missing: 'state: working') not ok - a plain herdr CLI call leaked FM_CREW_STATE_META_OVERRIDE into the herdr client environmentEvidence: fm-crew-state suite (target)
Source: fm-crew-state suite (target)
Evidence: fm-backend-herdr suite (target)
Source: fm-backend-herdr suite (target)
Evidence: Real fm-fleet-snapshot.sh captured-status read via matched override
Source: Real fm-fleet-snapshot.sh captured-status read via matched override
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
bin/backends/herdr.sh:482- fm_backend_herdr_client_status (used by protocol_mismatch reselection and fm-remote-doctor) still invokes the herdr client with the caller's full environment. Per the adapter's verified note a bare CLI call never auto-starts a server, so this is not a leak path; noted only for completeness.git diff dd80265..5233b30 -- docs/herdr-backend.md, which does not establish a live result. The parag…bash tests/fm-crew-state.test.sh(new: test_mismatched_state_override_is_ignored, test_matched_state_override_is_honoured)bash tests/fm-backend-herdr.test.sh(new: test_cli_helper_strips_per_call_state_from_plain_calls, test_cli_helper_strips_per_call_state_from_server_launch)Same two suites against base-commit bin/fm-crew-state.sh and bin/backends/herdr.sh (dd80265) to prove the regression tests fail before the fixLive drive ofbin/fm-crew-state.sh mytaskwith FM_CREW_STATE_*_OVERRIDE set to another task's files (present and vanished), near-miss basenames (xmytask.meta, mytask.meta.bak, swapped .status/.meta), matched absolute, matched relative, matched-but-missing, and emptyLive drive offm_backend_herdr_cli(status --json, server, pane get with protocol_mismatch reselection) with two env-dumping fake herdr clients on PATHLive drive offm_backend_herdr_server_ensure defaultfrom a polluted environment with a fake headless herdr that records the environment the server inheritsbash tests/fm-bearings-snapshot.test.sh(test_current_state_uses_captured_status_observation drives real fm-fleet-snapshot.sh through the matched override)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
Caller and reader survey (pre-edit check)
grep -rn FM_CREW_STATE_META_OVERRIDE bin/finds exactly one setter (bin/fm-fleet-snapshot.sh, whose per-child override copies each task's meta/status to$SNAPSHOT_TASK_DIR/$id.meta/$id.statusand passes the same$idtofm-crew-state.sh, so its basename always matches the guard) and one reader (bin/fm-crew-state.sh, where the guard now lands once at the shared read). Every caller offm_backend_herdr_clilives inbin/and routes through the single scrubbed helper (bin/backends/herdr.sh,bin/fm-herdr-session-cleanup.sh,bin/fm-afk-launch.sh,bin/fm-backend.sh,bin/fm-remote-doctor.sh, plus test fakes), so no call site bypasses the environment scrub.