Skip to content

fix(bin): refuse test runs in the primary checkout when a task marker is set - #3891

Merged
kunchenguid merged 3 commits into
kunchenguid:mainfrom
3264studios:fm/fm-test-run-primary-checkout-refuse
Sep 7, 2026
Merged

kunchenguid merged 3 commits into
kunchenguid:mainfrom
3264studios:fm/fm-test-run-primary-checkout-refuse

Conversation

@3264studios

Copy link
Copy Markdown
Contributor

Intent

Fixes #3848 (triaged ready-for-pr, contract class restore).

Ship and scout briefs verify worktree isolation exactly once, at setup (bin/fm-brief.sh:451-453); nothing re-checks afterwards. A worker that later changes directory into the repository's primary checkout runs its Git commands, and any branch-switching test suite, against the checkout every sibling worktree resolves against and every landing merges into. Observed: a worker whose brief had passed the setup assertion ran a branch-creating test suite from the primary checkout; the run died on an assertion, and the primary happened to end back on its main branch with the stray branch gone. bin/fm-spawn.sh protects launch-time placement (#3783 strengthened that for linked worktrees), but there is no post-launch guard, and bin/fm-test-run.sh has no notion of where it runs.

This change makes the test runner refuse the unsafe case, in the shape the issue triage named: when a task marker is present and the runner's top level resolves to the repository's primary checkout, fm-test-run.sh exits non-zero before selecting any suite, with one remediation line naming the primary path and telling the caller to run from the assigned task worktree. The primary-checkout predicate is the one bin/fm-spawn.sh already uses for launch placement: the working tree's git dir is the repository's common git dir, which distinguishes the primary from every linked worktree even when their top levels differ. A run with no task marker, a person in their own checkout, is unchanged. Inspection modes that execute nothing are unchanged.

The task marker is FM_TASK_ID. bin/fm-spawn.sh exports it into the worker's pane shell before the launch command, beside the existing TRACEPARENT export, and carries it through the sanitized launch environment allowlist, so every ship and scout worker runs with it set. The PATH-wrapper shape from closed #3728 is not part of this change.

What Changed

  • bin/fm-test-run.sh gains a placement refusal: when FM_TASK_ID is set and the runner's root is the repository's primary checkout (its git dir is the common git dir, the same predicate bin/fm-spawn.sh uses for launch placement), every executing mode exits non-zero before selecting any suite with one line naming the primary path and pointing at the assigned task worktree. Runs without the marker, linked worktrees, and inspection modes (--list, --list-scheduled, and the family/lane/coverage listings) are unchanged, as is a root git cannot resolve.
  • bin/fm-spawn.sh exports FM_TASK_ID=<task-id> into every ship and scout pane before the launch command, on the same channel as GOTMPDIR and TRACEPARENT, and adds FM_TASK_ID to the sanitized launch-environment allowlist; secondmate panes are not marked.
  • Tests and docs: tests/fm-test-run.test.sh adds a primary-plus-linked-worktree fixture covering the refusal, the linked-worktree run, the unmarked run, and --list; tests/fm-kimi-harness.test.sh asserts the export lands in the pane; tests/lib.sh unsets an inherited FM_TASK_ID so fixture repositories still run. docs/architecture.md, docs/configuration.md, docs/scripts.md, and docs/verification/trace-context.md record the marker and the refusal.

Risk Assessment

✅ Low: A well-bounded guard whose predicate matches the spawn placement check, with the refusal, linked-worktree, unmarked, and inspection cases all traced through the code and covered by an executing test, and the inherited-marker fixture hazard closed at the shared test library.

Testing

Ran the four directly affected suites through the runner (fm-test-run, kimi harness, trace-context spawn, spawn dispatch profile): three pass, and the kimi suite fails only because this machine's default python3 lacks tomllib, a pre-existing failure that reproduces at the base commit and passes in full with Homebrew's python3 on PATH. Beyond automated tests, a manual primary-plus-linked-worktree fixture shows the base runner executing a branch-switching suite in the primary under the marker while the fixed runner refuses with one remediation line, exit 2, no suite output, and an untouched primary branch, including when the primary is reached via a symlink; linked-worktree, unmarked, and inspection runs are unchanged. Real ship and scout spawns through a logging fake tmux show the marker export before the launch and beside TRACEPARENT, and a sanitized replay shows the harness receiving it through the allowlist while unrelated variables are stripped. The new regression case fails against the base runner and passes after the fix, and the runner's own suite passes when run with the marker set from this linked worktree. Overall result: pass, with no actionable findings.

Evidence: fm-test-run.sh primary-checkout refusal: before/after transcript in a primary + linked worktree fixture

Source: fm-test-run.sh primary-checkout refusal: before/after transcript in a primary + linked worktree fixture

# fm-test-run.sh primary-checkout refusal: manual transcript
# fixture: <tmp>/repo is the primary checkout (branch main); <tmp>/linked is a linked worktree (branch task-z1)
# <tmp>/repo-alias is a symlink to the primary, so the same primary is reachable by a different top-level path
   git dir of primary : /private<tmp>/repo/.git
   common dir         : /private<tmp>/repo/.git
   git dir of linked  : /private<tmp>/repo/.git/worktrees/linked
   primary branch: main | probe ran in primary: no | probe ran in linked: no

