Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(ssh): adopt sessions left on the legacy tmux socket instead of shadowing them

review8542123765ac
diff --git a/CLAUDE.md b/CLAUDE.md
index c4807224f..f31d51b58 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -890,11 +890,23 @@ locally on the server and the same folder opened over SSH from a laptop were two
same-named sessions that never saw each other, and every switch of machines cold-restored into a
fresh shell (field report; issue #1319 was the mobile half of it). The original "never collide with
the user's own tmux" rationale is satisfied by `node-terminal` already — the user's own tmux is on
-`default`. `nodeterm-rmt` survives only as `LEGACY_RMT_TMUX_SOCKET`: the session-memory sweep, the
-dev-ports sweep, the reaper and the by-name kill still list it so sessions an older build left there
-stay visible as orphans and reapable/killable; nothing is spawned or re-attached there (a node whose
-session is still on the legacy socket cold-restores onto `node-terminal`, exactly as after a host
-reboot, and the old one shows up in the session-memory panel as an orphan). Do not give the SSH path
+`default`. `nodeterm-rmt` survives as `LEGACY_RMT_TMUX_SOCKET`, and **a session an older build left
+there is ADOPTED in place, never shadowed**: nothing is CREATED on it, but every remote command
+about ONE session first asks the host which socket holds that name (`sessionSocketProbe` →
+`sessionTmuxCmd`, `control-master.ts`) and targets it — attach, write, capture, pane queries, kill —
+and the warm/cold list (`remoteListSessionsArgs`) reads both sockets, so an adopted session reads
+WARM and nothing is typed into it. The first-merged unification did the opposite ("cold-restore onto
+`node-terminal`, exactly as after a host reboot") and it was wrong in a way a reboot is not: a reboot
+ENDS the old process, an upgrade does not. Measured on the reporting host, 2026-11-15, first launch
+after the upgrade: 27 nodes respawned in one second, 13 of them into a bare `claude` with no
+`--resume`, while all 27 originals kept running detached on the legacy socket. Rules that fall out:
+**a new builder for a per-session remote tmux command goes through `sessionTmuxCmd` and names the
+socket as `SESSION_SOCKET_REF`, never `RMT_TMUX_SOCKET`** (a bare constant silently misses every
+adopted session); the unified socket wins when both hold the name; the probe is stateless on purpose
+(most of these commands run for nodes we hold no live session for). It is generated shell, so it is
+run for real under `/bin/sh` against a two-socket fake tmux in `adopt-legacy-socket.realsh.test.ts`
+— keep it that way. The sweeps, the reaper and the by-name kill still list the legacy socket for
+what no node claims. Do not give the SSH path
a socket of its own again. **Known limit, deliberately out of scope here:** hook events reach ONE
nodeterm — the endpoint baked into the session's env at creation, or the failover winner when that
one is dead (`agents/hooks/managed-script.ts`) — so a session two machines share shows its RUNNING /
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index acbc69e7e..643b180a1 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -1606,8 +1606,11 @@ a read that slices a `\n`-bearing literal without it.
**An SSH project spawns on the host's `node-terminal` socket — the same one a nodeterm running on
that host uses.** That is what lets the same folder, opened locally on the server and over SSH from a
-laptop, attach the same `nt-<id>` sessions. `nodeterm-rmt` is a legacy name the sweeps and kills still
-list; never spawn on it, and never give the SSH path a socket of its own again
+laptop, attach the same `nt-<id>` sessions. `nodeterm-rmt` is the legacy socket: never spawn on it,
+but a session an older build left there is **adopted in place** — so a remote tmux command about ONE
+session must go through `sessionTmuxCmd` and name the socket as `SESSION_SOCKET_REF`
+(`control-master.ts`), not `RMT_TMUX_SOCKET`; a bare constant silently misses every adopted session
+and the node respawns beside its own live agent. Never give the SSH path a socket of its own again
(`src/core/remote-ssh/unified-socket.test.ts` pins the equality; CLAUDE.md "One tmux socket per host").
**A test never touches a live tmux server.** You will most likely run `npm test` from inside a
diff --git a/src/core/pty-manager.capture-visible.test.ts b/src/core/pty-manager.capture-visible.test.ts
index 1a19a437a..7c348ebf0 100644
--- a/src/core/pty-manager.capture-visible.test.ts
+++ b/src/core/pty-manager.capture-visible.test.ts
@@ -185,7 +185,7 @@ describe('captureVisible — SSH project', () => {
expect(calls).toHaveLength(1)
expect(calls[0].file).toBe('/usr/bin/ssh')
const remote = calls[0].args.at(-1)!
- expect(remote).toContain(`tmux -L ${RMT_TMUX_SOCKET} capture-pane -p -e -t '${TARGET}' ';' display-message`)
+ expect(remote).toContain(`tmux -L "$_nts" capture-pane -p -e -t '${TARGET}' ';' display-message`)
expect(remote).not.toMatch(/-S\b/)
expect(calls[0].args).toContain('ControlPath=/tmp/cm-abc')
})
@@ -236,7 +236,7 @@ describe('readWindowSize — the size a watcher client is spawned at', () => {
expect(calls).toHaveLength(1)
expect(calls[0].file).toBe('/usr/bin/ssh')
expect(calls[0].args.at(-1)).toContain(
- `tmux -L ${RMT_TMUX_SOCKET} display-message -p -t '${TARGET}' '#{window_width} #{window_height} #{status}'`
+ `tmux -L "$_nts" display-message -p -t '${TARGET}' '#{window_width} #{window_height} #{status}'`
)
})
diff --git a/src/core/pty-manager.control-input.test.ts b/src/core/pty-manager.control-input.test.ts
index 4182ffb92..2cf804023 100644
--- a/src/core/pty-manager.control-input.test.ts
+++ b/src/core/pty-manager.control-input.test.ts
@@ -211,7 +211,7 @@ describe('controlInput — ssh', () => {
expect(calls).toEqual([
{
file: '/usr/bin/ssh',
- args: remoteKeysArgs(SSH_REMOTE.conn, SSH_REMOTE.controlPath),
+ args: remoteKeysArgs(SSH_REMOTE.conn, SSH_REMOTE.controlPath, NAME),
input: keysCommandText(NAME, 'ls\r')
}
])
diff --git a/src/core/pty-manager.pane-owner.test.ts b/src/core/pty-manager.pane-owner.test.ts
index 09c795a21..27cfd3340 100644
--- a/src/core/pty-manager.pane-owner.test.ts
+++ b/src/core/pty-manager.pane-owner.test.ts
@@ -255,7 +255,7 @@ describe('PtyManager.paneOwner', () => {
const script = calls[0].args.at(-1) as string
// The HOST's socket, reached over ssh (the one exec above is the ssh client — no local tmux ran,
// so a local `nt-<id>`, which would be another machine's session, was never asked).
- expect(script).toContain(`tmux -L ${RMT_TMUX_SOCKET} display-message`)
+ expect(script).toContain(`tmux -L "$_nts" display-message`)
// Both halves of the read live in the one script: the fenced identity, then the ps rows.
expect(script).toContain("printf '%s\\n'")
expect(script).toContain('ps -ww -o pid= -o pgid= -o stat= -o args= -t "$tty"')
diff --git a/src/core/relay-keys.test.ts b/src/core/relay-keys.test.ts
index 2d8aae875..6034ea143 100644
--- a/src/core/relay-keys.test.ts
+++ b/src/core/relay-keys.test.ts
@@ -50,7 +50,7 @@ describe('key encodings', () => {
it('the remote send-keys line names only the closed set', () => {
const conn = { host: 'box.test', user: 'u' }
const args = remoteSendKeyArgs(conn, '/tmp/cm', 'nt-n1', ['-l', '1'])
- expect(args[args.length - 1]).toContain("tmux -L node-terminal send-keys -t '=nt-n1:' -l 1")
+ expect(args[args.length - 1]).toContain(`tmux -L "$_nts" send-keys -t '=nt-n1:' -l 1`)
expect(() => remoteSendKeyArgs(conn, '/tmp/cm', 'nt-n1', ['-l', '1;id'])).toThrow()
expect(() => remoteSendKeyArgs(conn, '/tmp/cm', 'nt n1', ['Enter'])).toThrow()
})
diff --git a/src/core/remote-ssh/adopt-legacy-socket.realsh.test.ts b/src/core/remote-ssh/adopt-legacy-socket.realsh.test.ts
new file mode 100644
index 000000000..a0292e4e3
--- /dev/null
+++ b/src/core/remote-ssh/adopt-legacy-socket.realsh.test.ts
@@ -0,0 +1,234 @@
+// The socket probe is generated shell that no compiler checks, and it decides which tmux SERVER a
+// node's commands reach — so it is run for real, under /bin/sh (and zsh, where installed: a remote
+// login shell is the user's), against a fake tmux with one state dir per socket.
+//
+// What it pins is the upgrade incident in control-master.ts `sessionSocketProbe`: a session an
+// older build left on `nodeterm-rmt` must be ATTACHED where it is, never shadowed by a fresh
+// `nt-<id>` on `node-terminal`.
+import { execFile, execFileSync } from 'child_process'
+import fs from 'fs'
+import os from 'os'
+import path from 'path'
+import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'
+import type { SshConnection } from '../../shared/ssh'
+import {
+ SESSION_SOCKET_REF,
+ remoteCapturePaneArgs,
+ remoteListSessionsArgs,
+ remoteTmuxKillArgs,
+ remoteTmuxPasteArgs,
+ remoteTmuxPtyArgs,
+ remoteTypedArgs,
+ sessionSocketProbe
+} from './control-master'
+import { TYPED_SOCKET_ENV_REF } from '../typed-input'
+
+const conn = { host: 'h.example.com', user: 'deploy' } as SshConnection
+const posix = process.platform !== 'win32'
+const zsh = posix
+ ? ['/bin/zsh', '/usr/bin/zsh', '/usr/local/bin/zsh', '/opt/homebrew/bin/zsh'].find((p) => fs.existsSync(p))
+ : undefined
+
+let dir: string, bin: string, log: string, stdinLog: string
+const stateOf = (socket: string): string => path.join(dir, `state-${socket}`)
+const add = (socket: string, session: string): void => {
+ fs.mkdirSync(stateOf(socket), { recursive: true })
+ fs.writeFileSync(path.join(stateOf(socket), session), '')
+}
+const calls = (): string[] =>
+ fs.existsSync(log) ? fs.readFileSync(log, 'utf8').split('\n').filter(Boolean) : []
+
+beforeAll(() => {
+ if (!posix) return
+ dir = fs.mkdtempSync(path.join(os.tmpdir(), 'nt-adopt-'))
+ bin = path.join(dir, 'bin')
+ log = path.join(dir, 'calls.log')
+ stdinLog = path.join(dir, 'stdin.log')
+ fs.mkdirSync(bin)
+ // Sessions are files in `state-<socket>`; a socket with no state dir has no server. Every call
+ // is logged as `<socket> <command> <target>`. `load-buffer` records what it read from stdin, so
+ // a probe that swallowed the payload shows up as an empty record.
+ fs.writeFileSync(
+ path.join(bin, 'tmux'),
+ [
+ '#!/bin/sh',
+ `D=${JSON.stringify(dir)}`,
+ 'sock=""; cmd=""; target=""',
+ 'while [ $# -gt 0 ]; do case "$1" in',
+ ' -L) shift; sock="$1";;',
+ ' -t) shift; [ -n "$target" ] || target="$1";;',
+ ' -s) shift; target="=$1";;',
+ ' has-session|new-session|capture-pane|kill-session|list-sessions|load-buffer|send-keys|if-shell|paste-buffer|attach-session|display-message|delete-buffer) [ -n "$cmd" ] || cmd="$1";;',
+ 'esac; shift; done',
+ 'S="$D/state-$sock"',
+ 'echo "$sock $cmd $target" >> "$D/calls.log"',
+ 'if [ "$FAKE_TMUX_BROKEN" = "$sock" ]; then echo "fake: cannot run" >&2; exit 127; fi',
+ 'name="${target#=}"; name="${name%:}"',
+ 'if [ ! -d "$S" ]; then echo "no server running on /tmp/tmux-1000/$sock" >&2; exit 1; fi',
+ 'case "$cmd" in',
+ ' list-sessions) ls "$S"; exit 0;;',
+ ' load-buffer) cat >> "$D/stdin.log"; exit 0;;',
+ ' new-session) : > "$S/$name"; exit 0;;',
+ ' kill-session) [ -e "$S/$name" ] || { echo "can\'t find session: $name" >&2; exit 1; }; rm -f "$S/$name"; exit 0;;',
+ ' *) [ -e "$S/$name" ] || { echo "can\'t find session: $name" >&2; exit 1; }; exit 0;;',
+ 'esac'
+ ].join('\n'),
+ { mode: 0o755 }
+ )
+})
+afterAll(() => {
+ if (posix) fs.rmSync(dir, { recursive: true, force: true })
+})
+beforeEach(() => {
+ if (!posix) return
+ for (const f of fs.readdirSync(dir)) if (f !== 'bin') fs.rmSync(path.join(dir, f), { recursive: true, force: true })
+})
+
+/** Run a remote command line the way sshd would: `<login shell> -c <line>`. */
+const run = (
+ shell: string,
+ line: string,
+ opts: { stdin?: string; env?: Record<string, string> } = {}
+): Promise<{ code: number; stdout: string; stderr: string }> =>
+ new Promise((resolve) => {
+ const child = execFile(
+ shell,
+ ['-c', line],
+ { env: { HOME: dir, PATH: `${bin}:/usr/bin:/bin`, ...opts.env } },
+ (err, stdout, stderr) => {
+ const code = err ? ((err as { code?: number }).code ?? 1) : 0
+ resolve({ code: typeof code === 'number' ? code : 1, stdout, stderr })
+ }
+ )
+ child.stdin?.end(opts.stdin ?? '')
+ })
+
+const last = (args: string[]): string => args[args.length - 1]
+
+describe.skipIf(!posix)('the session socket probe (real shell, fake tmux)', () => {
+ const shells = ['/bin/sh', ...(zsh ? [zsh] : [])]
+
+ for (const shell of shells) {
+ describe(shell, () => {
+ const resolved = async (session: string): Promise<string> =>
+ (await run(shell, `${sessionSocketProbe(session)}printf %s ${SESSION_SOCKET_REF}`)).stdout
+
+ it('a session only the legacy socket holds resolves to the legacy socket', async () => {
+ add('nodeterm-rmt', 'nt-a')
+ expect(await resolved('nt-a')).toBe('nodeterm-rmt')
+ })
+
+ it('a session the unified socket holds resolves there, without asking the legacy one', async () => {
+ add('node-terminal', 'nt-a')
+ add('nodeterm-rmt', 'nt-a')
+ expect(await resolved('nt-a')).toBe('node-terminal')
+ expect(calls()).toEqual(['node-terminal has-session =nt-a'])
+ })
+
+ it('a session NEITHER holds resolves to the unified socket: nothing is created on the legacy one', async () => {
+ add('nodeterm-rmt', 'nt-other')
+ expect(await resolved('nt-a')).toBe('node-terminal')
+ })
+
+ it('the target is exact: a longer legacy name does not adopt a shorter node', async () => {
+ add('nodeterm-rmt', 'nt-a-12')
+ expect(await resolved('nt-a-1')).toBe('node-terminal')
+ })
+
+ it('a host where tmux cannot run still resolves (to the unified socket) and the body runs', async () => {
+ const r = await run(shell, `${sessionSocketProbe('nt-a')}printf %s ${SESSION_SOCKET_REF}`, {
+ env: { FAKE_TMUX_BROKEN: 'node-terminal' }
+ })
+ expect(r.stdout).toBe('node-terminal')
+ })
+
+ it('SPAWN: attaches the legacy session instead of creating a twin on the unified socket', async () => {
+ add('nodeterm-rmt', 'nt-a')
+ const r = await run(shell, last(remoteTmuxPtyArgs(conn, '/s.sock', 'nt-a', '/srv/app')))
+ expect(r.code).toBe(0)
+ expect(calls().filter((c) => c.includes('new-session'))).toEqual(['nodeterm-rmt new-session =nt-a'])
+ expect(fs.existsSync(path.join(stateOf('node-terminal'), 'nt-a'))).toBe(false)
+ })
+
+ it('SPAWN: a genuinely new node is created on the unified socket even while a legacy server lives', async () => {
+ add('nodeterm-rmt', 'nt-other')
+ fs.mkdirSync(stateOf('node-terminal'))
+ await run(shell, last(remoteTmuxPtyArgs(conn, '/s.sock', 'nt-new', '/srv/app')))
+ expect(calls().filter((c) => c.includes('new-session'))).toEqual(['node-terminal new-session =nt-new'])
+ expect(fs.readdirSync(stateOf('nodeterm-rmt'))).toEqual(['nt-other'])
+ })
+
+ it('READ + KILL follow the session to the legacy socket, and the exit code is the body\'s', async () => {
+ add('nodeterm-rmt', 'nt-a')
+ expect((await run(shell, last(remoteCapturePaneArgs(conn, '/s.sock', 'nt-a', false)))).code).toBe(0)
+ expect(calls().at(-1)).toBe('nodeterm-rmt capture-pane =nt-a:')
+ expect((await run(shell, last(remoteTmuxKillArgs(conn, '/s.sock', 'nt-a')))).code).toBe(0)
+ expect(fs.existsSync(path.join(stateOf('nodeterm-rmt'), 'nt-a'))).toBe(false)
+ // Gone everywhere now: the kill answers tmux's own exit 1, which callers read as "already gone".
+ expect((await run(shell, last(remoteTmuxKillArgs(conn, '/s.sock', 'nt-a')))).code).toBe(1)
+ })
+
+ it('WRITE: the stdin payload reaches load-buffer on the legacy socket — the probe never reads it', async () => {
+ add('nodeterm-rmt', 'nt-a')
+ const r = await run(shell, last(remoteTmuxPasteArgs(conn, '/s.sock', 'nt-a', 'nt-paste-deadbeef', true)), {
+ stdin: 'hello adopted pane'
+ })
+ expect(r.code).toBe(0)
+ expect(fs.readFileSync(stdinLog, 'utf8')).toBe('hello adopted pane')
+ expect(calls().filter((c) => c.includes('load-buffer'))).toEqual(['nodeterm-rmt load-buffer =nt-a:'])
+ })
+
+ it('TYPED: the inner sh script inherits the probed socket through its environment', async () => {
+ expect(TYPED_SOCKET_ENV_REF).toBe(SESSION_SOCKET_REF)
+ add('nodeterm-rmt', 'nt-a')
+ const r = await run(shell, last(remoteTypedArgs(conn, '/s.sock', 'nt-a', 'nt-paste-deadbeef')), {
+ stdin: '\nhi\n'
+ })
+ expect(r.code).toBe(0)
+ const after = calls().filter((c) => !c.includes('has-session'))
+ expect(after.length).toBeGreaterThan(0)
+ for (const c of after) expect(c.startsWith('nodeterm-rmt ')).toBe(true)
+ expect(fs.readFileSync(stdinLog, 'utf8')).toBe('hi')
+ })
+
+ describe('the warm/cold list', () => {
+ const list = (env?: Record<string, string>): ReturnType<typeof run> =>
+ run(shell, last(remoteListSessionsArgs(conn, '/s.sock')), { env })
+ const names = (stdout: string): string[] => stdout.split('\n').filter(Boolean).sort()
+
+ it('legacy-only host: exit 0 and the legacy names — the node reads WARM, nothing is typed into it', async () => {
+ add('nodeterm-rmt', 'nt-a')
+ const r = await list()
+ expect(r.code).toBe(0)
+ expect(names(r.stdout)).toEqual(['nt-a'])
+ })
+
+ it('both sockets: the union', async () => {
+ add('node-terminal', 'nt-b')
+ add('nodeterm-rmt', 'nt-a')
+ const r = await list()
+ expect(r.code).toBe(0)
+ expect(names(r.stdout)).toEqual(['nt-a', 'nt-b'])
+ })
+
+ it('no server on either: tmux\'s own exit 1, the only evidence of absence', async () => {
+ const r = await list()
+ expect(r.code).toBe(1)
+ expect(names(r.stdout)).toEqual([])
+ })
+
+ it('a FAILED read of the unified socket stays a failed read, whatever the legacy one lists', async () => {
+ add('nodeterm-rmt', 'nt-a')
+ const r = await list({ FAKE_TMUX_BROKEN: 'node-terminal' })
+ expect(r.code).toBe(127)
+ })
+ })
+ })
+ }
+
+ it('the fake tmux is on PATH for these runs (a self-check: a silent miss would pass every "unified" case)', () => {
+ expect(execFileSync('/bin/sh', ['-c', 'command -v tmux'], { env: { PATH: `${bin}:/usr/bin:/bin` } }).toString().trim()).toBe(
+ path.join(bin, 'tmux')
+ )
+ })
+})
diff --git a/src/core/remote-ssh/control-master.injection.test.ts b/src/core/remote-ssh/control-master.injection.test.ts
index 0f12a1df3..62803f629 100644
--- a/src/core/remote-ssh/control-master.injection.test.ts
+++ b/src/core/remote-ssh/control-master.injection.test.ts
@@ -166,7 +166,8 @@ describe('remoteTmuxPtyArgs: an attacker-controlled node id is DATA, never comma
// and the command still carries exactly one tmux invocation with the expected shape (the
// PATH prologue + tmux-missing fallback now precede it, so the head is indexOf, not slice).
const t = argv.lastIndexOf('tmux') // the guard's `command -v tmux` also carries the word
- expect(argv.slice(t, t + 3)).toEqual(['tmux', '-L', 'node-terminal'])
+ // The socket is the probed one (`sessionSocketProbe`), a shell word — never a spliced name.
+ expect(argv.slice(t, t + 3)).toEqual(['tmux', '-L', '"$_nts"'])
expect(argv.filter((a) => a === 'new-session')).toHaveLength(1)
expect(argv).toContain('nt-n1')
})
diff --git a/src/core/remote-ssh/control-master.test.ts b/src/core/remote-ssh/control-master.test.ts
index 28689dea1..c02afe6e5 100644
--- a/src/core/remote-ssh/control-master.test.ts
+++ b/src/core/remote-ssh/control-master.test.ts
@@ -1,6 +1,8 @@
import os from 'os'
import { describe, expect, it } from 'vitest'
import {
+ SESSION_SOCKET_REF,
+ sessionSocketProbe,
controlPathFor,
masterArgs,
childArgs,
@@ -42,6 +44,8 @@ import { VISIBLE_CAPTURE_FORMAT } from '../watch-link/capture-route'
/** The PATH-append prologue every remote tmux line now starts with (issue #449). */
const TP = remoteTmuxPathPrologue()
+// Every command about ONE session probes which socket holds it first (`sessionSocketProbe`).
+const SX = `${TP}${sessionSocketProbe('nt-x')}`
const conn = { host: 'h.example.com', user: 'deploy', port: 2222, identityFile: '/k/id' }
@@ -180,7 +184,7 @@ describe('childArgs', () => {
})
describe('remoteTmuxPasteArgs', () => {
- const TMUX = `tmux -L ${RMT_TMUX_SOCKET}`
+ const TMUX = `tmux -L ${SESSION_SOCKET_REF}`
const BUF = 'nt-paste-deadbeef'
const cmd = (session: string, enter: boolean): string =>
remoteTmuxPasteArgs(conn, '/s.sock', session, BUF, enter).slice(-1)[0]
@@ -189,7 +193,7 @@ describe('remoteTmuxPasteArgs', () => {
expect(remoteTmuxPasteArgs(conn, '/s.sock', 'nt-x', BUF, true)).toEqual([
...childPrefix,
- `${TP}${TMUX} load-buffer -b ${BUF} - ';' ` +
+ `${SX}${TMUX} load-buffer -b ${BUF} - ';' ` +
`if-shell -F -t '=nt-x:' '#{pane_in_mode}' 'send-keys -t =nt-x: -X cancel' ';' ` +
`paste-buffer -d -p -r -b ${BUF} -t '=nt-x:' ';' send-keys -t '=nt-x:' Enter`
])
@@ -250,25 +254,25 @@ describe('remoteTmuxEnterArgs', () => {
expect(remoteTmuxEnterArgs(conn, '/s.sock', 'nt-x')).toEqual([
...childPrefix,
- `${TP}tmux -L ${RMT_TMUX_SOCKET} send-keys -t '=nt-x:' Enter`
+ `${SX}tmux -L ${SESSION_SOCKET_REF} send-keys -t '=nt-x:' Enter`
])
})
it('steps the cursor left first for a typed message ending in a backslash', () => {
const args = remoteTmuxEnterArgs(conn, '/s.sock', 'nt-x', { cursorLeftFirst: true })
- expect(args[args.length - 1]).toBe(`${TP}tmux -L ${RMT_TMUX_SOCKET} send-keys -t '=nt-x:' Left Enter`)
+ expect(args[args.length - 1]).toBe(`${SX}tmux -L ${SESSION_SOCKET_REF} send-keys -t '=nt-x:' Left Enter`)
})
})
describe('remoteCapturePaneArgs', () => {
it('captures the whole scrollback (-S -) when full', () => {
const args = remoteCapturePaneArgs(conn, '/s.sock', 'nt-x', true)
- expect(args[args.length - 1]).toBe(`${TP}tmux -L ${RMT_TMUX_SOCKET} capture-pane -p -e -t '=nt-x:' -S -`)
+ expect(args[args.length - 1]).toBe(`${SX}tmux -L ${SESSION_SOCKET_REF} capture-pane -p -e -t '=nt-x:' -S -`)
})
it('captures the recent ~200 lines (-S -200) when not full', () => {
const args = remoteCapturePaneArgs(conn, '/s.sock', 'nt-x', false)
- expect(args[args.length - 1]).toBe(`${TP}tmux -L ${RMT_TMUX_SOCKET} capture-pane -p -e -t '=nt-x:' -S -200`)
+ expect(args[args.length - 1]).toBe(`${SX}tmux -L ${SESSION_SOCKET_REF} capture-pane -p -e -t '=nt-x:' -S -200`)
})
})
@@ -284,7 +288,7 @@ describe('remoteCaptureVisibleArgs', () => {
const args = remoteCaptureVisibleArgs(conn, '/s.sock', 'nt-x')
expect(args.slice(0, childPrefix.length)).toEqual(childPrefix)
expect(args[args.length - 1]).toBe(
- `${TP}tmux -L ${RMT_TMUX_SOCKET} capture-pane -p -e -t '=nt-x:' ';' ` +
+ `${SX}tmux -L ${SESSION_SOCKET_REF} capture-pane -p -e -t '=nt-x:' ';' ` +
`display-message -p -t '=nt-x:' '${VISIBLE_CAPTURE_FORMAT}'`
)
})
@@ -296,7 +300,7 @@ describe('remoteTmuxWatcherArgs', () => {
expect(args[0]).toBe('-t')
expect(args.slice(1, 1 + childPrefix.length)).toEqual(childPrefix)
expect(args[args.length - 1]).toBe(
- `${TP}tmux -L ${RMT_TMUX_SOCKET} attach-session -E -f 'ignore-size,read-only' -t '=nt-x:'`
+ `${SX}tmux -L ${SESSION_SOCKET_REF} attach-session -E -f 'ignore-size,read-only' -t '=nt-x:'`
)
})
@@ -313,7 +317,7 @@ describe('remoteWindowSizeArgs', () => {
const args = remoteWindowSizeArgs(conn, '/s.sock', 'nt-x')
expect(args.slice(0, childPrefix.length)).toEqual(childPrefix)
expect(args[args.length - 1]).toBe(
- `${TP}tmux -L ${RMT_TMUX_SOCKET} display-message -p -t '=nt-x:' '#{window_width} #{window_height} #{status}'`
+ `${SX}tmux -L ${SESSION_SOCKET_REF} display-message -p -t '=nt-x:' '#{window_width} #{window_height} #{status}'`
)
})
})
@@ -322,7 +326,7 @@ describe('remotePaneCommandArgs', () => {
it('asks the remote tmux for the pane_current_command of the session', () => {
const args = remotePaneCommandArgs(conn, '/s.sock', 'nt-x')
expect(args[args.length - 1]).toBe(
- `${TP}tmux -L ${RMT_TMUX_SOCKET} display-message -p -t '=nt-x:' '#{pane_current_command}'`
+ `${SX}tmux -L ${SESSION_SOCKET_REF} display-message -p -t '=nt-x:' '#{pane_current_command}'`
)
})
})
@@ -331,7 +335,7 @@ describe('remotePaneCwdArgs', () => {
it('asks the remote tmux for the pane_current_path of the session', () => {
const args = remotePaneCwdArgs(conn, '/s.sock', 'nt-x')
expect(args[args.length - 1]).toBe(
- `${TP}tmux -L ${RMT_TMUX_SOCKET} display-message -p -t '=nt-x:' '#{pane_current_path}'`
+ `${SX}tmux -L ${SESSION_SOCKET_REF} display-message -p -t '=nt-x:' '#{pane_current_path}'`
)
})
})
@@ -340,7 +344,7 @@ describe('remote foreground process termination', () => {
it('reads pane pid + command through the existing ControlMaster', () => {
const args = remotePaneProcessArgs(conn, '/s.sock', 'nt-x')
expect(args[args.length - 1]).toBe(
- `${TP}tmux -L ${RMT_TMUX_SOCKET} display-message -p -t '=nt-x:' '#{pane_pid}|#{pane_current_command}'`
+ `${SX}tmux -L ${SESSION_SOCKET_REF} display-message -p -t '=nt-x:' '#{pane_pid}|#{pane_current_command}'`
)
})
@@ -644,9 +648,9 @@ describe('killing a session by name (both sockets, exact target)', () => {
expect([...localKillSockets(null, true)].sort()).toEqual(['node-terminal', 'nodeterm-rmt'])
})
- it('keeps the remote default on the host socket, and overrides it explicitly', () => {
+ it('kills on the socket that HOLDS the session by default, and on a named one explicitly', () => {
expect(remoteTmuxKillArgs(conn, '/s.sock', 'nt-x').at(-1)).toBe(
- `${TP}tmux -L ${RMT_TMUX_SOCKET} kill-session -t '=nt-x'`
+ `${SX}tmux -L ${SESSION_SOCKET_REF} kill-session -t '=nt-x'`
)
expect(remoteTmuxKillArgs(conn, '/s.sock', 'nt-x', 'nodeterm-rmt').at(-1)).toBe(
`${TP}tmux -L nodeterm-rmt kill-session -t '=nt-x'`
@@ -668,3 +672,27 @@ describe('killing a session by name (both sockets, exact target)', () => {
// The `remoteFramedDelivery` suite that lived here is gone with the plan itself (issue #453) —
// the envelope now rides `remotePasteDelivery` (enter=true); see the tombstones in
// control-master.ts and tmux-naming.ts.
+
+describe('sessionSocketProbe — adopting a session the pre-unification build left on the legacy socket', () => {
+ it('is pinned text: unified socket first, legacy only on a miss, stdin never read', () => {
+ expect(sessionSocketProbe('nt-x')).toBe(
+ '_nts=node-terminal; ' +
+ 'tmux -L node-terminal has-session -t "=nt-x" </dev/null >/dev/null 2>&1 || ' +
+ '{ tmux -L nodeterm-rmt has-session -t "=nt-x" </dev/null >/dev/null 2>&1 && _nts=nodeterm-rmt; }; '
+ )
+ expect(SESSION_SOCKET_REF).toBe('"$_nts"')
+ })
+
+ it('never splices an id it did not expect: no probe, unified socket', () => {
+ for (const hostile of ['nt-x;id', 'nt-$(id)', 'nt-"x', "nt-'x", 'nt x', '']) {
+ expect(sessionSocketProbe(hostile)).toBe('_nts=node-terminal; ')
+ }
+ })
+
+ it('lists BOTH sockets for the warm/cold decision, keeping the unified exit code', () => {
+ const cmd = remoteListSessionsArgs(conn, '/cm/p1').at(-1)!
+ expect(cmd).toContain("tmux -L node-terminal list-sessions -F '#{session_name}'")
+ expect(cmd).toContain("tmux -L nodeterm-rmt list-sessions -F '#{session_name}' 2>/dev/null")
+ expect(cmd.endsWith('exit $r')).toBe(true)
+ })
+})
diff --git a/src/core/remote-ssh/control-master.ts b/src/core/remote-ssh/control-master.ts
index 6d5f41e4e..12c358fb4 100644
--- a/src/core/remote-ssh/control-master.ts
+++ b/src/core/remote-ssh/control-master.ts
@@ -44,11 +44,14 @@ import { WATCHER_CLIENT_FLAGS, WINDOW_SIZE_FORMAT } from '../watch-link/watcher-
export const RMT_TMUX_SOCKET: string = TMUX_SOCKET
/**
- * The socket the SSH path used BEFORE the unification. Nothing is spawned here any more; the sweeps
- * (session memory, dev ports), the reaper and the by-name kill still list it so sessions an older
- * build left there stay visible as orphans and reapable/killable instead of leaking. A session
- * still living here is NOT re-attached — the node cold-restores onto `TMUX_SOCKET` exactly as after
- * a host reboot, and the old one shows up in the session-memory panel as an orphan.
+ * The socket the SSH path used BEFORE the unification. Nothing is CREATED here any more, but a
+ * session an older build left here is ADOPTED in place — re-attached, written to, captured and
+ * killed on this socket — for as long as it lives (`sessionSocketProbe`, which is also where the
+ * incident that forced this is written down). The first-merged unification did the opposite: it
+ * cold-restored the node onto `TMUX_SOCKET` "exactly as after a host reboot" and left the original
+ * running as an orphan. A reboot ends the old process; an upgrade does not, so that turned every
+ * upgrade into a duplicated, half-resumed canvas. The sweeps (session memory, dev ports), the
+ * reaper and the by-name kill still list this socket for what no node claims.
*/
export const LEGACY_RMT_TMUX_SOCKET = 'nodeterm-rmt'
@@ -65,6 +68,56 @@ export function tmuxCmd(body: string): string {
return `${remoteTmuxPathPrologue()}${body}`
}
+/** The shell variable `sessionSocketProbe` sets, as the word a builder splices after `tmux -L`. */
+export const SESSION_SOCKET_REF = '"$_nts"'
+
+/**
+ * WHICH SOCKET HOLDS THIS SESSION, decided on the host, in the same shell line that then uses it.
+ *
+ * The unification (2026-11) moved every SSH spawn onto `RMT_TMUX_SOCKET` and, as first merged,
+ * simply stopped looking at `LEGACY_RMT_TMUX_SOCKET`. A session living there was therefore
+ * invisible on the first launch after the upgrade: `new-session -A` on the new socket found nothing
+ * and CREATED a second `nt-<id>`, the node cold-restored, and the original — a live agent CLI with
+ * its conversation — kept running detached beside it. Measured on the reporting host (2026-11-15):
+ * 27 nodes respawned in one second, 13 of them into a bare `claude` with no `--resume`, while all
+ * 27 originals (and 45 more) sat on the legacy socket holding RAM.
+ *
+ * tmux cannot move a session between servers, so the session is ADOPTED where it is: when the
+ * unified socket does not hold the name and the legacy one does, every command about that session
+ * targets the legacy socket. Nothing is ever CREATED there by choice — a name neither socket holds
+ * resolves to the unified one — so the legacy server only drains as its sessions end.
+ *
+ * Stateless on purpose. The desktop could remember "this node is on the legacy socket", but most
+ * commands here run for nodes it holds no live session for (after an app restart, for a backgrounded
+ * project), and a remembered answer outlives the session it was about. Asking costs one host-local
+ * `has-session` (two when the unified socket misses) inside an ssh exec we were making anyway.
+ *
+ * The unified socket WINS when both hold the name: that is what the first-merged build left behind
+ * on every host it ran against, and the pane the user has been typing into since is the new one.
+ *
+ * `</dev/null` because several callers ride a payload on the ssh child's stdin (`load-buffer -`);
+ * the probe must never be the one that reads it. The exact `=name` target is double-quoted — under
+ * zsh a bare leading `=` is a command lookup — and the id is spliced only when it is the
+ * `[A-Za-z0-9._-]` shape `sessionName()` produces; anything else gets the unified socket and no
+ * probe, so a hostile id never reaches a shell line through here.
+ */
+export function sessionSocketProbe(sessionId: string): string {
+ if (!/^[A-Za-z0-9._-]+$/.test(sessionId)) return `_nts=${RMT_TMUX_SOCKET}; `
+ const t = `"=${sessionId}"`
+ return (
+ `_nts=${RMT_TMUX_SOCKET}; ` +
+ `tmux -L ${RMT_TMUX_SOCKET} has-session -t ${t} </dev/null >/dev/null 2>&1 || ` +
+ `{ tmux -L ${LEGACY_RMT_TMUX_SOCKET} has-session -t ${t} </dev/null >/dev/null 2>&1 && _nts=${LEGACY_RMT_TMUX_SOCKET}; }; `
+ )
+}
+
+/** `tmuxCmd` for a command about ONE session: PATH prologue, the socket probe, then the body —
+ * which names the socket as `SESSION_SOCKET_REF`. The body stays last, so its exit code is the
+ * command's, exactly as with `tmuxCmd`. */
+export function sessionTmuxCmd(sessionId: string, body: string): string {
+ return tmuxCmd(`${sessionSocketProbe(sessionId)}${body}`)
+}
+
/**
* Per-project ControlMaster socket path. Deliberately SHORT and space-free. The macOS userData dir
* (`~/Library/Application Support/<app>`) cannot host the socket: it both exceeds the unix-domain
@@ -312,7 +365,17 @@ export function remoteListSessionsArgs(conn: SshConnection, controlPath: string)
return childArgs(
conn,
controlPath,
- tmuxCmd(`tmux -L ${RMT_TMUX_SOCKET} list-sessions -F '#{session_name}'`)
+ tmuxCmd(
+ // Both sockets, one exec: a session still on the legacy socket is ADOPTED
+ // (`sessionSocketProbe`), so it must also read as PRESENT here — this list is what decides
+ // warm vs cold, and "cold" types `claude --resume` into the pane. The exit code stays the
+ // unified socket's own (1 = no server = evidence of absence), except that a legacy server
+ // that listed something turns that 1 into 0: the host does hold sessions.
+ `a=$(tmux -L ${RMT_TMUX_SOCKET} list-sessions -F '#{session_name}'); r=$?; ` +
+ `b=$(tmux -L ${LEGACY_RMT_TMUX_SOCKET} list-sessions -F '#{session_name}' 2>/dev/null); ` +
+ `[ -n "$b" ] && [ "$r" = 1 ] && r=0; ` +
+ `printf '%s\\n%s\\n' "$a" "$b"; exit $r`
+ )
)
}
@@ -365,7 +428,7 @@ export function remoteTmuxPasteArgs(
enter: boolean
): string[] {
assertPasteTarget(sessionId, buffer)
- const tmux = `tmux -L ${RMT_TMUX_SOCKET}`
+ const tmux = `tmux -L ${SESSION_SOCKET_REF}`
// EXACT target (`exactPaneTarget`): a bare name prefix-matches a longer session on a miss.
// Quoted for the remote shell where it is a word of its own (zsh expands a leading `=`); inside
// the single-quoted `if-shell` body tmux's own lexer reads it.
@@ -376,7 +439,7 @@ export function remoteTmuxPasteArgs(
`if-shell -F -t ${t} '#{pane_in_mode}' 'send-keys -t ${pane} -X cancel' ';' ` +
`paste-buffer -d -p -r -b ${buffer} -t ${t}`
if (enter) cmd += ` ';' send-keys -t ${t} Enter`
- return childArgs(conn, controlPath, tmuxCmd(cmd))
+ return childArgs(conn, controlPath, sessionTmuxCmd(sessionId, cmd))
}
/**
@@ -404,7 +467,12 @@ export function remoteTypedArgs(
return childArgs(
conn,
controlPath,
- tmuxCmd(`sh -c ${posixQuote(typedInputScript('tmux', RMT_TMUX_SOCKET, sessionId, buffer))}`)
+ // The script runs under its own `sh`, which does not see this line's variables: hand the probed
+ // socket over as that process's environment.
+ sessionTmuxCmd(
+ sessionId,
+ `_nts="$_nts" sh -c ${posixQuote(typedInputScript('tmux', SESSION_SOCKET_REF, sessionId, buffer))}`
+ )
)
}
@@ -435,7 +503,7 @@ export function remoteTmuxEnterArgs(
return childArgs(
conn,
controlPath,
- tmuxCmd(`tmux -L ${RMT_TMUX_SOCKET} send-keys -t ${posixQuote(exactPaneTarget(sessionId))} ${keys}`)
+ sessionTmuxCmd(sessionId, `tmux -L ${SESSION_SOCKET_REF} send-keys -t ${posixQuote(exactPaneTarget(sessionId))} ${keys}`)
)
}
@@ -443,10 +511,19 @@ export function remoteTmuxEnterArgs(
export function remoteDeleteBufferArgs(
conn: SshConnection,
controlPath: string,
- buffer: string
+ buffer: string,
+ /** The session the paste was for — the buffer lives on THAT session's server
+ * (`sessionSocketProbe`). Omitted = the unified socket. */
+ sessionId?: string
): string[] {
assertPasteBuffer(buffer)
- return childArgs(conn, controlPath, tmuxCmd(`tmux -L ${RMT_TMUX_SOCKET} delete-buffer -b ${buffer}`))
+ return childArgs(
+ conn,
+ controlPath,
+ sessionId === undefined
+ ? tmuxCmd(`tmux -L ${RMT_TMUX_SOCKET} delete-buffer -b ${buffer}`)
+ : sessionTmuxCmd(sessionId, `tmux -L ${SESSION_SOCKET_REF} delete-buffer -b ${buffer}`)
+ )
}
/**
@@ -471,7 +548,7 @@ export function remotePasteDelivery(
return {
args: remoteTmuxPasteArgs(conn, controlPath, sessionId, buffer, enter),
body,
- cleanup: remoteDeleteBufferArgs(conn, controlPath, buffer)
+ cleanup: remoteDeleteBufferArgs(conn, controlPath, buffer, sessionId)
}
}
/**
@@ -547,10 +624,17 @@ export function remoteTmuxKillArgs(
conn: SshConnection,
controlPath: string,
sessionId: string,
- socket: string = RMT_TMUX_SOCKET
+ socket?: string
): string[] {
// Quoted: on a zsh login shell an unquoted word starting with `=` is a command-path lookup.
- return childArgs(conn, controlPath, tmuxCmd(`tmux -L ${socket} kill-session -t ${posixQuote(exactTarget(sessionId))}`))
+ const kill = (word: string): string => `tmux -L ${word} kill-session -t ${posixQuote(exactTarget(sessionId))}`
+ // No socket named = "this node's session, wherever it lives": the one the probe resolves, so an
+ // ADOPTED legacy session ends with its node instead of leaking as an orphan.
+ return childArgs(
+ conn,
+ controlPath,
+ socket === undefined ? sessionTmuxCmd(sessionId, kill(SESSION_SOCKET_REF)) : tmuxCmd(kill(socket))
+ )
}
/**
@@ -574,7 +658,7 @@ export function remoteCapturePaneArgs(conn: SshConnection, controlPath: string,
return childArgs(
conn,
controlPath,
- tmuxCmd(`tmux -L ${RMT_TMUX_SOCKET} capture-pane -p -e -t ${posixQuote(exactPaneTarget(sessionId))} -S ${full ? '-' : '-200'}`)
+ sessionTmuxCmd(sessionId, `tmux -L ${SESSION_SOCKET_REF} capture-pane -p -e -t ${posixQuote(exactPaneTarget(sessionId))} -S ${full ? '-' : '-200'}`)
)
}
/**
@@ -590,8 +674,9 @@ export function remoteCaptureVisibleArgs(conn: SshConnection, controlPath: strin
return childArgs(
conn,
controlPath,
- tmuxCmd(
- `tmux -L ${RMT_TMUX_SOCKET} capture-pane -p -e -t ${target} ';' ` +
+ sessionTmuxCmd(
+ sessionId,
+ `tmux -L ${SESSION_SOCKET_REF} capture-pane -p -e -t ${target} ';' ` +
`display-message -p -t ${target} ${posixQuote(VISIBLE_CAPTURE_FORMAT)}`
)
)
@@ -613,8 +698,9 @@ export function remoteTmuxWatcherArgs(conn: SshConnection, controlPath: string,
...childArgs(
conn,
controlPath,
- tmuxCmd(
- `tmux -L ${RMT_TMUX_SOCKET} attach-session -E -f ${posixQuote(WATCHER_CLIENT_FLAGS)} ` +
+ sessionTmuxCmd(
+ sessionId,
+ `tmux -L ${SESSION_SOCKET_REF} attach-session -E -f ${posixQuote(WATCHER_CLIENT_FLAGS)} ` +
`-t ${posixQuote(capturePaneTarget(sessionId))}`
)
)
@@ -626,8 +712,9 @@ export function remoteWindowSizeArgs(conn: SshConnection, controlPath: string, s
return childArgs(
conn,
controlPath,
- tmuxCmd(
- `tmux -L ${RMT_TMUX_SOCKET} display-message -p -t ${posixQuote(capturePaneTarget(sessionId))} ` +
+ sessionTmuxCmd(
+ sessionId,
+ `tmux -L ${SESSION_SOCKET_REF} display-message -p -t ${posixQuote(capturePaneTarget(sessionId))} ` +
posixQuote(WINDOW_SIZE_FORMAT)
)
)
@@ -653,8 +740,9 @@ export function remoteSessionAgeArgs(conn: SshConnection, controlPath: string, s
return childArgs(
conn,
controlPath,
- tmuxCmd(
- `printf '%s %s\n' "$(tmux -L ${RMT_TMUX_SOCKET} display-message -p -t '=${sessionId}:' '#{session_created}')" "$(date +%s)"`
+ sessionTmuxCmd(
+ sessionId,
+ `printf '%s %s\n' "$(tmux -L ${SESSION_SOCKET_REF} display-message -p -t '=${sessionId}:' '#{session_created}')" "$(date +%s)"`
)
)
}
@@ -685,7 +773,7 @@ export function remotePaneCommandArgs(conn: SshConnection, controlPath: string,
return childArgs(
conn,
controlPath,
- tmuxCmd(`tmux -L ${RMT_TMUX_SOCKET} display-message -p -t ${posixQuote(exactPaneTarget(sessionId))} '#{pane_current_command}'`)
+ sessionTmuxCmd(sessionId, `tmux -L ${SESSION_SOCKET_REF} display-message -p -t ${posixQuote(exactPaneTarget(sessionId))} '#{pane_current_command}'`)
)
}
@@ -705,7 +793,7 @@ export function remoteSendKeyArgs(
return childArgs(
conn,
controlPath,
- tmuxCmd(`tmux -L ${RMT_TMUX_SOCKET} send-keys -t ${posixQuote(exactPaneTarget(sessionId))} ${keyArgs.join(' ')}`)
+ sessionTmuxCmd(sessionId, `tmux -L ${SESSION_SOCKET_REF} send-keys -t ${posixQuote(exactPaneTarget(sessionId))} ${keyArgs.join(' ')}`)
)
}
@@ -714,7 +802,7 @@ export function remotePaneCwdArgs(conn: SshConnection, controlPath: string, sess
return childArgs(
conn,
controlPath,
- tmuxCmd(`tmux -L ${RMT_TMUX_SOCKET} display-message -p -t ${posixQuote(exactPaneTarget(sessionId))} '#{pane_current_path}'`)
+ sessionTmuxCmd(sessionId, `tmux -L ${SESSION_SOCKET_REF} display-message -p -t ${posixQuote(exactPaneTarget(sessionId))} '#{pane_current_path}'`)
)
}
@@ -727,7 +815,7 @@ export function remotePaneProcessArgs(
return childArgs(
conn,
controlPath,
- tmuxCmd(`tmux -L ${RMT_TMUX_SOCKET} display-message -p -t ${posixQuote(exactPaneTarget(sessionId))} '#{pane_pid}|#{pane_current_command}'`)
+ sessionTmuxCmd(sessionId, `tmux -L ${SESSION_SOCKET_REF} display-message -p -t ${posixQuote(exactPaneTarget(sessionId))} '#{pane_pid}|#{pane_current_command}'`)
)
}
@@ -794,7 +882,7 @@ export function remotePaneOwnerCombinedArgs(
assertPasteTarget(sessionId)
const ps = PS_FOREGROUND_FLAGS.join(' ')
const script =
- `o=$(${tmuxCmd(`tmux -L ${RMT_TMUX_SOCKET} display-message -p -t ${posixQuote(exactPaneTarget(sessionId))} '${PANE_OWNER_FMT}'`)}) || exit 9; ` +
+ `o=$(${sessionTmuxCmd(sessionId, `tmux -L ${SESSION_SOCKET_REF} display-message -p -t ${posixQuote(exactPaneTarget(sessionId))} '${PANE_OWNER_FMT}'`)}) || exit 9; ` +
`printf '%s\\n' "${COMBINED_PANE_MARKER.trimEnd()} $o"; ` +
'tty=${o#*|}; tty=${tty%%|*}; ' +
`case "$tty" in /dev/*) ps ${ps} -t "$tty" 2>/dev/null || : ;; esac`
@@ -825,7 +913,7 @@ export function remotePaneCursorArgs(
return childArgs(
conn,
controlPath,
- tmuxCmd(`tmux -L ${RMT_TMUX_SOCKET} display-message -p -t ${posixQuote(exactPaneTarget(sessionId))} '#{cursor_x} #{cursor_y} #{cursor_flag}'`)
+ sessionTmuxCmd(sessionId, `tmux -L ${SESSION_SOCKET_REF} display-message -p -t ${posixQuote(exactPaneTarget(sessionId))} '#{cursor_x} #{cursor_y} #{cursor_flag}'`)
)
}
export function tmuxProbeArgs(conn: SshConnection, controlPath: string): string[] {
@@ -1056,7 +1144,7 @@ export function remoteTmuxPtyArgs(
confPath?: string,
sessionEnv?: RemoteSessionEnv
): string[] {
- let cmd = remoteTmuxCommand({ sessionId, remoteCwd, program, programArgs, socket: RMT_TMUX_SOCKET, confPath })
+ let cmd = remoteTmuxCommand({ sessionId, remoteCwd, program, programArgs, socket: SESSION_SOCKET_REF, confPath })
if (extraEnv.length)
// The replacement is a FUNCTION, not a string. This is load-bearing and not a style choice:
// in a STRING replacement `$'`, `` $` ``, `$&` and `$$` are expansion patterns, and `$'`
@@ -1072,7 +1160,7 @@ export function remoteTmuxPtyArgs(
// The PATH prologue goes at the very FRONT of the composed line: the session-env prologue's own
// tmux calls (start-server / show-options) and the `command -v tmux` guard must resolve the
// binary the same way new-session does.
- return ['-t', ...childArgs(conn, controlPath, tmuxCmd(cmd))]
+ return ['-t', ...childArgs(conn, controlPath, sessionTmuxCmd(sessionId, cmd))]
}
/** What a tmux-less remote loses, told to the user IN the pane. English + apostrophe-free: each
@@ -1124,7 +1212,7 @@ export interface RemoteSessionEnv {
* upload. The `rm -f` runs unconditionally so a late-landing file cannot linger at rest. */
function remoteSessionEnvPrologue(sessionEnv: RemoteSessionEnv, confPath?: string): string {
const f = posixQuote(sessionEnv.file)
- const t = `tmux -L ${RMT_TMUX_SOCKET}`
+ const t = `tmux -L ${SESSION_SOCKET_REF}`
const parts: string[] = []
// Names only ever come from isSafeEnvName-shaped keys, but this builder is exported territory —
// re-filter at the splice point, the same idiom every other remote builder here uses.
diff --git a/src/core/remote-ssh/share-team-remote.test.ts b/src/core/remote-ssh/share-team-remote.test.ts
index b64961b82..54e88bf08 100644
--- a/src/core/remote-ssh/share-team-remote.test.ts
+++ b/src/core/remote-ssh/share-team-remote.test.ts
@@ -40,7 +40,7 @@ beforeAll(() => {
// A fake tmux: sessions are files in $STATE; a "*.stuck" one survives kill-session. Like real
// tmux, a target WITHOUT the leading `=` that matches no session exactly falls back to a prefix
// match, and a miss prints tmux's own message (measured on tmux 3.4) with exit 1. Any socket but
- // the host's `node-terminal` is recorded and refused, so a kill aimed at another socket fails.
+ // the host's `node-terminal` and the legacy `nodeterm-rmt` is recorded and refused.
// FAKE_TMUX_MODE makes every call fail with one of tmux's connect or version errors.
write(
path.join(bin, 'tmux'),
@@ -50,12 +50,13 @@ beforeAll(() => {
`W=${JSON.stringify(wrongSocketLog)}`,
'cmd=""; target=""; sock=""',
'while [ $# -gt 0 ]; do case "$1" in -L) shift; sock="$1";; -t) shift; target="$1";; kill-session|has-session|list-panes) cmd="$1";; esac; shift; done',
- 'if [ "$sock" != node-terminal ]; then echo "$sock $cmd $target" >> "$W"; echo "fake tmux: unexpected socket" >&2; exit 99; fi',
+ // The legacy socket is a second, separate server with its own state dir (`<state>-rmt`).
+ 'case "$sock" in node-terminal) ;; nodeterm-rmt) S="$S-rmt"; mkdir -p "$S";; *) echo "$sock $cmd $target" >> "$W"; echo "fake tmux: unexpected socket" >&2; exit 99;; esac',
'case "$FAKE_TMUX_MODE" in',
" mismatch) echo 'protocol version mismatch (client 8, server 7)' >&2; exit 1;;",
- " denied) echo 'error connecting to /tmp/tmux-1000/node-terminal (Permission denied)' >&2; exit 1;;",
- " nofile) echo 'error connecting to /tmp/tmux-1000/node-terminal (No such file or directory)' >&2; exit 1;;",
- " refused) echo 'error connecting to /tmp/tmux-1000/node-terminal (Connection refused)' >&2; exit 1;;",
+ " denied) echo 'error connecting to /tmp/tmux-1000/$sock (Permission denied)' >&2; exit 1;;",
+ " nofile) echo 'error connecting to /tmp/tmux-1000/$sock (No such file or directory)' >&2; exit 1;;",
+ " refused) echo 'error connecting to /tmp/tmux-1000/$sock (Connection refused)' >&2; exit 1;;",
'esac',
'name="${target#=}"',
'exact=0; [ "$name" != "$target" ] && exact=1',
@@ -65,7 +66,7 @@ beforeAll(() => {
' for f in "$S/$name"*; do [ -e "$f" ] || continue; b=$(basename "$f"); name="${b%.stuck}"; return 0; done',
' return 1',
'}',
- "missing() { if [ -n \"$(ls \"$S\")\" ]; then echo \"can't find session: $name\" >&2; else echo 'no server running on /tmp/tmux-1000/node-terminal' >&2; fi; exit 1; }",
+ "missing() { if [ -n \"$(ls \"$S\")\" ]; then echo \"can't find session: $name\" >&2; else echo \"no server running on /tmp/tmux-1000/$sock\" >&2; fi; exit 1; }",
'case "$cmd" in',
' list-panes) for f in "$S"/*; do [ -e "$f" ] || continue; b=$(basename "$f"); b="${b%.stuck}"; echo "$b|$(cat "$f")"; done; exit 0;;',
' kill-session) resolve || missing; [ -e "$S/$name.stuck" ] && exit 0; rm -f "$S/$name"; exit 0;;',
@@ -101,7 +102,7 @@ beforeAll(() => {
})
afterAll(() => fs.rmSync(dir, { recursive: true, force: true }))
afterEach(() => {
- // Only this desktop's socket may ever be addressed (see the fake tmux).
+ // Only nodeterm's own two sockets may ever be addressed (see the fake tmux).
const wrong = fs.existsSync(wrongSocketLog) ? fs.readFileSync(wrongSocketLog, 'utf8') : ''
fs.rmSync(wrongSocketLog, { force: true })
expect(wrong).toBe('')
@@ -357,6 +358,24 @@ describe.skipIf(process.platform === 'win32')('share-team remote shell (real /bi
expect(fs.existsSync(path.join(state, 'nt-term-12'))).toBe(true) // exact target: a longer id is untouched
for (const f of fs.readdirSync(state)) fs.rmSync(path.join(state, f))
})
+ it('an ADOPTED session on the legacy socket is killed and verified too: gone means gone from both', async () => {
+ const legacy = `${state}-rmt`
+ fs.mkdirSync(legacy, { recursive: true })
+ fs.writeFileSync(path.join(legacy, 'nt-term-1'), 'x')
+ fs.writeFileSync(path.join(legacy, 'nt-term-2.stuck'), 'x')
+ fs.writeFileSync(path.join(legacy, 'nt-term-12'), 'x')
+ const ids = ['term-1', 'term-2']
+ const r = parseKillVerify(await sh(killVerifyCommand(ids)), ids)
+ expect(r).toEqual([
+ { nodeId: 'term-1', state: 'gone' },
+ // Gone from the unified socket, still alive on the legacy one: NOT gone — resuming it on the
+ // server would start a second agent beside the survivor.
+ { nodeId: 'term-2', state: 'alive' }
+ ])
+ expect(fs.existsSync(path.join(legacy, 'nt-term-1'))).toBe(false)
+ expect(fs.existsSync(path.join(legacy, 'nt-term-12'))).toBe(true)
+ fs.rmSync(legacy, { recursive: true, force: true })
+ })
it('a node with no session is gone without touching a session whose name it prefixes', async () => {
fs.writeFileSync(path.join(state, 'nt-term-9x'), 'x')
const r = parseKillVerify(await sh(killVerifyCommand(['term-9'])), ['term-9'])
diff --git a/src/core/remote-ssh/share-team-remote.ts b/src/core/remote-ssh/share-team-remote.ts
index 4f3306903..71e9e1543 100644
--- a/src/core/remote-ssh/share-team-remote.ts
+++ b/src/core/remote-ssh/share-team-remote.ts
@@ -19,7 +19,7 @@
import { posixQuote, quoteRemotePath, remoteTmuxPathPrologue } from '../../shared/ssh'
import type { ShareProbe } from '../../shared/share-team'
import { isSafeNodeId } from '../../shared/safe-id'
-import { RMT_TMUX_SOCKET } from './control-master'
+import { LEGACY_RMT_TMUX_SOCKET, RMT_TMUX_SOCKET } from './control-master'
import { sessionName } from '../tmux-naming'
import { CONTROL_RE } from '../relay/team-admin'
import { isRecord } from '../../shared/is-record'
@@ -125,7 +125,7 @@ export function shareProbeCommand(remoteCwd: string, systemUnit: string = SYSTEM
" echo '##BOOTSTRAP no'",
'fi',
`if cd ${quoteRemotePath(remoteCwd)} 2>/dev/null; then printf '##CWD %s\\n' "$(pwd -P)"; else echo '##CWD'; fi`,
- `${remoteTmuxPathPrologue()}echo '##PANES'; tmux -L ${RMT_TMUX_SOCKET} list-panes -a -F '#{session_name}|#{pane_current_command}' 2>/dev/null; echo '##PANESEND'`,
+ `${remoteTmuxPathPrologue()}echo '##PANES'; tmux -L ${LEGACY_RMT_TMUX_SOCKET} list-panes -a -F '#{session_name}|#{pane_current_command}' 2>/dev/null; tmux -L ${RMT_TMUX_SOCKET} list-panes -a -F '#{session_name}|#{pane_current_command}' 2>/dev/null; echo '##PANESEND'`,
"echo '##END'"
].join('\n')
)
@@ -336,8 +336,13 @@ export function killVerifyCommand(nodeIds: readonly string[]): string {
const t = posixQuote(`=${sessionName(id)}`)
const n = posixQuote(sessionName(id))
return [
+ // Both sockets: a node's session may be an ADOPTED one on the legacy socket
+ // (control-master.ts `sessionSocketProbe`), and "gone" must mean gone from wherever a
+ // reattach would find it — a survivor there is a second agent beside the resumed one.
`tmux -L ${RMT_TMUX_SOCKET} kill-session -t ${t} >/dev/null 2>&1`,
+ `tmux -L ${LEGACY_RMT_TMUX_SOCKET} kill-session -t ${t} >/dev/null 2>&1`,
`o=$(tmux -L ${RMT_TMUX_SOCKET} has-session -t ${t} 2>&1); r=$?`,
+ `if [ "$(nt_state "$r" "$o")" = gone ]; then o=$(tmux -L ${LEGACY_RMT_TMUX_SOCKET} has-session -t ${t} 2>&1); r=$?; fi`,
`printf '##K %s %s\\n' ${n} "$(nt_state "$r" "$o")"`
].join('\n')
})
@@ -364,7 +369,9 @@ export function parseKillVerify(
return nodeIds.map((nodeId) => ({ nodeId, state: states.get(sessionName(nodeId)) ?? 'unknown' }))
}
-/** Map probe panes onto node ids (session names come only from `sessionName`). */
+/** Map probe panes onto node ids (session names come only from `sessionName`). Last row wins, and
+ * the probe lists the legacy socket FIRST — so a name on both resolves to the unified socket's
+ * pane, the same precedence `sessionSocketProbe` applies. */
export function paneCommandsByNode(panes: ShareProbe['panes'], nodeIds: readonly string[]): Record<string, string> {
const bySession = new Map(panes.map((p) => [p.session, p.command]))
const out: Record<string, string> = {}
diff --git a/src/core/remote-ssh/watcher-attach.realsh.test.ts b/src/core/remote-ssh/watcher-attach.realsh.test.ts
index 3423e877d..8a2b25f0d 100644
--- a/src/core/remote-ssh/watcher-attach.realsh.test.ts
+++ b/src/core/remote-ssh/watcher-attach.realsh.test.ts
@@ -74,10 +74,12 @@ beforeAll(() => {
fs.writeFileSync(path.join(recordDir, 'tmux'), `#!/bin/sh\nfor a in "$@"; do printf '%s\\0' "$a"; done\n`, {
mode: 0o755
})
- // tmux 3.1c's own answer to `attach-session -f …`: a usage line and exit 1. Every call is counted.
+ // tmux 3.1c's own answer to `attach-session -f …`: a usage line and exit 1. Every call is counted
+ // except the socket probe's `has-session` (control-master.ts `sessionSocketProbe`), which is not
+ // an attach attempt.
fs.writeFileSync(
path.join(oldDir, 'tmux'),
- `#!/bin/sh\n: > "${markerDir}/old-tmux-$$"\necho 'usage: attach-session [-dErx] [-c working-directory] [-t target-session]' >&2\nexit 1\n`,
+ `#!/bin/sh\ncase " $* " in *' has-session '*) exit 1;; esac\n: > "${markerDir}/old-tmux-$$"\necho 'usage: attach-session [-dErx] [-c working-directory] [-t target-session]' >&2\nexit 1\n`,
{ mode: 0o755 }
)
if (!REAL_TMUX) return
diff --git a/src/core/typed-input.ts b/src/core/typed-input.ts
index cf084d75e..2198a62e4 100644
--- a/src/core/typed-input.ts
+++ b/src/core/typed-input.ts
@@ -56,6 +56,10 @@ export function typedLines(text: string): string[] {
.split('\n')
}
+/** The socket as a shell word read from the script's environment — see control-master.ts
+ * `SESSION_SOCKET_REF`, which must be this exact text (pinned in typed-input.test.ts). */
+export const TYPED_SOCKET_ENV_REF = '"$_nts"'
+
/**
* The script that types stdin into the pane. `tmux` is a FIXED shell word that runs tmux
* (`"$NT_TYPED_TMUX"` locally, see `localTypedArgs`; `tmux` on an SSH host) — never a path spliced in.
@@ -64,7 +68,10 @@ export function typedLines(text: string): string[] {
*/
export function typedInputScript(tmux: string, socket: string, target: string, buffer: string): string {
assertPasteTarget(target, buffer)
- if (!/^[A-Za-z0-9._-]+$/.test(socket)) throw new Error(`unsafe tmux socket: ${JSON.stringify(socket)}`)
+ // A socket NAME, or the one fixed shell word the SSH leg passes when the host decides which socket
+ // holds the session (`TYPED_SOCKET_ENV_REF`, set in this script's environment by the caller).
+ if (socket !== TYPED_SOCKET_ENV_REF && !/^[A-Za-z0-9._-]+$/.test(socket))
+ throw new Error(`unsafe tmux socket: ${JSON.stringify(socket)}`)
const t = `${tmux} -L ${socket}`
// The EXACT target (tmux-naming.ts `exactPaneTarget`): a bare name prefix-matches a longer session
// on a miss. Single-quoted for the shell (`sh -c` here, and the same text runs on an SSH host): a
diff --git a/src/core/watch-link/pane-input.test.ts b/src/core/watch-link/pane-input.test.ts
index 62c153284..df329749b 100644
--- a/src/core/watch-link/pane-input.test.ts
+++ b/src/core/watch-link/pane-input.test.ts
@@ -13,7 +13,7 @@ import {
remoteKeysArgs,
remotePasteArgs
} from './pane-input'
-import { RMT_TMUX_SOCKET } from '../remote-ssh/control-master'
+import { SESSION_SOCKET_REF, sessionSocketProbe } from '../remote-ssh/control-master'
import { remoteTmuxPathPrologue } from '../../shared/ssh'
const CONN = { host: 'h.example.com', user: 'deploy', port: 2222, identityFile: '/k/id' }
@@ -113,17 +113,17 @@ describe('the plan one chunk runs (local)', () => {
})
describe('the remote twins (over the ControlMaster)', () => {
- it('keys: ssh runs `tmux -L nodeterm-rmt source-file -` on the host; the command text rides stdin', () => {
- const args = remoteKeysArgs(CONN, CM)
+ it('keys: ssh runs `tmux source-file -` on the socket HOLDING the session; the command text rides stdin', () => {
+ const args = remoteKeysArgs(CONN, CM, 'nt-a')
expect(args).toContain(`ControlPath=${CM}`)
- expect(args.at(-1)).toBe(`${remoteTmuxPathPrologue()}tmux -L ${RMT_TMUX_SOCKET} source-file -`)
+ expect(args.at(-1)).toBe(`${remoteTmuxPathPrologue()}${sessionSocketProbe('nt-a')}tmux -L ${SESSION_SOCKET_REF} source-file -`)
expect(args.at(-2)).toBe('[email protected]')
})
it('paste: exact quoted target, mode cancel, -p, no Enter, and the text is not in argv', () => {
const cmd = remotePasteArgs(CONN, CM, 'nt-a', 'nt-paste-0a').at(-1)!
expect(cmd).toBe(
- `${remoteTmuxPathPrologue()}tmux -L ${RMT_TMUX_SOCKET} load-buffer -b nt-paste-0a - ';' ` +
+ `${remoteTmuxPathPrologue()}${sessionSocketProbe('nt-a')}tmux -L ${SESSION_SOCKET_REF} load-buffer -b nt-paste-0a - ';' ` +
`if-shell -F -t '=nt-a:' '#{pane_in_mode}' 'copy-mode -q -t =nt-a:' ';' ` +
`paste-buffer -d -p -r -b nt-paste-0a -t '=nt-a:'`
)
@@ -134,7 +134,7 @@ describe('the remote twins (over the ControlMaster)', () => {
it('a remote plan carries the same body as the local one and sweeps on the host', () => {
const keys = remoteControlInputPlan(CONN, CM, 'nt-a', { kind: 'keys', data: '\x02s' })
- expect(keys).toEqual({ args: remoteKeysArgs(CONN, CM), body: keysCommandText('nt-a', '\x02s'), cleanup: null })
+ expect(keys).toEqual({ args: remoteKeysArgs(CONN, CM, 'nt-a'), body: keysCommandText('nt-a', '\x02s'), cleanup: null })
const paste = remoteControlInputPlan(CONN, CM, 'nt-a', { kind: 'paste', text: 'p\x1bq' })!
expect(paste.body).toBe('pq')
const buffer = /load-buffer -b (nt-paste-[a-z0-9]+) -/.exec(paste.args.at(-1)!)![1]
diff --git a/src/core/watch-link/pane-input.ts b/src/core/watch-link/pane-input.ts
index d4919600c..96525a59b 100644
--- a/src/core/watch-link/pane-input.ts
+++ b/src/core/watch-link/pane-input.ts
@@ -83,7 +83,7 @@ import {
pasteBufferName,
type PasteDelivery
} from '../tmux-naming'
-import { RMT_TMUX_SOCKET, childArgs, remoteDeleteBufferArgs, tmuxCmd } from '../remote-ssh/control-master'
+import { SESSION_SOCKET_REF, childArgs, remoteDeleteBufferArgs, sessionTmuxCmd } from '../remote-ssh/control-master'
/** One unit of a controller's input. `keys` are typed byte for byte; `paste` is text tmux frames
* per the pane's own bracketed-paste state. */
@@ -156,8 +156,9 @@ export function localPasteArgs(socket: string, session: string, buffer: string):
}
/** ssh args running `tmux -L node-terminal source-file -` on the host; the command text rides stdin. */
-export function remoteKeysArgs(conn: SshConnection, controlPath: string): string[] {
- return childArgs(conn, controlPath, tmuxCmd(`tmux -L ${RMT_TMUX_SOCKET} source-file -`))
+export function remoteKeysArgs(conn: SshConnection, controlPath: string, session: string): string[] {
+ // The socket is the one HOLDING `session` (an adopted legacy session lives on the other server).
+ return childArgs(conn, controlPath, sessionTmuxCmd(session, `tmux -L ${SESSION_SOCKET_REF} source-file -`))
}
/**
@@ -173,8 +174,9 @@ export function remotePasteArgs(conn: SshConnection, controlPath: string, sessio
return childArgs(
conn,
controlPath,
- tmuxCmd(
- `tmux -L ${RMT_TMUX_SOCKET} load-buffer -b ${buffer} - ';' ` +
+ sessionTmuxCmd(
+ session,
+ `tmux -L ${SESSION_SOCKET_REF} load-buffer -b ${buffer} - ';' ` +
`if-shell -F -t ${q} '#{pane_in_mode}' ${posixQuote(`copy-mode -q -t ${t}`)} ';' ` +
`paste-buffer -d -p -r -b ${buffer} -t ${q}`
)
@@ -206,7 +208,7 @@ export function remoteControlInputPlan(
chunk: ControlInputChunk
): PasteDelivery | null {
if (chunk.kind === 'keys') {
- return { args: remoteKeysArgs(conn, controlPath), body: keysCommandText(session, chunk.data), cleanup: null }
+ return { args: remoteKeysArgs(conn, controlPath, session), body: keysCommandText(session, chunk.data), cleanup: null }
}
const body = sanitizePasteText(chunk.text)
if (body.length === 0) return null
@@ -214,6 +216,6 @@ export function remoteControlInputPlan(
return {
args: remotePasteArgs(conn, controlPath, session, buffer),
body,
- cleanup: remoteDeleteBufferArgs(conn, controlPath, buffer)
+ cleanup: remoteDeleteBufferArgs(conn, controlPath, buffer, session)
}
}
diff --git a/src/main/remote-ssh/ssh-project.killSessions.test.ts b/src/main/remote-ssh/ssh-project.killSessions.test.ts
index 358de8681..7c8418def 100644
--- a/src/main/remote-ssh/ssh-project.killSessions.test.ts
+++ b/src/main/remote-ssh/ssh-project.killSessions.test.ts
@@ -12,6 +12,7 @@ vi.mock('electron', () => ({
import { SshProjectManager } from './ssh-project'
import { remoteTmuxPathPrologue } from '../../shared/ssh'
+import { SESSION_SOCKET_REF, sessionSocketProbe } from '../../core/remote-ssh/control-master'
/** The PATH-append prologue every remote tmux line now starts with (issue #449). */
const TP = remoteTmuxPathPrologue()
@@ -39,6 +40,7 @@ function managerWithConn(): { mgr: SshProjectManager; runs: string[][] } {
}
const commands = (runs: string[][]): string[] => runs.map((r) => r.at(-1)!).sort()
+const PROBED_KILL = `${TP}${sessionSocketProbe('nt-abc')}tmux -L ${SESSION_SOCKET_REF} kill-session -t '=nt-abc'`
describe('SshProjectManager.killSessions', () => {
it('kills the name on EVERY tmux socket when the caller opts in', async () => {
@@ -53,18 +55,19 @@ describe('SshProjectManager.killSessions', () => {
])
})
- it('stays on the project s own socket by default', async () => {
- // Project deletion knows its own nodes and they are all on the host's `node-terminal`. The
- // legacy `nodeterm-rmt` holds only what an older build left, so a delete must not speculate there.
+ it('kills ONE session by default: the one the node is attached to, on whichever socket holds it', async () => {
+ // Project deletion knows its own nodes. Each lives on the host's `node-terminal` — or, when an
+ // older build left it there and it was adopted, on the legacy `nodeterm-rmt`. The host decides
+ // (`sessionSocketProbe`); a delete still fires exactly one kill and never fans out.
const { mgr, runs } = managerWithConn()
await mgr.killSessions('p1', ['abc'])
- expect(commands(runs)).toEqual([`${TP}tmux -L node-terminal kill-session -t '=nt-abc'`])
+ expect(commands(runs)).toEqual([PROBED_KILL])
})
it('demands a literal true — the flag comes off the wire', async () => {
const { mgr, runs } = managerWithConn()
await mgr.killSessions('p1', ['abc'], { everySocket: 'yes' as unknown as boolean })
- expect(commands(runs)).toEqual([`${TP}tmux -L node-terminal kill-session -t '=nt-abc'`])
+ expect(commands(runs)).toEqual([PROBED_KILL])
})
it('is best-effort: a socket that refuses does not spare the others', async () => {
diff --git a/src/main/remote-ssh/ssh-project.pendingKills.test.ts b/src/main/remote-ssh/ssh-project.pendingKills.test.ts
index ebc05be96..606c4cead 100644
--- a/src/main/remote-ssh/ssh-project.pendingKills.test.ts
+++ b/src/main/remote-ssh/ssh-project.pendingKills.test.ts
@@ -17,6 +17,7 @@ vi.mock('electron', () => ({
import { SshProjectManager } from './ssh-project'
import { remoteTmuxPathPrologue } from '../../shared/ssh'
+import { SESSION_SOCKET_REF, sessionSocketProbe } from '../../core/remote-ssh/control-master'
import { initPlatform, resetPlatformForTests } from '../../core/platform'
import { fakePlatform } from '../../core/platform-fake'
import { pendingRemoteKillsFor, recordPendingRemoteKill } from '../../core/pending-remote-kills'
@@ -66,7 +67,9 @@ describe('SshProjectManager: settling owed remote kills on connect', () => {
await settle(mgr)
- expect(runs.map((r) => r.at(-1))).toEqual([`${TP}tmux -L node-terminal kill-session -t '=nt-abc'`])
+ expect(runs.map((r) => r.at(-1))).toEqual([
+ `${TP}${sessionSocketProbe('nt-abc')}tmux -L ${SESSION_SOCKET_REF} kill-session -t '=nt-abc'`
+ ])
expect(await pendingRemoteKillsFor(HOST)).toEqual([])
})