Skip to content

fix(bin): gate the first spawn send on proven pane-shell readiness - #3101

Open
adriantoczydlowski wants to merge 12 commits into
kunchenguid:mainfrom
adriantoczydlowski:fm/fm-spawn-first-send-hardening
Open

adriantoczydlowski wants to merge 12 commits into
kunchenguid:mainfrom
adriantoczydlowski:fm/fm-spawn-first-send-hardening

Conversation

@adriantoczydlowski

Copy link
Copy Markdown

Intent

Harden the first spawn-time send in bin/fm-spawn.sh against shell-init keystroke loss, and land it properly with a regression test.

THE BUG. After a fresh pane is created, fm-spawn.sh sends treehouse get as its first text line. The pane's shell can still be sourcing its rc files when that send lands, and a slow init eats the first byte(s). Observed live on herdr under load on 2026-08-17: the leading 't' was swallowed three times in a row, so the pane received reehouse get and the worktree was never entered. The failure is silent from firstmate's side - the spawn appears to proceed.

PRIOR ART THAT HAD TO BE RECONCILED, NOT COPIED. An uncommitted hand hotfix sits in the primary checkout (not in this worktree) adding a sacrificial leading space: spawn_send_text_line "$WT_TARGET" ' treehouse get'. It was explicitly rejected as-is for three reasons given to me: its comment block and call lost their two-space indentation inside the enclosing if block; it was applied to only one send path even though the same first-send hazard exists on the others; and a leading space is a mitigation, not a fix - it buys exactly as many bytes as spaces you send.

WHAT I WAS ASKED TO DECIDE AND BUILD. Choose between (a) a readiness-verified send that probes the pane's shell is actually accepting input before the first text line goes out, and (b) the sacrificial-prefix approach done properly on every first-send path with the rationale and byte budget stated. I was told to prefer (a) if I could make it deterministic and bounded, that it must fail loudly on timeout rather than silently proceeding, that it must not add meaningful latency to a healthy spawn, to fall back to (b) only if (a) could not be made reliable across the supported backends, and to say plainly in the PR body which I chose and why. Whichever I picked, EVERY first-send path after pane creation had to be covered, not only the relaunch branch.

ACCEPTANCE CRITERIA I WAS GIVEN. Every post-pane-creation first send in bin/fm-spawn.sh is protected by the chosen mechanism, with no path left on the bare unguarded send. A colocated regression test proves the protection is in place and, where the mechanism allows, that a delayed or slow shell init does not corrupt the command. shellcheck clean per this repo's style rules. The relaunch-path indentation is correct - the hotfix's broken indentation must not survive into the PR. If I chose (a), a timeout is a loud failure with a clear message, never a silent continue.

CONSTRAINTS I WAS GIVEN. Load and follow the firstmate-coding-guidelines skill because this changes firstmate's shared tracked material: one-owner rule for contracts, script header ownership, one sentence per line in tracked Markdown, plain dash never an em dash, shellcheck-clean bin scripts, colocated tests named .test.sh extending the existing runner, tests must exercise behavior through an executable or public interface and must never assert implementation-source bytes, and maintainer-verification evidence where a guarantee changes. bin/fm-spawn.sh's own header owns its launch-flag and validation contract, so if behavior changes the header changes with it. Do NOT add a Co-Authored-By trailer to any commit - this repo forbids it. PR base is the default branch main; no retargeting. The captain's home has config/backend=herdr, which is where the failure was observed, but the fix must stay backend-agnostic with tmux as the reference backend. I do not answer my own ask-user findings; they are escalated.

WHAT I CHOSE, AND WHY. I implemented (a). spawn_await_shell_ready sends touch '<marker>' into the pane and polls the filesystem for that marker. The load-bearing property is that the command word touch cannot survive ANY head truncation: every prefix loss turns it into some other word, the shell reports command-not-found, and the marker stays absent. So the marker exists only after one byte-exact line was received AND executed at a live prompt, which is exactly the condition that also makes the next send safe - that is what makes this a fix rather than padding. The verdict comes from the filesystem, never from rendered pane output, so it is backend-agnostic and carries no per-harness assumption at all; the gate runs strictly before any launch command, so no harness has started yet.

DELIBERATE DESIGN DECISIONS A REVIEWER READING ONLY THE DIFF WOULD NOT KNOW.

  1. Both first-send points are gated and the gate is deliberately NOT memoized per spawn. On the ordinary path treehouse get hands the pane to a NEW subshell that sources its own rc files, so readiness proven before that send says nothing about the launch-environment send that follows it; and on the relaunch, secondmate, and Orca paths that launch-environment line IS the spawn's first send. Two probes cost about 0.2s total on a healthy spawn. I verified by inspection that these are the only two send call sites reached after pane creation.

  2. Relaunch is gated too even though an adopted endpoint is not strictly post-pane-creation. A relaunch already requires a positively agent-free endpoint, so a pane that cannot execute a command line would fail the launch anyway; failing loudly at the probe is better than launching into it.

  3. FM_SPAWN_READY_BYPASS=1 is an intentional test-fixture escape hatch, with the same shape and the same reasoning as the existing bin/fm-gate-refuse-lib.sh FM_GATE_REFUSE_BYPASS precedent. Nearly every suite in this repo drives the real fm-spawn.sh against a FAKE backend whose send channel has no shell behind it at all, so no marker can ever appear there and the gate would time out on fixtures that are not testing a shell. tests/lib.sh exports it for those suites; the real-backend smoke suites deliberately do not source tests/lib.sh, so they keep exercising the gate for real; and tests/fm-spawn-first-send.test.sh strips it to verify the gate itself. A dedicated test case pins both halves so a future change cannot quietly turn the gate into a default no-op. This is a deliberate, documented fail-open surface, not an oversight.

  4. tests/remote-herdr-fixture.sh gained a pane shell for that one command shape instead of the env knob crossing the remote boundary. The remote job worker composes every child with env -i and a small allowlist, so no test env var can cross it - by design. My change genuinely regressed tests/fm-remote-secondmate-parent-binding.test.sh, and I fixed it by teaching that fixture's fake herdr pane run to execute a delivered touch '<path>', which is strictly additive and changes no fixture state. I deliberately did NOT widen the remote worker's security-relevant env allowlist to carry a test-only knob. That suite is green again.

  5. Two small fail-closed guards were added on purpose: a floor of 1 on FM_SPAWN_READY_RESEND_EVERY so a zero value cannot divide by zero, and a refusal if the probe path contains a single quote rather than sending a line whose quoting the pane's shell would parse differently than intended.

  6. Each retry after the first submits a bare Enter before re-probing, so a prior attempt left half-typed on the input line is flushed as its own failing command instead of being concatenated onto the next one. A healthy shell never pays this.

  7. I deliberately did NOT update docs/verification/runtime-backends.md, and this is a judgment call worth reviewing rather than an omission. The firstmate-coding-guidelines rule for harness-dependent checks applies when a verdict comes from vendor-emitted output - a process name, rendered output, a glyph, a banner. This verdict comes from the filesystem. The gate also introduces no new backend command: it reuses send_text_line and send_key Enter, both already recorded in that doc's per-backend matrices. So no new live-harness guard and no new dated per-harness evidence is owed.

  8. Knowledge placement followed the guidelines' decision tree: the env knobs and mechanics are exact flags and commands, so they live in bin/fm-spawn.sh's own header rather than in AGENTS.md, a skill, or a second documentation owner. No AGENTS.md change - nothing here is needed by every session or every turn.