=== BEFORE the fix (runner from base commit 1533f47 copied into the primary) ===

## base runner, task marker set, primary checkout: the hazard from #3848 (suite runs and moves the primary's branch)
$ FM_TASK_ID=task-z1 <tmp>/repo/bin/fm-test-run.sh tests/probe.test.sh 
   > FM_TEST_BEGIN 2026-09-07T03:18:40Z tests/probe.test.sh family=unclassified expected_gate_skip=none
   > ok - probe suite ran in /private<tmp>/repo and switched to probe-stray
   > FM_TEST_END 2026-09-07T03:18:40Z tests/probe.test.sh exit=0 duration_ms=51 gate_skip=false
   > FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=125
   > FM_TEST_SUMMARY_FAMILY family=unclassified count=1 duration_ms=51 failed=0
   > FM_TEST_SLOWEST rank=1 script=tests/probe.test.sh duration_ms=51
   exit=0
   primary branch: probe-stray | probe ran in primary: yes | probe ran in linked: no

=== AFTER the fix (runner from target commit 51a3279) ===

## task marker set, primary checkout, explicit suite: refused before any suite runs
$ FM_TASK_ID=task-z1 <tmp>/repo/bin/fm-test-run.sh tests/probe.test.sh 
   > fm-test-run: refusing to run in the repository primary checkout /private<tmp>/repo while FM_TASK_ID=task-z1 is set; run from the assigned task worktree instead
   exit=2
   primary branch: main | probe ran in primary: no | probe ran in linked: no

## task marker set, primary checkout, --all: refused before selection
$ FM_TASK_ID=task-z1 <tmp>/repo/bin/fm-test-run.sh --all 
   > fm-test-run: refusing to run in the repository primary checkout /private<tmp>/repo while FM_TASK_ID=task-z1 is set; run from the assigned task worktree instead
   exit=2
   primary branch: main | probe ran in primary: no | probe ran in linked: no

## task marker set, primary reached through a different path (symlink alias): still refused, remediation names the resolved primary
$ FM_TASK_ID=task-z1 <tmp>/repo-alias/bin/fm-test-run.sh tests/probe.test.sh 
   > fm-test-run: refusing to run in the repository primary checkout /private<tmp>/repo while FM_TASK_ID=task-z1 is set; run from the assigned task worktree instead
   exit=2
   primary branch: main | probe ran in primary: no | probe ran in linked: no

## task marker set, linked task worktree (the assigned placement): runs
$ FM_TASK_ID=task-z1 <tmp>/linked/bin/fm-test-run.sh tests/probe.test.sh 
   > FM_TEST_BEGIN 2026-09-07T03:18:40Z tests/probe.test.sh family=unclassified expected_gate_skip=none
   > ok - probe suite ran in /private<tmp>/linked and switched to probe-stray
   > FM_TEST_END 2026-09-07T03:18:40Z tests/probe.test.sh exit=0 duration_ms=53 gate_skip=false
   > FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=193
   > FM_TEST_SUMMARY_FAMILY family=unclassified count=1 duration_ms=53 failed=0
   > FM_TEST_SLOWEST rank=1 script=tests/probe.test.sh duration_ms=53
   exit=0
   primary branch: main | probe ran in primary: no | probe ran in linked: yes

## no task marker, primary checkout (a person in their own checkout): unchanged, runs
$ <tmp>/repo/bin/fm-test-run.sh tests/probe.test.sh 
   > FM_TEST_BEGIN 2026-09-07T03:18:41Z tests/probe.test.sh family=unclassified expected_gate_skip=none
   > ok - probe suite ran in /private<tmp>/repo and switched to probe-stray
   > FM_TEST_END 2026-09-07T03:18:41Z tests/probe.test.sh exit=0 duration_ms=50 gate_skip=false
   > FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=133
   > FM_TEST_SUMMARY_FAMILY family=unclassified count=1 duration_ms=50 failed=0
   > FM_TEST_SLOWEST rank=1 script=tests/probe.test.sh duration_ms=50
   exit=0
   primary branch: probe-stray | probe ran in primary: yes | probe ran in linked: no

## task marker set, primary checkout, inspection --list: still available, executes nothing
$ FM_TASK_ID=task-z1 <tmp>/repo/bin/fm-test-run.sh --list tests/probe.test.sh 
   > tests/probe.test.sh
   exit=0
   primary branch: main | probe ran in primary: no | probe ran in linked: no

## task marker set, primary checkout, inspection --list-families: still available
$ FM_TASK_ID=task-z1 <tmp>/repo/bin/fm-test-run.sh --list-families 
   > pure-contract-unit
   > watcher-wake-lock
   > real-herdr-gated
   > secondmate
   > session-bootstrap
   > live-harness-optin
   > backend-dispatch
   > pr-forge
   > afk
   > snapshot-bearings
   > cmux
   > zellij
   > orca
   > standalone
   > unclassified
   exit=0
   primary branch: main | probe ran in primary: no | probe ran in linked: no

