Skip to content

fix(bin): keep test and lab tmux cleanup off the operator's server - #6703

Open
PabloAraya6 wants to merge 4 commits into
kunchenguid:mainfrom
PabloAraya6:fm/fm-upstream-tmux-fix
Open

PabloAraya6 wants to merge 4 commits into
kunchenguid:mainfrom
PabloAraya6:fm/fm-upstream-tmux-fix

Conversation

@PabloAraya6

@PabloAraya6 PabloAraya6 commented Oct 6, 2026 •

Copy link
Copy Markdown

Intent

«si si es algo que le pasa a todos», en respuesta a: «¿Abro un PR con este arreglo en el firstmate oficial (kunchenguid/firstmate)? Sería público, a tu nombre.»

El arreglo: la limpieza de salida de tests/fm-live-lab.test.sh ejecutaba tmux kill-server con su directorio privado de terminales ya borrado; con TMUX_TMPDIR ausente o vacío tmux cae a /tmp/tmux-/default, el servidor real del operador, y lo mata con todas las sesiones de los workers. Pasó dos veces el 2026-10-06 en esta máquina. El fix es local en los commits 2c125285 (test: pin that suites and lab cleanups cannot reach the operator's tmux server) y 9fbc00e8 (fix: never let tests or lab cleanups address the operator's tmux server): bin/fm-lab-home.sh tmux <dir> <args> es el único camino para direccionar el servidor del laboratorio, nombra el socket explícitamente y se niega sin directorio privado; cambian también bin/fm-live-lab.sh, bin/fm-brief.sh, tests/lib.sh y tres tests.

What Changed

  • bin/fm-lab-home.sh adds a tmux <dir> <args...> subcommand as the single safe way to address a lab's server: it validates the marked lab home, names the private socket explicitly (-S), strips inherited TMUX/TMUX_PANE, and refuses when no private tmux directory exists. tmux-dir and teardown now share the same record-validation helper.
  • bin/fm-live-lab.sh and bin/fm-brief.sh route every lab tmux call through that subcommand instead of TMUX_TMPDIR, and tests/lib.sh mints each suite a private TMUX_TMPDIR (unsets inherited TMUX/TMUX_PANE) with cleanup that kills only servers on its own sockets.
  • Tests cover that a suite or lab cleanup cannot reach the inherited operator server, that a lab with no private directory refuses without running tmux, and that the orphan sweep reaps an abandoned private tmux directory plus any server still listening in it.

Risk Assessment

✅ Low: The change is well-bounded, fail-closed, and covered by behavioral tests: the lab helper names the socket explicitly and refuses without a validated private directory, all in-repo lab/tmux cleanup paths route through it or an explicit -S/-L, and the global tests/lib.sh private TMUX_TMPDIR removes the ambient fallback that caused the original operator-server kill.

Testing

Drove the lab/test tmux-isolation product live: ran the four targeted behavior suites that real-socket tmux servers back, plus an independent manual scenario script and a regression reproduction against a private stand-in operator server. Confirmed the pre-fix tests/lib.sh lets an inherited TMUX kill the operator server while the fix prevents it, that fm-lab-home.sh tmux refuses once no private directory exists (before tmux-dir and after it is removed) without ever invoking tmux, and that it addresses only the lab's private socket when one exists. The emitted --herdr-lab brief carries the corrected addressing guidance. No rendered UI exists, so no screenshot/HTML artifact applies; CLI transcripts are the reviewer-visible evidence. All scenarios passed and the real operator fleet stayed intact.

  • Live validation: ✅ go - 6 of 6 scenarios driven live against the product
Scenario Result Live Evidence
A test suite launched from a worker tmux pane (inheriting TMUX/TMUX_PANE) runs tmux kill-server and the operator's tmux server plus all its windows survives ✅ pass live bash tests/fm-test-fixtures.test.sh -> 'ok - a suite that inherits the operator's TMUX cannot address that tmux server' (evidence/01M48NYWAGD5AZF7MXW5TPM6HS/test-fixtures.out); manual-lab-tmux.out s…
bin/fm-lab-home.sh tmux &lt;lab&gt; kill-server refuses when no private tmux directory exists (before tmux-dir and after it is removed), never invoking tmux, and leaves any operator/inherited server alive ✅ pass live bash tests/fm-gate-refuse.test.sh -> 'ok - fm-lab-home tmux reaches only the lab's private server and refuses once no private directory exists'; manual-lab-tmux.out scenarios B (exit=1) and D (priva…
bin/fm-lab-home.sh tmux &lt;lab&gt; ... with a private directory reaches only the lab's private socket server even when the caller's TMUX names the operator server, and stopping it leaves the operator ser… ✅ pass live tests/fm-gate-refuse.test.sh new test (spy tmux proves no tmux call on refusal; has-session/kill-server reach only the private socket; stand-in operator session still present); manual-lab-tmux.out…
An orphan sweep reaps an abandoned private tmux socket directory and the server still listening in it after a suite's own EXIT trap skipped cleanup ✅ pass live bash tests/fm-test-fixture-cleanup.test.sh -> 'ok - the orphan sweep reaps an abandoned private tmux directory and its server' (evidence/01M48NYWAGD5AZF7MXW5TPM6HS/fixture-cleanup.out)
bin/fm-live-lab.sh drives its lab tmux server only through fm-lab-home.sh tmux on the private socket, with readiness/teardown still working ✅ pass live bash tests/fm-live-lab.test.sh -> 30/30 ok including 'down stops only recorded lab processes...' and 'up launches primary after worker status...' (evidence/01M48NYWAGD5AZF7MXW5TPM6HS/live-lab.out)
Scaffolding a --herdr-lab brief emits the corrected lab-tmux addressing contract (use fm-lab-home.sh tmux, never address the server through TMUX_TMPDIR alone) ✅ pass live FM_HOME=&lt;tmp&gt; bash bin/fm-brief.sh brief-lab-guidance firstmate --mode no-mistakes --herdr-lab; emitted brief lines at evidence/01M48NYWAGD5AZF7MXW5TPM6HS/brief-lab-tmux-guidance.txt
Evidence: Four targeted suites pass (gate-refuse, test-fixtures, fixture-cleanup, live-lab)
ok - fm-lab-home tmux reaches only the lab's private server and refuses once no private directory exists
ok - a suite that inherits the operator's TMUX cannot address that tmux server
ok - the orphan sweep reaps an abandoned private tmux directory and its server
fm-live-lab.test.sh: 30/30 ok, exit 0
Evidence: Independent live drive of fm-lab-home.sh tmux against a stand-in operator server

Source: Independent live drive of fm-lab-home.sh tmux against a stand-in operator server

A. suite inherits operator TMUX, then bare tmux kill-server -> operator server survived B. fm-lab-home.sh tmux with no private dir -> exit=1, operator server intact C. fm-lab-home.sh tmux with private dir -> reached only the lab server, operator intact D. private dir removed then kill-server -> exit=1, operator server intact ALL MANUAL SCENARIOS PASSED

operator server pid=25309 sessions=       1

== A. suite inherits operator TMUX/TMUX_PANE, then runs bare tmux kill-server ==
error connecting to /private/tmp/fmt.fP5p0G/tmux-501/default (No such file or directory)
PASS: operator server survived the suite's bare kill-server

== B. fm-lab-home.sh tmux refuses with no private dir (before tmux-dir) ==
fm-lab-home: refusing '/tmp/fm-manual.ak6IHd/labB': it has no private tmux directory, so there is no lab server to address
exit=1
PASS: refused and operator server intact

== C. fm-lab-home.sh tmux reaches only the lab server ==
lab socket dir=/tmp/fml.TSzz97
PASS: reached only the lab server; operator server intact