TEST DESIGN, INCLUDING ONE VACUOUSNESS BUG I FOUND AND FIXED. tests/fm-spawn-first-send.test.sh drives the real fm-spawn.sh against a fake tmux that models a byte-lossy shell: it drops the leading character of every delivery in a configurable window, records what the pane actually received, and executes a delivered touch '<path>' for real so the gate's own readiness signal is observable end to end. Assertions are on the exact bytes the pane saw, never on the script's source. Two details matter. First, the truncated forms are substrings of the intact ones - reehouse get sits inside treehouse get, xport GOTMPDIR= inside export GOTMPDIR= - so unanchored matching cannot tell them apart; the helpers anchor on line prefix. Second, my initial second-gate case keyed its loss window on a delivery NUMBER and therefore passed without the fix, which made it vacuous; I re-keyed it on delivery CONTENT (the window opens on the delivery after treehouse get lands) so it stays non-vacuous however many probes precede it. I verified case by case that removing the gate makes the four substantive cases fail, reproducing the incident verbatim as reehouse get and xport GOTMPDIR=.

VERIFICATION PERFORMED, AND ITS LIMITS. bin/fm-lint.sh is clean (pinned ShellCheck 0.11.0 and actionlint 1.7.12; actionlint was absent on this machine and I installed the pinned version). The new suite's 6 cases pass and is registered in the backend-dispatch family; the coverage guard accepts it. The whole backend-dispatch family is green: 15 suites, 0 failures. The secondmate and session-bootstrap families show 4 failures, and I reproduced every one of them on HEAD~1 - fm-remote-doctor in the same four-suite order, fm-remote-secondmate-lifecycle-e2e, fm-remote-secondmate-trace-context, and fm-gotmp. fm-kimi-harness, fm-muse-harness, and fm-composer-lib are also pre-existing failures on this machine. What I could NOT verify: no real-shell backend run. tmux, zellij, orca, and cmux are not installed here, and herdr 0.7.4 is installed but exercising it would drive Herdr lifecycle, which my task's own safety gate forbade without a --herdr-lab scaffold. Real-backend coverage therefore rests on the herdr and tmux smoke suites in CI, which now run the gate unbypassed.

What Changed

  • bin/fm-spawn.sh gains spawn_await_shell_ready, a readiness gate that sends a touch <marker> line into a freshly created pane and polls the filesystem for that marker before any text line the spawn depends on. The command word touch cannot survive head truncation, so the marker appears only after one byte-exact line executed at a live prompt - the same condition that makes the next send safe. This replaces the rejected sacrificial-leading-space mitigation, which buys only as many bytes as spaces sent. Both post-pane-creation first sends are gated - treehouse get and the launch-environment export GOTMPDIR=... that follows treehouse's new subshell or opens a relaunch, secondmate, or Orca spawn - and the gate is deliberately not memoized, since readiness proven before treehouse get says nothing about the subshell that sources its own rc files. A pane that never answers refuses the spawn with a message naming the window, whether it survives, and the published task record, rather than launching into a possibly corrupted command. FM_SPAWN_READY_POLLS, FM_SPAWN_READY_INTERVAL, and FM_SPAWN_READY_RESEND_EVERY tune the budget and fall back to their own defaults on a zero or non-numeric value; the probe root falls back from TMPDIR to /tmp with a notice; consecutive undeliverable probes refuse on the send channel rather than blaming the pane. bin/fm-spawn.sh's header, which owns the launch-flag and validation contract, documents the gated sends, knobs, refusal rules, and bypass.
  • FM_SPAWN_READY_BYPASS=1 is a documented test-fixture escape hatch modelled on bin/fm-gate-refuse-lib.sh's FM_GATE_REFUSE_BYPASS, exported from tests/lib.sh because nearly every suite drives the real fm-spawn.sh against a fake backend with no shell behind its send channel. Real-backend smoke suites do not source tests/lib.sh, so they keep exercising the gate unbypassed. tests/remote-herdr-fixture.sh's fake herdr pane run now executes a delivered touch '<path>' - strictly additive, honouring the existing send-fail flag - instead of widening the remote worker's env -i allowlist to carry a test-only knob.
  • New tests/fm-spawn-first-send.test.sh drives the real fm-spawn.sh against a fake tmux modelling a byte-lossy shell: it drops the leading character of deliveries in a configurable window, records what the pane received, and executes delivered touch lines for real. Cases assert on the exact bytes the pane saw with line-prefix anchoring (the truncated reehouse get and xport GOTMPDIR= are substrings of the intact forms), and cover both gated sends, loud refusal on timeout, probe-scratch cleanup on success and refusal, send-channel and uncleared-input failure modes, TMPDIR fallback, zero-knob fallback, and that the gate stands down only for the explicit bypass. The suite is registered in the backend-dispatch family in bin/fm-test-run.sh; bin/backends/tmux.sh, bin/backends/herdr.sh, and docs/agent-control.md record the gate's use of the existing send_text_line channel.

Risk Assessment

✅ Low: The gate is additive, bounded, and fail-loud; every prior round's prescribed fix is verifiably applied in the current source, the coverage-honesty comments now match the suite/family classification I independently enumerated, and the colocated suite proves the protection with non-vacuous before/after cases.

Testing

Ran the new colocated suite tests/fm-spawn-first-send.test.sh (12 cases, all pass) and then proved it is not vacuous by reverting bin/fm-spawn.sh to the base commit and running each case individually: 10 of 12 fail pre-fix, the two exceptions being the guard-rail halves that assert a spawn succeeds. For product-level evidence I drove the real fm-spawn.sh against the suite's byte-lossy fake shell and captured the exact bytes the pane received before and after the fix: pre-fix the pane runs reehouse get and xport GOTMPDIR= while fm-spawn.sh reports spawned &lt;id&gt; and exits 0, post-fix the probe absorbs the same three byte losses and both treehouse get and export GOTMPDIR= arrive intact, each preceded by its own gate. A never-ready pane exits 1 with a refusal that names the send it refused, delivers no task command, and leaves no probe scratch. I also verified the gate's load-bearing premise against real sh, bash and zsh - only the byte-exact probe line creates the marker, every truncation is command-not-found - which is the one thing the fake models rather than proves. Neighbouring suites (fm-remote-secondmate-parent-binding, fm-test-run, and the three other backend-dispatch spawn suites) are green, the new suite is registered in the backend-dispatch family, and the runner's coverage guard accepts it. No visual evidence applies: this change is a shell-level spawn guard with no rendered surface, so the reviewer-visible artifacts are CLI transcripts of what a pane's shell actually received. One limit, already documented in the code with an owned follow-up task: no delivery through a real multiplexer into a shell mid-rc-sourcing, because tmux, zellij, cmux and orca are not installed here and herdr is excluded by this task's safety gate. All temporary drivers and the reverted source were removed; the worktree is clean.

Evidence: Pane transcript: incident reproduced pre-fix, fixed post-fix (exact bytes the pane's shell received)

Source: Pane transcript: incident reproduced pre-fix, fixed post-fix (exact bytes the pane's shell received)

== PRE-FIX (bin/fm-spawn.sh at base 6a2cd6c) == --- fm-spawn.sh exit status: 0 spawned incident-repro harness=codex kind=ship mode=no-mistakes yolo=off window=firstmate:fm-incident-repro ... --- what the pane's shell actually received (in order) --- reehouse get xport GOTMPDIR=/tmp/fm-incident-repro/gotmp literal env -u CURSOR_AGENT ... codex ... key Enter == POST-FIX (bin/fm-spawn.sh at fa5aafc) == --- fm-spawn.sh exit status: 0 spawned incident-repro harness=codex kind=ship mode=no-mistakes yolo=off window=firstmate:fm-incident-repro ... --- what the pane's shell actually received (in order) --- ouch <TMPDIR>/fm-spawn-ready.QXasDn/ready 2>/dev/null key Enter ouch <TMPDIR>/fm-spawn-ready.QXasDn/ready 2>/dev/null key Enter ouch <TMPDIR>/fm-spawn-ready.QXasDn/ready 2>/dev/null key Enter touch <TMPDIR>/fm-spawn-ready.QXasDn/ready 2>/dev/null treehouse get touch <TMPDIR>/fm-spawn-ready.R6S4Hh/ready 2>/dev/null export GOTMPDIR=/tmp/fm-incident-repro/gotmp literal env -u CURSOR_AGENT ... codex ... key Enter

== PRE-FIX (bin/fm-spawn.sh at base 6a2cd6c) ==
--- fm-spawn.sh exit status: 0
--- fm-spawn.sh stdout/stderr (tail) ---
warning: /var/folders/wg/l58p0r3s0f90qy6rt44vnh_00000gn/T//fm-spawn-first-send.pkwcRE/incident/home/data/incident-repro/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 incident-repro harness=codex kind=ship mode=no-mistakes yolo=off window=firstmate:fm-incident-repro worktree=/var/folders/wg/l58p0r3s0f90qy6rt44vnh_00000gn/T//fm-spawn-first-send.pkwcRE/incident/wt
--- what the pane's shell actually received (in order) ---
reehouse get
xport GOTMPDIR=/tmp/fm-incident-repro/gotmp
literal env -u CURSOR_AGENT -u CURSOR_INVOKED_AS codex --dangerously-bypass-approvals-and-sandbox -c "notify=[\"bash\",\"-c\",\"touch '/private/var/folders/wg/l58p0r3s0f90qy6rt44vnh_00000gn/T/fm-spawn-first-send.pkwcRE/incident/home/state/incident-repro.turn-ended'\"]" "$('<REPO>/bin/fm-operational-input.sh' encode launch-brief < '<HOME>/data/incident-repro/brief.md')"
key Enter

== POST-FIX (bin/fm-spawn.sh at fa5aafc) ==
--- fm-spawn.sh exit status: 0
--- fm-spawn.sh stdout/stderr (tail) ---
warning: /var/folders/wg/l58p0r3s0f90qy6rt44vnh_00000gn/T//fm-spawn-first-send.TrswN0/incident/home/data/incident-repro/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 incident-repro harness=codex kind=ship mode=no-mistakes yolo=off window=firstmate:fm-incident-repro worktree=/var/folders/wg/l58p0r3s0f90qy6rt44vnh_00000gn/T//fm-spawn-first-send.TrswN0/incident/wt
--- what the pane's shell actually received (in order) ---
ouch <TMPDIR>/fm-spawn-ready.QXasDn/ready 2>/dev/null
key Enter
ouch <TMPDIR>/fm-spawn-ready.QXasDn/ready 2>/dev/null
key Enter
ouch <TMPDIR>/fm-spawn-ready.QXasDn/ready 2>/dev/null
key Enter
touch <TMPDIR>/fm-spawn-ready.QXasDn/ready 2>/dev/null
treehouse get
touch <TMPDIR>/fm-spawn-ready.R6S4Hh/ready 2>/dev/null
export GOTMPDIR=/tmp/fm-incident-repro/gotmp
literal env -u CURSOR_AGENT -u CURSOR_INVOKED_AS codex --dangerously-bypass-approvals-and-sandbox -c "notify=[\"bash\",\"-c\",\"touch '/private/var/folders/wg/l58p0r3s0f90qy6rt44vnh_00000gn/T/fm-spawn-first-send.TrswN0/incident/home/state/incident-repro.turn-ended'\"]" "$('<REPO>/bin/fm-operational-input.sh' encode launch-brief < '<HOME>/data/incident-repro/brief.md')"
key Enter
Evidence: Loud refusal: a pane that never accepts a command line stops the spawn

Source: Loud refusal: a pane that never accepts a command line stops the spawn

--- fm-spawn.sh exit status: 1 error: task never-ready-repro's pane shell never confirmed it can read a command line (5 probes over 5 polls at 0.05s on firstmate:fm-never-ready-repro); refusing to send 'treehouse get' into a pane that may silently drop its leading bytes; inspect window firstmate:fm-never-ready-repro, which survives this refusal and is left for you to clean up --- what the pane's shell received (only probes; no task command) --- ouch <TMPDIR>/fm-spawn-ready.sqeZt4/ready 2>/dev/null key Enter ... (5 probes, 4 bare Enters, no C-c, no task command) --- probe scratch left behind under <TMPDIR> --- 0 directories

--- fm-spawn.sh exit status: 1
--- captain-visible output (last 3 lines) ---
warning: <HOME>/data/never-ready-repro/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 never-ready-repro's pane shell never confirmed it can read a command line (5 probes over 5 polls at 0.05s on firstmate:fm-never-ready-repro); refusing to send 'treehouse get' into a pane that may silently drop its leading bytes; inspect window firstmate:fm-never-ready-repro, which survives this refusal and is left for you to clean up
--- what the pane's shell received (only probes; no task command) ---
ouch <TMPDIR>/fm-spawn-ready.sqeZt4/ready 2>/dev/null
key Enter
ouch <TMPDIR>/fm-spawn-ready.sqeZt4/ready 2>/dev/null
key Enter
ouch <TMPDIR>/fm-spawn-ready.sqeZt4/ready 2>/dev/null
key Enter
ouch <TMPDIR>/fm-spawn-ready.sqeZt4/ready 2>/dev/null
key Enter
ouch <TMPDIR>/fm-spawn-ready.sqeZt4/ready 2>/dev/null
--- probe scratch left behind under <TMPDIR> ---
0 directories
Evidence: Non-vacuousness: each case run individually against pre-fix bin/fm-spawn.sh (10 of 12 fail)

Source: Non-vacuousness: each case run individually against pre-fix bin/fm-spawn.sh (10 of 12 fail)

not ok - the pane never received an intact treehouse get (no delivered line starts with 'treehouse get') not ok - the pane never received an intact launch environment (no delivered line starts with 'export GOTMPDIR=') not ok - spawn exited 0 with a shell that never accepted a command line not ok - the readiness probe did not precede the first task command (first delivery: 'treehouse get') ok - a zero budget knob falls back to its default instead of refusing every spawn [asserts success; passes without the gate by construction] not ok - the refusal did not attribute the failure to the send channel not ok - the refusal did not attribute the failure to the send channel (status 2 on tmux) not ok - the refusal did not report the uncleared input line the cmux adapter signalled not ok - two non-consecutive send hiccups were reported as a broken send channel instead of an unready pane not ok - the probe root fallback was silent, so the condition is invisible to the captain ok - the gate stands down only for an explicit fixture bypass [asserts success; passes without the gate by construction] not ok - the refusal half of the cleanup case did not refuse

### bin/fm-spawn.sh reverted to base commit 6a2cd6c (pre-fix); tests/fm-spawn-first-send.test.sh run one case at a time

=== test_swallowed_leading_bytes_never_corrupt_the_first_command ===
not ok - the pane never received an intact treehouse get (no delivered line starts with 'treehouse get')
--- delivered ---
reehouse get
xport GOTMPDIR=/tmp/fm-first-send-swallow-three-a1/gotmp
literal env -u CURSOR_AGENT -u CURSOR_INVOKED_AS codex --dangerously-bypass-approvals-and-sandbox -c "notify=[\"bash\",\"-c\",\"touch '/private/var/folders/wg/l58p0r3s0f90qy6rt44vnh_00000gn/T/fm-spawn-first-send.F916SA/swallow-three/home/state/first-send-swallow-three-a1.turn-ended'\"]" "$('/Users/adriantoczydlowski/.no-mistakes/worktrees/b0d3d72ad777/01M0VZE71XBW5ZGWMQR44P3XBZ/bin/fm-operational-input.sh' encode launch-brief < '/var/folders/wg/l58p0r3s0f90qy6rt44vnh_00000gn/T//fm-spawn-first-send.F916SA/swallow-three/home/data/first-send-swallow-three-a1/brief.md')"
key Enter
[case exited nonzero]

=== test_second_gate_protects_the_launch_environment ===
not ok - the pane never received an intact launch environment (no delivered line starts with 'export GOTMPDIR=')
--- delivered ---
treehouse get
xport GOTMPDIR=/tmp/fm-first-send-swallow-later-b2/gotmp
literal env -u CURSOR_AGENT -u CURSOR_INVOKED_AS codex --dangerously-bypass-approvals-and-sandbox -c "notify=[\"bash\",\"-c\",\"touch '/private/var/folders/wg/l58p0r3s0f90qy6rt44vnh_00000gn/T/fm-spawn-first-send.RsYhqy/swallow-later/home/state/first-send-swallow-later-b2.turn-ended'\"]" "$('/Users/adriantoczydlowski/.no-mistakes/worktrees/b0d3d72ad777/01M0VZE71XBW5ZGWMQR44P3XBZ/bin/fm-operational-input.sh' encode launch-brief < '/var/folders/wg/l58p0r3s0f90qy6rt44vnh_00000gn/T//fm-spawn-first-send.RsYhqy/swallow-later/home/data/first-send-swallow-later-b2/brief.md')"
key Enter
[case exited nonzero]

=== test_unready_shell_fails_loudly ===
not ok - spawn exited 0 with a shell that never accepted a command line
[case exited nonzero]

=== test_healthy_shell_pays_one_probe_per_gate ===
not ok - the readiness probe did not precede the first task command (first delivery: 'treehouse get')
[case exited nonzero]

=== test_misconfigured_budget_knob_falls_back_to_its_default ===
ok - a zero budget knob falls back to its default instead of refusing every spawn

=== test_broken_send_channel_refuses_on_the_channel_not_the_pane ===
not ok - the refusal did not attribute the failure to the send channel (missing: 'send path is failing, not its shell')
--- output ---
warning: /var/folders/wg/l58p0r3s0f90qy6rt44vnh_00000gn/T//fm-spawn-first-send.MTabpi/dead-channel/home/data/first-send-dead-channel-k1/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
[case exited nonzero]

=== test_status_2_is_not_read_as_uncleared_input_on_tmux ===
not ok - the refusal did not attribute the failure to the send channel (missing: 'send path is failing')
--- output ---
warning: /var/folders/wg/l58p0r3s0f90qy6rt44vnh_00000gn/T//fm-spawn-first-send.2s5TVW/status2/home/data/first-send-status2-m2/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
[case exited nonzero]

=== test_uncleared_probe_input_is_terminal_on_cmux ===
not ok - the refusal did not report the uncleared input line the cmux adapter signalled (missing: 'probe input could not be cleared')
--- output ---
warning: /var/folders/wg/l58p0r3s0f90qy6rt44vnh_00000gn/T//fm-spawn-first-send.FSKQrV/cmux-uncleared/home/data/first-send-cmux-uncleared-p4/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
[case exited nonzero]

=== test_intermittent_send_hiccups_still_refuse_on_the_pane ===
not ok - two non-consecutive send hiccups were reported as a broken send channel instead of an unready pane (missing: 'never confirmed it can read a command line')
--- output ---
warning: /var/folders/wg/l58p0r3s0f90qy6rt44vnh_00000gn/T//fm-spawn-first-send.r2ZPF4/hiccup/home/data/first-send-hiccup-n3/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
[case exited nonzero]

=== test_unusable_tmpdir_falls_back_instead_of_refusing ===
not ok - the probe root fallback was silent, so the condition is invisible to the captain (missing: 'falling back to /tmp')
--- output ---
warning: /var/folders/wg/l58p0r3s0f90qy6rt44vnh_00000gn/T//fm-spawn-first-send.7LLaN2/odd-tmpdir/home/data/first-send-odd-tmpdir-j9/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 first-send-odd-tmpdir-j9 harness=codex kind=ship mode=no-mistakes yolo=off window=firstmate:fm-first-send-odd-tmpdir-j9 worktree=/var/folders/wg/l58p0r3s0f90qy6rt44vnh_00000gn/T//fm-spawn-first-send.7LLaN2/odd-tmpdir/wt
[case exited nonzero]

=== test_fixture_bypass_is_explicit ===
ok - the gate stands down only for an explicit fixture bypass

=== test_probe_scratch_is_cleaned_up ===
not ok - the refusal half of the cleanup case did not refuse
[case exited nonzero]
Evidence: Gate premise against real shells: only a byte-exact probe line creates the marker

Source: Gate premise against real shells: only a byte-exact probe line creates the marker

SHELL LOST COMMAND WORD RECEIVED MARKER WHAT THE SHELL WOULD SAY (redirect removed) sh 0 touch CREATED <silent, succeeded> sh 1 ouch absent /bin/sh: ouch: command not found sh 2 uch absent /bin/sh: uch: command not found bash 0 touch CREATED <silent, succeeded> bash 1 ouch absent /bin/bash: ouch: command not found zsh 0 touch CREATED <silent, succeeded> zsh 1 ouch absent zsh:1: command not found: ouch (4 truncation depths per shell; every prefix loss leaves the marker absent)

The gate's load-bearing premise, checked against REAL shells on this machine
(sh, bash, zsh). No multiplexer is needed for this half of the claim.

Probe line the gate sends:  touch <marker> 2>/dev/null
Claim: the marker appears ONLY on a byte-exact delivery; every head
truncation degrades the command word into something the shell cannot run.

SHELL      LOST   COMMAND WORD RECEIVED    MARKER           WHAT THE SHELL WOULD SAY (redirect removed)
sh         0      touch                    CREATED          <silent, succeeded>
sh         1      ouch                     absent           /bin/sh: ouch: command not found
sh         2      uch                      absent           /bin/sh: uch: command not found
sh         3      ch                       absent           /bin/sh: ch: command not found
sh         4      h                        absent           /bin/sh: h: command not found
bash       0      touch                    CREATED          <silent, succeeded>
bash       1      ouch                     absent           /bin/bash: ouch: command not found
bash       2      uch                      absent           /bin/bash: uch: command not found
bash       3      ch                       absent           /bin/bash: ch: command not found
bash       4      h                        absent           /bin/bash: h: command not found
zsh        0      touch                    CREATED          <silent, succeeded>
zsh        1      ouch                     absent           zsh:1: command not found: ouch
zsh        2      uch                      absent           zsh:1: command not found: uch
zsh        3      ch                       absent           zsh:1: command not found: ch
zsh        4      h                        absent           zsh:1: command not found: h

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

🔧 **Rebase** - 1 issue found → auto-fixed ✅
  • ⚠️ bin/fm-test-run.sh - merge conflict rebasing onto origin/main

🔧 Fix applied.
✅ Re-checked - no issues remain.

⚠️ **Review** - 1 info
  • ⚠️ bin/fm-spawn.sh:2343 - All three gate refusal messages (lines 2343, 2348, 2363) end with the unconditional claim "inspect window $T, which survives this refusal and is left for you to clean up", but on the herdr presentation-projection path the pane does not survive. HERDR_PROJECTION_ABORT_CLEANUP is set to 1 at bin/fm-spawn.sh:2046 (or :1990 on reclaim) and is only cleared at :3046, i.e. after BOTH gate call sites (:2443 and :3024). So a gate refusal exits nonzero with the flag still 1, the EXIT trap runs fm_backend_herdr_projection_cleanup_exact (:766-771), and the exact projected task pane is closed - then the operator is told to go inspect it. Concrete path: config/backend=herdr with presentation enabled (fm_backend_herdr_presentation_enabled, :1955) -> projected task pane created -> pane shell slow to init -> gate at :2443 or :3024 exhausts its budget -> message points at a window that no longer exists. This is the exact backend and layout where the original incident was observed. The header documents this as a known residual (:166-173), so it is a deliberate accepted gap rather than an oversight, but the operator sees the stderr message during the failure, not --help. Suggested fix: make the survival clause conditional on HERDR_PROJECTION_ABORT_CLEANUP (and factor the shared suffix into one local so all three refusals stay in step).
  • ℹ️ bin/fm-spawn.sh:3024 - On the herdr projected path the presentation-order lock is held from pane creation (:2046) through :3048, so it now also spans both gates. At the defaults that adds up to 2 x 30s to the hold window for an unresponsive pane. spawn_herdr_presentation_order_lock_acquire only waits 50 x 0.1s (:832-847), so a concurrent herdr spawn during that window warns and silently degrades to the flat layout. The failure mode this gate targets is "herdr under load", which is precisely when concurrent spawns are most likely, so the degraded-layout path will be hit more often than before. The header documents this residual explicitly (:166-169) and it is bounded and non-corrupting, so I am flagging it as an acknowledged tradeoff rather than a defect.
  • ℹ️ bin/fm-spawn.sh:137 - The gate's contract is now stated in full twice in the same file: the --help header block at :137-176 (~40 lines) and the function comment at :2193-2228 (~36 lines) both cover the incident, the truncation property, the three knobs, the FM_SPAWN_READY_BYPASS rationale, the send-channel/status-2 rules, and the no-interrupt reasoning - with a third partial restatement in the body's inline comments (:2261-2265, :2271-2280, :2327-2337). The firstmate-coding-guidelines one-owner rule states a contract in full exactly once and makes every other mention a one-line cross-reference, precisely because two copies drift once only one is edited. The survival-claim drift in the previous finding is already a symptom of that: the header carries the corrected "on every flat layout" qualifier while the message it describes does not. Tier 7 of the placement tree puts the exact flags and knob defaults in the header/--help, which suggests the header is the owner and the function comment should shrink to the maintainer-only rationale plus a pointer. This is a documentation-structure judgment on deliberately authored prose, so it needs the author's call rather than a mechanical edit.

🔧 Fix: scope gate refusal survival claim, fold contract to header
4 issues (2 warnings, 2 infos) still open:

  • ⚠️ tests/lib.sh:46 - The new gate is a mandatory hard-fail on every spawn path, and nothing in a portable CI lane exercises it against a real shell. tests/lib.sh:46 exports FM_SPAWN_READY_BYPASS=1 for every fixture suite, and the two suites named as the real-backend fallback do NOT compensate: tests/fm-backend-tmux-smoke.test.sh mentions fm-spawn.sh only in comments (lines 69 and 108) and tests/fm-backend-herdr-smoke.test.sh only at line 332 - neither ever invokes bin/fm-spawn.sh, so neither can run the gate at all, bypassed or not. Enumerating every suite that actually executes bin/fm-spawn.sh without the bypass on its source path gives exactly five: fm-backend-autodetect-smoke, fm-backend-herdr-launcher-workspace-e2e, fm-backend-herdr-presentation-e2e, fm-backend-herdr-workspace-per-home-e2e (all four classified real-herdr-gated at bin/fm-test-run.sh:164-171) and fm-cmux-claude-composer-live-e2e (live opt-in). bin/fm-test-run.sh:33 states portable CI lanes exclude real-herdr-gated, and each of those suites exits 0 early when herdr/jq/treehouse or cmux is absent. Net effect: on a portable lane the gate's real-shell behavior is never executed, and there is no coverage whatsoever on tmux even though tmux is the declared reference backend. tests/fm-spawn-first-send.test.sh proves the gate against a modelled byte-lossy shell, which is real coverage of the LOGIC but not of the assumption that a live pane shell executes touch &lt;marker&gt; and that the marker becomes visible to fm-spawn - the one assumption whose failure refuses every spawn on that backend. Worth deciding explicitly whether to accept that (the intent already records "no real-shell backend run" as a limit) or to add a real-tmux case that drives bin/fm-spawn.sh unbypassed, since tmux is installable in CI where herdr is not.
  • ⚠️ bin/fm-spawn.sh:3029 - The second gate runs after the task record is already published, so its refusal leaves a phantom task and the refusal text points the operator at the wrong thing. On the ordinary path SPAWN_META_PATH is "$STATE/$ID.meta" (bin/fm-spawn.sh:2858) and the record is written directly there at :2923; on relaunch it is mv'd into place at :2931. The gate call is at :3029, after both. spawn_abort_cleanup (:731-825) never removes a published meta - it only unwinds a relaunch's pending replacement wiring and the temp file. So the concrete sequence is: slow pane shell at the second gate (the exact scenario this gate exists for) -> spawn_await_shell_ready exhausts its budget -> exit 1 -> $STATE/$ID.meta remains, recording window, worktree, harness and backend for a task whose pane never received the launch command. The task is then enumerable by the fleet as live while its pane sits at a bare shell. Meanwhile the refusal's cleanup clause built at :2260 says only "inspect window $T, which survives this refusal and is left for you to clean up" - it names the window, not the record, so an operator who closes the pane leaves the meta behind. Two mitigating facts, which is why I am not calling this an error: the message prefix does name "task $ID", and the pre-existing trace-context refusal at :3041 sits at the same point with the same consequence and no cleanup guidance at all, so this is an existing hole rather than a new one. What the change does is turn it from a rare send-channel failure into the gate's documented common outcome. Your call whether that warrants naming the teardown in the refusal, or moving nothing at all.
  • ℹ️ bin/fm-spawn.sh:820 - bin/fm-spawn.sh:820 open-codes [ -z &#34;$SPAWN_READY_DIR&#34; ] || rm -rf &#34;$SPAWN_READY_DIR&#34; 2&gt;/dev/null || true, which is exactly what spawn_ready_cleanup (:2224-2228) already owns, minus the SPAWN_READY_DIR reset. Bash resolves function calls at runtime, so spawn_abort_cleanup can call spawn_ready_cleanup despite being defined earlier in the file, and the two copies then cannot drift on the removal semantics. Purely mechanical; no behavior change either way.
  • ℹ️ bin/fm-spawn.sh:2361 - Deferred probes can spray touch: No such file or directory into the crewmate's pane just before the guarded command. The gate submits one probe per resend stride (bin/fm-spawn.sh:2330) but removes the probe directory the instant the marker appears (:2361). A pane whose shell is blocked for most of the budget has every queued probe sitting unread in the tty; when the shell finally comes up it drains them in order, the first creates the marker, the gate returns and rm -rf's the directory, and each remaining queued touch then fails visibly. At the defaults that is bounded by 30 probes, so a shell that comes up around poll 250 leaves roughly two dozen error lines in the pane immediately ahead of treehouse get or the launch environment. Purely cosmetic - terminal input is a FIFO, so ordering is preserved and nothing the gate protects is affected - but it is operator-visible noise in exactly the degraded case an operator would be inspecting. Redirecting the probe's stderr would silence it at the cost of putting a metacharacter into a line the header currently documents as metacharacter-free, so it is a tradeoff rather than a clear fix.

🔧 Fix: name published record in gate refusal, silence probe stderr
3 issues (2 warnings, 1 info) still open:

  • ⚠️ bin/fm-spawn.sh:2279 - The new published-record clause fires on the relaunch path, where fm-teardown.sh is the wrong and destructive remedy. The condition is [ -e &#34;$STATE/$ID.meta&#34; ] || [ -L ... ] evaluated at gate entry (bin/fm-spawn.sh:2278). At the second gate (:3049) with RELAUNCH=1 that is unconditionally true: the task record existed before this spawn (relaunch adopts an existing task) and is re-published at :2941 via mv -f &#34;$SPAWN_META_TMP&#34; &#34;$STATE/$ID.meta&#34;. So the concrete sequence is: relaunch a task whose adopted endpoint's shell cannot execute a command line -> spawn_await_shell_ready exhausts its budget at :3049 -> the refusal appends "task record $STATE/$ID.meta is published and this refusal does not retract it, so clear the task with '<root>/bin/fm-teardown.sh <id>'". But on relaunch the record is not a phantom - it is a live task the operator was trying to hand a fresh agent - and fm-teardown.sh's own header (bin/fm-teardown.sh:1-10) states it returns/hard-resets/removes the worktree and kills the recorded endpoint. The correct remedy there is fixing the pane and retrying the relaunch. Teardown's unlanded-work refusal limits the blast radius but does not make the guidance right: a relaunch of a task whose work has already landed would be torn down on the first try. Also worth noting while you are here: no case in tests/fm-spawn-first-send.test.sh produces a second-gate refusal (test_second_gate_protects_the_launch_environment succeeds; both refusal cases refuse at the first gate, before publication), so neither branch of this clause is executed by any test. Suggested scope: gate the clause on [ &#34;$RELAUNCH&#34; -ne 1 ], or give the relaunch case its own wording that names retry rather than teardown.
  • ⚠️ bin/fm-spawn.sh:2232 - The round-3 honesty statement was appended without removing the claim it contradicts, and the identical claim in tests/lib.sh was left untouched. bin/fm-spawn.sh:2232-2233 says "tests/lib.sh exports the bypass for those, while the real-backend smoke suites - which do not source it - exercise the gate for real", and :2236-2237 then says "the tmux and herdr smoke suites never invoke this script at all". The second statement is the accurate one: tests/fm-backend-tmux-smoke.test.sh mentions fm-spawn.sh only in comments (lines 69, 108) and tests/fm-backend-herdr-smoke.test.sh only at line 332 - neither ever executes it, so neither can run the gate. tests/lib.sh:43-44 carries the same unqualified overclaim with no correction at all: "The real-backend smoke suites deliberately do NOT source this library, so they still exercise the gate against a real shell." Round 2's instruction for this exact text was "state plainly that the gate premise ... is unproven against any real shell in portable CI lanes ... Do not soften that statement and do not claim coverage that does not exist." The surviving clause claims coverage that does not exist and is the softening that instruction forbade. The only suites that really do drive bin/fm-spawn.sh unbypassed are the herdr-gated e2e suites plus fm-backend-autodetect-smoke, all of which exit 0 early without herdr/jq/treehouse - name those, or drop the clause and let the corrected sentence stand alone.
  • ℹ️ bin/fm-spawn.sh:166 - The --help header block was made the single owner of the gate contract in round 1, and usage() emits it verbatim (bin/fm-spawn.sh:241-246), but it was not updated when round 3 added a new refusal element. Line 166-168 still describes the refusal as only "Every gate refusal names the window and says whether it survives, and the gate removes nothing itself" - a refusal now also names the published task record at $STATE/$ID.meta and prescribes a concrete fm-teardown.sh &lt;id&gt; command (:2278-2280). That is exactly the kind of exact-command detail the placement rule puts in the header, and it is the one part of the refusal an operator acts on. One sentence in the header block closes the gap.

🔧 Fix: split relaunch refusal from orphan-record teardown advice
2 issues (1 warning, 1 info) still open:

  • ⚠️ bin/fm-spawn.sh:2289 - The round-3 split keys the record wording on RELAUNCH alone, but relaunch is not the only non-orphan path, so the destructive teardown guidance is still reachable. Concrete sequence: bin/fm-bootstrap.sh's liveness sweep respawns an existing secondmate whose agent is dead/missing with fm-spawn.sh &#34;$id&#34; --secondmate (bin/fm-bootstrap.sh:752 and :789). That runs with RELAUNCH=0 and a pre-existing $STATE/$ID.meta - bootstrap just read that same meta for backend/target, and fm-spawn re-resolves the home from it at bin/fm-spawn.sh:1646 ([ -z &#34;$FIRSTMATE_HOME&#34; ] &amp;&amp; [ -f &#34;$STATE/$ID.meta&#34; ]). A new pane is created, the record is re-published, and the second gate at :3060 refuses if that pane's shell is slow - the gate's whole target scenario. The RELAUNCH branch at :2287 is false, so the elif at :2289 fires and the refusal says the record 'is published for a pane that never received its launch command' and to 'clear the orphaned task with <root>/bin/fm-teardown.sh <id>'. That record is not orphaned: it is a live secondmate. bin/fm-teardown.sh on kind=secondmate refuses only while the home has in-flight CHILD meta files (:2545-2555); an idle secondmate passes that check and is then destroyed by remove_firstmate_home at :2795, which removes the home, releases its treehouse lease, and drops the registry entry. The same shape recurs on the remote launch path, where bin/fm-remote-secondmate-control.sh:154-177 re-launches over an existing meta with RELAUNCH=0 and additionally under FM_STATE_OVERRIDE, so the printed fm-teardown.sh &lt;id&gt; would not even address the record the message names. The code's own stated invariant at :2282-2286 is 'named only where the record is genuinely orphaned', and the header at :170 restates it as 'on a fresh spawn the record is an orphan' - both are violated by these paths. Earliest shared boundary: decide the wording from whether THIS spawn created the record rather than from RELAUNCH - capture a flag once where $STATE/$ID.meta is first consulted (before publication, e.g. near :1646/:1016) and branch the aftermath on that, which covers relaunch, secondmate respawn, and the remote launch with one condition. The header sentence at :170 needs the same correction since it is the contract owner.
  • ℹ️ tests/lib.sh:46 - The coverage-honesty statement's supporting enumeration is contradicted by the sentence two lines above it. tests/lib.sh:44 correctly says tests/fm-spawn-first-send.test.sh strips the bypass; tests/lib.sh:46-47 then says 'every suite that drives it unbypassed is classified real-herdr-gated or live-harness-optin'. fm-spawn-first-send.test.sh drives bin/fm-spawn.sh unbypassed (env -u FM_SPAWN_READY_BYPASS at tests/fm-spawn-first-send.test.sh:190) and is classified backend-dispatch (bin/fm-test-run.sh:209), which portable lanes DO run. bin/fm-spawn.sh:2241 carries the same over-broad enumeration ('every suite that does either bypasses the gate or is classified real-herdr-gated or live-harness-optin'). The headline claim - unproven against a REAL shell - is accurate; only the enumeration is wrong, because it omits the fake-shell suite it just named. Round 3's instruction was to stop leaving two sentences that disagree a few lines apart, so qualifying the enumeration ('every suite that drives it against a real backend') or excepting fm-spawn-first-send explicitly finishes that correction.

🔧 Fix: drop remedy from gate record refusal, fix coverage claims
1 info still open:

  • ℹ️ bin/fm-spawn.sh:158 - The gate re-derives its probe root on each of the two entries per spawn, so an unusable TMPDIR emits the fallback notice twice (bin/fm-spawn.sh:2317-2325 runs once at :2476 and again at :3060), while the header at :158-160 describes the fallback as happening "with one stderr notice". The fallback itself is correct on both entries and the scratch is cleaned each time, so this is operator-visible duplication of a diagnostic rather than a defect; recording it only so the header wording is not mistaken for a per-spawn guarantee.
✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-spawn-first-send.test.sh - all 12 cases pass on the target commit (~27s)
  • Non-vacuousness: git checkout 6a2cd6c -- bin/fm-spawn.sh, then ran each of the 12 test functions individually via a throwaway driver; 10 fail pre-fix, including test_swallowed_leading_bytes_never_corrupt_the_first_command, test_second_gate_protects_the_launch_environment, test_unready_shell_fails_loudly and test_healthy_shell_pays_one_probe_per_gate. Restored with git checkout fa5aafc -- bin/fm-spawn.sh.
  • Incident reproduction / fix transcript: drove the suite's own fixture with the loss window on deliveries 1-3 and dumped the exact bytes the pane's shell received, once with pre-fix and once with post-fix bin/fm-spawn.sh
  • Loud-refusal check: same fixture with a pane that truncates every delivery and FM_SPAWN_READY_POLLS=5 - captured exit status, the captain-visible refusal text, the full pane delivery log, and the probe-scratch count
  • Real-shell premise check: delivered touch &lt;marker&gt; 2&gt;/dev/null and its 1-4 byte head truncations to /bin/sh, /bin/bash and /bin/zsh, recording marker existence and the shell's own diagnostic
  • grep -n &#39;spawn_send_text_line|spawn_await_shell_ready|spawn_send_key &#39; bin/fm-spawn.sh - confirmed only two post-pane-creation first sends (2480, 3061), both gated at 2479/3060
  • bash tests/fm-remote-secondmate-parent-binding.test.sh - the suite the fixture change was needed for; ALL TESTS PASSED
  • bash tests/fm-test-run.test.sh - passed
  • bash tests/fm-spawn-dispatch-profile.test.sh, bash tests/fm-trace-context-spawn.test.sh, bash tests/fm-spawn-worktree-settle.test.sh - same family, all passed
  • bash bin/fm-test-run.sh --list --family backend-dispatch (new suite listed) and bash bin/fm-test-run.sh --check-coverage (FM_TEST_COVERAGE ok total=162)
⚠️ **Document** - 2 issues (1 warning, 1 info)
  • ⚠️ docs/fm-test-portable-shards.md:84 - docs/fm-test-portable-shards.md's portable-serial shard table is stale and this change adds to the drift. It documents 29/28/30/30 scripts (117 total); the lane actually resolves to 30/32/32/32 (126) after this change, and already resolved to 30/31/32/32 (125) at the base commit. The doc's own instruction is to refresh the weight hints and this table whenever the serial lane gains scripts, but doing that correctly requires per-shard timing artifacts from a green CI run, which are not reachable from this worktree; recomputing only the counts would leave the Estimated duration and imbalance columns inconsistent with them. Left unchanged and proposed as a follow-up: download the fm-test-timing-portable-serial-* artifacts from a green run, replace portable_serial_weight_hints in bin/fm-test-run.sh, and regenerate the table. Coverage is unaffected either way - the guard keeps the partition complete and disjoint whatever the hints say - so the cost is shard balance only.
  • ℹ️ docs/verification/runtime-backends.md - Judgment call the author flagged for review: docs/verification/runtime-backends.md was deliberately not updated for the readiness gate. I checked it and concur, so I made no change. The gate introduces no new backend command - it reuses send_text_line and send_key Enter, both already recorded in every per-backend matrix in that doc - and its verdict comes from a marker file on the filesystem rather than from anything the vendor emits (process name, rendered output, glyph, banner), so the firstmate-coding-guidelines rule for harness-dependent checks does not fire and no new live-harness guard or dated per-harness evidence is owed. Recording it here because it is a deliberate omission a reviewer would otherwise have to re-derive.
✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

A freshly created pane's shell can still be sourcing its rc files when
fm-spawn.sh's first text line lands, and a slow init eats the leading
byte(s). Seen live on herdr under load (2026-08-17): the leading 't' of
`treehouse get` was swallowed three times running, the pane ran
`reehouse get`, and the worktree was never entered - silently, with
nothing on firstmate's side to notice.

Gate every post-pane-creation first send on a readiness proof instead of
padding it. spawn_await_shell_ready sends `touch <marker>` and polls the
filesystem for <marker>. The command word cannot survive any head
truncation - every prefix loss turns `touch` into some other word, the
shell reports command-not-found, and the marker stays absent - so the
marker exists only after one byte-exact line was received and executed
at a live prompt, which is the same condition that makes the next send
safe. A sacrificial leading space only buys as many bytes as spaces are
sent, so it could not close this.

Both first-send points are gated, not just one: `treehouse get`, and the
launch environment that follows treehouse's new subshell or opens a
relaunch, secondmate, or Orca spawn. The verdict comes from the
filesystem rather than rendered pane output, so it holds identically on
every send-capable backend and involves no harness at all - the gate runs
strictly before any launch command. Exhausting the budget refuses the
spawn with the endpoint named rather than sending into an unproven pane.

FM_SPAWN_READY_BYPASS=1 is a test-fixture escape hatch with the same
shape and reasoning as bin/fm-gate-refuse-lib.sh's: nearly every suite
drives the real fm-spawn.sh against a fake backend with no shell behind
its send channel, so tests/lib.sh exports it for those while the
real-backend suites keep exercising the gate for real.
tests/remote-herdr-fixture.sh instead grows a pane shell for that one
command shape, because the remote job boundary composes its children's
environment with env -i and must not learn a test knob.

tests/fm-spawn-first-send.test.sh is the colocated regression: a fake
tmux that drops leading bytes in a configurable window, records what the
pane actually received, and executes a delivered marker command for
real. Without the gate its cases reproduce the incident exactly
(`reehouse get`, `xport GOTMPDIR=`).
@greptile-apps

greptile-apps Bot commented Aug 26, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge, with no concrete unacknowledged failure found in the changed behavior.

Both first-send boundaries are gated, failures stop before dependent commands are sent, probe scratch is cleaned on success and refusal, and the investigated backend and lifecycle concerns were either explicitly documented tradeoffs or lacked a concrete reachable failure.

Reviews (1): Last reviewed commit: "no-mistakes(document): fix first-send ga..." | Re-trigger Greptile

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