## task marker set, primary checkout, no selection mode: usage error wins (not the refusal)
$ FM_TASK_ID=task-z1 <tmp>/repo/bin/fm-test-run.sh 
   > fm-test-run: select with --all, --family <name>, --lane <name>, --proven-isolated, --changed, or one or more script paths (see --help)
   exit=2
   primary branch: main | probe ran in primary: no | probe ran in linked: no
Evidence: fm-spawn.sh FM_TASK_ID pane export and sanitized-launch replay for ship (trace off/on), scout, and secondmate

Source: fm-spawn.sh FM_TASK_ID pane export and sanitized-launch replay for ship (trace off/on), scout, and secondmate

# fm-spawn.sh FM_TASK_ID pane export: manual transcript
# Each case drives the real bin/fm-spawn.sh with a fake tmux that logs pane payloads in send order,
# a fake 'codex' harness that prints the FM_TASK_ID it inherits, and launch-env-allowlist enabled.

## ship spawn (trace context off): fm-spawn.sh ship-z1
$ fm-spawn.sh ship-z1 <tmp>/ship/project --harness codex --backend tmux --mode no-mistakes --yolo off 
   > warning: <tmp>/ship/home/data/ship-z1/launch-brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
   > spawned ship-z1 harness=codex kind=ship mode=no-mistakes yolo=off window=firstmate:fm-ship-z1 worktree=<tmp>/ship/wt
   spawn exit=0
   pane payloads in send order (fake tmux log):
          1	treehouse get
          2	export GOTMPDIR=/tmp/fm-ship-z1/gotmp
          3	export FM_TASK_ID=ship-z1
          4	/usr/bin/env -i ${HOME+"HOME=$HOME"} ${PATH+"PATH=$PATH"} ${USER+"USER=$USER"} ${LOGNAME+"LOGNAME=$LOGNAME"} ${SHELL+"SHELL=$SHELL"} ${TERM+"TERM=$TERM"} ${COLORTERM+"COLORTERM=$COLORTERM"} ${LANG+"LANG=$LANG"} ${LC_ALL+"LC_ALL=$LC_ALL"} ${LC_CTYPE+"LC_CTYPE=$LC_CTYPE"} ${TMPDIR+"TMPDIR=$TMPDIR"} ${TMP+"TMP=$TMP"} ${TEMP+"TEMP=$TEMP"} ${GOTMPDIR+"GOTMPDIR=$GOTMPDIR"} ${TMUX+"TMUX=$TMUX"} ${TMUX_PANE+"TMUX_PANE=$TMUX_PANE"} ${HERDR_ENV+"HERDR_ENV=$HERDR_ENV"} ${HERDR_SESSION+"HERDR_SESSION=$HERDR_SESSION"} ${HERDR_SOCKET_PATH+"HERDR_SOCKET_PATH=$HERDR_SOCKET_PATH"} ${HERDR_PANE_ID+"HERDR_PANE_ID=$HERDR_PANE_ID"} ${CMUX_WORKSPACE_ID+"CMUX_WORKSPACE_ID=$CMUX_WORKSPACE_ID"} ${CMUX_SURFACE_ID+"CMUX_SURFACE_ID=$CMUX_SURFACE_ID"} ${CMUX_TAB_ID+"CMUX_TAB_ID=$CMUX_TAB_ID"} ${CMUX_PANEL_ID+"CMUX_PANEL_ID=$CMUX_PANEL_ID"} ${CMUX_SOCKET_PATH+"CMUX_SOCKET_PATH=$CMUX_SOCKET_PATH"} ${ZELLIJ+"ZELLIJ=$ZELLIJ"} ${ZELLIJ_SESSION_NAME+"ZELLIJ_SESSION_NAME=$ZELLIJ_SESSION_NAME"} ${ZELLIJ_PANE_ID+"ZELLIJ_PANE_ID=$ZELLIJ_PANE_ID"} ${FM_ZELLIJ_SESSION+"FM_ZELLIJ_SESSION=$FM_ZELLIJ_SESSION"} ${FM_TASK_ID+"FM_TASK_ID=$FM_TASK_ID"} ${FM_TEST_ALLOWED+"FM_TEST_ALLOWED=$FM_TEST_ALLOWED"} /bin/sh -c 'env -u CURSOR_AGENT -u CURSOR_INVOKED_AS -u GEMINI_CLI codex --dangerously-bypass-approvals-and-sandbox -c "notify=[\"bash\",\"-c\",\"touch '\''<tmp>/ship/home/state/ship-z1.turn-ended'\''\"]" "$('\''~/.no-mistakes/worktrees/9b0bfac143a1/01M1WXEKZ6SED7F8CWQ95EZMSB/bin/fm-operational-input.sh'\'' encode launch-brief < '\''<tmp>/ship/home/data/ship-z1/launch-brief.md'\'')"'
   task record marker line: kind=ship 
   replaying the pane in /bin/sh (env -i HOME PATH TERM TMUX + FM_TEST_ALLOWED + an unrelated AMBIENT_SECRET):
     codex probe sees: FM_TASK_ID=ship-z1 GOTMPDIR=/tmp/fm-ship-z1/gotmp AMBIENT_SECRET=unset
   control: same replay WITHOUT the FM_TASK_ID export line (what a pre-fix spawn sent):
     codex probe sees: FM_TASK_ID=unset GOTMPDIR=/tmp/fm-ship-z1/gotmp AMBIENT_SECRET=unset

## ship spawn (trace context on): fm-spawn.sh shiptrace-z1
$ fm-spawn.sh shiptrace-z1 <tmp>/shiptrace/project --harness codex --backend tmux --mode no-mistakes --yolo off 
   > warning: <tmp>/shiptrace/home/data/shiptrace-z1/launch-brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
   > spawned shiptrace-z1 harness=codex kind=ship mode=no-mistakes yolo=off window=firstmate:fm-shiptrace-z1 worktree=<tmp>/shiptrace/wt
   spawn exit=0
   pane payloads in send order (fake tmux log):
          1	treehouse get
          2	export GOTMPDIR=/tmp/fm-shiptrace-z1/gotmp
          3	export FM_TASK_ID=shiptrace-z1
          4	export TRACEPARENT=00-e8b4ef02d5b11f612b19da68f849ef85-5cce89325e359f55-01
          5	/usr/bin/env -i ${HOME+"HOME=$HOME"} ${PATH+"PATH=$PATH"} ${USER+"USER=$USER"} ${LOGNAME+"LOGNAME=$LOGNAME"} ${SHELL+"SHELL=$SHELL"} ${TERM+"TERM=$TERM"} ${COLORTERM+"COLORTERM=$COLORTERM"} ${LANG+"LANG=$LANG"} ${LC_ALL+"LC_ALL=$LC_ALL"} ${LC_CTYPE+"LC_CTYPE=$LC_CTYPE"} ${TMPDIR+"TMPDIR=$TMPDIR"} ${TMP+"TMP=$TMP"} ${TEMP+"TEMP=$TEMP"} ${GOTMPDIR+"GOTMPDIR=$GOTMPDIR"} ${TMUX+"TMUX=$TMUX"} ${TMUX_PANE+"TMUX_PANE=$TMUX_PANE"} ${HERDR_ENV+"HERDR_ENV=$HERDR_ENV"} ${HERDR_SESSION+"HERDR_SESSION=$HERDR_SESSION"} ${HERDR_SOCKET_PATH+"HERDR_SOCKET_PATH=$HERDR_SOCKET_PATH"} ${HERDR_PANE_ID+"HERDR_PANE_ID=$HERDR_PANE_ID"} ${CMUX_WORKSPACE_ID+"CMUX_WORKSPACE_ID=$CMUX_WORKSPACE_ID"} ${CMUX_SURFACE_ID+"CMUX_SURFACE_ID=$CMUX_SURFACE_ID"} ${CMUX_TAB_ID+"CMUX_TAB_ID=$CMUX_TAB_ID"} ${CMUX_PANEL_ID+"CMUX_PANEL_ID=$CMUX_PANEL_ID"} ${CMUX_SOCKET_PATH+"CMUX_SOCKET_PATH=$CMUX_SOCKET_PATH"} ${ZELLIJ+"ZELLIJ=$ZELLIJ"} ${ZELLIJ_SESSION_NAME+"ZELLIJ_SESSION_NAME=$ZELLIJ_SESSION_NAME"} ${ZELLIJ_PANE_ID+"ZELLIJ_PANE_ID=$ZELLIJ_PANE_ID"} ${FM_ZELLIJ_SESSION+"FM_ZELLIJ_SESSION=$FM_ZELLIJ_SESSION"} ${FM_TASK_ID+"FM_TASK_ID=$FM_TASK_ID"} ${FM_TEST_ALLOWED+"FM_TEST_ALLOWED=$FM_TEST_ALLOWED"} ${TRACEPARENT+"TRACEPARENT=$TRACEPARENT"} /bin/sh -c 'env -u CURSOR_AGENT -u CURSOR_INVOKED_AS -u GEMINI_CLI codex --dangerously-bypass-approvals-and-sandbox -c "notify=[\"bash\",\"-c\",\"touch '\''<tmp>/shiptrace/home/state/shiptrace-z1.turn-ended'\''\"]" "$('\''~/.no-mistakes/worktrees/9b0bfac143a1/01M1WXEKZ6SED7F8CWQ95EZMSB/bin/fm-operational-input.sh'\'' encode launch-brief < '\''<tmp>/shiptrace/home/data/shiptrace-z1/launch-brief.md'\'')"'
   task record marker line: kind=ship 
   replaying the pane in /bin/sh (env -i HOME PATH TERM TMUX + FM_TEST_ALLOWED + an unrelated AMBIENT_SECRET):
     codex probe sees: FM_TASK_ID=shiptrace-z1 GOTMPDIR=/tmp/fm-shiptrace-z1/gotmp AMBIENT_SECRET=unset
   control: same replay WITHOUT the FM_TASK_ID export line (what a pre-fix spawn sent):
     codex probe sees: FM_TASK_ID=unset GOTMPDIR=/tmp/fm-shiptrace-z1/gotmp AMBIENT_SECRET=unset

