Skip to content

chore: update pull request - #3132

Closed
tomashco wants to merge 14 commits into
kunchenguid:mainfrom
tomashco:fm/spawn-shell-ready-r1
Closed

tomashco wants to merge 14 commits into
kunchenguid:mainfrom
tomashco:fm/spawn-shell-ready-r1

Conversation

@tomashco

@tomashco tomashco commented Aug 26, 2026 •

Copy link
Copy Markdown

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 get sat 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:

M	AGENTS.md
M	bin/backends/cmux.sh
M	bin/backends/herdr.sh
M	bin/backends/orca.sh
M	bin/backends/tmux.sh
M	bin/backends/zellij.sh
M	bin/fm-spawn.sh
M	bin/fm-test-run.sh
M	docs/architecture.md
M	tests/fm-backend-cmux.test.sh
M	tests/fm-backend-herdr.test.sh
M	tests/fm-backend-orca.test.sh
M	tests/fm-backend-zellij.test.sh
M	tests/fm-backend.test.sh
M	tests/fm-busy-adapter-wiring.test.sh
M	tests/fm-control-relaunch.test.sh
M	tests/fm-gate-refuse.test.sh
M	tests/fm-grok-harness.test.sh
M	tests/fm-kimi-harness.test.sh
M	tests/fm-muse-harness.test.sh
M	tests/fm-secondmate-harness.test.sh
M	tests/fm-secondmate-liveness.test.sh
M	tests/fm-secondmate-sync.test.sh
M	tests/fm-session-start.test.sh
M	tests/fm-shared-captain-inheritance.test.sh
M	tests/fm-spawn-dispatch-profile.test.sh
M	tests/fm-spawn-pool-base-freshen.test.sh
A	tests/fm-spawn-shell-ready.test.sh
M	tests/fm-spawn-worktree-settle.test.sh
M	tests/fm-tangle-guard.test.sh
M	tests/fm-trace-context-spawn.test.sh
M	tests/lib.sh
M	tests/remote-herdr-fixture.sh
M	tests/secondmate-helpers.sh

Risk Assessment

⚠️ Medium: The implementation traces clean against its stated intent with strong behavioral coverage, but it is a broad change on the spawn critical path for every backend that adds two 60s-budget gates and several new refusal classes to every spawn, so the residual concerns are latency for synchronous callers like fm-bootstrap and the wide fan-out of test fakes that had to learn to execute typed lines - both better confirmed by the test step than deferred, while the single finding above is safe as a follow-up.

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 swallowed treehouse get burning the whole 60s settle budget, and a swallowed launch command exiting 0 with spawned … 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)

# fm/spawn-shell-ready-r1 — end-to-end evidence

Intent: fm-spawn must prove the endpoint shell is actually READING INPUT before
each fixed spawn-time send, by a side effect the shell itself produces (not by
pane text), and refuse with a named diagnostic where readiness cannot be proven
or a send is typed but neither submitted nor cleared.

Every transcript below is raw output of the real `bin/fm-spawn.sh`, driven
against a fake backend that models a pty line discipline with a swallow budget:
the first N submitted lines are discarded (what direnv+devenv startup does live
on 2026-08-25), every line after that is executed. The "fake pty line log"
section is the shell's own record of what it swallowed vs. what it ran — so a
command that only *appears* in the pane cannot pass as one that ran.

`base` = 10b93b2cc6f4241e87fccaee2e357c33a7347a53, `target` = 4bf7b32.

## Reproducing the reported defect (base commit)

| artifact | what it shows |
| --- | --- |
| `01-before-swallowed-send-lost.txt` | `treehouse get` is swallowed; the worktree-settle loop burns its whole 60s budget waiting on a command that never executed, then blames the worktree. No agent. |
| `01b-before-launch-swallowed-reports-spawned.txt` | The swallow lands in the worktree shell instead: the export and the launch command are both swallowed, yet the spawn exits 0 and prints `spawned …`, and the fleet sees a published task record. **A task that reports as spawned while no agent is working** — the exact reported symptom. |

## The fix (target commit)

| artifact | what it shows |
| --- | --- |
| `02-after-swallowed-send-delivered.txt` | Same swallowing shell. The probe `touch '<task-tmp>/shell-ready.XXXX/worktree-entry'` is swallowed 3× and re-sent until the shell itself creates the marker; only then is `treehouse get` typed — and it *runs*. Spawn succeeds. |
| `03-after-swallowed-launch-delivered.txt` | The sibling gate: the worktree shell's own startup swallows 2 probes, the launch gate waits it out, and the agent process really starts. |
| `04-refusal-shell-never-reads.txt` | A shell that never reads: bounded refusal naming the unconfirmed readiness, exit 1, no meta, no agent, per-task temp root removed. |
| `05-refusal-recorded-in-status.txt` | The post-meta launch gate: refusal is recorded as the task's durable last state in `state/<id>.status`, so a background spawn is not silently reported as fine. |
| `06-refusal-unreachable-endpoint.txt` | An endpoint that cannot be reached at all is told as itself, with the backend's own error, after **1** send attempt out of a 40-poll budget — not a full budget of silent retries misdiagnosed as a slow shell. |
| `07-refusal-uncleared-input.txt` | A composed send (cmux) typed but neither submitted nor cleared: refusal names the text sitting in the shell's input line, and the probe is typed exactly once (no re-send appended onto it). |
| `08-herdr-send-status-collapse.txt` | Head commit: the real herdr adapter's status before/after. A herdr CLI exit of 2 or 3 used to be retold as a pane state herdr's one-call `pane run` cannot produce; it now arrives as 1 (undelivered). |

