Repository navigation
feat: grant Codex workers task-scoped writable roots - #3708
npayette84 wants to merge 41 commits into
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Launch Claude with --permission-mode auto, Codex with -s workspace-write -a never, and Cursor with --auto-review --sandbox enabled, instead of the three full-bypass flags (--dangerously-skip-permissions, --dangerously-bypass-approvals-and-sandbox, --yolo). A crewmate now runs under its harness's own approval, review, and sandbox controls rather than with them switched off. Codex's workspace-write confines writes to the task worktree plus /tmp and $TMPDIR. That is the intended blast radius, but it also denies the supervision paths a crewmate's contract needs outside its worktree. Granting those back narrowly is a separate, independently reviewable change and is deliberately not bundled here. Refreshes the launch expectations in the three suites that assert the composed command, and the Cursor adapter reference rows. Other tracked uses of the bypass flags are one-off CLI invocations in guard docs and live probes, not spawn output, and are left untouched.
…mpting launch, pin claude auto mode
Confidence Score: 5/5The PR appears safe to merge because the previously reported shared-state exposure is no longer present. No blocking failure remains; the Codex scout now receives only task-specific state, inbox, lock, and report roots while retaining every path required by its current workflows. Reviews (4): Last reviewed commit: "no-mistakes(ci): scope scout artifacts t..." | Re-trigger Greptile |
Supersedes an aborted fix round that would have made an auto-detected cursor silently fall back to another adapter. Silently substituting a different tool changes which adapter runs the captain's work without saying so, which is harder to notice than a refusal. The bar now holds however cursor was selected, explicit or inherited, and the refusal names the exact remedy: set config/crew-harness to a verified adapter, or add an eligible crew-dispatch profile. Firstmate does not pick one on the captain's behalf. The two exemption grants are no longer interchangeable across relaunch. envelope:<name> describes a mechanically proven outer isolation envelope that still governs the replacement agent, so it is inherited and automatic recovery keeps working. `attended` asserts a person is in the pane right now; the captain who attested may have left long before stuck-worker recovery relaunches, so inheriting it would let one attestation authorize unlimited unattended launches. It is never inherited. A cursor exemption is refused outright on a non-cursor harness rather than recorded, so no stale grant can sit in a task's metadata waiting to authorize a later relaunch onto cursor. Remote secondmate launches forward only an envelope grant, through self-describing arguments whose compatibility degradation is stated in the code: an older host misbinds the token and fails validation there, and a cursor secondmate reaching fm-spawn without a grant is refused by the bar. Both paths fail closed. An attended grant cannot describe a worker on another host and is refused for a remote launch. Bootstrap now diagnoses a cursor crew-dispatch rule instead of validating clean and failing later at spawn, since those rules resolve the harness for crewmate and scout spawns and both are barred. Also adds a contains mode to the bootstrap row runner with a guard that fails on an unknown mode; the previous case statement let an unrecognized mode pass vacuously.
…lign guards and docs
…cept legacy carrier
…and recovery docs
…, validate wire grant
… share grant owner
…n-inherited refusal
Codex runs under -s workspace-write, which confines writes to the task
worktree. Every task worktree is a LINKED worktree, so that confinement
denied the three things every brief requires outside it: the scout report
at data/<id>/report.md, the status appends supervision reads, and the
captain-hold completion gate - and denied `git add` too, since a linked
worktree's index lock lives in the primary checkout's git directory.
Observed 2026-08-26: a codex scout produced a full report it could not
deliver, and the completion gate recursed inside its own lock retry until
the filename was too long. Both were the same denial. Codex has been out
of rotation since, for plumbing reasons rather than capability.
The launch now composes repeatable --add-dir roots, scoped per kind:
ship crewmate its own state/<id>.status and state/<id>.turn-ended FILES
(pre-created so single-file roots resolve), plus the
out-of-tree git common dir
scout state/ itself, its own data/<id>/, plus the git common dir
secondmate only the parent's state/<id>.status file
state/ must be a whole directory for the scout alone because the gate
creates a lock symlink and a mktemp-named owner directory in it, and
neither can be named ahead of time. $FM_HOME, .env, config/, projects/,
and the shared data/ root are never granted. --add-dir is used rather
than -c sandbox_workspace_write.writable_roots, which would REPLACE an
operator's own configured roots instead of adding to these.
Two suites cover it. The portable one pins the composition and proves
each root load-bearing with no codex present. The opt-in live guard
(FM_CODEX_LIVE_E2E=1) proves the vendor still enforces exactly these
roots, including the completion gate, and refuses to pass without the
real binary.
The dispatch notice claims only what is invariant: ~/.no-mistakes stays
denied, so a codex worker cannot run validation itself. Network is the
operator's own sandbox_workspace_write.network_access and varies per
machine, so it is deliberately not asserted.
…cuous isolation guards
…rebase The rebase onto main picked up the brief split (kunchenguid#3597): a spawn now refuses a brief without nonempty `## Captain's intent` and `## Firstmate spec` subsections, so both codex sandbox-grant suites failed at the first ship spawn on their one-line fixture brief. Both fixtures now carry the two subsections, matching what tests/fixtures.sh fm_test_spawn_brief writes. Nothing about the grant under test changes.
…dings Two hosted behavior failures and one stale attestation were all that stood between PR 3385 and green; each is fixed at its root, and every automated review finding still open on the exact head is implemented. - The remote trace-context suite launched a real cursor second mate through a transport that composes the remote child's PATH from the filesystem (env -i with the remote root's bin first), so the cursor launch only resolved on machines that happen to have the vendor CLI installed. The remote fixture now ships its own cursor-agent stub in the remote root's bin, where the worker's composed PATH is guaranteed to find it. - The transport-lanes fixture staged a partial remote root missing the two libraries fm-remote-secondmate-control.sh now sources, so every control-state call died at the missing source; the fixture's copy list now carries the full source closure and states the invariant. - The git-metadata grant is pinned to the recorded project's own common directory: a linked worktree's .git file is writable by exactly the previous worker, so a repointed one must refuse the spawn rather than grant another repository's refs and hooks. - A hard-linked state record refuses the spawn: a second name for one inode is never a shape firstmate creates, and the granted worker would write through the link into whatever shares the inode outside the task's boundary. - Pre-creation now refuses loudly on a wrong-typed record and on a creation failure instead of reporting success for a root the worker cannot write. - A raw launch through cursor's legacy agent alias resolves through the verified cursor owner and is held to the cursor unattended bar; an unrelated executable named agent stays on the unverified escape hatch. - patsub_replacement is pinned off for launch-command assembly: the flagged substitution quotes its operand and was already literal on bash 5.2, but the adjacent unquoted substitutions carry the real hazard, and stock bash 3.2 semantics are the only ones this script may rely on. - A remote spawn records the grant the endpoint reports carrying rather than the one the launch request carried, so a reused endpoint never leaves the parent claiming cursor authority the live worker does not have; print_route reports the endpoint's own grant for that purpose. Every regression here fails on the defect it pins and passes after the fix, driven through the public spawn and transport interfaces.
f466963 to
aab9308
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f466963a99
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| exit 2 if $words[$index] =~ m{/(?:bash|csh|dash|deno|env|exec|fish|ksh|nice|node|nohup|perl|python(?:\d+(?:\.\d+)?)?|ruby|sh|sudo|tcsh|time|zsh)\z}; | ||
| exit 2 if $words[$index] =~ /\A(?:bash|command|csh|dash|deno|exec|fish|ksh|nice|node|nohup|perl|python(?:\d+(?:\.\d+)?)?|ruby|sh|sudo|tcsh|time|zsh)\z/; |
There was a problem hiding this comment.
Reject wrapper commands that conceal Cursor
Captain, when a raw launch wraps Cursor with an executable not in this blacklist, such as stdbuf -oL cursor-agent ... or setsid cursor-agent ..., the parser identifies the wrapper as the harness; its family is therefore unknown and fm_control_launch_refusal skips the Cursor bar. This launches an unattended Cursor worker that can park invisibly on an approval prompt, so wrappers must either be unwrapped reliably or refused as ambiguous.
AGENTS.md reference: AGENTS.md:L202-L202
Useful? React with 👍 / 👎.
| CODEX_ADD_DIRS=$(codex_add_dir_flags "$KIND" "$WT" "$PROJ_ABS" "$ID") || { | ||
| echo "error: refusing to launch $ID on codex: its writable-root grant could not be composed safely (see the refusal above); repair the named path, because launching without it would strand the worker outside the paths its brief requires" >&2 | ||
| exit 1 |
There was a problem hiding this comment.
Validate Codex roots before stopping a relaunch
Captain, when a Codex relaunch encounters an unsafe or unwritable status file, inbox, data directory, or git metadata path, this newly fallible validation runs only after fm-control.sh has stopped the existing agent and fm-spawn.sh has published the replacement metadata. The resulting exit 1 rolls back metadata but cannot restore the stopped agent, leaving the task stranded without a worker; perform the non-mutating root checks before do_exit, or otherwise make this failure recover the previous agent.
Useful? React with 👍 / 👎.
| if [ "$HARNESS" = codex ] && [ "$MODE" = no-mistakes ]; then | ||
| echo "notice: $ID ships mode=$MODE on codex, whose sandbox denies the no-mistakes data directory - the worker can commit and reach the network but cannot run validation itself; expect to land it another way or choose another harness" >&2 | ||
| fi |
There was a problem hiding this comment.
Refuse Codex for no-mistakes ships
Captain, when a ship selects mode=no-mistakes with the Codex harness, this branch knowingly continues even though the sandbox prevents that worker from invoking the required no-mistakes pipeline. The suggested “land it another way” contradicts the delivery contract: the same task worker must start and drive the pipeline, while Firstmate must not take over its responses. This combination therefore cannot complete its selected delivery path and should be refused before allocating the worker, or the required pipeline state should be granted safely.
AGENTS.md reference: AGENTS.md:L357-L359
Useful? React with 👍 / 👎.
| echo "error: $file could not be created; refusing to grant a codex writable root the worker cannot actually write - inspect the state directory's permissions" >&2 | ||
| return 1 | ||
| fi | ||
| if ! fm_wake_signal_mark_current "$STATE" "$file" 2>/dev/null; then |
There was a problem hiding this comment.
Detect same-second turn-end notifications
Captain, when a Codex worker exits or completes its first turn within the same timestamp second in which this pre-created turn-ended file is marked current, the real notify-hook touch leaves the recorded size:mtime signature unchanged (0:<same second> on Linux). The watcher consequently treats the notification as already reported and never queues that turn end; the regression test misses this because it appends a byte instead of exercising the actual touch behavior. Use a signature with sufficient timestamp precision or otherwise ensure the first touch differs from the seeded marker.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6041119695
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| | Autonomy | `--permission-mode auto`, so the worker runs under Claude's own classifier rather than `--dangerously-skip-permissions`, which bypassed every check. The spawn also sets `CLAUDE_CODE_DISABLE_FAST_MODE=1`; see "Auto mode" below. | | ||
|
|
||
| Fresh-worktree or first-machine launch may show the workspace-trust confirmation. | ||
| That is the only launch surface that still requires a keypress: inspect within about 20 seconds, accept the required choice with `FM_HOME=<active-home> ../../../bin/fm-send.sh <window> --key Enter` unless already bound, and verify instructions started. |
There was a problem hiding this comment.
Do not submit Claude's default trust choice
Captain, when a Claude secondmate starts in a home that has not been trusted yet, this command presses Enter while the workspace-trust dialog defaults to No, exit; the verified capture in docs/verification/runtime-backends.md:239-247 and the shared guidance in references/common/control-and-recovery.md:20-27 both confirm that this terminates the worker rather than accepting trust. Since the harness adapter is the required trust-handling guide, retain operator-driven selection or document a sequence that actually selects Yes.
AGENTS.md reference: AGENTS.md:L200-L200
Useful? React with 👍 / 👎.
| # cannot silently drop a crewmate back to interactive prompting. The | ||
| # remaining triggers are plan/model/server-side; the harness-adapters skill | ||
| # documents the resulting dialog so a degraded worker is recognizable. | ||
| claude) printf '%s' 'CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION=false CLAUDE_CODE_DISABLE_FAST_MODE=1 claude --permission-mode auto __MODELFLAG____EFFORTFLAG__"$(__OPINPUT__ encode launch-brief < __BRIEF__)"' ;; |
There was a problem hiding this comment.
Preserve Claude feedback suppression
When a Claude worker encounters content that triggers the /bug or /feedback flow, this replacement launch no longer sets either CLAUDE_CODE_SEND_FEEDBACK=0 or feedbackDrafts=off. The parent version explicitly layered those controls so a fleet worker could not queue or submit a report on the captain's behalf even under managed settings; changing the permission mode does not replace that independent safeguard, so retain the feedback controls alongside --permission-mode auto.
Useful? React with 👍 / 👎.
| if ! SPAWN_LAUNCH_REFUSAL=$(fm_control_launch_refusal "$HARNESS" "$KIND" "$CURSOR_EXEMPTION"); then | ||
| echo "error: $SPAWN_LAUNCH_REFUSAL" >&2 | ||
| exit 1 |
There was a problem hiding this comment.
Reject sandbox-disabling flags in raw Cursor launches
When a caller supplies a raw command such as cursor-agent --force ... together with --cursor-exemption attended, this check recognizes the command as Cursor and accepts the exemption, but the unchanged raw command is then launched with --force (or --yolo). The repository's own verification establishes that either flag overrides --sandbox enabled regardless of flag order, so a grant intended to attest attendance also silently removes filesystem confinement; reject those flags for recognized raw Cursor commands or route exempted Cursor launches through the hardened template.
Useful? React with 👍 / 👎.
Intent
Repair the red checks on the existing upstream Firstmate PR #3385 (a recovery of the same PR, never a duplicate) and reach green hosted checks without merging.
Diagnose every failing check from its full hosted log and reproduce every code-related defect locally before fixing it, separating stale attestation, runner variance, and unrelated upstream failures from actual regressions. The current failures are: 'PR must be raised via no-mistakes' (stale attestation: the PR body binds an older head than the pushed tip), 'Behavior portable serial 2' (fm-remote-secondmate-trace-context: the enveloped cursor remote launch resolves cursor only on machines that happen to have the vendor CLI), and 'Behavior portable serial 4' (fm-remote-transport-lanes: the staged remote root lacks libraries fm-remote-secondmate-control.sh now sources).
Preserve the accepted feature: the narrow Codex writable-root grant that lets a worker write only the brief-permitted Firstmate paths while retaining the stronger sandbox and no-escalation posture. Preserve all already-green behavior for launch hardening, out-of-workspace denial, captain-question reporting, and every supported worker runtime and session provider.
Read and address every current human or automated review comment on the exact PR head; implement sound findings and document reasoned rejections. Address in particular: pinning the out-of-tree git-metadata grant to the recorded project (a worktree .git file is worker-rewritable), rejecting hard-linked writable-root files, refusing wrong-typed or uncreatable pre-created records, holding a raw cursor 'agent' alias launch to the cursor unattended bar through verified resolution, keeping launch-command substitution literal under bash 5.2 patsub_replacement, and recording the remote endpoint's actual cursor grant rather than an undelivered launch request.
Use behavioral tests through public script interfaces, never source-byte assertions; add regressions that fail on each defect and pass after the correction. Keep the branch limited to this PR's accepted scope; check the final diff against current upstream main; run relevant focused suites, bin/fm-doc-audience-check.sh, shellcheck on changed shell, and bin/fm-lint.sh.
Drive the full no-mistakes path against the corrected exact head, update the SAME PR 3385 (never a duplicate), reach green hosted checks, and never merge.
What Changed
Risk Assessment
✅ Low: The change is bounded and the reviewed sandbox-root, Cursor exemption, remote-route, and marker-safety paths contain no newly substantiated defect.
Testing
Focused public-script integration checks exercised the scoped Codex write grant, remote Cursor launch/grant delivery, remote transport staging, relaunch safety, and raw Cursor alias handling; all passed. The saved CLI transcript is the appropriate reviewer-visible evidence because this shell control-plane change has no rendered UI.
Evidence: Focused behavioral CLI transcript
Source: Focused behavioral CLI transcript
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 2 issues found → auto-fixed (6) ✅
bin/fm-wake-lib.sh:1735- Criterion: “the narrow Codex writable-root grant that lets a worker write only the brief-permitted Firstmate paths while retaining the stronger sandbox.” A prior Codex scout can createstate/.seen-<id>_turn-endedas a symlink; this new redirection follows it when a later ship spawn pre-creates that task’s marker, letting unsandboxed Firstmate overwrite the symlink target. Refuse unsafe marker entries and publish markers safely for both status and turn-ended paths.bin/fm-spawn.sh:1552- Criterion: the grant “lets a worker write” its brief-permitted paths. Existing regular status/turn-ended files return success without a writability check, and an existing inbox/handled directory is accepted bymkdir -pwithout verifying its type or writability. A prior scout can leave either unwritable, causing a successful spawn whose Codex worker cannot report or acknowledge steers. Refuse unusable pre-existing files and inbox directories before launch.🔧 Fix: Safeguard Codex writable roots
1 error still open:
bin/fm-spawn.sh:1850- The required criterion says to “hold[] a raw cursor ‘agent’ alias launch to the cursor unattended bar through verified resolution.” The new check only runs when the first non-assignment word isagent; a supported raw command such asenv FOO=bar agent --flagis classified asenvat the added hunk, skips Cursor verification and the shared refusal, then is delivered to an unattended pane without--cursor-exemption. Recognize leadingenvsetup before classifying the executable (and cover that public raw-command invocation).🔧 Fix: Guard env-wrapped Cursor agent aliases
1 error still open:
bin/fm-spawn.sh:1852- Captain: required criterion says to “hold[] a raw cursor ‘agent’ alias launch to the cursor unattended bar through verified resolution.”env -S agent(orenv -S 'agent --flag') skipsagentas the-Sargument, leavingHARNESSempty and allowing the raw Cursor alias to launch outside the bar. Decide whether to parse the split string or fail closed onenv -S; recommend fail closed until it can be recognized reliably.🔧 Fix: Reject ambiguous Cursor split-string launches
2 errors still open:
bin/fm-spawn.sh:1633- Required criterion: “the narrow Codex writable-root grant that lets a worker write only the brief-permitted Firstmate paths.” The changed scout branch grants the entire sharedstate/directory. A running Codex scout can directly overwritestate/<other-task>.statusor metadata for another task, despite neither being in its brief. Move the scout completion-lock protocol to a task-scoped precreated root, then grant that root plus the scout’s own required files instead of sharedstate/.bin/fm-spawn.sh:1837- Required criterion: “holding a raw cursor ‘agent’ alias launch to the cursor unattended bar through verified resolution.” The shell-unsafefor word in $linetokenizer misclassifiesFOO='two words' agent --flagas executablewords';/usr/bin/env -S agent --flagalso bypasses the exact-envcheck. Both launch the real Cursor alias as an unverified raw command, outside the unattended bar. Parse only a conservative, shell-aware supported wrapper grammar or fail closed on quoted/absolute-wrapper raw commands before classification.🔧 Fix: Parse raw Cursor launch wrappers safely
2 errors still open:
bin/fm-spawn.sh:1843- Captain: required criterion: “holding a raw cursor ‘agent’ alias launch to the cursor unattended bar through verified resolution.”PATH=/cursor-bin agent --flagorenv PATH=/cursor-bin agent --flagis classified asagent, but resolution uses Firstmate’s current PATH, not the command’s assigned PATH. It records unverifiedagentand bypasses the bar, while the pane launches Cursor unattended.bash -c agentsimilarly bypasses classification. Fail closed on PATH/CWD-changing and interpreter wrappers unless their effective executable is Cursor-verified.bin/fm-spawn.sh:1567- If safe marker publication fails after creating a status or turn-ended file, the failed spawn leaves that untracked signal behind. With a pre-existing.seen-<id>_turn-endedsymlink, the watcher later sees the orphaned turn-ended file and its existing marker write follows the symlink, recreating the out-of-bound write this guard was meant to prevent. Remove or safely reconcile records created by this invocation when marker publication fails.🔧 Fix: Harden raw launches and marker rollback
2 errors still open:
bin/fm-control-lib.sh:194-envelope:*is inherited based only on its shape and the target harness. A legacy/stalecursor_exemption=on a task recorded asharness=codextherefore authorizesfm-control ... relaunch --harness cursorwithout a new grant, reopening the unattended Cursor bar. Require the recorded source harness to be Cursor before inheriting a grant.bin/fm-spawn.sh:791- The remote route records any shape-valid endpoint exemption without checking that the returned endpoint harness is Cursor. A reused older non-Cursor endpoint with a stale grant can repopulate the parent record, then authorize a later Cursor recovery. Drop remote grants unlessremote_harnessis Cursor; cover reuse through the public remote route.🔧 Fix: Bind exemptions to Cursor provenance
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
bin/fm-test-run.sh --per-script-timeout-secs 900 tests/fm-codex-sandbox-grant.test.sh tests/fm-remote-secondmate-trace-context.test.sh tests/fm-remote-transport-lanes.test.sh tests/fm-control-relaunch.test.sh tests/fm-spawn-dispatch-profile.test.shVerified the worktree remained clean after test cleanup.✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.