Repository navigation
fix(bin): start the herdr server without Claude parent-session markers - #7925
Open
mangocabs2025 wants to merge 2 commits into
Open
mangocabs2025 wants to merge 2 commits into
mangocabs2025 wants to merge 2 commits into
Conversation
fm_backend_herdr_server_ensure is the single place Firstmate starts a local herdr server, including the implicit start a pane read reaches through fm_backend_herdr_target_ready. The server outlives its launcher and passes its startup environment to every later pane, including the panes it restores from a saved session on start. It already drops the home, harness-identity, and supervision-model values it inherited, but not the per-session markers a Claude tool shell carries (CLAUDE_CODE_CHILD_SESSION, CLAUDE_CODE_SESSION_ID, CLAUDE_CODE_SESSION_ATTENDED, CLAUDE_CODE_BRIDGE_SESSION_ID) or the one-task FM_CREW_STATE_META_OVERRIDE and FM_CREW_STATE_STATUS_OVERRIDE a fleet snapshot sets. A server started from a Claude tool shell therefore hands that shell's child-session marker to every Claude pane it later restores, and a server started inside a snapshot child carries that task's captured-record overrides into every pane. Remove those names too. CLAUDE_CONFIG_DIR stays, because it selects the Claude account rather than a session, and unrelated environment and the explicit named-session routing stay intact. An already-running server is still reused untouched. Drove: tests/fm-backend-herdr.test.sh's stub herdr records the environment its `server` call receives; the case starts the server through fm_backend_herdr_server_ensure from a launcher environment carrying every removed name plus CLAUDE_CONFIG_DIR and an unrelated sentinel. Observed: on the unchanged adapter the case fails with "server_ensure leaked FM_CREW_STATE_META_OVERRIDE into the long-lived Herdr server"; with this change every removed name arrives unset while CLAUDE_CONFIG_DIR, the sentinel, HERDR_SESSION, and the trailing --session flag survive. Re-check: bin/fm-test-run.sh tests/fm-backend-herdr.test.sh, bin/fm-lint.sh, bin/fm-doc-audience-check.sh. The real-herdr end-to-end restore path was not run for this change.
[Medium impact] The PR appears safe to merge, with the previous finding fully addressed and no new issues found. Reviews (2) · Last reviewed commit: "no-mistakes(ci): Of the three failing ch..." · Reviewed by Greptile |
…me from this PR's code, and a one-line comment change fixes it. - **Greptile Review (fixed):** It failed on its open P2 comment. The comment above `fm_backend_herdr_server_ensure` in `bin/backends/herdr.sh` called it "the single place Firstmate starts a local herdr server". That isn't true: `fm_herdr_lab_provision` in `bin/fm-herdr-lab.sh` (line 437) also starts one, through `fm_herdr_lab_raw`. I reworded it to "the adapter's single local herdr server startup path", as the reviewer suggested. No behavior changed. - **CI and Require no-mistakes (no code change):** Both runs on `fm/upstream-pr-herdr-env` ended as `action_required` after 0s. GitHub holds workflow runs from fork PRs until a maintainer approves them, so neither check actually ran and the code didn't cause either. **Testing:** `bash -n bin/backends/herdr.sh` passes. I ran `tests/fm-backend-herdr.test.sh` six times on this branch: - Run 1 exited 1 with one failure: "container_ensure should echo '<session>:<workspace_id>\t<seeded_default_tab_id>', got ''" (`test_container_ensure_starts_server_and_workspace`, line 1208). - Run 2 printed no "not ok" lines; I didn't capture its exit code. - Runs 3–5 exited 0. - Run 6 was stopped at the command's time limit before it finished. - The suite also exited 0 on the base commit 4a67799. This PR doesn't change the failing test, and it passed in 4 of the 5 completed runs, so it's almost certainly an intermittent failure rather than something this change broke. My best guess, not proven, is a race in the test's fake `herdr`. The fake answers calls in numbered order, and the backgrounded `herdr server` call (call 3) can take the response meant for the status poll (call 4). I left that test alone because it's outside this PR and wasn't one of the reported checks. If it fails in upstream CI once the run is approved, it needs its own fix to make it deterministic
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.
Summary
fm_backend_herdr_server_ensurenow also starts the herdr server without the Claude Code parent-session markers and the one-task crew-state record overrides it may inherit from the shell that started it.Why
The herdr server outlives its launcher and passes its startup environment to every later pane, including the panes it restores from a saved session on start.
fm_backend_herdr_server_ensureis the adapter's single local herdr server startup path, including the implicit start a pane read reaches throughfm_backend_herdr_target_ready, and it already removes Firstmate home overrides, harness identity markers, and the supervision-model override for exactly that reason.It did not remove:
CLAUDE_CODE_CHILD_SESSION,CLAUDE_CODE_SESSION_ID,CLAUDE_CODE_SESSION_ATTENDED, andCLAUDE_CODE_BRIDGE_SESSION_ID, the per-session markers a Claude tool shell carries.A server started from a Claude tool shell hands that shell's child-session marker to every Claude pane it later restores, so each restored pane looks like a nested child of an unrelated session.
FM_CREW_STATE_META_OVERRIDEandFM_CREW_STATE_STATUS_OVERRIDE, whichbin/fm-fleet-snapshot.shsets for one task.bin/fm-crew-state.shalready ignores them for every other task, as its comment about a long-lived server started inside a snapshot child explains, but the server still has no reason to carry them into every pane.Change
bin/backends/herdr.sh: add those six names to thefm_backend_herdr_server_ensureunset list and extend its comment.CLAUDE_CONFIG_DIRis deliberately kept, because it selects the Claude account rather than a session.HERDR_SESSION, and the trailing--sessionflag stay intact, and an already-running server is still reused without restart.docs/herdr-backend.md"Named server and session routing" lists the new removed names and the restored-pane path.tests/fm-backend-herdr.test.sh: the stub server reports the new names, andtest_server_ensure_scrubs_home_and_harness_identitypollutes the launcher with them and withCLAUDE_CONFIG_DIR.Verification
tests/fm-backend-herdr.test.shrecords the environment itsservercall receives, and the case starts the server throughfm_backend_herdr_server_ensurefrom a launcher environment carrying every removed name,CLAUDE_CONFIG_DIR, and an unrelated sentinel.server_ensure leaked FM_CREW_STATE_META_OVERRIDE into the long-lived Herdr server.With this change every removed name arrives unset, while
CLAUDE_CONFIG_DIR, the sentinel,HERDR_SESSION, andargs=server --session fmtestsurvive.bin/fm-test-run.sh tests/fm-backend-herdr.test.sh(235 cases pass),bin/fm-lint.sh, andbin/fm-doc-audience-check.sh.fm_backend_herdr_server_ensure, and read a restored pane's environment) was not run for this change; the pipeline's real-herdr server and new-pane check below covers the server start, and a fresh pane inherits the server environment the same way a restored pane does.Pipeline test evidence
I ran the herdr backend test script (it passes). I also showed the new server-environment case fails on the base adapter and passes on the fix. Then I ran it end to end with real herdr 0.7.5 in isolated lab sessions. On the fix, the live server process and a new pane have no Claude parent-session markers or crew-state overrides, while
CLAUDE_CONFIG_DIRand the sentinel are kept. On the base adapter, every marker shows up in the server and in the pane. The before/after transcripts and the script are in the evidence directory. I did not exercise a realclaude --resumerestore from a saved herdr session. A freshly created pane takes its environment from the server the same way, so the pane check stands in for that path. All checks passed and the worktree is clean.Evidence: Real herdr: server and pane environment with the fix (markers unset, CLAUDE_CONFIG_DIR kept)
Source: Real herdr: server and pane environment with the fix (markers unset, CLAUDE_CONFIG_DIR kept)
--- live herdr server process environment, filtered: CLAUDE_CONFIG_DIR=/tmp/kept-claude-config FM_HERDR_SENTINEL=kept CLAUDE_CODE_CHILD_SESSION: <unset> CLAUDE_CODE_SESSION_ID: <unset> CLAUDE_CODE_SESSION_ATTENDED: <unset> CLAUDE_CODE_BRIDGE_SESSION_ID: <unset> FM_CREW_STATE_META_OVERRIDE: <unset> FM_CREW_STATE_STATUS_OVERRIDE: <unset> --- new pane (w1:p1) shell environment, filtered: PANE_ENV CLAUDE_CONFIG_DIR=/tmp/kept-claude-config PANE_ENV FM_HERDR_SENTINEL=keptEvidence: Real herdr: same run on the base adapter (markers leak into server and pane)
Source: Real herdr: same run on the base adapter (markers leak into server and pane)
--- new pane (w1:p1) shell environment, filtered: PANE_ENV CLAUDE_CODE_BRIDGE_SESSION_ID=session_parent PANE_ENV CLAUDE_CODE_CHILD_SESSION=1 PANE_ENV CLAUDE_CODE_SESSION_ATTENDED=1 PANE_ENV CLAUDE_CODE_SESSION_ID=parent-session PANE_ENV CLAUDE_CONFIG_DIR=/tmp/kept-claude-config PANE_ENV FM_CREW_STATE_META_OVERRIDE=/tmp/other-task.meta PANE_ENV FM_CREW_STATE_STATUS_OVERRIDE=/tmp/other-task.status PANE_ENV FM_HERDR_SENTINEL=keptEvidence: Real-herdr lab check script used to produce the transcripts
Source: Real-herdr lab check script used to produce the transcripts
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/backends/herdr.sh:1696- Scope check: besides the Claude Code session markers, the commit also unsetsFM_CREW_STATE_META_OVERRIDEandFM_CREW_STATE_STATUS_OVERRIDE, whichbin/fm-fleet-snapshot.shsets for one task, with matching doc and test changes. Confirmed in scope as part of the same fix.✅ **Test** - passed
✅ No issues found.
bin/fm-test-run.sh tests/fm-backend-herdr.test.sh(whole herdr backend script, exit 0)Fail-before check: copied the target tree to /tmp, made a runner that calls onlytest_server_ensure_scrubs_home_and_harness_identity, and ran it on the target adapter (ok) and on the base4a67799:bin/backends/herdr.shadapter (not ok:server_ensure leaked FM_CREW_STATE_META_OVERRIDE into the long-lived Herdr server)Real-herdr end-to-end check~/.no-mistakes/evidence/01M61KD4HDQWY8Z7QZC0MSXCCB/real-herdr-env-check.sh <tree> <label>: in an isolatedfm-lab-*session (with the fm-herdr-lab default-session tripwire), calledfm_backend_herdr_server_ensurefrom a launcher env carrying the Claude markers, CLAUDECODE, crew-state overrides, CLAUDE_CONFIG_DIR and a sentinel, then read/proc/<server pid>/environand ranenvin a new pane throughherdr workspace create/pane run/pane readRan the same real-herdr check against the base-commit adapter for contrastTeardown check: lab sessions deleted and tripwire unchanged, no leftover lab herdr servers, temp tree removed,git statusclean✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.