## Reproduce

`` `
bash repro-shell-ready.sh            <repo-root> <base-commit> <out-dir>
bash repro-before-launch-swallow.sh  <repo-root> <base-commit> <out-dir>
bash repro-herdr-status-collapse.sh  <repo-root> <base-commit> <out-dir>
`` `

Artifacts 04-07 shorten the readiness budget to 10 polls x 0.3s (the shipped
default is 300 x 0.2s = 60s) so the refusal arrives in seconds; that budget is
the only thing the `FM_SPAWN_SHELL_READY_*` knobs change, and it appears in the
refusal text as "within 3s".

Automated coverage run alongside these transcripts, all passing:

`` `
bash bin/fm-test-run.sh tests/fm-spawn-shell-ready.test.sh          # 18 cases, the gate itself
bash bin/fm-test-run.sh tests/fm-backend-herdr.test.sh \
                        tests/fm-backend-orca.test.sh               # send-adapter status contracts
bash bin/fm-test-run.sh tests/fm-spawn-worktree-settle.test.sh \
                        tests/fm-backend.test.sh                    # the spawn paths this gate sits in
`` `
Evidence: BEFORE (base 10b93b2): swallowed `treehouse get` burns the whole settle budget

Source: BEFORE (base 10b93b2): swallowed treehouse get burns 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)

$ bin/fm-spawn.sh ev-before-63891 <project> --mode no-mistakes --yolo off --backend tmux
warning: /var/folders/0y/wlpqfzpn1td3s1n54dfwkfg80000gn/T//fm-spawn-shell-ready.u6QIKv/ev-before/home/data/ev-before-63891/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
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)
--- task last state state/ev-before-63891.status: (absent)
Evidence: BEFORE (base 10b93b2): the reported symptom - reports `spawned` with no agent working

Source: BEFORE (base 10b93b2): the reported symptom - reports spawned with 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)

$ bin/fm-spawn.sh ev-before-launch-35591 <project> --mode no-mistakes --yolo off --backend tmux
warning: /var/folders/0y/wlpqfzpn1td3s1n54dfwkfg80000gn/T//fm-spawn-shell-ready.iZZxNq/ev-before-launch/home/data/ev-before-launch-35591/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 ev-before-launch-35591 harness=codex kind=ship mode=no-mistakes yolo=off window=firstmate:fm-ev-before-launch-35591 worktree=/var/folders/0y/wlpqfzpn1td3s1n54dfwkfg80000gn/T//fm-spawn-shell-ready.iZZxNq/ev-before-launch/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 -u CURSOR_INVOKED_AS codex --dangerously-bypass-approvals-and-sandbox -c "notify=[\"bash\",\"-c\",\"touch '/private/var/folders/0y/wlpqfzpn1td3s1n54dfwkfg80000gn/T/fm-spawn-shell-ready.iZZxNq/ev-before-launch/home/state/ev-before-launch-35591.turn-ended'\"]" "$('/var/folders/0y/wlpqfzpn1td3s1n54dfwkfg80000gn/T/fm-ready-evidence-b.N14USX/base/bin/fm-operational-input.sh' encode launch-brief < '/var/folders/0y/wlpqfzpn1td3s1n54dfwkfg80000gn/T//fm-spawn-shell-ready.iZZxNq/ev-before-launch/home/data/ev-before-launch-35591/brief.md')"
--- 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 get runs

$ 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: YES

$ bin/fm-spawn.sh ev-after-63891 <project> --mode no-mistakes --yolo off --backend tmux
warning: /var/folders/0y/wlpqfzpn1td3s1n54dfwkfg80000gn/T//fm-spawn-shell-ready.u6QIKv/ev-after/home/data/ev-after-63891/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 ev-after-63891 harness=codex kind=ship mode=no-mistakes yolo=off window=firstmate:fm-ev-after-63891 worktree=/var/folders/0y/wlpqfzpn1td3s1n54dfwkfg80000gn/T//fm-spawn-shell-ready.u6QIKv/ev-after/wt
--- exit status: 0
--- what the endpoint shell actually did (fake pty line log)
    swallowed	touch '/tmp/fm-ev-after-63891/shell-ready.WunHN8za/worktree-entry'
    swallowed	touch '/tmp/fm-ev-after-63891/shell-ready.WunHN8za/worktree-entry'
    swallowed	touch '/tmp/fm-ev-after-63891/shell-ready.WunHN8za/worktree-entry'
    ran	touch '/tmp/fm-ev-after-63891/shell-ready.WunHN8za/worktree-entry'
    ran	treehouse get
    ran	touch '/tmp/fm-ev-after-63891/shell-ready.WunHN8za/launch'
    ran	export GOTMPDIR=/tmp/fm-ev-after-63891/gotmp
    ran	env -u CURSOR_AGENT -u CURSOR_INVOKED_AS codex --dangerously-bypass-approvals-and-sandbox -c "notify=[\"bash\",\"-c\",\"touch '/private/var/folders/0y/wlpqfzpn1td3s1n54dfwkfg80000gn/T/fm-spawn-shell-ready.u6QIKv/ev-after/home/state/ev-after-63891.turn-ended'\"]" "$('/Users/tomashco/.no-mistakes/worktrees/b149989db62a/01M117X8090S191SWWN1060HHH/bin/fm-operational-input.sh' encode launch-brief < '/var/folders/0y/wlpqfzpn1td3s1n54dfwkfg80000gn/T//fm-spawn-shell-ready.u6QIKv/ev-after/home/data/ev-after-63891/brief.md')"
