Skip to content

fix(bin): bind live-lab tmux calls to explicit sockets so cleanup cannot kill the default server - #6422

Merged
kunchenguid merged 21 commits into
kunchenguid:mainfrom
jaig-in:fm/live-lab-tmux-scope
Nov 3, 2026
Merged

kunchenguid merged 21 commits into
kunchenguid:mainfrom
jaig-in:fm/live-lab-tmux-scope

Conversation

@jaig-in

@jaig-in jaig-in commented Oct 2, 2026 •

Copy link
Copy Markdown

Problem

Running tests/fm-live-lab.test.sh from inside tmux silently killed the user's default tmux server, and with it every session the user had open.
Nothing in the test output said so: the suite finished, and the terminal it ran in was gone.

Root cause

tmux uses TMUX_TMPDIR only while that directory exists.
When it is missing, tmux 3.4 silently falls back to the default socket directory /tmp/tmux-$UID/.

The live lab and its tests addressed their private server through TMUX_TMPDIR alone:

  • the test's EXIT cleanup ran env -u TMUX TMUX_TMPDIR="$dir" tmux kill-server;
  • bin/fm-live-lab.sh's lab_tmux() ran env -u TMUX TMUX_TMPDIR="$TMUX_DIR" tmux "$@", including its lab_tmux kill-server in down.

Once the lab's private directory is gone, each of those commands reaches the user's real server instead.
Minimal reproduction (run it only in a private /tmp, for example under unshare -Urm sh -c 'mount -t tmpfs tmpfs /tmp && exec sh'):

unset TMUX                              # as the cleanup did with env -u TMUX
tmux new-session -d -s users-session    # stands in for the user's own server
dir=$(mktemp -d) && rmdir "$dir"        # a lab directory that no longer exists
TMUX_TMPDIR="$dir" tmux kill-server     # kills /tmp/tmux-$UID/default
tmux has-session -t users-session       # fails: the session is gone

Fix

  • bin/fm-live-lab.sh names the lab's socket explicitly on every tmux call (tmux -S "$TMUX_DIR/tmux-$UID/default"), including the server start, and never relies on TMUX_TMPDIR alone.
    down kills the server only while that socket exists, and does nothing otherwise.
  • tests/fm-live-lab.test.sh and tests/fm-live-lab-up-mate.test.sh do the same for every tmux call they make, including the EXIT cleanup and the stub spawn scripts that run inside the lab.
  • tests/fm-gate-refuse.test.sh drives and stops its lab server through the explicit socket path, with the same exists-only cleanup.
  • The lab cleanup guidance in bin/fm-brief.sh (Herdr-lab briefs) and the bin/fm-lab-home.sh header now say to kill a lab server by its explicit socket, and only while it exists.
  • tests/lib.sh gains fm_tmux_isolation_gate.
    A suite that starts or kills tmux servers runs only when no live tmux server answers in the default socket directory, as under a private /tmp or on a CI runner.
    Otherwise it skips with the isolation it needs, like the other gated suites:
    skip: tmux isolation: a live tmux server answers on <socket>; run under a private /tmp (unshare -Urm sh -c 'mount -t tmpfs tmpfs /tmp && exec bin/fm-test-run.sh <test>').
    Both live-lab suites open with it.
    Each probe has a 5-second deadline (FM_TMUX_ISOLATION_PROBE_SECONDS), so a stopped or stuck server makes the gate skip instead of hang, and a checkout under /tmp, which the private tmpfs would hide, skips the isolation suite's decoy cases with that reason.

Left as is, on purpose:

  • The lab still exports TMUX_TMPDIR to the processes it launches, because that is how the lab's own firstmate backend finds the lab server.
    Those processes run only while the lab server, and so its directory, exists.
  • tests/fm-gate-refuse.test.sh still starts its server through TMUX_TMPDIR, because that test proves the private-directory contract; the directory exists at that point.

Regression coverage