## scout spawn (trace context off): fm-spawn.sh scout-z1
$ fm-spawn.sh scout-z1 <tmp>/scout/project --harness codex --backend tmux --scout 
   > spawned scout-z1 harness=codex kind=scout window=firstmate:fm-scout-z1 worktree=<tmp>/scout/wt
   spawn exit=0
   pane payloads in send order (fake tmux log):
          1	treehouse get
          2	export GOTMPDIR=/tmp/fm-scout-z1/gotmp
          3	export FM_TASK_ID=scout-z1
          4	/usr/bin/env -i ${HOME+"HOME=$HOME"} ${PATH+"PATH=$PATH"} ${USER+"USER=$USER"} ${LOGNAME+"LOGNAME=$LOGNAME"} ${SHELL+"SHELL=$SHELL"} ${TERM+"TERM=$TERM"} ${COLORTERM+"COLORTERM=$COLORTERM"} ${LANG+"LANG=$LANG"} ${LC_ALL+"LC_ALL=$LC_ALL"} ${LC_CTYPE+"LC_CTYPE=$LC_CTYPE"} ${TMPDIR+"TMPDIR=$TMPDIR"} ${TMP+"TMP=$TMP"} ${TEMP+"TEMP=$TEMP"} ${GOTMPDIR+"GOTMPDIR=$GOTMPDIR"} ${TMUX+"TMUX=$TMUX"} ${TMUX_PANE+"TMUX_PANE=$TMUX_PANE"} ${HERDR_ENV+"HERDR_ENV=$HERDR_ENV"} ${HERDR_SESSION+"HERDR_SESSION=$HERDR_SESSION"} ${HERDR_SOCKET_PATH+"HERDR_SOCKET_PATH=$HERDR_SOCKET_PATH"} ${HERDR_PANE_ID+"HERDR_PANE_ID=$HERDR_PANE_ID"} ${CMUX_WORKSPACE_ID+"CMUX_WORKSPACE_ID=$CMUX_WORKSPACE_ID"} ${CMUX_SURFACE_ID+"CMUX_SURFACE_ID=$CMUX_SURFACE_ID"} ${CMUX_TAB_ID+"CMUX_TAB_ID=$CMUX_TAB_ID"} ${CMUX_PANEL_ID+"CMUX_PANEL_ID=$CMUX_PANEL_ID"} ${CMUX_SOCKET_PATH+"CMUX_SOCKET_PATH=$CMUX_SOCKET_PATH"} ${ZELLIJ+"ZELLIJ=$ZELLIJ"} ${ZELLIJ_SESSION_NAME+"ZELLIJ_SESSION_NAME=$ZELLIJ_SESSION_NAME"} ${ZELLIJ_PANE_ID+"ZELLIJ_PANE_ID=$ZELLIJ_PANE_ID"} ${FM_ZELLIJ_SESSION+"FM_ZELLIJ_SESSION=$FM_ZELLIJ_SESSION"} ${FM_TASK_ID+"FM_TASK_ID=$FM_TASK_ID"} ${FM_TEST_ALLOWED+"FM_TEST_ALLOWED=$FM_TEST_ALLOWED"} /bin/sh -c 'env -u CURSOR_AGENT -u CURSOR_INVOKED_AS -u GEMINI_CLI codex --dangerously-bypass-approvals-and-sandbox -c "notify=[\"bash\",\"-c\",\"touch '\''<tmp>/scout/home/state/scout-z1.turn-ended'\''\"]" "$('\''~/.no-mistakes/worktrees/9b0bfac143a1/01M1WXEKZ6SED7F8CWQ95EZMSB/bin/fm-operational-input.sh'\'' encode launch-brief < '\''<tmp>/scout/home/data/scout-z1/launch-brief.md'\'')"'
   task record marker line: kind=scout 
   replaying the pane in /bin/sh (env -i HOME PATH TERM TMUX + FM_TEST_ALLOWED + an unrelated AMBIENT_SECRET):
     codex probe sees: FM_TASK_ID=scout-z1 GOTMPDIR=/tmp/fm-scout-z1/gotmp AMBIENT_SECRET=unset
   control: same replay WITHOUT the FM_TASK_ID export line (what a pre-fix spawn sent):
     codex probe sees: FM_TASK_ID=unset GOTMPDIR=/tmp/fm-scout-z1/gotmp AMBIENT_SECRET=unset