== D. the reported failure: cleanup kill-server after the private dir is gone ==
fm-lab-home: recorded tmux directory is missing or unsafe
exit=1
PASS: refused after the private dir vanished; operator server intact

ALL MANUAL SCENARIOS PASSED
Evidence: Regression reproduction: pre-fix lib.sh kills the inherited server, fixed lib.sh protects it

Source: Regression reproduction: pre-fix lib.sh kills the inherited server, fixed lib.sh protects it

== BEFORE FIX: suite inherits operator TMUX, private dir gone, bare tmux kill-server ==
REPRODUCED: with inherited TMUX and no private dir, kill-server killed the operator server

== AFTER FIX: tests/lib.sh drops the inherited TMUX, same bare kill-server ==
error connecting to /private/tmp/fmt.PXuRwp/tmux-501/default (No such file or directory)
PASS: fixed lib.sh protected the inherited operator server
Evidence: Real operator tmux fleet window list, unchanged before/after (18 windows)

Source: Real operator tmux fleet window list, unchanged before/after (18 windows)

@1 fm-pp-canvas-01
@10 fm-pp-canvas-24
@11 fm-pp-canvas-26
@12 fm-pp-canvas-35
@13 fm-pp-ola2-l-embeddings
@14 fm-pp-tour-fotos
@15 fm-pp-tour-t05
@16 fm-pp-tour-t06
@17 fm-fm-upstream-tmux-fix
@18 fm-fm-locale-subshell-sweep
@2 fm-pp-canvas-04
@3 fm-pp-canvas-05
@4 fm-pp-canvas-06
@5 fm-pp-canvas-09
@6 fm-pp-canvas-10
@7 fm-pp-canvas-12
@8 fm-pp-canvas-17
@9 fm-pp-canvas-18
Evidence: Emitted --herdr-lab brief lab-tmux addressing guidance

Source: Emitted --herdr-lab brief lab-tmux addressing guidance

15:For tmux-based lab primaries, `bin/fm-lab-home.sh` owns the short private socket directory and the only safe way to address its server; do not place `TMUX_TMPDIR` under the lab home or worktree.
16:Use `LAB_HOME_HELPER='~/.no-mistakes/worktrees/a09ae54b258e/01M48NYWAGD5AZF7MXW5TPM6HS/bin/fm-lab-home.sh'`, create the directory with `"$LAB_HOME_HELPER" tmux-dir "$FM_HOME"`, and run every tmux command for the lab server as `"$LAB_HOME_HELPER" tmux "$FM_HOME" <tmux arguments...>`; never address it through `TMUX_TMPDIR` alone.
17:Your single EXIT cleanup trap must run `"$LAB_HOME_HELPER" tmux "$FM_HOME" kill-server`, call `"$LAB_HOME_HELPER" teardown "$FM_HOME"`, and call the Herdr teardown below; do not install a second trap that replaces either cleanup.
Evidence: fm-gate-refuse suite transcript

Source: fm-gate-refuse suite transcript

ok - fm-gate-refuse-lib: refuses when NO_MISTAKES_GATE is set
ok - fm-gate-refuse-lib: refuses when NO_MISTAKES_GATE is set empty
ok - fm-gate-refuse-lib: refuses from a gate worktree via git-common-dir (marker unset)
ok - fm-gate-refuse-lib: no-op for a normal session (neither signal, set -eu clean)
ok - fm-gate-refuse-lib: marked lab home permitted in a gate; unmarked home or an override stay refused
ok - fm-lab-home: create mints marked stock homes only on fresh empty dirs; anything else is refused
ok - fm-lab-home: a primary starts on a private short tmux socket from a long lab path and teardown removes it
ok - fm-lab-home tmux reaches only the lab's private server and refuses once no private directory exists
ok - fm-spawn: refuses on marker and gate-worktree backstop; a normal crew spawn is unaffected
ok - fm-send: refuses on marker and gate-worktree backstop; a normal steer uses the inbox
ok - fm-teardown: refuses on marker and gate-worktree backstop; a normal teardown is unaffected
Evidence: fm-test-fixtures suite transcript

Source: fm-test-fixtures suite transcript

ok - runner and shared helpers isolate host Git config and preserve explicit config and outside commits
ok - fm_touch_epoch preserves both epochs in the repeated DST hour
ok - fake no-mistakes --version is the shared constant and overridable
ok - init/doctor no-mistakes stub touches markers and refuses other verbs
ok - fake gh authenticates and fake gh-axi reports the shared version
ok - spawn fakebin answers pane path, logs -l payloads, and installs extra tools
ok - send stubs log typed text and fake ssh records argv with a controllable exit
ok - spawn-home layout writes harness pin, beat, and brief
ok - a suite that inherits the operator's TMUX cannot address that tmux server
Evidence: fm-test-fixture-cleanup suite transcript

Source: fm-test-fixture-cleanup suite transcript

ok - fm_test_tmproot cleans up its fixture root on normal exit
ok - fm_test_tmproot cleans up its fixture root on SIGTERM
ok - the cleanup registry cannot be injected through path precreation
ok - failed fixture registration rolls back the new root
ok - the orphan sweep reaps only old fixtures without a live owner
ok - the orphan sweep reaps read-only package fixtures
ok - the orphan sweep reaps an abandoned private tmux directory and its server
ok - test registries and fixture roots stay out of a git worktree TMPDIR
Evidence: fm-live-lab suite transcript

Source: fm-live-lab suite transcript

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
tests/fm-live-lab.test.sh: line 428: 99262 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 535: 39354 Killed: 9                  perl -e 'setpgrp(0,0); exec @ARGV' "$@" > /dev/null 2>&1
tests/fm-live-lab.test.sh: line 535: 39355 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

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
A test suite launched from a worker tmux pane (inheriting TMUX/TMUX_PANE) runs tmux kill-server and the operator's tmux server plus all its windows survives ✅ pass live bash tests/fm-test-fixtures.test.sh -> 'ok - a suite that inherits the operator's TMUX cannot address that tmux server' (evidence/01M48NYWAGD5AZF7MXW5TPM6HS/test-fixtures.out); manual-lab-tmux.out s…
bin/fm-lab-home.sh tmux &lt;lab&gt; kill-server refuses when no private tmux directory exists (before tmux-dir and after it is removed), never invoking tmux, and leaves any operator/inherited server alive ✅ pass live bash tests/fm-gate-refuse.test.sh -> 'ok - fm-lab-home tmux reaches only the lab's private server and refuses once no private directory exists'; manual-lab-tmux.out scenarios B (exit=1) and D (priva…
bin/fm-lab-home.sh tmux &lt;lab&gt; ... with a private directory reaches only the lab's private socket server even when the caller's TMUX names the operator server, and stopping it leaves the operator ser… ✅ pass live tests/fm-gate-refuse.test.sh new test (spy tmux proves no tmux call on refusal; has-session/kill-server reach only the private socket; stand-in operator session still present); manual-lab-tmux.out…
An orphan sweep reaps an abandoned private tmux socket directory and the server still listening in it after a suite's own EXIT trap skipped cleanup ✅ pass live bash tests/fm-test-fixture-cleanup.test.sh -> 'ok - the orphan sweep reaps an abandoned private tmux directory and its server' (evidence/01M48NYWAGD5AZF7MXW5TPM6HS/fixture-cleanup.out)
bin/fm-live-lab.sh drives its lab tmux server only through fm-lab-home.sh tmux on the private socket, with readiness/teardown still working ✅ pass live bash tests/fm-live-lab.test.sh -> 30/30 ok including 'down stops only recorded lab processes...' and 'up launches primary after worker status...' (evidence/01M48NYWAGD5AZF7MXW5TPM6HS/live-lab.out)
Scaffolding a --herdr-lab brief emits the corrected lab-tmux addressing contract (use fm-lab-home.sh tmux, never address the server through TMUX_TMPDIR alone) ✅ pass live FM_HOME=&lt;tmp&gt; bash bin/fm-brief.sh brief-lab-guidance firstmate --mode no-mistakes --herdr-lab; emitted brief lines at evidence/01M48NYWAGD5AZF7MXW5TPM6HS/brief-lab-tmux-guidance.txt
  • bash tests/fm-gate-refuse.test.sh (includes new test_lab_home_tmux_reaches_only_the_private_server)
  • bash tests/fm-test-fixtures.test.sh (includes new test_suite_cannot_reach_inherited_tmux_server)
  • bash tests/fm-test-fixture-cleanup.test.sh (includes new test_orphan_sweep_reaps_abandoned_tmux_dir)
  • bash tests/fm-live-lab.test.sh (lab_tmux now driven through bin/fm-lab-home.sh tmux)
  • bash manual-lab-tmux-scenario.sh independent live drive of bin/fm-lab-home.sh tmux against a private stand-in operator server
  • bash regression-repro.sh baseline (pre-fix lib.sh) vs fixed lib.sh kill-server behavior
  • bin/fm-brief.sh brief-lab-guidance firstmate --mode no-mistakes --herdr-lab emitted brief inspection
  • operator tmux fleet window-list snapshot before/after every scenario (tmux list-windows -t firstmate)
  • tmux server lifecycle verified with tmux -S &lt;stand-in socket&gt; has-session and tmux list-sessions
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…ux server

A suite launched from a worker's pane inherits TMUX naming the server every
live worker runs in, and a bare tmux kill-session there takes the whole
session. A lab tmux call made after its private directory is gone must refuse
instead of letting tmux fall back to /tmp/tmux-<uid>. Both cases fail today.
tests/fm-live-lab.test.sh's exit cleanup ran `TMUX_TMPDIR=<lab dir> tmux
kill-server` for every lab it had built, after fm-live-lab.sh down had
already removed those private directories. tmux treats a missing or empty
TMUX_TMPDIR as absent and falls back to /tmp/tmux-<uid>, so each call killed
the operator's default server and every live worker in it. Both fleet-wide
crashes landed at that cleanup.

bin/fm-lab-home.sh now owns addressing the lab server as well as its
directory: `tmux <dir> <args>` names the socket explicitly and refuses while
no private directory exists. fm-live-lab.sh, its test, the deep-path lab
test, and the herdr-lab brief text use it instead of TMUX_TMPDIR.

tests/lib.sh also gives every suite a private TMUX_TMPDIR and drops an
inherited TMUX and TMUX_PANE, so a suite started from a worker's pane can
no longer reach that pane's server with a bare tmux command.
@greptile-apps

greptile-apps Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[High risk] Changes how test and lab scripts manage tmux servers.

The PR appears safe to merge; no outstanding finding or new actionable issue was established.

Reviews (2) · Last reviewed commit: "fix(tests): reap a private tmux director..."

Comment thread tests/lib.sh Resolved
…ndoned

tests/lib.sh mints a /tmp/fmt.* tmux socket directory for every suite and
releases it from fm_test_cleanup, but a suite that replaces the EXIT trap
without calling fm_test_cleanup, such as fm-tmux-submit-busy.test.sh, left
that directory behind on every run, and the orphan sweep never looked there.

The directory now carries the same ownership marker as a fixture root, and the
orphan sweep also scans /tmp/fmt.* and stops any tmux server still listening in
a directory before removing it.
@PabloAraya6 PabloAraya6 changed the title fix(bin): never let lab or test tmux cleanups address the operator's server fix(bin): keep test and lab tmux cleanup off the operator's server Oct 6, 2026
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.

1 participant