tests/fm-live-lab-isolation.test.sh is new.

  • It exercises the gate both ways: it runs where no server answers, skips with its message beside a live server (also under CI=true), and runs again once only a dead socket is left.
  • It re-executes itself under unshare -Urm with a fresh tmpfs on /tmp, refuses to continue unless that /tmp is provably not the host one, and starts a decoy tmux server on the default socket there.
    It then points pane, say, check and down at a lab whose tmux directory has been removed, and asserts the decoy survives untouched.
    It also asserts that the old TMUX_TMPDIR-only form does reach the decoy, so the case cannot pass vacuously.
    The decoy is stopped by its explicit socket, then TERM and KILL on its recorded pid, each with a bounded poll, and a decoy that survives all three fails the suite instead of hanging it; cases prove the cleanup stops TERM-ignoring processes and returns promptly and reports failure for one it cannot stop.
    Where no private mount namespace is available, the decoy cases skip with the namespace they need.
  • The cleanup treats an exited but unreaped decoy (a zombie that still answers kill -0) as gone, with a real zombie case, so a runner whose PID 1 does not reap orphans cannot fail the suite falsely.
  • Against the pre-fix bin/fm-live-lab.sh, the suite fails: pane reads the decoy's window, and with only the kill path reverted, down kills the decoy server.

Testing

  • tests/fm-live-lab.test.sh, tests/fm-live-lab-up-mate.test.sh, tests/fm-gate-refuse.test.sh and tests/fm-live-lab-isolation.test.sh pass in full through bin/fm-test-run.sh inside a private /tmp.
  • Beside a live default tmux server, both live-lab suites gate-skip, and the server keeps all of its sessions.
  • A real bin/fm-live-lab.sh up --harness claude in a private /tmp passed its readiness checks, and down stopped only the lab's server while a decoy default server in the same /tmp survived.
  • bin/fm-lint.sh, bin/fm-doc-audience-check.sh and bin/fm-test-run.sh --check-coverage pass.
  • The isolation suite's deliberate cleanup waits are shortened (assertions unchanged) so it fits the portable serial budget, with a measured 6459 ms serial hint in bin/fm-test-run.sh.

CI keeps running the live-lab suites: a CI runner has no live default tmux server, so the gate passes there.
The only suite that uses the runner's ambient default server is tests/fm-afk-launch.test.sh, and it kills every session it creates.
Where a runner blocks unprivileged user namespaces, only the isolation suite's decoy cases skip; its gate cases still run.

Pipeline

Updates from git push no-mistakes

  • Review - passed with no findings.
  • Test - passed.
  • Document - no changes needed.
  • Lint - passed.
  • Push - passed.

…not kill the default server

tmux honours TMUX_TMPDIR only while that directory exists; once it is gone,
tmux silently resolves the default socket under /tmp/tmux-<uid>. The live
lab and its tests addressed their private server through TMUX_TMPDIR alone,
so a cleanup aimed at a removed lab directory ran kill-server against the
user's own default server and ended every session on it.

Every tmux call in bin/fm-live-lab.sh and its tests now names the lab socket
with tmux -S, and every kill-server runs only while that socket exists. The
lab's stub spawns, the fm-gate-refuse lab-socket test, and the lab cleanup
guidance in fm-brief.sh and fm-lab-home.sh follow the same rule.

tests/lib.sh gains fm_tmux_isolation_gate: a suite that starts or kills tmux
servers runs only when no live server answers in the default socket
directory (a private /tmp, or a disposable CI runner), skips with the
isolation it needs otherwise, and fails instead of skipping under CI. The
live-lab suites open with it. tests/fm-live-lab-isolation.test.sh covers the
gate both ways and proves that pane, say, check and down aimed at a missing
lab directory leave a decoy server on the default socket alive.
@greptile-apps

greptile-apps Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issue remains.

Reviews (6) · Last reviewed commit: "Merge origin/main into fm/live-lab-tmux-..." · Reviewed by Greptile

