Skip to content

fix(bin): address lab tmux servers by explicit socket so cleanup never hits the default server - #6902

Open
mitchellderijcke wants to merge 1 commit into
kunchenguid:mainfrom
mitchellderijcke:fm/fm-tmux-kill-default
Open

mitchellderijcke wants to merge 1 commit into
kunchenguid:mainfrom
mitchellderijcke:fm/fm-tmux-kill-default

Conversation

@mitchellderijcke

Copy link
Copy Markdown

Intent

A firstmate test run wiped the shared tmux session that hosts every worker, stopping the whole fleet (2026-10-08 ~21:11). Cause found by the worker that ran it, with evidence in ~/Projects/OSS/firstmate/data/fm-startup-summary/tmux-kill-evidence.md: tests/fm-live-lab.test.sh cleanup (live_lab_cleanup, around line 26-30) runs env -u TMUX TMUX_TMPDIR="$dir" tmux kill-server for lab socket dirs, some of which fm-live-lab.sh down already removed; tmux 3.6a ignores a TMUX_TMPDIR that does not exist and falls back to /tmp, so kill-server hits the default server. Fix it so no test or lab helper can ever address the default tmux server.

The PR description must include this note, in plain words and without addressing anyone: this change was authored by Claude via Firstmate and has not been reviewed by a human, but it fixes a real bug hit in practice (live-lab test cleanup killed the default tmux server and the whole fleet with it).

What Changed

  • bin/fm-live-lab.sh now sends every lab tmux call, including the initial new-session, to an explicit socket (tmux -S "$TMUX_DIR/tmux-<uid>/default") through a new lab_socket helper. The helper refuses to return a socket when the private directory is missing. Before this, tmux treated a missing TMUX_TMPDIR as unset and fell back to /tmp, which is the user's default server.
  • Test cleanup now uses explicit sockets as well. tests/fm-live-lab.test.sh cleanup skips directories that are already gone, and its lab_tmux helper fails if the lab directory has been removed. tests/fm-gate-refuse.test.sh stops the deep-path lab server with -S "$socket_path". The fm-brief.sh instructions and the fm-lab-home.sh header now tell lab callers to kill their server with tmux -S ... kill-server and not through TMUX_TMPDIR alone.
  • Added a regression test that runs fm-live-lab.sh down on a lab whose tmux directory has been deleted. A tmux shim records any call that would fall back to the default server and sends it to a sentinel server instead. The test asserts that no fallback call happened and that the sentinel server is still running.

This change was written by Claude via Firstmate and no human has reviewed it yet. It fixes a real bug that happened in practice: the live-lab test cleanup killed the default tmux server, and the whole fleet went down with it.

🤖 Generated with Claude Code

Risk Assessment

✅ Low: The change is small and focused: every lab tmux call in fm-live-lab.sh and the live-lab test helpers now names the socket explicitly with -S, or is skipped when the private directory is gone, so the default-server fallback can't be reached; a behavioral shim test reproduces the original failure.

Testing

I first reproduced the root cause on tmux 3.6a without touching the real default server. A removed TMUX_TMPDIR silently reached a /tmp probe server, while the new explicit -S address failed with "No such file". The patched fm-live-lab and fm-gate-refuse tests both passed. Run against the pre-fix fm-live-lab.sh, the new regression test failed: the old down sent kill-server through the fallback, which the shim caught. I brought up a real Claude live lab with fm-live-lab.sh up; the primary answered its readiness probe, then check and down succeeded, and a repeated down was refused cleanly. I also ran the brief's cleanup recipe twice, the second time after its directory was removed. The real default tmux server kept the same pid through every step, and no temp dirs or worktree changes were left behind.

  • Live validation: ✅ go - 6 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Root cause: a removed TMUX_TMPDIR reaches the /tmp server, but the explicit -S socket does not ✅ pass live tmux-fallback-repro.txt
Live-lab test cleanup and down with an already-removed private dir never touch the default server ✅ pass live fm-live-lab.test.log; default-server-after-live-lab-test.txt
Regression test fails against the pre-fix fm-live-lab.sh ✅ pass live fail-before-old-fm-live-lab.log
Real fm-live-lab.sh up --harness claude starts a lab on its private explicit socket; check and down work, and a repeated down is refused cleanly ✅ pass live live-lab-up.log; live-lab-check-down.log; default-server-after-live-lab.txt
The brief's EXIT-trap recipe (explicit -S kill, then fm-lab-home teardown) is safe to run again after its directory is gone ✅ pass live brief-trap-recipe.log
fm-lab-home private-socket deep-path test, using the new -S cleanup ✅ pass live bash tests/fm-gate-refuse.test.sh
Evidence: tmux fallback repro and explicit-socket safety

Source: tmux fallback repro and explicit-socket safety

# tmux tmux 3.6a; probe label=fmtestprobe-76103 stands in for the default server (lives in /tmp/tmux-501/)
started probe server in /tmp fallback dir
$ TMUX_TMPDIR=/tmp/fml.aTLc9L (removed) tmux -L fmtestprobe-76103 has-session   # old addressing style
=> reached the /tmp server: fallback CONFIRMED (root cause)
$ tmux -S /tmp/fml.aTLc9L/tmux-501/fmtestprobe-76103 kill-server   # new explicit-socket style
error connecting to /tmp/fml.aTLc9L/tmux-501/fmtestprobe-76103 (No such file or directory)
exit=1
=> /tmp probe server still alive after explicit-socket kill: SAFE
Evidence: fm-live-lab test run (patched)

Source: fm-live-lab test run (patched)

ok - a ready Claude lab passes every readiness check
ok - primary fails when session start never took the lab lock
ok - primary fails when the primary runs in a linked worktree instead of the lab's primary checkout
ok - probe fails when the primary never answered its nonce
ok - trust fails when the lab home has no registered Claude trust
ok - mirror fails when the feed is unwired or has not recorded a whole turn
ok - host passes and fails according to --expect-host
ok - watcher fails on a stale beacon
ok - mate fails when its window is gone or it never reached its charter
ok - mate off readiness requires inherited material and a disabled home gate
ok - worker readiness follows current crew state and the recorded accessible gate
ok - treehouse fails when a pool lands in ~/.treehouse
ok - extensions fail when the Pi lab lacks the branch extension or loads a stale build
ok - down refuses anything up did not build
ok - down stops only recorded lab processes, removes trust entries and task temp dirs
ok - check and down use the recorded Claude store and keep a symlinked store linked
ok - down never reaches the default tmux server through a removed private directory
tests/fm-live-lab.test.sh: line 464: 87517 Killed: 9                  perl -e 'setpgrp(0,0); exec @ARGV' "$@" > /dev/null 2>&1
ok - down waits for TERM handlers and escalates before removing trust
ok - down waits for captured descendants after their root exits
ok - down tracks descendants spawned during TERM
ok - down ignores roots with mismatched start times
tests/fm-live-lab.test.sh: line 571: 95117 Killed: 9                  perl -e 'setpgrp(0,0); exec @ARGV' "$@" > /dev/null 2>&1
tests/fm-live-lab.test.sh: line 571: 95118 Killed: 9                  perl -e 'setpgrp(0,0); exec @ARGV' "$@" > /dev/null 2>&1
ok - down drops empty groups permanently before their ids can be reused
ok - down revalidates process identity during its bounded wait
ok - trust fails on Pi when the lab wrote the persistent Pi trust store
ok - down removes the lab but reports, without reverting, a written Pi trust store
ok - up refuses an existing root and an unsupported harness
ok - up gives both task IDs a long nonce and down cleans partial setup
ok - up launches primary after worker status without weakening final parked readiness
ok - up fails immediately when a spawned worker has no pane PID
ok - up re-registers primary trust after a concurrent Claude write
ok - fm-claude-trust.sh --lab-home trusts only a marked lab primary checkout
Evidence: Fail-before: new regression test against pre-fix fm-live-lab.sh

Source: Fail-before: new regression test against pre-fix fm-live-lab.sh

ok - a ready Claude lab passes every readiness check
ok - primary fails when session start never took the lab lock
ok - primary fails when the primary runs in a linked worktree instead of the lab's primary checkout
ok - probe fails when the primary never answered its nonce
ok - trust fails when the lab home has no registered Claude trust
ok - mirror fails when the feed is unwired or has not recorded a whole turn
ok - host passes and fails according to --expect-host
ok - watcher fails on a stale beacon
ok - mate fails when its window is gone or it never reached its charter
ok - mate off readiness requires inherited material and a disabled home gate
ok - worker readiness follows current crew state and the recorded accessible gate
ok - treehouse fails when a pool lands in ~/.treehouse
ok - extensions fail when the Pi lab lacks the branch extension or loads a stale build
ok - down refuses anything up did not build
ok - down stops only recorded lab processes, removes trust entries and task temp dirs
ok - check and down use the recorded Claude store and keep a symlinked store linked
not ok - down with a removed tmux directory addresses no fallback socket: stopped: lab tmux server and lab processes
fm-lab-home: recorded tmux directory is missing or unsafe
fm-live-lab: cannot remove the private tmux directory (unexpected: 'fallback')
--- output ---
fallback kill-server
Evidence: Live Claude lab up

Source: Live Claude lab up

lab: /private/tmp/fmlab.nm34657 (tear down with: bin/fm-live-lab.sh down /private/tmp/fmlab.nm34657)
tree: cb507b4fc2e8958f391b864f09ef9ac75db8d39b from ~/.no-mistakes/worktrees/b92d2298a54a/01M4ENNNW2XKJVF5TY609PA7DZ
primary: claude --setting-sources project,local --model sonnet --effort medium --permission-mode auto
ok primary: claude pid 35015 in /private/tmp/fmlab.nm34657/home
ok probe: the primary answered LABREADY-1acf9dba0615
ok trust: /private/tmp/fmlab.nm34657/home is trusted in the Claude store
ok host: skipped (empty fleet arms no supervision)
ok watcher: skipped (empty fleet)
ok treehouse: ~/.treehouse unchanged
ready: /private/tmp/fmlab.nm34657
Evidence: Live lab check/pane/down/second down

Source: Live lab check/pane/down/second down

--- check
ok primary: claude pid 35015 in /private/tmp/fmlab.nm34657/home
ok probe: the primary answered LABREADY-1acf9dba0615
ok trust: /private/tmp/fmlab.nm34657/home is trusted in the Claude store
ok host: skipped (empty fleet arms no supervision)
ok watcher: skipped (empty fleet)
ok treehouse: ~/.treehouse unchanged
check_exit=0
--- pane main
 ▐▛███▛█   Claude Code v2.1.292
▝▜██████▀  Sonnet 5.5 with medium effort · Claude Max
 ▝▝   ▝▝   /private/tmp/fmlab.nm34657/home
❯ Lab readiness probe from bin/fm-live-lab.sh. Run no tool or command for this message. Reply with only the word LABREADY, a hyphen, and then 1acf9dba0615, with no spaces.                                                 
⏺ LABREADY-1acf9dba0615                                                                                                                                                                                                     
✻ Cogitated for 3s · done 11:15 PM                                                                                                                                                                                          
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
❯                                                                                                                                                                                                                         
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  ⏵⏵ auto mode on (shift+tab to cycle) · ← for agents                                                                                                                                                         58345 tokens
--- down
stopped: lab tmux server and lab processes
removed: 1 Claude project entries under /private/tmp/fmlab.nm34657
removed: /private/tmp/fmlab.nm34657
down_exit=0
ls: /tmp/fml.KpCAwk: No such file or directory
ls: /tmp/fmlab.nm34657: No such file or directory
--- second down on a removed lab (dir gone)
fm-live-lab: no lab at '/tmp/fmlab.nm34657'
down2_exit=1
Evidence: Brief cleanup recipe, run twice

Source: Brief cleanup recipe, run twice