--- agent process started: YES
--- task record state/ev-after-63891.meta: 
    window=firstmate:fm-ev-after-63891
    endpoint_task_id=ev-after-63891
    worktree=/var/folders/0y/wlpqfzpn1td3s1n54dfwkfg80000gn/T//fm-spawn-shell-ready.u6QIKv/ev-after/wt
    project=/var/folders/0y/wlpqfzpn1td3s1n54dfwkfg80000gn/T/fm-spawn-shell-ready.u6QIKv/ev-after/project
    harness=codex
    kind=ship
    mode=no-mistakes
    yolo=off
    tasktmp=/tmp/fm-ev-after-63891
    model=default
    effort=default
    spawn_gen=s1787825010.77775.14319
--- task last state state/ev-after-63891.status: (absent)
Evidence: 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

$ bin/fm-spawn.sh ev-inner-63891 <project> --mode no-mistakes --yolo off --backend tmux
warning: /var/folders/0y/wlpqfzpn1td3s1n54dfwkfg80000gn/T//fm-spawn-shell-ready.u6QIKv/ev-inner/home/data/ev-inner-63891/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 ev-inner-63891 harness=codex kind=ship mode=no-mistakes yolo=off window=firstmate:fm-ev-inner-63891 worktree=/var/folders/0y/wlpqfzpn1td3s1n54dfwkfg80000gn/T//fm-spawn-shell-ready.u6QIKv/ev-inner/wt
--- exit status: 0
--- what the endpoint shell actually did (fake pty line log)
    ran	touch '/tmp/fm-ev-inner-63891/shell-ready.Uy6exluF/worktree-entry'
    ran	treehouse get
    swallowed	touch '/tmp/fm-ev-inner-63891/shell-ready.Uy6exluF/launch'
    swallowed	touch '/tmp/fm-ev-inner-63891/shell-ready.Uy6exluF/launch'
    ran	touch '/tmp/fm-ev-inner-63891/shell-ready.Uy6exluF/launch'
    ran	export GOTMPDIR=/tmp/fm-ev-inner-63891/gotmp
    ran	env -u CURSOR_AGENT -u CURSOR_INVOKED_AS codex --dangerously-bypass-approvals-and-sandbox -c "notify=[\"bash\",\"-c\",\"touch '/private/var/folders/0y/wlpqfzpn1td3s1n54dfwkfg80000gn/T/fm-spawn-shell-ready.u6QIKv/ev-inner/home/state/ev-inner-63891.turn-ended'\"]" "$('/Users/tomashco/.no-mistakes/worktrees/b149989db62a/01M117X8090S191SWWN1060HHH/bin/fm-operational-input.sh' encode launch-brief < '/var/folders/0y/wlpqfzpn1td3s1n54dfwkfg80000gn/T//fm-spawn-shell-ready.u6QIKv/ev-inner/home/data/ev-inner-63891/brief.md')"
--- agent process started: YES
--- task record state/ev-inner-63891.meta: 
    window=firstmate:fm-ev-inner-63891
    endpoint_task_id=ev-inner-63891
    worktree=/var/folders/0y/wlpqfzpn1td3s1n54dfwkfg80000gn/T//fm-spawn-shell-ready.u6QIKv/ev-inner/wt
    project=/var/folders/0y/wlpqfzpn1td3s1n54dfwkfg80000gn/T/fm-spawn-shell-ready.u6QIKv/ev-inner/project
    harness=codex
    kind=ship
    mode=no-mistakes
    yolo=off
    tasktmp=/tmp/fm-ev-inner-63891
    model=default
    effort=default
    spawn_gen=s1787825014.78818.29212
--- task last state state/ev-inner-63891.status: (absent)
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)

$ bin/fm-spawn.sh ev-never-63891 <project> --mode no-mistakes --yolo off --backend tmux
warning: /var/folders/0y/wlpqfzpn1td3s1n54dfwkfg80000gn/T//fm-spawn-shell-ready.u6QIKv/ev-never/home/data/ev-never-63891/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
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'
    swallowed	touch '/tmp/fm-ev-never-63891/shell-ready.FE7y6r2h/worktree-entry'
    swallowed	touch '/tmp/fm-ev-never-63891/shell-ready.FE7y6r2h/worktree-entry'
--- agent process started: NO
--- task record state/ev-never-63891.meta: (absent)
--- task last state state/ev-never-63891.status: (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: NO

$ bin/fm-spawn.sh ev-launch-63891 <project> --mode no-mistakes --yolo off --backend tmux
warning: /var/folders/0y/wlpqfzpn1td3s1n54dfwkfg80000gn/T//fm-spawn-shell-ready.u6QIKv/ev-launch/home/data/ev-launch-63891/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
error: 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
--- exit status: 1
--- what the endpoint shell actually did (fake pty line log)
    ran	touch '/tmp/fm-ev-launch-63891/shell-ready.R5guUQFD/worktree-entry'
    ran	treehouse get
    swallowed	touch '/tmp/fm-ev-launch-63891/shell-ready.R5guUQFD/launch'
    swallowed	touch '/tmp/fm-ev-launch-63891/shell-ready.R5guUQFD/launch'
    swallowed	touch '/tmp/fm-ev-launch-63891/shell-ready.R5guUQFD/launch'
--- agent process started: NO
--- task record state/ev-launch-63891.meta: 
    window=firstmate:fm-ev-launch-63891
    endpoint_task_id=ev-launch-63891
    worktree=/var/folders/0y/wlpqfzpn1td3s1n54dfwkfg80000gn/T//fm-spawn-shell-ready.u6QIKv/ev-launch/wt
    project=/var/folders/0y/wlpqfzpn1td3s1n54dfwkfg80000gn/T/fm-spawn-shell-ready.u6QIKv/ev-launch/project
    harness=codex
    kind=ship
    mode=no-mistakes
    yolo=off
    tasktmp=/tmp/fm-ev-launch-63891
    model=default
    effort=default
    spawn_gen=s1787825025.80022.32510
--- 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
Evidence: 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: NO

$ bin/fm-spawn.sh ev-unreachable-63891 <project> --mode no-mistakes --yolo off --backend tmux
warning: /var/folders/0y/wlpqfzpn1td3s1n54dfwkfg80000gn/T//fm-spawn-shell-ready.u6QIKv/ev-unreachable/home/data/ev-unreachable-63891/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
can't find pane: @1
error: task ev-unreachable-63891'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-63891
--- exit status: 1
--- send attempts made before refusing: 1 (budget was 40 polls)
--- agent process started: NO
Evidence: 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: NO

$ bin/fm-spawn.sh ev-stranded-63891 <project> --mode no-mistakes --yolo off --backend cmux
warning: /var/folders/0y/wlpqfzpn1td3s1n54dfwkfg80000gn/T//fm-spawn-shell-ready.u6QIKv/ev-stranded/home/data/ev-stranded-63891/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
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: NO
Evidence: 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 continues

Real adapter fm_backend_herdr_send_text_line, driven against a fake herdr CLI
whose `pane run` exits with the status in column 1.

herdr CLI exit   | adapter status -> fm-spawn     | what the operator is told
-----------------+--------------------------------+-----------------------------------------
0                | before 0 / after 0             | before: send landed - spawn continues
                 |                                | after:  send landed - spawn continues
1                | before 1 / after 1             | before: endpoint could not be reached: the herdr backend failed to deliver <text> (undelivered)
                 |                                | after:  endpoint could not be reached: the herdr backend failed to deliver <text> (undelivered)
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: the herdr backend failed to deliver <text> (undelivered)
7                | before 7 / after 1             | before: unknown status
                 |                                | after:  endpoint could not be reached: the herdr backend failed to deliver <text> (undelivered)
Evidence: Targeted suite results
$ bash bin/fm-test-run.sh tests/fm-spawn-shell-ready.test.sh
(18 ok lines) FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0

$ bash bin/fm-test-run.sh tests/fm-backend-herdr.test.sh tests/fm-backend-orca.test.sh
ok - fm_backend_herdr_send_text_line: collapses every herdr CLI failure status to 1, never into spawn_send_text_line's reserved 2/3
ok - fm-spawn.sh --backend orca: a rejected send is undelivered, never uncleared input
FM_TEST_SUMMARY total=2 failed=0 skipped_gate=0

$ bash bin/fm-test-run.sh tests/fm-spawn-worktree-settle.test.sh tests/fm-backend.test.sh
FM_TEST_SUMMARY total=2 failed=0 skipped_gate=0
Evidence: Reproduction harnesses (re-runnable, take <repo-root> <base-commit> <out-dir>)

Source: Reproduction harnesses (re-runnable, take <repo-root> <base-commit> <out-dir>)

#!/usr/bin/env bash
# Evidence harness for fm/spawn-shell-ready-r1.
#
# Drives the REAL bin/fm-spawn.sh against the fake pty-line-discipline backend
# that tests/fm-spawn-shell-ready.test.sh owns (a shell stub with a swallow
# budget: the first N submitted lines are discarded, every line after that is
# executed). Captures the operator-visible CLI transcript of each scenario,
# once against the base commit (the reported defect) and once against the
# target commit (the fix), plus the refusal paths.
#
# Usage: repro-shell-ready.sh <repo-root> <base-commit> <out-dir>
set -u

REPO=$1
BASE=$2
OUT=$3
mkdir -p "$OUT"

WORK=$(mktemp -d "${TMPDIR:-/tmp}/fm-ready-evidence.XXXXXX")
trap 'rm -rf "$WORK"' EXIT

# The base tree, extracted read-only from git, so the same scenario can be run
# against the code as it was before this change.
mkdir -p "$WORK/base"
git -C "$REPO" archive "$BASE" | tar -x -C "$WORK/base"

# The suite's fixture builders, cut above the line that invokes its test cases
# so sourcing defines the helpers without running the suite. The lib.sh source
# line is rewritten to an absolute path because BASH_SOURCE no longer points
# into tests/.
HELPERS="$WORK/helpers.sh"
sed -n '1,1001p' "$REPO/tests/fm-spawn-shell-ready.test.sh" \
  | sed "s|\. \"\$(dirname \"\${BASH_SOURCE\[0\]}\")/lib.sh\"|. \"$REPO/tests/lib.sh\"|" \
  > "$HELPERS"
# shellcheck disable=SC1090
. "$HELPERS"

TAG=$$

banner() { printf '\n===== %s =====\n' "$1"; }

# ---------------------------------------------------------------------------
# Scenario 1 - the reported defect, against the BASE commit.
# A pane whose shell swallows its first 3 submitted lines (what direnv+devenv
# startup does live).
# ---------------------------------------------------------------------------
run_case() {  # <label> <spawn-binary> <outfile> <case-name> <id> <outer> <inner> <backend> [extra env...]
  local label=$1 spawn_bin=$2 outfile=$3 name=$4 id=$5 outer=$6 inner=$7 backend=$8
  shift 8
  local rec out status
  use_task_tmp "$id"
  rec=$(make_shell_case "$name" "$id" "$outer" "$inner" "$backend")
  read_shell_record "$rec"
  SPAWN=$spawn_bin
  out=$(run_shell_spawn "$id" "$@")
  status=$?
  {
    printf '$ bin/fm-spawn.sh %s <project> --mode no-mistakes --yolo off --backend %s\n' "$id" "$backend"
    printf '%s\n' "$out"
    printf -- '--- exit status: %s\n' "$status"
    printf -- '--- what the endpoint shell actually did (fake pty line log)\n'
    if [ -s "$STATE_DIR/lines.log" ]; then
      sed 's/^/    /' "$STATE_DIR/lines.log"
    else
      printf '    (no line was ever submitted to the shell)\n'
    fi
    printf -- '--- agent process started: '
    if [ -f "$STATE_DIR/launched.log" ]; then printf 'YES\n'; else printf 'NO\n'; fi
    printf -- '--- task record state/%s.meta: ' "$id"
    if [ -f "$HOME_DIR/state/$id.meta" ]; then
      printf '\n'; sed 's/^/    /' "$HOME_DIR/state/$id.meta"
    else
      printf '(absent)\n'
    fi
    printf -- '--- task last state state/%s.status: ' "$id"
    if [ -f "$HOME_DIR/state/$id.status" ]; then
      printf '\n'; sed 's/^/    /' "$HOME_DIR/state/$id.status"
    else
      printf '(absent)\n'
    fi
  } > "$outfile" 2>&1
  banner "$label"
  cat "$outfile"
}

run_case \
  "1. BEFORE (base $BASE): shell swallows its first sends" \
  "$WORK/base/bin/fm-spawn.sh" \
  "$OUT/01-before-swallowed-send-lost.txt" \
  ev-before "ev-before-$TAG" 3 0 tmux \
  FM_SPAWN_SHELL_READY_INTERVAL=0.05

run_case \
  "2. AFTER (target): same swallowing shell" \
  "$REPO/bin/fm-spawn.sh" \
  "$OUT/02-after-swallowed-send-delivered.txt" \
  ev-after "ev-after-$TAG" 3 0 tmux \
  FM_SPAWN_SHELL_READY_INTERVAL=0.05

run_case \
  "3. AFTER (target): worktree shell swallows the launch command" \
  "$REPO/bin/fm-spawn.sh" \
  "$OUT/03-after-swallowed-launch-delivered.txt" \
  ev-inner "ev-inner-$TAG" 0 2 tmux \
  FM_SPAWN_SHELL_READY_INTERVAL=0.05

run_case \
  "4. AFTER (target): shell never reads input - refusal" \
  "$REPO/bin/fm-spawn.sh" \
  "$OUT/04-refusal-shell-never-reads.txt" \
  ev-never "ev-never-$TAG" 999 0 tmux \
  FM_SPAWN_SHELL_READY_POLLS=10 FM_SPAWN_SHELL_READY_INTERVAL=0.3 FM_SPAWN_SHELL_READY_RESEND=3

run_case \
  "5. AFTER (target): worktree shell never reads - refusal recorded as the task's last state" \
  "$REPO/bin/fm-spawn.sh" \
  "$OUT/05-refusal-recorded-in-status.txt" \
  ev-launch "ev-launch-$TAG" 0 999 tmux \
  FM_SPAWN_SHELL_READY_POLLS=10 FM_SPAWN_SHELL_READY_INTERVAL=0.3 FM_SPAWN_SHELL_READY_RESEND=3

# Endpoint that cannot be reached at all: a different named diagnostic.
unreachable_case() {
  local id="ev-unreachable-$TAG" rec out status
  use_task_tmp "$id"
  rec=$(make_shell_case ev-unreachable "$id" 0 0 tmux)
  read_shell_record "$rec"
  : > "$STATE_DIR/send-fails"
  SPAWN="$REPO/bin/fm-spawn.sh"
  out=$(run_shell_spawn "$id" FM_SPAWN_SHELL_READY_POLLS=40 FM_SPAWN_SHELL_READY_INTERVAL=0.05)
  status=$?
  {
    printf '$ bin/fm-spawn.sh %s <project> --mode no-mistakes --yolo off --backend tmux\n' "$id"
    printf '%s\n' "$out"
    printf -- '--- exit status: %s\n' "$status"
    printf -- '--- send attempts made before refusing: %s (budget was 40 polls)\n' \
      "$(wc -l < "$STATE_DIR/send-attempts" 2>/dev/null | tr -d ' ')"
    printf -- '--- agent process started: '
    if [ -f "$STATE_DIR/launched.log" ]; then printf 'YES\n'; else printf 'NO\n'; fi
  } > "$OUT/06-refusal-unreachable-endpoint.txt" 2>&1
  banner "6. AFTER (target): endpoint unreachable - refuses at once with the backend's own error"
  cat "$OUT/06-refusal-unreachable-endpoint.txt"
}
unreachable_case

# A composed send (cmux) that is typed but neither submitted nor cleared.
stranded_case() {
  local id="ev-stranded-$TAG" rec out status
  use_task_tmp "$id"
  rec=$(make_shell_case ev-stranded "$id" 0 0 cmux)
  read_shell_record "$rec"
  printf 'worktree-entry\n' > "$STATE_DIR/stranded"
  SPAWN="$REPO/bin/fm-spawn.sh"
  out=$(run_shell_spawn "$id" FM_SPAWN_SHELL_READY_POLLS=4 FM_SPAWN_SHELL_READY_INTERVAL=0.05 FM_SPAWN_SHELL_READY_RESEND=2)
  status=$?
  {
    printf '$ bin/fm-spawn.sh %s <project> --mode no-mistakes --yolo off --backend cmux\n' "$id"
    printf '%s\n' "$out"
    printf -- '--- exit status: %s\n' "$status"
    printf -- '--- probe lines typed into the pane: %s (a re-send would have appended a second)\n' \
      "$(grep -c 'touch ' "$STATE_DIR/lines.log" 2>/dev/null | tr -d ' ')"
    printf -- '--- agent process started: '
    if [ -f "$STATE_DIR/launched.log" ]; then printf 'YES\n'; else printf 'NO\n'; fi
  } > "$OUT/07-refusal-uncleared-input.txt" 2>&1
  banner "7. AFTER (target): probe typed but neither submitted nor cleared - refuses as uncleared input"
  cat "$OUT/07-refusal-uncleared-input.txt"
}
stranded_case

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ⚠️ bin/backends/herdr.sh:2539 - This change makes statuses 2 and 3 from spawn_send_text_line mean 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_line is the one send adapter left passing an unbounded external status straight through: line 2538 collapses target_ready to 1, but line 2539 returns fm_backend_herdr_cli's exit code verbatim, and that is herdr'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 &#34;$T&#34; launch ... (bin/fm-spawn.sh:3386) sends the probe; herdr ... pane run exits 2. bin/fm-spawn.sh:2712 matches spawn_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 run failure - 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 1 to line 2539. Secondary, in the same line: the &gt;/dev/null 2&gt;&amp;1 discards 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, but tmux send-keys only ever exits 0 or 1, so it is safe today; adding the same || return 1 there would make the rule uniform rather than incidentally true.

  • ℹ️ bin/fm-spawn.sh:2738 - spawn_wait_shell_ready carries 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 begin rm -f &#34;$marker&#34;, 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_cleared were 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 &lt;status&gt; &lt;label&gt; &lt;unreachable-phrase&gt; &lt;what&gt; returning 0 when the send landed and 1 with SPAWN_READY_REFUSAL set otherwise; the caller keeps the rm -f &#34;$marker&#34; 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 &#34;$dir&#34; ] || [ -L &#34;$dir&#34; ]; then SPAWN_READY_ROOT_PRIVACY_ISSUE=&#34;it is not a plain directory any more - gone, or replaced by a symlink&#34;; 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 shipfoo on a host where /tmp/fm-shipfoo exists as a regular file this account owns (a stray shell redirect is the ordinary way that happens):

  1. :2464 (umask 077; mkdir &#34;$TASK_TMP&#34;) fails EEXIST, so SPAWN_TASK_TMP_CREATED=0.
  2. :2626 [ &#34;$SPAWN_TASK_TMP_CREATED&#34; != 1 ] and [ -e &#34;$TASK_TMP&#34; ] both hold, so the adopted-root identity check runs.
  3. :2509 [ ! -d &#34;$dir&#34; ] is true, so KIND becomes identity.
  4. spawn_refuse_unprivate_task_tmp (:2571) sets remedy only when KIND is mode, 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-shipfoo then shows -rw-r--r-- 1 &lt;them&gt; &lt;them&gt; - 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-mode value 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, where rm /tmp/fm-shipfoo is the complete and safe fix. On a --relaunch this message is the operator's whole guidance, with the previous agent already stopped.

The sibling call sites are unaffected: $SPAWN_READY_ROOT really was a directory mktemp -d created, 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 stat says 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's test_send_text_line_collapses_every_cli_status_to_undelivered and fm-spawn.sh --backend orca: a rejected send is undelivered, never uncleared input
  • bash bin/fm-test-run.sh tests/fm-spawn-worktree-settle.test.sh tests/fm-backend.test.sh — the spawn paths the new gate sits inside
  • Manual before/after reproduction: bash repro-shell-ready.sh &lt;repo&gt; 10b93b2 &lt;out&gt; — 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>.status
  • Manual reproduction of the false-success symptom: bash repro-before-launch-swallow.sh &lt;repo&gt; 10b93b2 &lt;out&gt; — base commit exits 0 and prints spawned … while the launch command was swallowed and no agent started
  • Manual adapter-status check: bash repro-herdr-status-collapse.sh &lt;repo&gt; 10b93b2 &lt;out&gt; — real fm_backend_herdr_send_text_line against a fake herdr CLI exiting 0/1/2/3/7, before vs after
  • Verified the worktree is clean (git status --porcelain empty) and no per-task temp roots or evidence scratch dirs were left under /tmp
⚠️ **Document** - 2 infos
  • ℹ️ bin/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.

@greptile-apps

greptile-apps Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

Confidence Score: 4/5

The 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

Comment thread bin/fm-spawn.sh Resolved
Comment thread bin/fm-spawn.sh Resolved
Comment thread bin/fm-spawn.sh
Comment on lines +863 to +864
if rmdir "$TASK_TMP/gotmp" 2>/dev/null; then
rmdir "$TASK_TMP" 2>/dev/null || mkdir "$TASK_TMP/gotmp" 2>/dev/null || true

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Shared temp cleanup race

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.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: triage for #3132 (tomashco, fix(bin): prove the endpoint shell reads input before spawn types into it).

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):

  • One captain, one interface — aligns. Turns silent swallowed keystrokes into a loud shell-readiness refusal instead of a false allocator/cwd diagnosis; evidence: bin/fm-spawn.sh readiness gate + tests/fm-spawn-shell-ready.test.sh + docs/architecture.md.
  • Authority explicit — aligns. Env-overridable bounds (FM_SPAWN_SHELL_READY_*); no new default captain autonomy.
  • Scripts own mechanics — aligns. Bounded probe/resend; private uid-owned marker dir; rmdir-only abort cleanup so shared task-tmp across homes is not rm -rf’d. Evidence: spawn abort trap + backend status 2/3 reservation in bin/backends/cmux.sh / zellij.sh / orca.sh.
  • Restart / Delegation / vendor / Scope — aligns. Backend-agnostic proof; adapters only for delivery semantics. Full diff reviewed (spawn + backends + many test fixtures); no .github/workflows/*.

OVERLAP (do not merge one leftover): open #3101 (adriantoczydlowski, fix(bin): gate the first spawn send on proven pane-shell readiness) is existing help for the same shell-readiness class as #3097. #3132 is a deeper marker-file readiness gate covering every fixed spawn-time send. Author bodies both target spawn typing before shell ready. Hold as overlap with #3101; do not land one leftover while the other is open. Body does not claim Fixes/Closes #3097.

Security / fishy: none. Greptile noted abort-cleanup / concurrent-home risk; the diff’s rmdir-only shared-root cleanup is intentional mitigation — not disguised malice.

Gates: mergeable=MERGEABLE. Cross-fork — approved first-time fork CI: runs 33010197563 (CI), 33010197571 (Require no-mistakes). Attestation stamps head_sha=3ca79221… ≠ current HEAD 3b5bcd20…. No auto-merge (attestation mismatch + unresolved overlap).

Decision: waiting-ci / waiting-author for matching attestation + green CI, and overlap resolution with #3101. Not pinging; not escalating.

@tomashco
tomashco force-pushed the fm/spawn-shell-ready-r1 branch from 3b5bcd2 to 2a5ae4c Compare August 27, 2026 09:01
Comment thread bin/fm-spawn.sh
Comment on lines +878 to +879
if rmdir "$TASK_TMP/gotmp" 2>/dev/null; then
rmdir "$TASK_TMP" 2>/dev/null || mkdir "$TASK_TMP/gotmp" 2>/dev/null || true

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Shared temp cleanup race

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.

Tommaso Cholewa and others added 14 commits August 27, 2026 11:13
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.
@tomashco
tomashco force-pushed the fm/spawn-shell-ready-r1 branch from 2a5ae4c to 8aadd2a Compare August 27, 2026 10:16
@tomashco tomashco changed the title fix(bin): prove the endpoint shell reads input before spawn types into it chore: update pull request Aug 27, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Reviewed HEAD 8aadd2a0c910233952a2f1bec4729212701ceb68 vs main 10b93b2cc6f4241e87fccaee2e357c33a7347a53. Whole thread read (prior stamp on older HEAD 3b5bcd20; Greptile still not merge-clean on abort-cleanup). Full diff reviewed: bin/fm-spawn.sh, all five bin/backends/*.sh send adapters, tests/fm-spawn-shell-ready.test.sh plus the fixture/fan-out test updates, AGENTS.md, docs/architecture.md. No .github/workflows/*. tomashco is not blocked. Not disguised security.

Class: corrective. Spawn typed treehouse get / env / launch into a pane whose shell was still in rc/direnv, so keystrokes were swallowed (pty echo is not proof of execution). This HEAD proves the endpoint shell is reading input via a private uid-owned marker file only an executing shell can create, refuses on timeout, and gives send failures three reserved statuses (undelivered / stranded uncleared / typed-then-cleared). Adapters that submit in one call collapse every failure to 1. Abort cleanup rmdirs the shared /tmp/fm-<id> root and only rm -rfs this spawn's private marker dir — Greptile's remaining shared-gotmp recreate note is that intentional rmdir/mkdir dance, not malice.

VISION (per rule, inspected evidence):

  • One captain, one interface — aligns. Turns silent swallowed keystrokes into a named shell-readiness refusal instead of a false allocator/cwd diagnosis (bin/fm-spawn.sh readiness gate + tests/fm-spawn-shell-ready.test.sh).
  • Authority is explicit — aligns. Env-overridable bounds (FM_SPAWN_SHELL_READY_*); no new default captain autonomy.
  • Scripts own the mechanics — aligns. Bounded probe/resend; private marker dir; rmdir-only shared-root cleanup (spawn_abort_cleanup).
  • A restart is a non-event — aligns. Post-meta refusals record durable failed: status so the endpoint stays reapable by id.
  • Delegation with a spine — aligns. Strengthens spawn refusal rather than launching a worker that will do nothing.
  • The fleet outlives any vendor — aligns. Backend-agnostic proof; adapters only for delivery semantics (tmux/herdr/orca/cmux/zellij).
  • Scope — aligns. Spawn/backend send path, not workshop.

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. no-mistakes-pipeline-attestation:v1 head_sha=8aadd2a0… is current HEAD. Require-no-mistakes succeeded on edited-body run 33062329572.

CI: current-HEAD CI run 33062307560 is still in progress. Greptile is not a merge gate. Not merge-ready (overlap leftover, CI not green).

First-time fork CI: previously approved on an earlier HEAD (33010197563 CI, 33010197571 Require no-mistakes). Current-HEAD CI 33062307560 is in flight. I did not re-approve stale action_required runs.

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.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Reviewed HEAD 8aadd2a0c910233952a2f1bec4729212701ceb68 vs main 10b93b2cc6f4241e87fccaee2e357c33a7347a53. Whole thread read (prior waiting-ci / overlap-hold on older HEAD; newer pushes since 2026-08-26T22:22:00Z; Greptile still raising concurrent-home temp-root concerns). Full diff reviewed: bin/fm-spawn.sh shell-readiness gate, bin/backends/{cmux,zellij,orca,tmux,herdr}.sh send-status reservations, tests/fm-spawn-shell-ready.test.sh + fixture updates, docs/AGENTS. No .github/workflows/*. Not disguised security. tomashco is not blocked.

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 touch <marker> probe in a private uid-owned marker dir, refuses on timeout, distinguishes undelivered / stranded / cleared / delivered send statuses, and uses rmdir-only abort cleanup so shared task-tmp across homes is not rm -rf'd.

VISION (per rule, inspected evidence):

  • One captain, one interface — aligns. Turns silent swallowed keystrokes into a loud shell-readiness refusal instead of a false allocator/cwd diagnosis.
  • Authority is explicit — aligns. Env-overridable bounds (FM_SPAWN_SHELL_READY_*); no new default captain autonomy.
  • Scripts own the mechanics — aligns. Bounded probe/resend; private marker dir; rmdir-only abort cleanup.
  • A restart is a non-event — aligns. Post-meta refusals record durable failed: last state.
  • Delegation with a spine — aligns. Backend-agnostic proof; adapters only for delivery semantics.
  • The fleet outlives any vendor — aligns. Works across cmux/zellij/orca/tmux/herdr.
  • Scope — aligns. Spawn boundary, not workshop.

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 rmdir-only shared-root cleanup and privacy re-checks — not disguised malice.

Attestation: no-mistakes-pipeline-attestation:v1 head_sha matches this HEAD. Edited Require-no-mistakes succeeded.

First-time fork CI: after that full-diff review I approved workflow runs 33062307560 (CI), 33062329572 (Require no-mistakes / edited), and 33062307526 (Require no-mistakes / synchronize) for this HEAD.

Not merging. Unresolved overlap with #3101; waiting on green CI for the newly approved runs. Not with the captain. Merge-eligible: NO.

@tomashco tomashco closed this Sep 7, 2026
@tomashco
tomashco deleted the fm/spawn-shell-ready-r1 branch September 7, 2026 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants