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(kill): the both-sockets fan-out is the panel's, not everyone's

enes3ecec9f91256
diff --git a/docs/session-memory.md b/docs/session-memory.md
index 3949ea6f1..6b6c01a89 100644
--- a/docs/session-memory.md
+++ b/docs/session-memory.md
@@ -248,9 +248,19 @@ name could be on**: `KILL_TMUX_SOCKETS`, via `remoteTmuxKillEverySocketArgs` (re
PREFIX matching whenever the name is not found, and "not found" is the normal outcome of a
speculative kill. Node ids end in a counter, so `nt-…-1` is a prefix of `nt-…-12`: a miss could
have killed a *different* session. The reaper already killed this way, for this reason.
-- The fan-out happens only when we do **not** know the socket. A destroy for a session we hold aims
- at that session's socket alone, so the ordinary node-`×` path still fires exactly one kill
- (pinned in `pty-single-user.test.ts`).
+- **The fan-out is opt-in, and only the panel opts in.** Two conditions have to hold: we do not know
+ the socket, *and* the caller asked for it (`localKillSockets(liveSocket, everySocket)`,
+ `sshProject.killSessions(…, { everySocket: true })`, `transport.destroy(id, { everySocket: true })`).
+ A destroy for a session we hold aims at that session's socket alone whatever the caller asked, so
+ the ordinary node-`×` on a mounted node still fires exactly one kill. But the **unheld** branch is
+ not rare — an ordinary node-`×` on a node that was never mounted in this process takes it every
+ time, which is the common case right after an app restart and for every non-active project's node
+ — and project deletion is the same shape remotely. Those callers know their own nodes, so they
+ stay narrow: speculating at `nodeterm-rmt` aims at sessions ANOTHER machine's nodeterm SSHed in to
+ spawn here, and speculating at a host's `node-terminal` aims at sessions a nodeterm running ON it
+ owns. Both defaults and both opt-ins are pinned (`pty-single-user.test.ts`,
+ `control-master.test.ts`, `ssh-project.killSessions.test.ts`), including that the wire flag must
+ be a literal `true`.
Note the deliberate duplication: the sweep and the reaper keep their own `[TMUX_SOCKET,
RMT_TMUX_SOCKET]` arrays. For them the ORDER is load-bearing — the sweep's `bySession` is first-wins,
diff --git a/src/core/pty-manager.ts b/src/core/pty-manager.ts
index 4e2033d8e..d6865ece2 100644
--- a/src/core/pty-manager.ts
+++ b/src/core/pty-manager.ts
@@ -655,8 +655,13 @@ export class PtyManager {
// event they get has to name WHO did it ("closed by <name>" — see `destroySession`).
// Registered ONLY here: `on` and `onWithSender` compose on the same channel, so a leftover
// plain listener would run the destroy — and its `tmux kill-session` — twice.
- platform().onWithSender(IPC.ptyDestroy, (senderId: number, persistKey: string) =>
- this.endFromClient(senderId, IPC.ptyDestroy, persistKey, 'delete')
+ // Optional TRAILING `everySocket`: only the session-memory panel's SPECULATIVE kill sets it,
+ // and only for a row it holds no session for (see `localKillSockets`). `=== true` because the
+ // value arrives verbatim off the wire; absent ⇒ the narrow, historical single-socket kill.
+ platform().onWithSender(
+ IPC.ptyDestroy,
+ (senderId: number, persistKey: string, everySocket?: unknown) =>
+ this.endFromClient(senderId, IPC.ptyDestroy, persistKey, 'delete', everySocket === true)
)
// Sender-aware for the opposite reason: the client that RECYCLED the node drives its own
// respawn, so it is the one client that must NOT be sent the restart notice.
@@ -746,12 +751,13 @@ export class PtyManager {
clientId: ClientId,
channel: string,
persistKey: string,
- intent: EndIntent
+ intent: EndIntent,
+ everySocket = false
): Promise<void> {
if (typeof persistKey !== 'string' || !persistKey || persistKey.length > REF_MAX_LEN)
return Promise.resolve()
if (!this.allowEnd(clientId, channel)) return Promise.resolve()
- return this.endSession(clientId, persistKey, intent)
+ return this.endSession(clientId, persistKey, intent, everySocket)
}
/** Take one token from this client's bucket for a session-ending channel (see PTY_END_BUDGET).
@@ -2123,8 +2129,12 @@ export class PtyManager {
*
* `clientId` is null when nothing/no-one attributable did it (an internal caller).
*/
- destroySession(clientId: ClientId | null, persistKey: string): Promise<void> {
- return this.endSession(clientId, persistKey, 'delete')
+ destroySession(
+ clientId: ClientId | null,
+ persistKey: string,
+ opts?: { everySocket?: boolean }
+ ): Promise<void> {
+ return this.endSession(clientId, persistKey, 'delete', opts?.everySocket === true)
}
/**
@@ -2161,7 +2171,8 @@ export class PtyManager {
private async endSession(
clientId: ClientId | null,
persistKey: string,
- intent: EndIntent
+ intent: EndIntent,
+ everySocket = false
): Promise<void> {
// Both callers run while the session is still live, so its sshRemote is known. Capture it
// synchronously before any await. The index is the co-attach one (UI sessions); the scan is
@@ -2239,15 +2250,16 @@ export class PtyManager {
// such session", which is already the ignored case below.
}
if (!this.tmuxPath) return
- // Which socket(s) to aim at. Holding the session ourselves means we know: it is the local one.
- // Holding NOTHING means the name is all we have, and on this machine a `nt-<id>` can also be
- // living on the `nodeterm-rmt` socket — that is where ANOTHER machine's nodeterm puts the
- // sessions it SSHes in to spawn. The session-memory panel lists those (it sweeps both sockets)
- // and offers to end them, so a kill that only ever tried `node-terminal` showed a confirm
- // saying "this stops its tmux session" and then did nothing. The common path — deleting a node
- // whose session we hold — is unchanged, and every extra call is the already-ignored
- // "no such session".
- for (const socket of localKillSockets(dying ? TMUX_SOCKET : null)) {
+ // Which socket(s) to aim at. Holding the session ourselves means we KNOW: it is the local one,
+ // one kill, unchanged. Holding nothing means the name is all we have — and then the fan-out is
+ // the CALLER's to ask for, because on this machine a `nt-<id>` we hold nothing for can also be
+ // living on the `nodeterm-rmt` socket, where ANOTHER machine's nodeterm puts the sessions it
+ // SSHes in to spawn. Only the session-memory panel's speculative kill sets `everySocket`: it
+ // sweeps both sockets and offers to end what it found, so a kill that only tried
+ // `node-terminal` showed a confirm saying "this stops its tmux session" and did nothing. An
+ // ordinary node-× on a node never mounted in this process takes the same unheld branch and
+ // must NOT inherit that blast radius.
+ for (const socket of localKillSockets(dying ? TMUX_SOCKET : null, everySocket)) {
try {
await runAsync(this.tmuxPath, localTmuxKillArgs(socket, sessionName(persistKey)))
} catch {
diff --git a/src/core/pty-single-user.test.ts b/src/core/pty-single-user.test.ts
index 271394e3c..a493f8a30 100644
--- a/src/core/pty-single-user.test.ts
+++ b/src/core/pty-single-user.test.ts
@@ -375,14 +375,14 @@ describe('SINGLE-USER REGRESSION: co-attach must not change the solo path', () =
})
// Destroying a name we hold NOTHING for is how the session-memory panel ends an ORPHAN row — a
- // tmux session with no node on any canvas. It is also every session that outlived the process
- // that spawned it. We cannot know which socket carries it, and on this machine a `nt-<id>` may be
- // on `nodeterm-rmt`: that is where ANOTHER machine's nodeterm puts the sessions it SSHes in to
- // spawn, and the panel sweeps (and offers to end) both sockets. Aiming only at `node-terminal`
- // meant a confirm reading "this stops its tmux session" that killed nothing at all.
- it('destroying a session we do not hold tries EVERY socket it could be on', async () => {
+ // tmux session with no node on any canvas. We cannot know which socket carries it, and on this
+ // machine a `nt-<id>` may be on `nodeterm-rmt`: that is where ANOTHER machine's nodeterm puts the
+ // sessions it SSHes in to spawn, and the panel sweeps (and offers to end) both sockets. Aiming
+ // only at `node-terminal` meant a confirm reading "this stops its tmux session" that killed
+ // nothing at all.
+ it('destroying a session we do not hold tries EVERY socket when the caller asks', async () => {
const m = await tmuxManager()
- await m.destroySession(SOLO, 'never-opened-here')
+ await m.destroySession(SOLO, 'never-opened-here', { everySocket: true })
const kills = tmuxCalls('kill-session')
expect(kills.map((c) => c.args[c.args.indexOf('-L') + 1]).sort()).toEqual([
'node-terminal',
@@ -393,6 +393,41 @@ describe('SINGLE-USER REGRESSION: co-attach must not change the solo path', () =
}
})
+ // ...but the fan-out is OPT-IN, and the unheld branch is not rare: an ordinary node-× on a node
+ // that was never mounted in this process takes it every time (the common case after an app
+ // restart, and every non-active project's node). Those callers know their own node and have no
+ // business speculating at `nodeterm-rmt`, which holds another machine's sessions.
+ it('destroying a session we do not hold stays on ONE socket by default', async () => {
+ const m = await tmuxManager()
+ await m.destroySession(SOLO, 'never-opened-here')
+ const kills = tmuxCalls('kill-session')
+ expect(kills.map((c) => c.args[c.args.indexOf('-L') + 1])).toEqual(['node-terminal'])
+ })
+
+ // The flag arrives verbatim from a renderer, so the wire path must demand a real `true` — and it
+ // must reach `endSession`, which is the half a `destroySession`-only test cannot see.
+ it('honours everySocket off the wire, and only for a literal true', async () => {
+ await tmuxManager()
+ await (fake.senderListeners[IPC.ptyDestroy](
+ SOLO,
+ 'never-opened-here',
+ true
+ ) as unknown as Promise<void>)
+ expect(tmuxCalls('kill-session').map((c) => c.args[c.args.indexOf('-L') + 1]).sort()).toEqual([
+ 'node-terminal',
+ 'nodeterm-rmt'
+ ])
+ execCalls.length = 0
+ await (fake.senderListeners[IPC.ptyDestroy](
+ SOLO,
+ 'never-opened-2',
+ 'yes' as unknown as boolean
+ ) as unknown as Promise<void>)
+ expect(tmuxCalls('kill-session').map((c) => c.args[c.args.indexOf('-L') + 1])).toEqual([
+ 'node-terminal'
+ ])
+ })
+
// ── recycle (move into worktree) = destroy, minus the "someone closed it" fan-out ─────────
// The solo user's node keeps its id and respawns in the new cwd: the tmux session must die
// exactly as the × kills it (otherwise `new-session -A` reattaches the OLD working directory),
diff --git a/src/core/remote-ssh/control-master.test.ts b/src/core/remote-ssh/control-master.test.ts
index de0967d13..1e8d8c74b 100644
--- a/src/core/remote-ssh/control-master.test.ts
+++ b/src/core/remote-ssh/control-master.test.ts
@@ -406,12 +406,19 @@ describe('killing a session by name (both sockets, exact target)', () => {
expect(remoteTmuxKillArgs(conn, '/s.sock', 'nt-a-1').at(-1)).toContain('-t =nt-a-1')
})
- it('aims a local destroy at the socket we hold, and at every socket when we hold nothing', () => {
- // Holding the session means we know which socket it is on. Holding nothing (an orphan row in
- // the session-memory panel, or any session that outlived the process that spawned it) means the
- // name is all we have.
+ it('aims a local destroy at the socket we hold, whatever the caller asked for', () => {
+ // Holding the session means we KNOW which socket it is on, so the fan-out flag is irrelevant:
+ // one kill either way. This is what keeps the ordinary node-x path at exactly one kill.
expect(localKillSockets('node-terminal')).toEqual(['node-terminal'])
- expect([...localKillSockets(null)].sort()).toEqual(['node-terminal', 'nodeterm-rmt'])
+ expect(localKillSockets('node-terminal', true)).toEqual(['node-terminal'])
+ })
+
+ it('fans a socket-less kill out only when the caller opts in', () => {
+ // Holding nothing means the name is all we have — but the unheld branch is NOT rare (an
+ // ordinary node-x on a node never mounted in this process takes it), so the blast radius is
+ // the caller's to ask for. Only the session-memory panel, which swept BOTH sockets, does.
+ expect(localKillSockets(null)).toEqual(['node-terminal'])
+ expect([...localKillSockets(null, true)].sort()).toEqual(['node-terminal', 'nodeterm-rmt'])
})
it('keeps the remote default on the ssh socket, and overrides it explicitly', () => {
diff --git a/src/core/remote-ssh/control-master.ts b/src/core/remote-ssh/control-master.ts
index 816d212a9..5ddd7008b 100644
--- a/src/core/remote-ssh/control-master.ts
+++ b/src/core/remote-ssh/control-master.ts
@@ -272,13 +272,27 @@ export function probeSaysAbsent(err: unknown): boolean {
export const KILL_TMUX_SOCKETS: readonly string[] = [TMUX_SOCKET, RMT_TMUX_SOCKET]
/**
- * Which local sockets a destroy must attempt. `liveSocket` is the socket of the session we actually
- * hold (which we know is the right one); `null` = we hold nothing, so the name is all we have and
- * every socket that could carry it has to be tried. An orphan row in the session-memory panel — and
- * any node whose session outlived the process that spawned it — takes the `null` branch.
+ * Which local sockets a destroy must attempt.
+ *
+ * `liveSocket` is the socket of the session we actually HOLD, which we know is the right one: one
+ * kill, and the fan-out below can never reach the ordinary path.
+ *
+ * With no live session the name is all we have, and then it depends on who is asking:
+ * - `everySocket: false` (the default, and every ordinary caller) → the local socket only. An
+ * ordinary node-× on a node that was never mounted in THIS process — the common case after an
+ * app restart — has no business speculating at `nodeterm-rmt`, which carries the sessions
+ * ANOTHER machine's nodeterm SSHed in to spawn here.
+ * - `everySocket: true` → every socket the name could be on. Only the session-memory panel's
+ * speculative kill asks for this, and it is the one caller that has earned it: the panel sweeps
+ * BOTH sockets, so an orphan row genuinely can be on either, and a kill aimed at one of them
+ * showed a confirm reading "this stops its tmux session" and then killed nothing at all.
*/
-export function localKillSockets(liveSocket: string | null): readonly string[] {
- return liveSocket ? [liveSocket] : KILL_TMUX_SOCKETS
+export function localKillSockets(
+ liveSocket: string | null,
+ everySocket = false
+): readonly string[] {
+ if (liveSocket) return [liveSocket]
+ return everySocket ? KILL_TMUX_SOCKETS : [TMUX_SOCKET]
}
/**
@@ -307,10 +321,14 @@ export function remoteTmuxKillArgs(
}
/**
- * One kill per socket, for a caller that knows only the session NAME (`SshProjectManager.
- * killSessions`, which the session-memory panel and project deletion both use). Best-effort by
- * contract: tmux exits non-zero with "can't find session" on every socket that does not hold it,
- * and that is an expected, ignored outcome rather than a failure.
+ * One kill per socket, for a caller that knows only the session NAME and does not know which socket
+ * carries it — i.e. `SshProjectManager.killSessions({ everySocket: true })`, which is the
+ * session-memory panel's route. Project deletion does NOT use this: it knows its own nodes, they
+ * are all on the SSH project's own socket, and speculating at the host's `node-terminal` would aim
+ * at sessions a nodeterm running ON that host owns.
+ *
+ * Best-effort by contract: tmux exits non-zero with "can't find session" on every socket that does
+ * not hold it, and that is an expected, ignored outcome rather than a failure.
*/
export function remoteTmuxKillEverySocketArgs(
conn: SshConnection,
diff --git a/src/main/remote-ssh/ssh-project.killSessions.test.ts b/src/main/remote-ssh/ssh-project.killSessions.test.ts
index 16f23976b..83dde11e1 100644
--- a/src/main/remote-ssh/ssh-project.killSessions.test.ts
+++ b/src/main/remote-ssh/ssh-project.killSessions.test.ts
@@ -37,29 +37,43 @@ function managerWithConn(): { mgr: SshProjectManager; runs: string[][] } {
const commands = (runs: string[][]): string[] => runs.map((r) => r.at(-1)!).sort()
describe('SshProjectManager.killSessions', () => {
- it('kills the name on EVERY tmux socket the host can carry it on', async () => {
+ it('kills the name on EVERY tmux socket when the caller opts in', async () => {
// The session-memory sweep lists both sockets, so its rows can come off either. A kill aimed
// only at `nodeterm-rmt` left every row from a host's own nodeterm-server running, after a
// confirm that said otherwise.
const { mgr, runs } = managerWithConn()
- await mgr.killSessions('p1', ['abc'])
+ await mgr.killSessions('p1', ['abc'], { everySocket: true })
expect(commands(runs)).toEqual([
'tmux -L node-terminal kill-session -t =nt-abc',
'tmux -L nodeterm-rmt kill-session -t =nt-abc'
])
})
+ it('stays on the project s own socket by default', async () => {
+ // Project deletion knows its own nodes and they are all on `nodeterm-rmt`. `node-terminal` on
+ // that host belongs to a nodeterm running ON it, so a delete must not speculate there.
+ const { mgr, runs } = managerWithConn()
+ await mgr.killSessions('p1', ['abc'])
+ expect(commands(runs)).toEqual(['tmux -L nodeterm-rmt kill-session -t =nt-abc'])
+ })
+
+ 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(['tmux -L nodeterm-rmt kill-session -t =nt-abc'])
+ })
+
it('is best-effort: a socket that refuses does not spare the others', async () => {
// The `node-terminal` run above throws. `killSessions` must still resolve, and the sibling
// kill must still have gone out.
const { mgr, runs } = managerWithConn()
- await expect(mgr.killSessions('p1', ['abc'])).resolves.toBeUndefined()
+ await expect(mgr.killSessions('p1', ['abc'], { everySocket: true })).resolves.toBeUndefined()
expect(runs).toHaveLength(2)
})
it('covers every id it was given', async () => {
const { mgr, runs } = managerWithConn()
- await mgr.killSessions('p1', ['a', 'b'])
+ await mgr.killSessions('p1', ['a', 'b'], { everySocket: true })
expect(commands(runs)).toEqual([
'tmux -L node-terminal kill-session -t =nt-a',
'tmux -L node-terminal kill-session -t =nt-b',
diff --git a/src/main/remote-ssh/ssh-project.ts b/src/main/remote-ssh/ssh-project.ts
index 65f828f4e..ef11f1560 100644
--- a/src/main/remote-ssh/ssh-project.ts
+++ b/src/main/remote-ssh/ssh-project.ts
@@ -21,6 +21,7 @@ import {
mkDirArgs,
exitMasterArgs,
checkMasterArgs,
+ remoteTmuxKillArgs,
remoteTmuxKillEverySocketArgs,
childArgs,
scpArgs,
@@ -870,19 +871,31 @@ export class SshProjectManager {
* are raw node ids; we map each to its `nt-<id>` session name (the same name `spawnSession` /
* `remoteTmuxHasSessionArgs` use). Best-effort per id, a missing session is ignored.
*
- * The kill goes to EVERY tmux socket on the host, not just the `nodeterm-rmt` one an SSH project
- * spawns on. Callers here know only a session NAME: project deletion knows its own nodes (always
- * remote), but the session-memory panel passes rows swept off BOTH of the host's sockets — and a
- * host that runs its own `nodeterm-server` keeps those sessions on `node-terminal`. Those rows
- * used to get a confirm reading "this stops its tmux session" followed by a kill aimed at the
- * other socket, so nothing died. See `KILL_TMUX_SOCKETS`.
+ * `everySocket` widens the kill to EVERY tmux socket on the host instead of just the
+ * `nodeterm-rmt` one an SSH project spawns on, and it is **opt-in for one caller**. The
+ * session-memory panel passes rows swept off BOTH of the host's sockets — a host that runs its
+ * own `nodeterm-server` keeps those on `node-terminal` — and such a row used to get a confirm
+ * reading "this stops its tmux session" followed by a kill aimed at the other socket, so nothing
+ * died. Project deletion deliberately stays narrow: it knows its own nodes, they are all on the
+ * project's own socket, and speculating at `node-terminal` would aim at sessions belonging to a
+ * nodeterm running ON that host. See `KILL_TMUX_SOCKETS`.
*/
- async killSessions(projectId: string, nodeIds: string[]): Promise<void> {
+ async killSessions(
+ projectId: string,
+ nodeIds: string[],
+ opts?: { everySocket?: boolean }
+ ): Promise<void> {
const c = this.conns.get(projectId)
if (!c) return
+ // `=== true`, not truthy: this value arrives from a renderer over IPC / the ws bridge.
+ const everySocket = opts?.everySocket === true
await Promise.all(
nodeIds
- .flatMap((id) => remoteTmuxKillEverySocketArgs(c.conn, c.controlPath, sessionName(id)))
+ .flatMap((id) =>
+ everySocket
+ ? remoteTmuxKillEverySocketArgs(c.conn, c.controlPath, sessionName(id))
+ : [remoteTmuxKillArgs(c.conn, c.controlPath, sessionName(id))]
+ )
.map((args) =>
this.r.run(args).then(
() => undefined,
@@ -1594,8 +1607,10 @@ export function initSshProject(
ipcMain.handle(IPC.sshDisconnectProject, (_e, projectId: string) =>
mgr.disconnect(projectId, { final: true })
)
- ipcMain.handle(IPC.sshKillSessions, (_e, projectId: string, nodeIds: string[]) =>
- mgr.killSessions(projectId, nodeIds)
+ ipcMain.handle(
+ IPC.sshKillSessions,
+ (_e, projectId: string, nodeIds: string[], opts?: { everySocket?: boolean }) =>
+ mgr.killSessions(projectId, nodeIds, opts)
)
ipcMain.handle(IPC.sshListDir, (_e, projectId: string, dir: string) => mgr.listDir(projectId, dir))
ipcMain.handle(IPC.sshMkdir, (_e, projectId: string, dir: string) => mgr.makeDir(projectId, dir))
diff --git a/src/preload/index.ts b/src/preload/index.ts
index 42d4fe3a1..022e3c49a 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -61,7 +61,8 @@ const api: NodeTerminalApi = {
setFlow: (sessionId, resume, viewerId) =>
ipcRenderer.send(IPC.ptyFlow, sessionId, resume, viewerId),
kill: (sessionId, viewerId) => ipcRenderer.send(IPC.ptyKill, sessionId, viewerId),
- destroy: (persistKey) => ipcRenderer.send(IPC.ptyDestroy, persistKey),
+ destroy: (persistKey, opts) =>
+ ipcRenderer.send(IPC.ptyDestroy, persistKey, opts?.everySocket === true),
recycle: (persistKey) => ipcRenderer.send(IPC.ptyRecycle, persistKey),
generateName: (persistKey, cwd) => ipcRenderer.invoke(IPC.ptyGenerateName, persistKey, cwd),
generateGroupName: (memberKeys, cwd) =>
@@ -191,8 +192,8 @@ const api: NodeTerminalApi = {
connect: (projectId, conn, remoteCwd) =>
ipcRenderer.invoke(IPC.sshConnectProject, projectId, conn, remoteCwd),
disconnect: (projectId) => ipcRenderer.invoke(IPC.sshDisconnectProject, projectId),
- killSessions: (projectId, nodeIds) =>
- ipcRenderer.invoke(IPC.sshKillSessions, projectId, nodeIds),
+ killSessions: (projectId, nodeIds, opts) =>
+ ipcRenderer.invoke(IPC.sshKillSessions, projectId, nodeIds, opts),
listDir: (projectId, dir) => ipcRenderer.invoke(IPC.sshListDir, projectId, dir),
mkdir: (projectId, dir) => ipcRenderer.invoke(IPC.sshMkdir, projectId, dir),
uploadFile: (projectId, localPath, fileName) =>
diff --git a/src/renderer/bridge/ws-bridge.ts b/src/renderer/bridge/ws-bridge.ts
index a882b4f84..f6c02616c 100644
--- a/src/renderer/bridge/ws-bridge.ts
+++ b/src/renderer/bridge/ws-bridge.ts
@@ -212,7 +212,9 @@ export function buildRealApi(
client.cast(IPC.ptyResize, sessionId, cols, rows, viewerId),
setFlow: (sessionId, resume, viewerId) => client.cast(IPC.ptyFlow, sessionId, resume, viewerId),
kill: (sessionId, viewerId) => client.cast(IPC.ptyKill, sessionId, viewerId),
- destroy: (persistKey) => client.cast(IPC.ptyDestroy, persistKey),
+ // The trailing flag rides as a plain boolean; the core handler re-checks `=== true`.
+ destroy: (persistKey, opts) =>
+ client.cast(IPC.ptyDestroy, persistKey, opts?.everySocket === true),
recycle: (persistKey) => client.cast(IPC.ptyRecycle, persistKey),
// No server handler — degrade gracefully (never reject the boot path).
generateName: () => Promise.resolve(AI_NAMING_UNAVAILABLE),
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 48a435077..2f90b27dc 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -6588,10 +6588,13 @@ export function Canvas() {
(nodeId: string, orphan: boolean) => {
const store = useProjects.getState()
const plan = planSessionKill(nodeId, store.projects, store.activeProjectId)
+ // `everySocket` on BOTH legs, and only here: the panel's rows are swept off both of the
+ // machine's tmux sockets, so a row it offers to end genuinely can be on either. Every other
+ // caller (project deletion, an ordinary node-×) knows its own nodes and stays narrow.
const remoteKill = plan.remoteProjectId
? () =>
void window.nodeTerminal.sshProject
- .killSessions(plan.remoteProjectId!, [nodeId])
+ .killSessions(plan.remoteProjectId!, [nodeId], { everySocket: true })
.catch(() => {})
: undefined
if (plan.ownerProjectId) {
@@ -6605,7 +6608,7 @@ export function Canvas() {
confirmLabel: 'End session',
danger: true,
onConfirm: () => {
- transport.destroy(nodeId)
+ transport.destroy(nodeId, { everySocket: true })
remoteKill?.()
// Nothing else to clean up: with no node anywhere, there is no canvas entry to remove and
// no parked terminal to dispose. Persisted agent status is dropped anyway, since a
diff --git a/src/renderer/terminal/local-transport.ts b/src/renderer/terminal/local-transport.ts
index 60ce9ff83..dbd95b07f 100644
--- a/src/renderer/terminal/local-transport.ts
+++ b/src/renderer/terminal/local-transport.ts
@@ -57,8 +57,8 @@ export class LocalTransport implements TerminalTransport {
this.pty.kill(sessionId, this.viewerId)
}
- destroy(persistKey: string): void {
- this.pty.destroy(persistKey)
+ destroy(persistKey: string, opts?: { everySocket?: boolean }): void {
+ this.pty.destroy(persistKey, opts)
}
recycle(persistKey: string): void {
diff --git a/src/renderer/terminal/transport.ts b/src/renderer/terminal/transport.ts
index 571a8ba41..4a86a1794 100644
--- a/src/renderer/terminal/transport.ts
+++ b/src/renderer/terminal/transport.ts
@@ -26,8 +26,12 @@ export interface TerminalTransport {
/**
* Permanently ends a node's persistent session because the node is being DELETED (× / delete).
* Co-viewers are told "closed by <name>" and must never respawn it.
+ *
+ * `opts.everySocket` widens a kill for a session this process holds NOTHING for to every local
+ * tmux socket the name could be on. Opt-in for the session-memory panel's speculative kill only
+ * (see `localKillSockets`); an ordinary × leaves it unset.
*/
- destroy(persistKey: string): void
+ destroy(persistKey: string, opts?: { everySocket?: boolean }): void
/**
* Ends a node's persistent session so the SAME node id can respawn in a new cwd ("move into
* worktree"). The tmux kill is identical to `destroy` — without it the respawn would just
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 3f2687202..ee18f3c01 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -532,8 +532,14 @@ export interface PtyApi {
* node attached; absent ⇒ the PRIMARY view. */
kill(sessionId: string, viewerId?: string): void
/** Permanently ends the persistent session for a node (kills its tmux session) because the node
- * is being DELETED. Co-viewers get `onClosed` and must not respawn it. */
- destroy(persistKey: string): void
+ * is being DELETED. Co-viewers get `onClosed` and must not respawn it.
+ *
+ * `everySocket` (optional, trailing) widens a kill for a session we hold NOTHING for to every
+ * local tmux socket the name could be on. Opt-in for one caller — the session-memory panel's
+ * speculative kill of a row it swept off either socket. An ordinary node-× must not set it: it
+ * takes the same unheld branch after an app restart, and `nodeterm-rmt` holds sessions another
+ * machine's nodeterm SSHed in to spawn. */
+ destroy(persistKey: string, opts?: { everySocket?: boolean }): void
/** Ends a node's persistent session so the SAME node id respawns in a new cwd ("move into
* worktree"). Same tmux kill as `destroy`, opposite intent: the node stays on the canvas, so
* co-viewers get `onRecycled` (restart + re-attach), never the permanent closed state. */
@@ -1103,8 +1109,17 @@ export interface SshProjectApi {
* Authoritative teardown on project delete: works regardless of whether the nodes are
* mounted, and must be awaited BEFORE disconnect (which kills the master). `nodeIds` are
* raw node ids; main maps them to `nt-<id>` session names.
+ *
+ * `everySocket` widens the kill to every tmux socket on the host rather than the `nodeterm-rmt`
+ * one an SSH project spawns on. Opt-in for ONE caller — the session-memory panel, whose rows are
+ * swept off both sockets. Project deletion stays narrow: `node-terminal` on that host belongs to
+ * a nodeterm running ON it, not to us.
*/
- killSessions(projectId: string, nodeIds: string[]): Promise<void>
+ killSessions(
+ projectId: string,
+ nodeIds: string[],
+ opts?: { everySocket?: boolean }
+ ): Promise<void>
/** List remote sub-directories of `path` (default ~). */
listDir(projectId: string, path: string): Promise<{ path: string; dirs: string[] }>
/** Create a remote directory (mkdir -p). Resolves false when not connected or the mkdir fails. */