Skip to content

fix(bin): start the herdr server without Claude parent-session markers - #7925

Open
mangocabs2025 wants to merge 2 commits into
kunchenguid:mainfrom
mangocabs2025:fm/upstream-pr-herdr-env
Open

mangocabs2025 wants to merge 2 commits into
kunchenguid:mainfrom
mangocabs2025:fm/upstream-pr-herdr-env

Conversation

@mangocabs2025

@mangocabs2025 mangocabs2025 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

fm_backend_herdr_server_ensure now 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_ensure is the adapter's single local herdr server startup path, including the implicit start a pane read reaches through fm_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, and CLAUDE_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_OVERRIDE and FM_CREW_STATE_STATUS_OVERRIDE, which bin/fm-fleet-snapshot.sh sets for one task.
    bin/fm-crew-state.sh already 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 the fm_backend_herdr_server_ensure unset list and extend its comment.
  • CLAUDE_CONFIG_DIR is deliberately kept, because it selects the Claude account rather than a session.
  • Unrelated environment, HERDR_SESSION, and the trailing --session flag 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, and test_server_ensure_scrubs_home_and_harness_identity pollutes the launcher with them and with CLAUDE_CONFIG_DIR.

Verification

  • Drove: the hermetic stub herdr in tests/fm-backend-herdr.test.sh records the environment its server call receives, and the case starts the server through fm_backend_herdr_server_ensure from a launcher environment carrying every removed name, 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 args=server --session fmtest survive.
  • Re-check: bin/fm-test-run.sh tests/fm-backend-herdr.test.sh (235 cases pass), bin/fm-lint.sh, and bin/fm-doc-audience-check.sh.
  • The real-herdr end-to-end restore path (start a polluted server, stop it, restart it through 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_DIR and 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 real claude --resume restore 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=kept

===== AFTER: target commit 50066de =====
tree: 50066de adapter sha1: 4bbb46928e7c
lab session: fm-lab-envafter-3122940-12372
launcher env: CLAUDE_CODE_CHILD_SESSION=1 CLAUDE_CODE_SESSION_ID=parent-session CLAUDE_CODE_SESSION_ATTENDED=1 CLAUDE_CODE_BRIDGE_SESSION_ID=session_parent CLAUDECODE=1 FM_CREW_STATE_META_OVERRIDE=/tmp/other-task.meta FM_CREW_STATE_STATUS_OVERRIDE=/tmp/other-task.status CLAUDE_CONFIG_DIR=/tmp/kept-claude-config FM_HERDR_SENTINEL=kept
server_ensure rc=0
--- live herdr server process (pid 3123269) 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=kept
PANE_ENV_DONE
teardown: lab session fm-lab-envafter-3122940-12372 removed, default-session tripwire unchanged
Evidence: 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=kept

===== BEFORE: base commit 4a67799 adapter =====
tree: /tmp/herdr-failbefore.0x9v adapter sha1: 01f928debd51
lab session: fm-lab-envbefore-3143907-3754
launcher env: CLAUDE_CODE_CHILD_SESSION=1 CLAUDE_CODE_SESSION_ID=parent-session CLAUDE_CODE_SESSION_ATTENDED=1 CLAUDE_CODE_BRIDGE_SESSION_ID=session_parent CLAUDECODE=1 FM_CREW_STATE_META_OVERRIDE=/tmp/other-task.meta FM_CREW_STATE_STATUS_OVERRIDE=/tmp/other-task.status CLAUDE_CONFIG_DIR=/tmp/kept-claude-config FM_HERDR_SENTINEL=kept
server_ensure rc=0
--- live herdr server process (pid 3144146) environment, filtered:
CLAUDE_CODE_BRIDGE_SESSION_ID=session_parent
CLAUDE_CODE_CHILD_SESSION=1
CLAUDE_CODE_SESSION_ATTENDED=1
CLAUDE_CODE_SESSION_ID=parent-session
CLAUDE_CONFIG_DIR=/tmp/kept-claude-config
FM_CREW_STATE_META_OVERRIDE=/tmp/other-task.meta
FM_CREW_STATE_STATUS_OVERRIDE=/tmp/other-task.status
FM_HERDR_SENTINEL=kept
--- 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=kept
PANE_ENV_DONE
teardown: lab session fm-lab-envbefore-3143907-3754 removed, default-session tripwire unchanged
Evidence: Real-herdr lab check script used to produce the transcripts

Source: Real-herdr lab check script used to produce the transcripts

#!/usr/bin/env bash
# Real-herdr end-to-end check: start an isolated lab herdr server through
# fm_backend_herdr_server_ensure from a launcher env polluted like a Claude tool
# shell, then report what the live server process and a fresh pane inherited.
# Usage: real-herdr-env-check.sh <firstmate-tree> <label>
set -u
TREE=$1; LABEL=$2
. "$TREE/bin/fm-herdr-lab.sh"
unset HERDR_ENV HERDR_PANE_ID HERDR_TAB_ID HERDR_WORKSPACE_ID HERDR_SOCKET_PATH HERDR_SESSION
S=$(fm_herdr_lab_name "$LABEL")
fm_herdr_lab_prepare "$S" || exit 1
trap 'fm_herdr_lab_teardown "$S" >/dev/null 2>&1 && echo "teardown: lab session $S removed, default-session tripwire unchanged"' EXIT
NAMES='CLAUDE_CODE_CHILD_SESSION|CLAUDE_CODE_SESSION_ID|CLAUDE_CODE_SESSION_ATTENDED|CLAUDE_CODE_BRIDGE_SESSION_ID|CLAUDECODE|FM_CREW_STATE_META_OVERRIDE|FM_CREW_STATE_STATUS_OVERRIDE|CLAUDE_CONFIG_DIR|FM_HERDR_SENTINEL'
echo "tree: $(git -C "$TREE" rev-parse --short HEAD 2>/dev/null || echo "$TREE") adapter sha1: $(sha1sum "$TREE/bin/backends/herdr.sh" | cut -c1-12)"
echo "lab session: $S"
echo "launcher env: CLAUDE_CODE_CHILD_SESSION=1 CLAUDE_CODE_SESSION_ID=parent-session CLAUDE_CODE_SESSION_ATTENDED=1 CLAUDE_CODE_BRIDGE_SESSION_ID=session_parent CLAUDECODE=1 FM_CREW_STATE_META_OVERRIDE=/tmp/other-task.meta FM_CREW_STATE_STATUS_OVERRIDE=/tmp/other-task.status CLAUDE_CONFIG_DIR=/tmp/kept-claude-config FM_HERDR_SENTINEL=kept"
CLAUDE_CODE_CHILD_SESSION=1 CLAUDE_CODE_SESSION_ID=parent-session CLAUDE_CODE_SESSION_ATTENDED=1 \
CLAUDE_CODE_BRIDGE_SESSION_ID=session_parent CLAUDECODE=1 \
FM_CREW_STATE_META_OVERRIDE=/tmp/other-task.meta FM_CREW_STATE_STATUS_OVERRIDE=/tmp/other-task.status \
CLAUDE_CONFIG_DIR=/tmp/kept-claude-config FM_HERDR_SENTINEL=kept \
  bash -c '. "$0/bin/backends/herdr.sh"; fm_backend_herdr_server_ensure "$1"' "$TREE" "$S"
echo "server_ensure rc=$?"
pid=$(pgrep -f -- "herdr server --session $S\$" | head -1)
echo "--- live herdr server process (pid $pid) environment, filtered:"
tr '\0' '\n' < /proc/$pid/environ | grep -E "^($NAMES)=" | sort || true
for n in CLAUDE_CODE_CHILD_SESSION CLAUDE_CODE_SESSION_ID CLAUDE_CODE_SESSION_ATTENDED CLAUDE_CODE_BRIDGE_SESSION_ID FM_CREW_STATE_META_OVERRIDE FM_CREW_STATE_STATUS_OVERRIDE; do
  tr '\0' '\n' < /proc/$pid/environ | grep -q "^$n=" || echo "$n: <unset>"
done
ws=$(fm_herdr_lab_raw "$S" workspace create --label envcheck --no-focus)
pane=$(printf '%s' "$ws" | jq -r '.. | objects | .pane_id? // empty' | head -1)
fm_herdr_lab_raw "$S" pane wait-output "$pane" --regex '\$ *$' --timeout 10000 >/dev/null 2>&1 || sleep 2
fm_herdr_lab_raw "$S" pane run "$pane" "env | grep -E '^($NAMES)=' | sed 's/^/PANE_ENV /' | sort; echo PANE_ENV_""DONE" >/dev/null
fm_herdr_lab_raw "$S" pane wait-output "$pane" --regex '^PANE_ENV_DONE' --timeout 10000 >/dev/null 2>&1 || sleep 2
echo "--- new pane ($pane) shell environment, filtered:"
fm_herdr_lab_raw "$S" pane read "$pane" --source recent-unwrapped 2>/dev/null | grep '^PANE_ENV' || true

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ℹ️ bin/backends/herdr.sh:1696 - Scope check: besides the Claude Code session markers, the commit also unsets FM_CREW_STATE_META_OVERRIDE and FM_CREW_STATE_STATUS_OVERRIDE, which bin/fm-fleet-snapshot.sh sets 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 only test_server_ensure_scrubs_home_and_harness_identity, and ran it on the target adapter (ok) and on the base 4a67799:bin/backends/herdr.sh adapter (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 &lt;tree&gt; &lt;label&gt;: in an isolated fm-lab-* session (with the fm-herdr-lab default-session tripwire), called fm_backend_herdr_server_ensure from a launcher env carrying the Claude markers, CLAUDECODE, crew-state overrides, CLAUDE_CONFIG_DIR and a sentinel, then read /proc/&lt;server pid&gt;/environ and ran env in a new pane through herdr workspace create / pane run / pane read
  • Ran the same real-herdr check against the base-commit adapter for contrast
  • Teardown check: lab sessions deleted and tripwire unchanged, no leftover lab herdr servers, temp tree removed, git status clean
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

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.
@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[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

Comment thread bin/backends/herdr.sh Resolved
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant