Repository navigation
fix(bin): bind live-lab tmux calls to explicit sockets so cleanup cannot kill the default server - #6422
Conversation
…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.
[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 |
9b29f50 to
7818021
Compare
4919ad6 to
9c4e801
Compare
|
Speaking as Kun's firstmate: thanks @jaig-in. First full read of head What it does: every tmux call in 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 Blocking (on you): the attestation is bound to |
9c4e801 to
e8a0084
Compare
|
Speaking as Kun's firstmate: thanks @jaig-in for bringing this up to date. The no-mistakes attestation now binds head I re-read the full diff against main (8 files, no 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 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. |
|
CI on |
|
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 Contract-class (mine): restore, unchanged. The live lab promises to kill only its own private tmux server, and that broke when its 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 |
|
Speaking as Kun's firstmate: thanks @jaig-in for bringing this up to date with main again. What I checked at Greptile scored this head below the 5/5 gate, with two test-harness findings. Neither touches the lab script itself:
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 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.
|
Speaking as Kun's firstmate: thanks @jaig-in. Both Greptile items are fixed, and fixed well. What I checked at
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. |
|
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 Waiting on you for one thing: a clean no-mistakes pass on this head. The attestation on Everything else holds. Greptile passes with all threads resolved, and your live private- |
|
Re-raised through no-mistakes on the same head |
|
Speaking as Kun's firstmate: thank you @jaig-in for the clean re-raise. The attestation on |
|
Speaking as Kun's firstmate: this is merged. Thank you @jaig-in, really appreciate you taking the time on this. |
…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.
Problem
Running
tests/fm-live-lab.test.shfrom 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_TMPDIRonly 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_TMPDIRalone:env -u TMUX TMUX_TMPDIR="$dir" tmux kill-server;bin/fm-live-lab.sh'slab_tmux()ranenv -u TMUX TMUX_TMPDIR="$TMUX_DIR" tmux "$@", including itslab_tmux kill-serverindown.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 underunshare -Urm sh -c 'mount -t tmpfs tmpfs /tmp && exec sh'):Fix
bin/fm-live-lab.shnames the lab's socket explicitly on every tmux call (tmux -S "$TMUX_DIR/tmux-$UID/default"), including the server start, and never relies onTMUX_TMPDIRalone.downkills the server only while that socket exists, and does nothing otherwise.tests/fm-live-lab.test.shandtests/fm-live-lab-up-mate.test.shdo 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.shdrives and stops its lab server through the explicit socket path, with the same exists-only cleanup.bin/fm-brief.sh(Herdr-lab briefs) and thebin/fm-lab-home.shheader now say to kill a lab server by its explicit socket, and only while it exists.tests/lib.shgainsfm_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
/tmpor 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:
TMUX_TMPDIRto 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.shstill starts its server throughTMUX_TMPDIR, because that test proves the private-directory contract; the directory exists at that point.Regression coverage
tests/fm-live-lab-isolation.test.shis new.CI=true), and runs again once only a dead socket is left.unshare -Urmwith a fresh tmpfs on/tmp, refuses to continue unless that/tmpis provably not the host one, and starts a decoy tmux server on the default socket there.It then points
pane,say,checkanddownat 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.
kill -0) as gone, with a real zombie case, so a runner whose PID 1 does not reap orphans cannot fail the suite falsely.bin/fm-live-lab.sh, the suite fails:panereads the decoy's window, and with only the kill path reverted,downkills the decoy server.Testing
tests/fm-live-lab.test.sh,tests/fm-live-lab-up-mate.test.sh,tests/fm-gate-refuse.test.shandtests/fm-live-lab-isolation.test.shpass in full throughbin/fm-test-run.shinside a private/tmp.bin/fm-live-lab.sh up --harness claudein a private/tmppassed its readiness checks, anddownstopped only the lab's server while a decoy default server in the same/tmpsurvived.bin/fm-lint.sh,bin/fm-doc-audience-check.shandbin/fm-test-run.sh --check-coveragepass.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