Repository navigation
Conversation
Confidence Score: 4/5The PR is not yet safe to merge because refusal cleanup can temporarily remove another home’s live GOTMPDIR and break that worker’s Go commands. The recursive cross-home deletion was narrowed, but cleanup still removes the shared empty gotmp directory before discovering that another spawn keeps the parent root live and recreating it. Files Needing Attention: bin/fm-spawn.sh Reviews (4): Last reviewed commit: "no-mistakes(document): correct fm-spawn ..." | Re-trigger Greptile |
| if rmdir "$TASK_TMP/gotmp" 2>/dev/null; then | ||
| rmdir "$TASK_TMP" 2>/dev/null || mkdir "$TASK_TMP/gotmp" 2>/dev/null || true |
There was a problem hiding this comment.
If two homes concurrently spawn the same task ID, the creator’s refusal cleanup checks only its own home’s metadata before removing the shared gotmp directory. This can remove the other spawn’s empty GOTMPDIR, replace it with a different directory, or remove the root before the other spawn creates its readiness marker, causing build-temp failures or a false readiness refusal.
|
Speaking as Kun's firstmate: triage for #3132 ( Classification: corrective (spawn types fixed commands before the shell line editor is up; probe via marker file only an executing shell can create; refuse on timeout; distinct stranded/cleared/undelivered send statuses). VISION (per-rule, inspected evidence):
OVERLAP (do not merge one leftover): open #3101 ( Security / fishy: none. Greptile noted abort-cleanup / concurrent-home risk; the diff’s Gates: mergeable=MERGEABLE. Cross-fork — approved first-time fork CI: runs Decision: waiting-ci / waiting-author for matching attestation + green CI, and overlap resolution with #3101. Not pinging; not escalating. |
3b5bcd2 to
2a5ae4c
Compare
| if rmdir "$TASK_TMP/gotmp" 2>/dev/null; then | ||
| rmdir "$TASK_TMP" 2>/dev/null || mkdir "$TASK_TMP/gotmp" 2>/dev/null || true |
There was a problem hiding this comment.
If two FM_HOME instances concurrently spawn the same task ID, the root creator's refusal cleanup can remove an empty gotmp or the shared root after the other spawn has adopted it. This makes the adopter's marker creation fail spuriously, or briefly removes a live worker's GOTMPDIR and causes its next Go command to fail.
fm-spawn types its fixed spawn-time commands into the endpoint shell as soon as the endpoint exists. A shell whose startup is still running - the common case when .envrc loads direnv or devenv - swallows anything typed before its line editor is up, so `treehouse get` and the launch command can be lost and the worker silently never starts. Screen text cannot detect this: the pty echoes the swallowed keystrokes, so seeing the command in the pane is not proof it ran. This adds a readiness gate that proves the shell is executing input by a side effect instead. Before the first fixed send, an idempotent probe writes a marker file that only an executing shell can create; the spawn proceeds once the marker appears. Details that matter for correctness: - The probe is re-sent while unconfirmed on a backing-off cadence, so a slow startup is probed to the end of the budget without burying the pane's scrollback. The real commands are never re-sent, because re-sending `treehouse get` would acquire a second worktree. - The marker lives in a private mode-0700 directory created ahead of the first send. A marker any local account could write would be forgeable, which would confirm readiness for a shell that executed nothing and reinstate exactly the failure this gate exists to catch. Privacy is re-established on every read, not assumed once. - A probe that cannot be delivered is reported differently from one that was delivered and never answered, because those need different operator action. - On timeout the spawn refuses loudly rather than launching into a shell that is not listening. Budgets are tunable via FM_SPAWN_SHELL_READY_POLLS, FM_SPAWN_SHELL_READY_INTERVAL and FM_SPAWN_SHELL_READY_RESEND, mirroring the existing per-harness readiness knobs (FM_KIMI_READY_POLLS, FM_KIMI_SUBMIT_SETTLE) that already solve this for the Kimi submit path, and generalising them to every backend. The test changes are required, not incidental: the existing spawn stubs accept typed lines without running them, so no marker would ever be created and the gate would correctly refuse in every spawn test. The stubs now execute what is typed into them, which is also a more faithful model of a real shell.
Narrows this change back to what it can prove. The readiness gate stands: it verifies the endpoint shell is executing input before each fixed spawn-time send, and the send-status taxonomy distinguishes an undelivered send from one left typed-but-uncleared. The post-launch confirmation added on top did not hold up. Its own header documented "`alive` confirms and stops waiting", but the loop only ever tested `[ "$state" = dead ] || return 0` on a first poll taken with no preceding sleep, so on tmux the flushed-launch case it existed to catch still returned success while the pane was busy with shell work. It also proceeded on `missing`, which bin/fm-backend.sh:878 defines as "the recorded endpoint is authoritatively absent" and :882 lists among the two verdicts that license recovery. Confirming a launch properly needs a bounded post-Enter agent-state wait that tolerates early ambiguity without conflating it with success - a larger behaviour change than this commit should carry. The launch line therefore keeps its pre-existing delivery-only check for every harness but kimi, unchanged from before this series, and the gap is left named rather than half-closed. Removed: spawn_confirm_launched_agent, its call site, the FM_SPAWN_LAUNCH_CONFIRM_* knobs, the now-unread SPAWN_LAUNCH_TEMPLATED flag, and the flushed-launch test that only exercised the removed path.
… in architecture doc
2a5ae4c to
8aadd2a
Compare
|
Speaking as Kun's firstmate: Reviewed HEAD Class: corrective. Spawn typed VISION (per rule, inspected evidence):
OVERLAP HOLD: #3101 (adriantoczydlowski) is still open — same shell-readiness class as #3097 (gate the first spawn send on proven pane-shell readiness). Do not land one leftover while the other is open. Body does not claim Fixes/Closes #3097. Attestation: matches. CI: current-HEAD CI run First-time fork CI: previously approved on an earlier HEAD ( Not merging. Overlap hold with #3101. Waiting on that leftover to clear, and on green CI. Not pinging. Not with the captain. Merge-eligible: NO. |
|
Speaking as Kun's firstmate: Reviewed HEAD Class: corrective. Spawn typed fixed commands before the endpoint shell's line editor was up; pty echo is not proof of execution. Diff gates every fixed spawn-time send behind an idempotent VISION (per rule, inspected evidence):
Overlap hold: #3101 (adriantoczydlowski) is still OPEN on the same spawn shell-readiness class. Do not land one leftover while the other is open. Body does not claim Fixes/Closes #3097. Security / fishy: none. Greptile's concurrent-home / temp-root notes match intentional Attestation: First-time fork CI: after that full-diff review I approved workflow runs Not merging. Unresolved overlap with #3101; waiting on green CI for the newly approved runs. Not with the captain. Merge-eligible: NO. |
Intent
Spawning a crewmate typed commands into an endpoint pane whose shell was not yet reading input, so they were silently swallowed. Seen live on 2026-08-25: the echoed
treehouse getsat ABOVE direnv's own loading line in the pane scrollback, never ran, and the worktree-settle loop then burned its whole budget waiting on a command that had never executed - leaving an orphan pane and a task that reported as spawned while no agent was working. Make fm-spawn prove, backend-agnostically, that the endpoint's shell is actually READING INPUT before each fixed spawn-time send, proven by a side effect the shell itself must produce rather than by pane text (the pty echoes swallowed keystrokes, so seeing the command is not proof it ran). Where readiness cannot be proven, or a send is typed but neither submitted nor cleared, refuse with a named diagnostic instead of launching a worker that will silently do nothing.What Changed
Final changed paths and statuses:
Risk Assessment
Testing
Ran the change's own regression suite (18 cases, all passing) plus the herdr, orca, worktree-settle and backend-dispatch suites that own the send-adapter status contracts and the surrounding spawn paths — all green, no failures or flakiness. For product-level evidence I drove the real bin/fm-spawn.sh against the suite's pty-line-discipline fake backend at both the base and target commits and captured verbatim CLI transcripts: the base commit reproduces the reported defect twice over (a swallowedtreehouse getburning the whole 60s settle budget, and a swallowed launch command exiting 0 withspawned …printed while no agent ran), and the target commit delivers both sends after the shell itself creates the readiness marker. Also captured the five named refusals (unproven readiness, post-meta refusal recorded in state/<id>.status, unreachable endpoint refusing after one send attempt, and a cmux send typed-but-uncleared) and a before/after table of the herdr adapter's send status. This is a CLI-only change with no rendered UI surface, so the artifacts are terminal transcripts rather than screenshots. No transient files were left in the worktree.Evidence: Evidence index (what each transcript proves, plus reproduction commands)
Source: Evidence index (what each transcript proves, plus reproduction commands)
Evidence: BEFORE (base 10b93b2): swallowed `treehouse get` burns the whole settle budget
Source: BEFORE (base 10b93b2): swallowed
treehouse getburns the whole settle budget$ bin/fm-spawn.sh ev-before-63891 <project> --mode no-mistakes --yolo off --backend tmux error: treehouse get did not enter a worktree within 60s; inspect window firstmate:fm-ev-before-63891 --- exit status: 1 --- what the endpoint shell actually did (fake pty line log) swallowed treehouse get --- agent process started: NO --- task record state/ev-before-63891.meta: (absent)Evidence: BEFORE (base 10b93b2): the reported symptom - reports `spawned` with no agent working
Source: BEFORE (base 10b93b2): the reported symptom - reports
spawnedwith no agent working$ bin/fm-spawn.sh ev-before-launch-35591 <project> --mode no-mistakes --yolo off --backend tmux spawned ev-before-launch-35591 harness=codex kind=ship mode=no-mistakes yolo=off window=firstmate:fm-ev-before-launch-35591 worktree=.../wt --- exit status: 0 (elapsed 7s) --- what the endpoint shell actually did (fake pty line log) ran treehouse get swallowed export GOTMPDIR=/tmp/fm-ev-before-launch-35591/gotmp swallowed env -u CURSOR_AGENT ... codex --dangerously-bypass-approvals-and-sandbox ... --- agent process started: NO --- fleet sees the task as: spawned (state/ev-before-launch-35591.meta published)Evidence: AFTER (target): same swallowing shell - probe re-sent until the shell creates the marker, then `treehouse get` runs
Source: AFTER (target): same swallowing shell - probe re-sent until the shell creates the marker, then
treehouse getruns$ bin/fm-spawn.sh ev-after-28244 <project> --mode no-mistakes --yolo off --backend tmux spawned ev-after-28244 harness=codex kind=ship mode=no-mistakes yolo=off window=firstmate:fm-ev-after-28244 worktree=.../wt --- exit status: 0 --- what the endpoint shell actually did (fake pty line log) swallowed touch '/tmp/fm-ev-after-28244/shell-ready.TxjWpVpe/worktree-entry' swallowed touch '/tmp/fm-ev-after-28244/shell-ready.TxjWpVpe/worktree-entry' swallowed touch '/tmp/fm-ev-after-28244/shell-ready.TxjWpVpe/worktree-entry' ran touch '/tmp/fm-ev-after-28244/shell-ready.TxjWpVpe/worktree-entry' ran treehouse get ran touch '/tmp/fm-ev-after-28244/shell-ready.TxjWpVpe/launch' ran export GOTMPDIR=/tmp/fm-ev-after-28244/gotmp ran env -u CURSOR_AGENT ... codex ... --- agent process started: YESEvidence: AFTER (target): the launch-side gate waits out the worktree shell's own startup
Source: AFTER (target): the launch-side gate waits out the worktree shell's own startup
Evidence: AFTER (target): a shell that never reads input refuses with a named diagnostic
Source: AFTER (target): a shell that never reads input refuses with a named diagnostic
error: task ev-never-63891's endpoint shell never confirmed it was reading input within 3s, so 'treehouse get' would have been typed into a shell that is not listening and silently lost; inspect window firstmate:fm-ev-never-63891 --- exit status: 1 --- what the endpoint shell actually did (fake pty line log) swallowed touch '/tmp/fm-ev-never-63891/shell-ready.FE7y6r2h/worktree-entry' (x3) --- agent process started: NO --- task record state/ev-never-63891.meta: (absent)Evidence: AFTER (target): post-meta launch refusal recorded as the task's durable last state
Source: AFTER (target): post-meta launch refusal recorded as the task's durable last state
--- task last state state/ev-launch-63891.status: failed: task ev-launch-63891's endpoint shell never confirmed it was reading input within 3s, so the agent launch command would have been typed into a shell that is not listening and silently lost; inspect window firstmate:fm-ev-launch-63891 --- agent process started: NOEvidence: AFTER (target): unreachable endpoint refuses after 1 send attempt out of a 40-poll budget
Source: AFTER (target): unreachable endpoint refuses after 1 send attempt out of a 40-poll budget
can't find pane: @1 error: task ev-unreachable-28244's endpoint could not be reached: the tmux backend failed to deliver the shell-readiness probe (status 1; its own diagnostic, if any, is above), so 'treehouse get' was never typed; inspect window firstmate:fm-ev-unreachable-28244 --- exit status: 1 --- send attempts made before refusing: 1 (budget was 40 polls) --- agent process started: NOEvidence: AFTER (target): a send typed but neither submitted nor cleared refuses as uncleared input
Source: AFTER (target): a send typed but neither submitted nor cleared refuses as uncleared input
error: task ev-stranded-63891's shell-readiness probe input could not be cleared for fm-ev-stranded-63891: the cmux backend typed it but could neither submit nor clear it, so it is sitting uncleared in that shell's input line where it would prefix whatever is typed there next; refusing to type 'treehouse get' into it; inspect window ws-fake:sf-fake --- exit status: 1 --- probe lines typed into the pane: 1 (a re-send would have appended a second) --- agent process started: NOEvidence: Head commit: herdr send-status collapse, real adapter before vs after
Source: Head commit: herdr send-status collapse, real adapter before vs after
herdr CLI exit | adapter status -> fm-spawn | what the operator is told 2 | before 2 / after 1 | before: input could not be cleared: typed but neither submitted nor cleared, sitting in that shell's input line | | after: endpoint could not be reached: the herdr backend failed to deliver <text> (undelivered) 3 | before 3 / after 1 | before: was typed into <window> and then cleared again, so that endpoint is reachable | | after: endpoint could not be reached ... 7 | before 7 / after 1 | before: unknown status 0 | before 0 / after 0 | send landed - spawn continuesEvidence: Targeted suite results
Evidence: Reproduction harnesses (re-runnable, take <repo-root> <base-commit> <out-dir>)
Source: Reproduction harnesses (re-runnable, take <repo-root> <base-commit> <out-dir>)
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/backends/herdr.sh:2539- This change makes statuses 2 and 3 fromspawn_send_text_linemean two specific endpoint states, backend-wide, and states the rule in bin/fm-spawn.sh:2277-2289: "an adapter that submits in one call has neither state and must collapse every failure to 1, however its own internals number them." bin/backends/orca.sh:186 was fixed in this same change to obey it (fm_backend_orca_run_json ... || return 1), and cmux/zellij legitimately earn 2/3 because they compose the line and each of their steps is collapsed explicitly.fm_backend_herdr_send_text_lineis the one send adapter left passing an unbounded external status straight through: line 2538 collapsestarget_readyto 1, but line 2539 returnsfm_backend_herdr_cli's exit code verbatim, and that isherdr's own process exit status (bin/backends/herdr.sh:380-384 runs the CLI with no status mapping).The adapter's own comment at :2533-2536 says
pane run"types the command and submits it in one call (verified)" - so herdr holds neither reserved state, exactly like orca and tmux. Any herdr exit of 2 or 3 is therefore reinterpreted as a pane state herdr cannot produce.Failure sequence: BACKEND=herdr, fresh ship spawn, past meta publication.
spawn_wait_shell_ready "$T" launch ...(bin/fm-spawn.sh:3386) sends the probe;herdr ... pane runexits 2. bin/fm-spawn.sh:2712 matchesspawn_send_stranded, and the refusal reads "shell-readiness probe input could not be cleared for <window>: the herdr backend typed it but could neither submit nor clear it, so it is sitting uncleared in that shell's input line where it would prefix whatever is typed there next". Nothing was typed. Because this gate is post-meta, bin/fm-spawn.sh:3394 writes that sentence into state/<id>.status as the task's durable last state, pointing the operator at a pane buffer to clear that does not exist. An exit of 3 tells the opposite-but-equally-false story ("typed into <window> and then cleared again ... that endpoint is reachable"), which would send an operator away from a dropped herdr server.I could not prove herdr 0.7.1 exits 2 or 3 for a
pane runfailure - bin/backends/herdr.sh:1859-1861 records that it exits 1 for business-logic "not found" - so I am raising this as a contract hole rather than a confirmed live misreport. The point is that the adapter is the only one whose status is not the adapter's to guarantee: it is whatever a third-party CLI version happens to return, and the repo already treats herdr's exit status as untrustworthy elsewhere (:1822 and :1859 both parse JSON "never from process exit status").Narrowest fix, matching the orca sibling exactly: append
|| return 1to line 2539. Secondary, in the same line: the>/dev/null 2>&1discards herdr's own stderr, so the undelivered refusal's promise that "its own diagnostic, if any, is above" is always empty on this backend - unlike tmux, whose adapter does not redirect. bin/backends/tmux.sh:113 is the same one-call shape and is also uncollapsed, buttmux send-keysonly ever exits 0 or 1, so it is safe today; adding the same|| return 1there would make the rule uniform rather than incidentally true.bin/fm-spawn.sh:2738-spawn_wait_shell_readycarries the same four-way send-status ladder twice: :2712-2723 for the initial probe and :2738-2752 for every re-send. The two copies differ only in three mechanical ways - the re-send arms each beginrm -f "$marker", the detail label is 'shell-readiness probe' vs 'shell-readiness probe re-send', and the undelivered arm says "endpoint could not be reached" vs "endpoint stopped being reachable while waiting for its shell". Everything else, including the order of the stranded/cleared/nonzero checks and the two message tails, is byte-identical.This is a maintenance hazard rather than a defect: the ladder's whole purpose is that no state is ever told as another one, and a future arm added to one copy and not the other reintroduces exactly the conflation
spawn_send_stranded/spawn_send_clearedwere written to prevent. Nothing is wrong with the current behaviour - I traced both copies and they agree.One helper collapses it without touching a single operator-visible string, e.g.
spawn_ready_send_refusal <status> <label> <unreachable-phrase> <what>returning 0 when the send landed and 1 with SPAWN_READY_REFUSAL set otherwise; the caller keeps therm -f "$marker"on the re-send path where it belongs. That preserves all six distinct messages verbatim while leaving one ladder to maintain.🔧 Fix: collapse one-call send adapter failures to status 1
1 info still open:
bin/fm-spawn.sh:2510-spawn_ready_root_private's first guard folds every non-directory into one message that names only two of them, and the refusal it feeds treats that whole class as "not this account's to begin with" - which is false for the shape most likely to hit it.:2509-2513:
if [ ! -d "$dir" ] || [ -L "$dir" ]; then SPAWN_READY_ROOT_PRIVACY_ISSUE="it is not a plain directory any more - gone, or replaced by a symlink"; SPAWN_READY_ROOT_PRIVACY_KIND=identity. That arm fires for a dangling symlink and a live symlink (both described accurately), but also for a regular file, a socket, or a fifo at the root path - none of which is gone and none of which is a symlink.Concrete sequence, fresh tmux ship spawn of
shipfooon a host where/tmp/fm-shipfooexists as a regular file this account owns (a stray shell redirect is the ordinary way that happens):(umask 077; mkdir "$TASK_TMP")fails EEXIST, soSPAWN_TASK_TMP_CREATED=0.[ "$SPAWN_TASK_TMP_CREATED" != 1 ]and[ -e "$TASK_TMP" ]both hold, so the adopted-root identity check runs.[ ! -d "$dir" ]is true, so KIND becomesidentity.spawn_refuse_unprivate_task_tmp(:2571) setsremedyonly when KIND ismode, so the operator gets: "per-task temp root /tmp/fm-shipfoo is not private: it is not a plain directory any more - gone, or replaced by a symlink, so another local account could replace the readiness-marker directory ... refusing to spawn" plus the standing-endpoint sentence - and nothing else.ls -l /tmp/fm-shipfoothen shows-rw-r--r-- 1 <them> <them>- not gone, not a symlink, and owned by the very account the message implies it is not. The remedy silence is deliberate for this KIND (:2504-2505 reasons that every non-modevalue is "a directory whose identity is not this account's to begin with"), but that premise does not hold for a plain file this account owns, whererm /tmp/fm-shipfoois the complete and safe fix. On a--relaunchthis message is the operator's whole guidance, with the previous agent already stopped.The sibling call sites are unaffected:
$SPAWN_READY_ROOTreally was a directorymktemp -dcreated, so "gone, or replaced by a symlink" is exact there. Only the adopted-root pre-check at :2626 can reach a never-was-a-directory path.Raising this as ask-user rather than auto-fix because it touches refusal wording the author has legislated across earlier rounds, and because extending the remedy to a second KIND revisits a stated design choice. The narrow version is to distinguish the arms - report a symlink and a missing path as they are today, and report any other non-directory as what
statsays it is - and to let the owned-and-removable case carry the same "remove it and spawn again" sentence the mode arm already has.✅ **Test** - passed
✅ No issues found.
bash bin/fm-test-run.sh tests/fm-spawn-shell-ready.test.sh— 18 cases, all passing (both spawn-time gates, five refusal classes, temp-root privacy, re-send backoff, one-poll cost on a ready shell)bash bin/fm-test-run.sh tests/fm-backend-herdr.test.sh tests/fm-backend-orca.test.sh— includes the head commit'stest_send_text_line_collapses_every_cli_status_to_undeliveredandfm-spawn.sh --backend orca: a rejected send is undelivered, never uncleared inputbash bin/fm-test-run.sh tests/fm-spawn-worktree-settle.test.sh tests/fm-backend.test.sh— the spawn paths the new gate sits insideManual before/after reproduction:bash repro-shell-ready.sh <repo> 10b93b2 <out>— real fm-spawn.sh run against a swallowing-shell fake backend at base vs target, capturing CLI output, exit status, the shell's own swallowed/ran line log, state/<id>.meta and state/<id>.statusManual reproduction of the false-success symptom:bash repro-before-launch-swallow.sh <repo> 10b93b2 <out>— base commit exits 0 and printsspawned …while the launch command was swallowed and no agent startedManual adapter-status check:bash repro-herdr-status-collapse.sh <repo> 10b93b2 <out>— real fm_backend_herdr_send_text_line against a fake herdr CLI exiting 0/1/2/3/7, before vs afterVerified the worktree is clean (git status --porcelainempty) and no per-task temp roots or evidence scratch dirs were left under /tmpbin/fm-spawn.sh:2691- Judgment call recorded for transparency, not a request. This change added FM_SPAWN_SHELL_READY_POLLS/INTERVAL/RESEND and a 60s default budget whose expiry is an operator-visible refusal ("never confirmed it was reading input within 60s"). I resolved the resulting doc inaccuracy by trimming docs/architecture.md's claim that the header owns those knobs, rather than by adding them to the header that fm-spawn.sh --help prints. Reasoning: the knobs' own comment declares them "test and pathological-host use, defaults are the contract", so advertising them in --help would promote them into the operator contract the author deliberately kept them out of, and the repo already keeps sibling spawn-internal knobs (FM_KIMI_*, FM_SPAWN_NO_GUARD) documented only at their definition. The consequence is that an operator on a genuinely slow host can only widen the budget by reading the script body. No action needed unless the budget is expected to be operator-tunable, in which case the three names and the default belong in the header block so --help carries them.docs/fm-test-portable-shards.md:79- Out-of-scope follow-up, flagged rather than fixed. The per-shard table records 29/28/30/30 scripts (117 total, measured on the 2026-08-21 CI run); the lanes today list 31/33/33/33 (130). That is pre-existing drift of 13 scripts, of which this change contributes exactly one (tests/fm-spawn-shell-ready.test.sh, which lands in portable-serial-4of4). I did not update it: the counts and durations are a snapshot of a specific green CI run, the doc's own refresh recipe requires downloading that run's timing artifacts, and past test-adding commits (60bedde, 9ce69ac, 3e5577b, fb2ce5b) did not refresh it either. Nothing is unsafe - the doc states that hints affect balance only and the coverage guard keeps the partition complete and disjoint whatever they say - but the doc also instructs refreshing hints whenever the serial lane gains scripts, and it is now 13 behind. Worth one dedicated pass that re-runs the recipe against a current green run.✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.