Comment thread tests/fm-live-lab-isolation.test.sh Resolved
@jaig-in
jaig-in force-pushed the fm/live-lab-tmux-scope branch from 9b29f50 to 7818021 Compare October 2, 2026 17:18
Comment thread tests/fm-live-lab-isolation.test.sh Resolved
@jaig-in
jaig-in force-pushed the fm/live-lab-tmux-scope branch from 4919ad6 to 9c4e801 Compare October 8, 2026 03:23
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @jaig-in. First full read of head 9c4e8019 against main 0ec1c5a4.

What it does: every tmux call in bin/fm-live-lab.sh now names the lab's socket explicitly (tmux -S), and down kills the lab server only while that socket exists. This closes the case where a missing TMUX_TMPDIR makes tmux silently fall back to the user's default server. The lab-home header, the brief's lab-cleanup sentence and the tests follow the same rule.

Contract-class: restore. The live lab's existing contract is that it kills only its own private server, and that was broken. No new default surface is added.

VISION, rule by rule: One captain, one interface (aligns: no silent loss of the captain's own sessions). Authority explicit (aligns: no destructive reach beyond the lab). Scripts own the mechanics (aligns). Restart a non-event (aligns). Delegation with a spine (aligns: lab isolation). Outlives any vendor (neutral). Scope (aligns: a test/lab harness, plus a one-sentence brief edit that stays inside the existing lab section).

Security review before approving fork CI: no network calls, secrets or workflow edits. It only narrows what tmux can kill. I approved CI 37722495993 and no-mistakes 37722494321.

Blocking (on you): the attestation is bound to 4919ad6c, but the head is 9c4e8019 after your rebase. Please re-raise through git push no-mistakes. Once that passes and CI is green, it can be merged as restore.

@jaig-in
jaig-in force-pushed the fm/live-lab-tmux-scope branch from 9c4e801 to e8a0084 Compare October 10, 2026 06:17
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @jaig-in for bringing this up to date. The no-mistakes attestation now binds head a599345b (your merge of main at 8ba34f1d), and live validation reads go. That clears the blocker from my last note.

I re-read the full diff against main (8 files, no .github/, no network or secrets). bin/fm-live-lab.sh addresses the lab server only through tmux -S <lab socket>, and down kills it only while that socket exists. The tests use the same explicit socket. The new fm_tmux_isolation_gate makes the live-lab suites skip, not run, when a real default tmux server answers. The Herdr-lab brief and the fm-lab-home.sh header now give the same rule. Main has moved one commit since your merge, and it only touches tests/fm-supervision-host.test.sh, which doesn't overlap. I approved fork CI for this head: CI 39096077138 and the no-mistakes/body-compliance runs 39096077121 and 39096107125.

Contract-class: restore (my own read). The lab's existing contract is to kill only its own private server, and that was broken whenever the lab's TMUX_TMPDIR was gone. No new default surface. VISION.md: it aligns. Nothing reaches beyond the lab, mechanics stay in the script, it's vendor-neutral, and it stays inside the lab harness.

Status: nothing is waiting on you. If CI comes back green, this can be squash-merged as a restore. Overlap note: #6902 and #6703 go after the same lab-socket cleanup bug. I'm leaving them open for now.

@jaig-in

jaig-in commented Oct 19, 2026

Copy link
Copy Markdown
Author

CI on a599345b: serial 2 hit the 30-minute limit in tests/fm-supervision-host.test.sh, as main's own CI did on 1aa2a21e and 8ba34f1d. Serial 4 failed in tests/fm-remote-reply.test.sh, which this PR doesn't touch; that suite fails the same way locally on main 8ba34f1d, which this branch merged. Could the failed jobs be re-run?

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @jaig-in. Sorry the 10-19 rerun question sat unanswered. Your new head moots it, since it brings in current main, where those serial-2/serial-4 failures came from.

What I checked at ed42b102 (0 behind main 7da4c362): the diff matches what I reviewed on 10-18. Every bin/fm-live-lab.sh tmux call uses the lab's explicit socket (tmux -S), and down kills the lab server only while that socket exists. fm_tmux_isolation_gate makes the tmux suites skip when a real default server answers. New since then: the tests/fm-live-lab-isolation.test.sh serial hint (3482 ms, documented as provisional in docs/fm-test-portable-shards.md) and the shorter cleanup polls. No .github/ changes, no network calls, no secrets. I approved fork CI for this head: CI 40458679296 and no-mistakes 40458679224, 40458735715. The no-mistakes attestation matches this head, and live validation reads go (8 of 9).

Contract-class (mine): restore, unchanged. The live lab promises to kill only its own private tmux server, and that broke when its TMUX_TMPDIR was gone. VISION.md: it aligns on every rule. Nothing reaches past the lab, the mechanics stay in the script, and there's no new default surface.

Status: waiting on CI, not on you. If it goes green and stays mergeable, it's on the auto-merge path. One thing to know: main's own CI is currently red in two known flaky classes, a fm-supervision-host return-fail and a watch-triage rearm-resurface case. Failures in only those would be main's, not yours.

Comment thread tests/fm-live-lab-isolation.test.sh Resolved
Comment thread tests/lib.sh Resolved
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @jaig-in for bringing this up to date with main again.

What I checked at 7a5ae33b: it's a merge of main (44153212) into the branch. The PR's own diff against main is byte-for-byte what I reviewed at ed42b102. There are no .github/ changes, no network calls, and no secrets, and the no-mistakes attestation binds this head. I approved fork CI for it: CI 40823741167, no-mistakes 40823741168 and 40823777296. On the last run (ed42b102), the only red was serial 1 return-fail: the host did not hand the wake to main. That's main's known flaky class, not yours, so a fresh run is the right next step.

Greptile scored this head below the 5/5 gate, with two test-harness findings. Neither touches the lab script itself:

  1. P1, tests/fm-live-lab-isolation.test.sh:179: when the checkout lives under /tmp, the fresh tmpfs mount hides the script before bash "$0" re-runs it, so the suite fails instead of running or skipping the decoy cases.
  2. P2, tests/lib.sh fm_tmux_isolation_gate: a stuck tmux server could leave tmux list-sessions hanging with no deadline, rather than reaching the skip message.

Both look real to me, and both are small. Since the Greptile check has to pass before this can merge, please either fix them (skip with a clear reason when $ROOT is under /tmp, and put a timeout on the probe) or reply on those threads if you see it differently.

Contract-class (mine): restore, unchanged, and VISION still aligns. So this is waiting on you for the Greptile items and on CI for the fresh run. Once both are green, it's on the auto-merge path.

fm_tmux_isolation_gate asked each socket's server for its sessions with no
deadline, so a stopped or stuck user tmux server held the gate, and with no
per-script deadline in the runner, the whole run, before it could skip.
Each probe now runs under fm_run_timed for FM_TMUX_ISOLATION_PROBE_SECONDS
(default 5), and a server that does not answer in time counts as live: the
gate skips and names the silent socket and the deadline.
The isolation suite re-runs itself under unshare -Urm after mounting a fresh
tmpfs on /tmp, so a checkout under /tmp lost the script to that mount: the
namespace check passed and the re-run failed on a missing file instead of
running its decoy cases. The suite now resolves its own physical path, skips
the decoy cases with a reason before mounting when that path is under /tmp,
and re-runs the physical path otherwise. A copy of the suite under /tmp pins
the skip.
…lation suite

The copy that pins the /tmp skip re-ran every host case, doubling the
suite's runtime and its exposure to their timing bounds. It now goes straight
to the decoy preflight it exists to exercise.
The probe-deadline and /tmp-checkout cases lengthen the suite from about 3.5 s
to 4.3-6.5 s in a private /tmp; the provisional hint now carries the slowest
of six new samples.
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @jaig-in. Both Greptile items are fixed, and fixed well.

What I checked at 5d9b5dbf: it merges main and adds four test-only commits.

  • The isolation gate now bounds each tmux list-sessions probe with fm_run_timed. A server that doesn't answer is treated as live, and the skip names it. There's a stopped-server regression test with a deadline check.
  • The isolation suite resolves its own physical path and skips the decoy cases when the checkout is under /tmp. It's pinned by a copy of the suite under /tmp.
  • The serial hint and shard doc are refreshed.

bin/fm-live-lab.sh itself is unchanged since my last review. There are no .github/, network, or secret changes, and the no-mistakes attestation binds this head. I approved fork CI for it: CI 41000846462, no-mistakes 41000846447 and 41000901336. Greptile passes and all review threads are resolved.

Contract-class (mine): restore, unchanged, and VISION still aligns. There's nothing more for you to do right now. It's waiting on the quick checks I just approved. After they pass, I'll run the full suite on our side, and if that's green it's on the auto-merge path.

@jaig-in jaig-in changed the title fix(bin): bind live-lab tmux calls to explicit sockets so cleanup cannot kill the default server fix(bin): keep live-lab tmux calls off the default server Nov 1, 2026
@jaig-in jaig-in changed the title fix(bin): keep live-lab tmux calls off the default server fix(bin): bind live-lab tmux calls to explicit sockets so cleanup cannot kill the default server Nov 1, 2026
@jaig-in jaig-in changed the title fix(bin): bind live-lab tmux calls to explicit sockets so cleanup cannot kill the default server fix(bin): pin every live-lab tmux call to the lab's explicit socket Nov 2, 2026
@jaig-in jaig-in changed the title fix(bin): pin every live-lab tmux call to the lab's explicit socket fix(bin): bind live-lab tmux calls to explicit sockets so cleanup cannot kill the default server Nov 2, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @jaig-in, and thanks for bringing main in yourself. You never need to do that for us, because conflicts are ours to fix, but it's appreciated. I checked 7a31116c against main 60f95dfa. The PR's own changes are the same as at 5d9b5dbf: same 10 files, and the merge only carried main through. It still merges cleanly. I approved this head's fork CI: CI 41539726883, plus no-mistakes 41539726948, 41539762326 and 41539872105.

Waiting on you for one thing: a clean no-mistakes pass on this head. The attestation on 7a31116c shows the ci step as skipped. Probably that's because the fork CI was still waiting for our approval when the pipeline reached it. Our rule is that every no-mistakes step must have completed on the head we merge, with no exceptions for a skip, so please run it through git push no-mistakes once more now that CI can start.

Everything else holds. Greptile passes with all threads resolved, and your live private-/tmp lab evidence is still in the body. Contract-class (my own read): restore, unchanged, because cleanup must never reach the user's default tmux server. VISION still aligns. Once the re-raise is clean and the quick checks pass, we run the full suite on our side, and if it's green it's on the auto-merge path.

@jaig-in jaig-in changed the title fix(bin): bind live-lab tmux calls to explicit sockets so cleanup cannot kill the default server fix(bin): address the live lab's tmux server by explicit socket, never TMUX_TMPDIR alone Nov 2, 2026
@jaig-in jaig-in changed the title fix(bin): address the live lab's tmux server by explicit socket, never TMUX_TMPDIR alone fix(bin): bind live-lab tmux calls to explicit sockets so cleanup cannot kill the default server Nov 2, 2026
@jaig-in

jaig-in commented Nov 3, 2026

Copy link
Copy Markdown
Author

Re-raised through no-mistakes on the same head 7a31116c with no skipped steps: all nine steps, pr and ci included, show completed in the attestation. The ci step was approved past the Full suite placeholder only; no code changed.

@kunchenguid kunchenguid added the full-ci Maintainer go-ahead: run the full CI suite on this outside pull request label Nov 3, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @jaig-in for the clean re-raise. The attestation on 7a31116c now shows all nine steps completed with nothing skipped, the quick checks pass, Greptile passes with every thread resolved, and it still merges cleanly with main. I've added the full-ci label so the full suite runs on this head. Nothing more is needed from you. Contract-class: restore, so if Full is green this is on the auto-merge path.

@kunchenguid
kunchenguid merged commit 87f26ac into kunchenguid:main Nov 3, 2026
55 of 59 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @jaig-in, really appreciate you taking the time on this.

joergoss pushed a commit to joergoss/firstmate that referenced this pull request Nov 23, 2026
…not kill the default server (kunchenguid#6422)

* fix(bin): bind live-lab tmux calls to explicit sockets so cleanup cannot kill the default server

tmux honours TMUX_TMPDIR only while that directory exists; once it is gone,
tmux silently resolves the default socket under /tmp/tmux-<uid>. The live
lab and its tests addressed their private server through TMUX_TMPDIR alone,
so a cleanup aimed at a removed lab directory ran kill-server against the
user's own default server and ended every session on it.

Every tmux call in bin/fm-live-lab.sh and its tests now names the lab socket
with tmux -S, and every kill-server runs only while that socket exists. The
lab's stub spawns, the fm-gate-refuse lab-socket test, and the lab cleanup
guidance in fm-brief.sh and fm-lab-home.sh follow the same rule.

tests/lib.sh gains fm_tmux_isolation_gate: a suite that starts or kills tmux
servers runs only when no live server answers in the default socket
directory (a private /tmp, or a disposable CI runner), skips with the
isolation it needs otherwise, and fails instead of skipping under CI. The
live-lab suites open with it. tests/fm-live-lab-isolation.test.sh covers the
gate both ways and proves that pane, say, check and down aimed at a missing
lab directory leave a decoy server on the default socket alive.

* no-mistakes(review): Run live-lab decoy only in private /tmp; drop gate bypasses

* no-mistakes(review): Drop inherited temp dirs inside the isolation namespace

* no-mistakes(document): Clarify live-lab down contract for socket-guarded server kill

* test(live-lab): bound the isolation decoy cleanup and report a decoy it cannot stop

* no-mistakes(review): Run bounded decoy cleanup tests on host; bound kill-server

* no-mistakes(document): Reflow stop_decoy doc comment in isolation test

* fix(tests): treat an exited unreaped decoy as gone in isolation cleanup

* no-mistakes(review): Make pid_running fail closed when ps errors

* no-mistakes(document): Document pid_running fail-closed ps behavior

* no-mistakes(review): add isolation suite serial hint; lane saturated, guard still fails

* no-mistakes(review): shorten isolation cleanup polls; hint 3482ms, guard passes

* test(tests): bound the tmux isolation gate's server probe

fm_tmux_isolation_gate asked each socket's server for its sessions with no
deadline, so a stopped or stuck user tmux server held the gate, and with no
per-script deadline in the runner, the whole run, before it could skip.
Each probe now runs under fm_run_timed for FM_TMUX_ISOLATION_PROBE_SECONDS
(default 5), and a server that does not answer in time counts as live: the
gate skips and names the silent socket and the deadline.

* test(tests): skip the live-lab decoy cases for a checkout under /tmp

The isolation suite re-runs itself under unshare -Urm after mounting a fresh
tmpfs on /tmp, so a checkout under /tmp lost the script to that mount: the
namespace check passed and the re-run failed on a missing file instead of
running its decoy cases. The suite now resolves its own physical path, skips
the decoy cases with a reason before mounting when that path is under /tmp,
and re-runs the physical path otherwise. A copy of the suite under /tmp pins
the skip.

* test(tests): run only the decoy preflight in the /tmp copy of the isolation suite

The copy that pins the /tmp skip re-ran every host case, doubling the
suite's runtime and its exposure to their timing bounds. It now goes straight
to the decoy preflight it exists to exercise.

* test(bin): refresh the live-lab isolation suite serial hint

The probe-deadline and /tmp-checkout cases lengthen the suite from about 3.5 s
to 4.3-6.5 s in a private /tmp; the provisional hint now carries the slowest
of six new samples.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-ci Maintainer go-ahead: run the full CI suite on this outside pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants