Repository navigation
fix(bin): refuse test runs in the primary checkout when a task marker is set - #3891
Conversation
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.
Confidence Score: 5/5The 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 |
|
Speaking as Kun's firstmate: this is merged. Thank you @3264studios — really appreciate you taking the time on this. Closes #3848: author body explicitly Attestation: MATCH ( 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 VISION.md (each rule)
Checks: CI |
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.shgains a placement refusal: whenFM_TASK_IDis set and the runner's root is the repository's primary checkout (its git dir is the common git dir, the same predicatebin/fm-spawn.shuses 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.shexportsFM_TASK_ID=<task-id>into every ship and scout pane before the launch command, on the same channel asGOTMPDIRandTRACEPARENT, and addsFM_TASK_IDto the sanitized launch-environment allowlist; secondmate panes are not marked.tests/fm-test-run.test.shadds a primary-plus-linked-worktree fixture covering the refusal, the linked-worktree run, the unmarked run, and--list;tests/fm-kimi-harness.test.shasserts the export lands in the pane;tests/lib.shunsets an inheritedFM_TASK_IDso fixture repositories still run.docs/architecture.md,docs/configuration.md,docs/scripts.md, anddocs/verification/trace-context.mdrecord 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
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
Evidence: New regression case fails against the base commit runner
Source: New regression case fails against the base commit runner
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
Evidence: What a task worker sees when it runs the suite from the primary checkout
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
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 assertingexport FM_TASK_ID=<id>in the pane log)Ran tests/fm-kimi-harness.test.sh from agit archive 1533f47copy of the base tree to confirm the tomllib failure is pre-existingOverlaid the new tests/fm-test-run.test.sh and tests/lib.sh onto the base-tree archive and ranbash tests/fm-test-run.test.sh: the new case fails against the unfixed runner (exit 1)Manual fixture: git-init primary (main) +git worktree addlinked worktree, copied base and fixed runners plus a branch-switching probe suite; ranFM_TASK_ID=task-z1 <primary>/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 markersManual spawn: drove realbin/fm-spawn.shfor 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 underenv -iwith a fake codex harness printing FM_TASK_ID, GOTMPDIR, and an unrelated ambient variable, with a control replay omitting the FM_TASK_ID exportFM_TASK_ID=task-z1 bin/fm-test-run.sh --list tests/fm-test-run.test.shandFM_TASK_ID=task-z1 bin/fm-test-run.sh tests/fm-test-run.test.shfrom this linked gate worktree (both exit 0; suite passes with the inherited marker)git status --porcelainafter testing (clean)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.