## secondmate spawn (trace context off): fm-spawn.sh sm-z1
$ fm-spawn.sh sm-z1 <tmp>/sm/secondmate-home --harness codex --backend tmux --secondmate 
   > warning: secondmate sm-z1 sync skipped before launch: primary default-branch commit cannot be resolved
   > spawned sm-z1 harness=codex kind=secondmate mode=secondmate yolo=off window=firstmate:fm-sm-z1 worktree=<tmp>/sm/secondmate-home
   spawn exit=0
   pane payloads in send order (fake tmux log):
          1	export GOTMPDIR=/tmp/fm-sm-z1/gotmp
          2	/usr/bin/env -i ${HOME+"HOME=$HOME"} ${PATH+"PATH=$PATH"} ${USER+"USER=$USER"} ${LOGNAME+"LOGNAME=$LOGNAME"} ${SHELL+"SHELL=$SHELL"} ${TERM+"TERM=$TERM"} ${COLORTERM+"COLORTERM=$COLORTERM"} ${LANG+"LANG=$LANG"} ${LC_ALL+"LC_ALL=$LC_ALL"} ${LC_CTYPE+"LC_CTYPE=$LC_CTYPE"} ${TMPDIR+"TMPDIR=$TMPDIR"} ${TMP+"TMP=$TMP"} ${TEMP+"TEMP=$TEMP"} ${GOTMPDIR+"GOTMPDIR=$GOTMPDIR"} ${TMUX+"TMUX=$TMUX"} ${TMUX_PANE+"TMUX_PANE=$TMUX_PANE"} ${HERDR_ENV+"HERDR_ENV=$HERDR_ENV"} ${HERDR_SESSION+"HERDR_SESSION=$HERDR_SESSION"} ${HERDR_SOCKET_PATH+"HERDR_SOCKET_PATH=$HERDR_SOCKET_PATH"} ${HERDR_PANE_ID+"HERDR_PANE_ID=$HERDR_PANE_ID"} ${CMUX_WORKSPACE_ID+"CMUX_WORKSPACE_ID=$CMUX_WORKSPACE_ID"} ${CMUX_SURFACE_ID+"CMUX_SURFACE_ID=$CMUX_SURFACE_ID"} ${CMUX_TAB_ID+"CMUX_TAB_ID=$CMUX_TAB_ID"} ${CMUX_PANEL_ID+"CMUX_PANEL_ID=$CMUX_PANEL_ID"} ${CMUX_SOCKET_PATH+"CMUX_SOCKET_PATH=$CMUX_SOCKET_PATH"} ${ZELLIJ+"ZELLIJ=$ZELLIJ"} ${ZELLIJ_SESSION_NAME+"ZELLIJ_SESSION_NAME=$ZELLIJ_SESSION_NAME"} ${ZELLIJ_PANE_ID+"ZELLIJ_PANE_ID=$ZELLIJ_PANE_ID"} ${FM_ZELLIJ_SESSION+"FM_ZELLIJ_SESSION=$FM_ZELLIJ_SESSION"} ${FM_TASK_ID+"FM_TASK_ID=$FM_TASK_ID"} ${FM_TEST_ALLOWED+"FM_TEST_ALLOWED=$FM_TEST_ALLOWED"} /bin/sh -c 'FM_ROOT_OVERRIDE= FM_STATE_OVERRIDE= FM_DATA_OVERRIDE= FM_PROJECTS_OVERRIDE= FM_CONFIG_OVERRIDE= FM_PUBLIC_FOLLOWUP_PRIMARY_HOME='\''<tmp>/sm/home'\'' FM_HOME='\''<tmp>/sm/secondmate-home'\'' FM_TRACE_CONTEXT=off FM_SUPERVISION_MODEL=persistent env -u CURSOR_AGENT -u CURSOR_INVOKED_AS -u GEMINI_CLI codex --dangerously-bypass-approvals-and-sandbox "$('\''~/.no-mistakes/worktrees/9b0bfac143a1/01M1WXEKZ6SED7F8CWQ95EZMSB/bin/fm-operational-input.sh'\'' encode launch-brief < '\''<tmp>/sm/secondmate-home/data/charter.md'\'')"'
   task record marker line: kind=secondmate 
Evidence: New regression case fails against the base commit runner

Source: New regression case fails against the base commit runner

# New regression case run against the BASE commit runner (1533f47, no guard) with the target commit test file + tests/lib.sh overlaid
$ (cd <base-tree> && bash tests/fm-test-run.test.sh)
   > ok - exact suite coverage: --all lists every tests/*.test.sh once
   > ok - family selection returns a proper subset of the suite
   > ok - single-script selection lists exactly that path
   > ok - changed-file selection stays conservative (never silent full suite)
   > not ok - the runner must refuse the primary checkout under a task marker
   exit=1
Evidence: Post-merge scenario: runner's own suite with FM_TASK_ID set from a linked worktree

Source: Post-merge scenario: runner's own suite with FM_TASK_ID set from a linked worktree

# Post-merge scenario: a ship worker (FM_TASK_ID set) runs the fixed runner from its LINKED task worktree
# runner checkout git dir : ~/.no-mistakes/repos/9b0bfac143a1.git/worktrees/01M1WXEKZ6SED7F8CWQ95EZMSB
# repository common dir   : ~/.no-mistakes/repos/9b0bfac143a1.git
# (git dir != common dir: a linked worktree, not the primary, so the guard must let it run)

$ FM_TASK_ID=task-z1 bin/fm-test-run.sh --list tests/fm-test-run.test.sh
   > tests/fm-test-run.test.sh
   exit=0

# The suite below builds git-init fixture primaries and runs a copied runner inside them.
# tests/lib.sh clears the inherited marker so those fixture runs are not refused; the new case sets FM_TASK_ID=probe-task itself.
$ FM_TASK_ID=task-z1 bin/fm-test-run.sh tests/fm-test-run.test.sh
   > FM_TEST_BEGIN 2026-09-07T03:24:27Z tests/fm-test-run.test.sh family=pure-contract-unit expected_gate_skip=none
   > ok - exact suite coverage: --all lists every tests/*.test.sh once
   > ok - family selection returns a proper subset of the suite
   > ok - single-script selection lists exactly that path
   > ok - changed-file selection stays conservative (never silent full suite)
   > ok - a task marker refuses execution in the primary checkout and leaves worktrees and inspection alone
   > ok - runner and its documentation surfaces select their curated family, not just their contract owners
   > ok - shell line-ending policy selects runner coverage
   > fm-test-run: no tests selected for changes vs HEAD (map is conservative; use --all for the complete suite)
   > ok - changed selection covers dependents, fails closed for live unmapped source, and accepts retired unconsumed source
   > ok - a bin reference selects the referencing scripts, and consumers still select their curated families
   > ok - changed defaults to bounded automatic scheduling with serial override
   > ok - Windows emulation exempts only synthetic POSIX modes
   > ok - a plain script list defaults to bounded automatic concurrency without an automatic timeout
   > ok - family proofs run concurrently only within separate family phases
   > ok - empty changed selection emits deterministic text and JSON summaries
   > ok - timing markers and JSON artifact are valid
   > ok - aggregate exit reflects any script failure
   > ok - gate-skip accounting is honest and non-failing
   > ok - fail-on-gate-skip converts herdr-not-found into a hard failure
   > ok - exclude-family drops the named primary family after selection
   > ok - portable shard union, disjointness, and coverage guard hold
   > ok - portable serial shards are a deterministic disjoint cover of the serial lane
   > ok - coverage guard reports and bounds the unmeasured portable serial share
   > ok - portable serial shard lanes refuse mismatched, out-of-range, and countless names
   > ok - --jobs refuses non-proven / stateful selections
   > ok - --jobs admits and schedules a family with a recorded concurrent proof
   > ok - an unclassified new test stays serial while the proven residual family runs concurrently
   > ok - a concurrent run starts the longest-hint script first
   > ok - --per-script-timeout-secs turns a hung script into a bounded failure
   > ok - --max-wall-ms fails an over-budget run and refuses a malformed budget
   > ok - jobs scheduler runs proven scripts; failure propagates; non-proven refused
   > ok - Herdr CI family-run step times out at 20 min under a 75 min job backstop
   > ok - aggregate-json merges lane timing artifacts
   > FM_TEST_END 2026-09-07T03:26:00Z tests/fm-test-run.test.sh exit=0 duration_ms=93197 gate_skip=false
   > FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=93277
   > FM_TEST_SUMMARY_FAMILY family=pure-contract-unit count=1 duration_ms=93197 failed=0
   > FM_TEST_SLOWEST rank=1 script=tests/fm-test-run.test.sh duration_ms=93197
   exit=0
Evidence: What a task worker sees when it runs the suite from the primary checkout
$ FM_TASK_ID=task-z1 <primary>/bin/fm-test-run.sh tests/probe.test.sh
fm-test-run: refusing to run in the repository primary checkout /private<tmp>/repo while FM_TASK_ID=task-z1 is set; run from the assigned task worktree instead
exit=2
primary branch: main | probe ran in primary: no

$ FM_TASK_ID=task-z1 <linked>/bin/fm-test-run.sh tests/probe.test.sh
FM_TEST_BEGIN ... tests/probe.test.sh family=unclassified expected_gate_skip=none
ok - probe suite ran in /private<tmp>/linked and switched to probe-stray
FM_TEST_END ... tests/probe.test.sh exit=0 ...
exit=0
- Outcome: ⚠️ 1 info across 1 run (12m2s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

⚠️ **Test** - 1 info
  • ℹ️ tests/fm-kimi-harness.test.sh:263 - tests/fm-kimi-harness.test.sh fails on this machine before reaching the case this change touched, because the default python3 on PATH (Anaconda) lacks tomllib and bin/fm-kimi-turnend-hook refuses to validate config.toml. The failure is identical at the base commit 1533f47 (verified by running the suite from a git archive of the base tree), so it is environmental, not introduced by this change. With Homebrew's python3 (3.14, tomllib present) first on PATH the whole suite passes, including the modified case that asserts the FM_TASK_ID pane export. This is most likely the cause of the earlier test round's declined 'tests failed with exit code 1'. No code change is needed; CI runs with a tomllib-capable python3.
  • bin/fm-test-run.sh tests/fm-test-run.test.sh tests/fm-kimi-harness.test.sh tests/fm-trace-context-spawn.test.sh tests/fm-spawn-dispatch-profile.test.sh (3 of 4 pass; kimi fails on environment python3)
  • PATH=/opt/homebrew/bin:$PATH bin/fm-test-run.sh tests/fm-kimi-harness.test.sh (passes, including the case asserting export FM_TASK_ID=&lt;id&gt; in the pane log)
  • Ran tests/fm-kimi-harness.test.sh from a git archive 1533f47 copy of the base tree to confirm the tomllib failure is pre-existing
  • Overlaid the new tests/fm-test-run.test.sh and tests/lib.sh onto the base-tree archive and ran bash tests/fm-test-run.test.sh: the new case fails against the unfixed runner (exit 1)
  • Manual fixture: git-init primary (main) + git worktree add linked worktree, copied base and fixed runners plus a branch-switching probe suite; ran FM_TASK_ID=task-z1 &lt;primary&gt;/bin/fm-test-run.sh tests/probe.test.sh, --all, via a symlink alias to the primary, from the linked worktree, unmarked in the primary, --list, --list-families, and with no selection mode; recorded exit codes, output, primary branch, and probe-ran markers
  • Manual spawn: drove real bin/fm-spawn.sh for a ship (trace context off and on), a scout, and a secondmate through a fake tmux logging every pane payload in send order with launch-env-allowlist enabled; replayed the export lines plus emitted launch under env -i with a fake codex harness printing FM_TASK_ID, GOTMPDIR, and an unrelated ambient variable, with a control replay omitting the FM_TASK_ID export
  • FM_TASK_ID=task-z1 bin/fm-test-run.sh --list tests/fm-test-run.test.sh and FM_TASK_ID=task-z1 bin/fm-test-run.sh tests/fm-test-run.test.sh from this linked gate worktree (both exit 0; suite passes with the inherited marker)
  • git status --porcelain after testing (clean)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

A task worker's isolated worktree placement is verified exactly once, when
its task starts, and nothing re-checks it afterwards. A worker that later
changes directory into the repository's primary checkout runs its Git
commands, and this branch-switching suite, against the one checkout every
linked worktree resolves against and every landing merges into. A run that
dies mid-suite can leave that checkout on a stray branch.

bin/fm-test-run.sh now refuses that case. When FM_TASK_ID marks a task
worker and the runner resolves to the primary checkout, every executing mode
exits non-zero before selecting a suite, with one line naming the primary
path and pointing at the assigned task worktree. The predicate is the one
bin/fm-spawn.sh already uses for launch placement: the working tree's own
git dir is the repository's common git dir, which separates the primary from
every linked worktree even when their top levels differ. A run with no
FM_TASK_ID set is unchanged, and so are the inspection modes, which execute
nothing. When git resolves neither directory - a non-repository fixture, a
detached copy - nothing proves this is the primary, so the run proceeds.

bin/fm-spawn.sh sets the marker: ship and scout launches export FM_TASK_ID
into the pane shell on the same pre-launch channel as GOTMPDIR, and the name
joins the sanitized launch environment allowlist so an isolated launch keeps
it.
@greptile-apps

greptile-apps Bot commented Sep 7, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge, with no concrete correctness or security failures identified in the changed behavior.

The refusal checks the same script-derived repository root from which suites execute, marker delivery covers fresh and relaunched ship/scout paths, and inspection modes do not execute test suites.

Reviews (1): Last reviewed commit: "no-mistakes(document): docs: record FM_T..." | Re-trigger Greptile

@kunchenguid
kunchenguid merged commit 6d396da into kunchenguid:main Sep 7, 2026
15 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @3264studios — really appreciate you taking the time on this.

Closes #3848: author body explicitly Fixes that issue (ready-for-pr restore stamp); verified against issue option (1).

Attestation: MATCH (34a5d083c37ae706c8710a075b675bc048b3d6e8).

Contract-class: restore — unconfigured task-marked runs regain the isolation default ship/scout briefs already promise (never the primary checkout). Unmarked human checkouts unchanged. Spawn's FM_TASK_ID export is scaffolding for that refuse, not a new captain-facing default.

VISION.md (each rule)

  • One captain, one interface: aligns — keeps primary checkout stable so sibling workers and landings do not tangle refs the captain must untangle.
  • Authority is explicit: aligns — refuses the unsafe path under a task marker; does not silently allow primary mutation.
  • Scripts own the mechanics: aligns — deterministic refuse in fm-test-run.sh; agent prose alone is not the enforcement spine.
  • A restart is a non-event: aligns — preventing stray branches on primary keeps fleet reconciliation predictable after crashes.
  • Delegation with a spine: aligns — isolation is already part of the ship/scout contract; enforce it at the test-run boundary.
  • The fleet outlives any vendor: aligns — cwd/git-dir predicate is harness-agnostic.
  • Scope: aligns — command-layer script guard around already-promised isolation; not workshop/validation scope.

Checks: CI 34079965356 SUCCESS; no-mistakes 34079965433 SUCCESS; Greptile 5/5. MERGEABLE/CLEAN. Squash merge 6d396da7c43f03315873332b2591119a8c780a97.