+(eval):1> bin/fm-lab-home.sh create /tmp/fm-lab.H9Mgv7
+(eval):1> LAB_TMUX_DIR=+(eval):1> bin/fm-lab-home.sh tmux-dir /tmp/fm-lab.H9Mgv7
+(eval):1> LAB_TMUX_DIR=/tmp/fml.MR0Whl 
+(eval):1> env -u TMUX 'TMUX_TMPDIR=/tmp/fml.MR0Whl' tmux -f /dev/null new-session -d -s primary 'exec sleep 300'
+(eval):1> id -u
+(eval):1> ls /tmp/fml.MR0Whl/tmux-501/
default
+(eval):1> cleanup
+cleanup:0> id -u
+cleanup:0> tmux -S /tmp/fml.MR0Whl/tmux-501/default kill-server
+cleanup:0> bin/fm-lab-home.sh teardown /tmp/fm-lab.H9Mgv7
+(eval):1> echo 'rc=0'
rc=0
+(eval):1> ls -d /tmp/fml.MR0Whl
ls: /tmp/fml.MR0Whl: No such file or directory
+(eval):1> cleanup
+cleanup:0> id -u
+cleanup:0> tmux -S /tmp/fml.MR0Whl/tmux-501/default kill-server
error connecting to /tmp/fml.MR0Whl/tmux-501/default (No such file or directory)
+cleanup:0> bin/fm-lab-home.sh teardown /tmp/fm-lab.H9Mgv7
+(eval):1> echo 'second-cleanup rc=0'
second-cleanup rc=0
+(eval):1> set +x
Evidence: Default server identity before/after
before: pid=31883 start=1791490336 sessions=1
after live-lab test: pid=31883
after fail-before run: pid=31883
after live lab up/down: pid=31883
after brief recipe: pid=31883

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 6 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Root cause: a removed TMUX_TMPDIR reaches the /tmp server, but the explicit -S socket does not ✅ pass live tmux-fallback-repro.txt
Live-lab test cleanup and down with an already-removed private dir never touch the default server ✅ pass live fm-live-lab.test.log; default-server-after-live-lab-test.txt
Regression test fails against the pre-fix fm-live-lab.sh ✅ pass live fail-before-old-fm-live-lab.log
Real fm-live-lab.sh up --harness claude starts a lab on its private explicit socket; check and down work, and a repeated down is refused cleanly ✅ pass live live-lab-up.log; live-lab-check-down.log; default-server-after-live-lab.txt
The brief's EXIT-trap recipe (explicit -S kill, then fm-lab-home teardown) is safe to run again after its directory is gone ✅ pass live brief-trap-recipe.log
fm-lab-home private-socket deep-path test, using the new -S cleanup ✅ pass live bash tests/fm-gate-refuse.test.sh
  • Read-only tmux -S /tmp/tmux-501/default display-message -p &#39;#{pid}...&#39;, run before and after every step, to confirm the fleet server survived
  • Root-cause repro with a uniquely labelled probe server in /tmp: TMUX_TMPDIR=&lt;removed dir&gt; tmux -L &lt;label&gt; has-session vs tmux -S &lt;removed dir&gt;/tmux-501/&lt;label&gt; kill-server
  • bash tests/fm-live-lab.test.sh (includes the new removed-directory regression)
  • Fail-before check: new tests/fm-live-lab.test.sh run against the pre-fix bin/fm-live-lab.sh (19fcbbd) in a /tmp git-archive copy, with a guard tmux shim that blocks any fallback
  • bash tests/fm-gate-refuse.test.sh (fm-lab-home private-socket deep-path test)
  • Live bin/fm-live-lab.sh up --harness claude --supervision-host none --expect-host no, then check, pane, down, and a second down on the removed lab
  • Ran the brief's EXIT-trap recipe on a disposable lab home (fm-lab-home create/tmux-dir, tmux -S $LAB_TMUX_DIR/tmux-$(id -u)/default kill-server, teardown), then ran it again after the directory was gone
✅ **Document** - passed

✅ No issues found.

⚠️ **Lint** - 1 warning
  • ⚠️ linter found issues (exit code 1)
✅ **Push** - passed

✅ No issues found.

…ivate dir never falls back to the default server
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @mitchellderijcke, and sorry this bit the fleet. A missing TMUX_TMPDIR silently falling back to the default server is a nasty trap. The repro, and the sentinel-server shim test that fails on the old down, make the fix easy to trust.

I compared head cb507b4f against main b75658b6. The attestation matches this head, and live validation is a go (6 of 6).

What I checked: lab_socket refuses when the private directory is gone, and every lab tmux call, including the first new-session, now goes through -S <dir>/tmux-<uid>/default. That's the same socket TMUX_TMPDIR used to resolve to, so existing labs are still addressable. The test cleanup skips directories that are already removed, fm-gate-refuse kills by its own socket path, and the brief and fm-lab-home.sh wording tell lab callers to do the same.

CI: this is a fork contribution whose runs were waiting on approval. I reviewed the diff first: lab scripts, brief text, and tests, with no workflow, secret, or network surface. Then I approved CI 37845684405 and Require no-mistakes 37845684464.

Contract-class: restore. bin/fm-lab-home.sh already promises that a lab cleanup kills "only the server addressed through that directory". Once the directory was gone, that promise broke and cleanup hit the default server. This brings it back without adding anything new.

VISION.md, rule by rule

  • One captain, one interface: aligns. A test run can no longer take the captain's whole fleet down.
  • Authority is explicit and never inferred: aligns. Nothing destructive runs outside the lab's own server.
  • Scripts own the mechanics, agents own the judgment: aligns.
  • A restart is a non-event: aligns. The live sessions on the default server survive lab cleanup.
  • Delegation with a spine: aligns. There's a regression test that fails on the old code, plus live evidence.
  • The fleet outlives any vendor: aligns. It uses plain tmux -S.
  • Scope: aligns. It's small and limited to the lab tooling. The field incident becomes regression coverage, as VISION asks.

Next step: waiting on CI only. Nothing is waiting on you or on Kun. If CI and no-mistakes come back fully green and the PR is still mergeable, I'll merge it on the next pass.

@LiamSarsfield

Copy link
Copy Markdown
Contributor

I can confirm this on tmux 3.7b, and it bit us twice in one day on one machine. live_lab_cleanup re-runs env -u TMUX TMUX_TMPDIR="$dir" tmux kill-server for every lab directory it recorded, but fm-live-lab.sh down has already deleted them through fm-lab-home.sh teardown, and tmux falls back to /tmp/tmux-$UID/default when TMUX_TMPDIR doesn't exist. So the suite passes and the operator's default server dies with it.

In a bwrap --dev-bind / / --tmpfs /tmp --unshare-pid sandbox with a sentinel default server, the unmodified suite goes 30/30 and kills the sentinel. Adding [ -d "$dir" ] || continue to the trap keeps it alive, still 30/30. Leaving TMUX set doesn't help, and fm-live-lab-up-mate.test.sh on its own is harmless.

bin/fm-live-lab.sh's lab_tmux has the same flaw: with a lab record whose socket directory is gone, say typed into the default server's firstmate:main window and down killed that server. The explicit -S socket plus a missing-directory refusal here covers both paths.

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks for the fresh confirmation, @LiamSarsfield — that matches the tip here, and it is a different bug from #1130 (that one is display-message reporting a gone window as alive; this one is kill-server falling back to the default server when TMUX_TMPDIR is already gone).

Re-check (tip cb507b4f vs main 5f2b81bc): still restore. lab_socket refuses a missing private directory; every lab tmux call uses -S; test cleanup skips removed dirs. Attestation still MATCH. Live validation still go (6/6). workflow-zero. No security surface.

CI: run 37845684405 attempt 2 still has Behavior portable serial 2 CANCELLED at the 30m ceiling (#7255 class). The one allowed re-run for this head is already spent, so I am not re-running again. Everything else on that run, including no-mistakes, is green.

Next: still nothing waiting on you. Auto-merge remains the path once serial 2 is green; if the ceiling keeps cancelling it, it falls under Firstmate's existing #7255 land-despite / raise-limit question rather than a new captain card for this PR alone.

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.

3 participants