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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(relay): a closed team tab is never reopened on the local core
reviewb90079a61e24
diff --git a/CLAUDE.md b/CLAUDE.mdindex 3523948f6..0d094b6a1 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -8508,15 +8508,24 @@ invariants:call, always passed by `VIEW_EVENTS`), because `workspace:server-change` ignores unknown idsand viewers never receive `canvas:authority-changed`. A tab the user closes is dismissed untilthe project is unshared; nothing shared keeps one placeholder tab. A hosted tab never cold-resumes- an agent (`canColdRestore` excludes `source === 'relay'`). A CLOSED team tab (any `remote`- project) is never offered by "Recently closed" (`isReopenableClosedProject`) or ⇧⌘T (`planReopen`- skips it, `performCloseProject` does not push it): its nodes are the host's sessions, and a reopen- from here mounts them on the LOCAL core.+ an agent (`canColdRestore` excludes `source === 'relay'`). A CLOSED team tab is NEVER reopened: once+ closed its relay session is disposed and `sessionForProject` falls back to the LOCAL session, so a+ reopen mounts the host's node ids on this core (local shells, agent cold-resume). The ONE reopen+ funnel, `reopenProjectUnchecked`, refuses any `remote` project with `CLOSED_TEAM_TAB_NOTICE`+ (so does every path through `reopenProject`); "Recently closed" lists neither the tab+ (`isReopenableClosedProject`) nor its closed sessions (`isClosedTeamTab`); `planReopen` answers+ `refuse` for ANY entry into a closed team tab BEFORE recreating a node into it (a `nodes` entry+ would otherwise be written into it and reopen it), and ⇧⌘T puts the entry back untouched;+ `performCloseProject` does not push a project entry for a relay tab. What brings the tab back is+ joining the team again with none of its tabs open, or an unshare + share (a reconnect keeps it+ dismissed, `lib/hostedTeamTabs.ts`).- **One node id, two projects: owner lookups go through `nodeOwner`** (`lib/nodeOwner.ts`). After ashare the closed, handed-off SSH project and the team tab hold the same node ids, and the SSHproject comes FIRST in the list (a team tab is appended), so a bare`projects.find(p => p.nodes.some(...))` sent every "go to node" to the reopen warning. `nodeOwner`- prefers an open project, then one without `handedOffTo`, then any; `focusNodeById`, the agent+ prefers an open project, then one without `handedOffTo`, then any, and skips a CLOSED team tab+ entirely (its reopen is refused; the shared node then falls back to the handed-off SSH project,+ whose reopen asks first); `focusNodeById`, the agentrename-node handler, `presenceTravel.nodeTravel` and the Omni board's rename use it. Deleting aproject keeps the agent status of node ids another project still holds (`nodeIdsHeldElsewhere`).Deliberately NOT moved to it: `routeControlSource` (a control request comes from a LOCAL agent, sodiff --git a/docs/hosted-team-relay.md b/docs/hosted-team-relay.mdindex c01e584b8..3b05de899 100644--- a/docs/hosted-team-relay.md+++ b/docs/hosted-team-relay.md@@ -376,7 +376,8 @@ After a share, the closed SSH project and the team's tab hold the **same node idtmux session names, and the server keeps them). Every "go to node" (a notification, the sessionssidebar, ⌘K, a teammate's face, a rename from the board) goes to the project that owns the node inthis order: an open project before a closed one, and one not handed off before one that was-(`lib/nodeOwner.ts`). So it lands on the team's tab, never on the reopen warning. Deleting the closed+(`lib/nodeOwner.ts`). So it lands on the team's tab, never on the reopen warning. A closed team tab+owns no node: with the team's tab closed, it goes to the SSH project, whose reopen warning asks first. Deleting the closedSSH project from "Recently closed" keeps the agent status of every node id another project stillholds.@@ -618,8 +619,12 @@ project of yours that holds the id is skipped, never renamed.a share event opens is added at the end of the tab bar.- **A tab you close stays closed** while its project stays shared, for the rest of the app run. Oncethe host unshares it the dismissal is forgotten, so sharing it again opens it again. A closed team- tab is not offered under "Recently closed", nor by ⇧⌘T: its nodes are the host's sessions, and- reopening it from there would mount them on this computer's core. It comes back through the team.+ tab is never reopened on this computer: once closed its relay connection is gone, and a reopen+ would mount the host's sessions on this computer's core. "Recently closed" lists neither the tab+ nor its closed sessions, and every other way back (⇧⌘T, a notification, ⌘K, a teammate's face)+ is refused with "This team tab was closed on this computer. It opens again when you join the team+ again (close its other tabs first), or when the team stops sharing the project and shares it+ again." Those two are what bring it back: a reconnect of the team's other tabs keeps it dismissed.- **A team with nothing shared keeps one placeholder tab**, named after the team, so the team staysvisible and reconnectable. The first shared project replaces it.- **One connection, all tabs.** A dropped connection greys all of a team's tabs together. A reconnect@@ -1341,5 +1346,8 @@ on a Mac and a second desktop as a teammate. Record `team status --json` at eachkeep running, and nothing is bootstrapped.25. **Going to a shared node lands on the team's tab.** After item 17, a completion notification ofthe resumed agent, its sessions-sidebar row, ⌘K and a teammate's face all open the team's tab- with the node focused, never the reopen warning of the closed SSH project. A closed team tab is- not listed under "Recently closed".+ with the node focused, never the reopen warning of the closed SSH project. Close the team's tab:+ it is not listed under "Recently closed" (nor are its closed sessions), ⇧⌘T on a node deleted in+ it shows the closed-tab notice and opens nothing, and a notification for the shared node now+ shows the SSH project's reopen warning. No `nt-<id>` session appears on this computer's own+ tmux socket at any point.diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex 0f46dc4ae..4f2e95caa 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -642,6 +642,8 @@ import { useReopenHistory, type ReopenEntry } from '../state/reopenHistory'import { snapshotNode, recreateNodeFromSnapshot } from '../lib/reopenNode'import {buildClosedSessionEntries,+ CLOSED_TEAM_TAB_NOTICE,+ isClosedTeamTab,recentlyClosedProjects,stateToReopenSnapshot} from '../lib/closedHistory'@@ -9195,12 +9197,21 @@ export function Canvas() {// The unchecked form asks nothing first: it is also "Share with team"'s own undo, which must put// the project back without a question. Declared here, beside switchProject and for the same TDZ// reason: the ⇧⌘T plan executor just below reopens through the guarded form.+ //+ // A relay (team) tab is refused here, the one funnel every reopen goes through: once closed its+ // relay session is gone, and `sessionForProject` would fall back to the LOCAL session, mounting+ // the host's node ids on this machine's core (local shells, an agent cold-resume). False = refused.const reopenProjectUnchecked = useCallback(- (id: string) => {+ (id: string): boolean => {+ if (useProjects.getState().getProject(id)?.remote) {+ setNotice({ kind: 'info', text: CLOSED_TEAM_TAB_NOTICE })+ return false+ }commitActiveToStore()useProjects.getState().reopenProject(id)setWelcomeOpen(false)void writeDisk()+ return true},[commitActiveToStore, writeDisk])@@ -9264,27 +9275,24 @@ export function Canvas() {/** The reopen every human path uses (Welcome's and the sidebar's "Recently closed", ⇧⌘T, ⌘K,* travel, "Open recent", Set folder…). A handed-off project asks first; any other reopens at* once, synchronously, exactly as before the question existed. Resolves false when the user- * declined, so a caller that staged follow-up work (a focus, a resume) can drop it. */+ * declined or the reopen was refused (a team tab), so a caller that staged follow-up work (a+ * focus, a resume) can drop it. */const reopenProject = useCallback((id: string): Promise<boolean> => {if (!useProjects.getState().getProject(id)?.handedOffTo) {- reopenProjectUnchecked(id)- return Promise.resolve(true)+ return Promise.resolve(reopenProjectUnchecked(id))}- return confirmHandedOffReopen(id).then((ok) => {- if (ok) reopenProjectUnchecked(id)- return ok- })+ return confirmHandedOffReopen(id).then((ok) => ok && reopenProjectUnchecked(id))},[confirmHandedOffReopen, reopenProjectUnchecked])/** Executes a `ReopenPlan` already decided by `planReopen` — the side-effecting half shared by* `Cmd+Shift+T` (`reopenLastClosedCommand`) and reopening a persisted closed-session entry- * from the sidebar (`reopenClosedSessionCommand`). Returns whether it did anything ('skip'- * plans are the caller's problem — this function never receives one). */+ * from the sidebar (`reopenClosedSessionCommand`). Returns whether it did anything ('skip' and+ * 'refuse' plans are the caller's problem — this function never receives one). */const executeReopenPlan = useCallback(- (plan: Exclude<ReopenPlan, { action: 'skip' }>): boolean => {+ (plan: Exclude<ReopenPlan, { action: 'skip' } | { action: 'refuse' }>): boolean => {switch (plan.action) {case 'reopenProject':// The guarded reopen: it commits the live canvas back to the store first (or whatever@@ -9334,20 +9342,6 @@ export function Canvas() {const entry = useReopenHistory.getState().popNext()if (!entry) return false- // The persisted twin of this batch (the sidebar's "Recently closed" rows the SAME delete- // recorded) must be consumed too — whether this entry ends up restored or skipped as stale,- // the ⇧⌘T stack is done with it either way, and leaving the sidebar row behind would let a- // later click there restore a duplicate. `writeDisk` runs unconditionally because- // `entry.projectId` may not be the active project, whose autosave debounce wouldn't cover it.- if (entry.kind === 'nodes') {- for (const n of entry.nodes) {- if (n.closedSessionId) {- useProjects.getState().discardClosedSession(entry.projectId, n.closedSessionId)- }- }- void writeDisk()- }-const { projects, activeProjectId } = useProjects.getState()const project = projects.find((p) => p.id === entry.projectId)const accounts = useSettings.getState().settings.claudeAccounts@@ -9364,6 +9358,27 @@ export function Canvas() {permissionModeFor: (agentId) => projectPermissionMode(project, agentId)}))+ // A closed team tab: nothing is written into it or reopened, and the entry goes back on the+ // stack untouched (its persisted twin too), so it still restores once the tab is back.+ if (plan.action === 'refuse') {+ useReopenHistory.getState().push(entry)+ setNotice({ kind: 'info', text: CLOSED_TEAM_TAB_NOTICE })+ return true+ }++ // The persisted twin of this batch (the sidebar's "Recently closed" rows the SAME delete+ // recorded) must be consumed too — whether this entry ends up restored or skipped as stale,+ // the ⇧⌘T stack is done with it either way, and leaving the sidebar row behind would let a+ // later click there restore a duplicate. `writeDisk` runs unconditionally because+ // `entry.projectId` may not be the active project, whose autosave debounce wouldn't cover it.+ if (entry.kind === 'nodes') {+ for (const n of entry.nodes) {+ if (n.closedSessionId) {+ useProjects.getState().discardClosedSession(entry.projectId, n.closedSessionId)+ }+ }+ void writeDisk()+ }if (plan.action === 'skip') continuereturn executeReopenPlan(plan)@@ -9394,6 +9409,12 @@ export function Canvas() {const reopenClosedSessionCommand = useCallback((projectId: string, entryId: string): boolean => {+ // Restoring a session into a closed team tab reopens that tab: refused before the entry is+ // consumed (the sidebar does not list these rows; this catches a stale click).+ if (isClosedTeamTab(useProjects.getState().getProject(projectId))) {+ setNotice({ kind: 'info', text: CLOSED_TEAM_TAB_NOTICE })+ return false+ }const consumed = useProjects.getState().consumeClosedSession(projectId, entryId)if (!consumed) return false// The ⇧⌘T-stack twin of this entry (if the SAME delete also pushed one) must go too, or a@@ -9423,7 +9444,7 @@ export function Canvas() {permissionModeFor: (agentId) => projectPermissionMode(project, agentId)}))- if (plan.action === 'skip') return false+ if (plan.action === 'skip' || plan.action === 'refuse') return falsereturn executeReopenPlan(plan)},[executeReopenPlan, writeDisk]diff --git a/src/renderer/canvas/canvas-wiring.test.tsx b/src/renderer/canvas/canvas-wiring.test.tsxindex 834a6d72e..c6bd3768c 100644--- a/src/renderer/canvas/canvas-wiring.test.tsx+++ b/src/renderer/canvas/canvas-wiring.test.tsx@@ -282,12 +282,12 @@ describe('deleteNodes also records persisted closed-session history', () => {describe('reopening a persisted closed-session entry shares reopenLastClosed\'s execution', () => {it('extracts the switch-on-plan-action body into its own callback', () => {expect(CANVAS_SRC).toContain('const executeReopenPlan = useCallback(')- expect(CANVAS_SRC).toContain('(plan: Exclude<ReopenPlan, { action: \'skip\' }>): boolean => {')+ expect(CANVAS_SRC).toContain('(plan: Exclude<ReopenPlan, { action: \'skip\' } | { action: \'refuse\' }>): boolean => {')})it('reopenLastClosedCommand delegates to it instead of inlining the switch', () => {const fnStart = CANVAS_SRC.indexOf('const reopenLastClosedCommand = useCallback(')- const fnBody = CANVAS_SRC.slice(fnStart, fnStart + 1700)+ const fnBody = CANVAS_SRC.slice(fnStart, fnStart + 2600)expect(fnBody).toContain('return executeReopenPlan(plan)')expect(fnBody).not.toContain('switch (plan.action)')})@@ -296,16 +296,17 @@ describe('reopening a persisted closed-session entry shares reopenLastClosed\'s// The bug this pins: restoring via ⇧⌘T without consuming the matching sidebar row would let a// later sidebar click restore the same closed session a second time.const fnStart = CANVAS_SRC.indexOf('const reopenLastClosedCommand = useCallback(')- const fnBody = CANVAS_SRC.slice(fnStart, fnStart + 1700)+ const fnBody = CANVAS_SRC.slice(fnStart, fnStart + 2600)expect(fnBody).toContain("if (entry.kind === 'nodes') {")expect(fnBody).toContain('.discardClosedSession(entry.projectId, n.closedSessionId)')expect(fnBody).toContain('void writeDisk()')})- it('consumes the entry before doing anything else, so a stale double-click cannot reopen it twice', () => {+ it('consumes the entry before anything restores it, so a stale double-click cannot reopen it twice', () => {+ // (Only the closed-team-tab refusal runs before it, and that one restores nothing.)const fnStart = CANVAS_SRC.indexOf('const reopenClosedSessionCommand = useCallback(')expect(fnStart).toBeGreaterThan(-1)- const fnBody = CANVAS_SRC.slice(fnStart, fnStart + 520)+ const fnBody = CANVAS_SRC.slice(fnStart, fnStart + 900)expect(fnBody).toContain('.consumeClosedSession(projectId, entryId)')expect(fnBody).toContain('if (!consumed) return false')expect(fnBody).toContain('void writeDisk()')@@ -313,23 +314,23 @@ describe('reopening a persisted closed-session entry shares reopenLastClosed\'sit('drops the matching ⇧⌘T-stack entry so the two histories cannot both reopen the same delete', () => {const fnStart = CANVAS_SRC.indexOf('const reopenClosedSessionCommand = useCallback(')- const fnBody = CANVAS_SRC.slice(fnStart, fnStart + 520)+ const fnBody = CANVAS_SRC.slice(fnStart, fnStart + 900)expect(fnBody).toContain('useReopenHistory.getState().dropByClosedSessionId(projectId, entryId)')})it('wraps the consumed entry as a synthetic ReopenEntry and reuses the pure planReopen', () => {const fnStart = CANVAS_SRC.indexOf('const reopenClosedSessionCommand = useCallback(')- const fnBody = CANVAS_SRC.slice(fnStart, fnStart + 1500)+ const fnBody = CANVAS_SRC.slice(fnStart, fnStart + 1900)expect(fnBody).toContain("kind: 'nodes'")expect(fnBody).toContain('nodes: [stateToReopenSnapshot(consumed)]')expect(fnBody).toContain('const plan = planReopen(')- expect(fnBody).toContain("if (plan.action === 'skip') return false")+ expect(fnBody).toContain("if (plan.action === 'skip' || plan.action === 'refuse') return false")expect(fnBody).toContain('return executeReopenPlan(plan)')})it('resolves permission mode and account against the TARGET project, same as reopenLastClosedCommand', () => {const fnStart = CANVAS_SRC.indexOf('const reopenClosedSessionCommand = useCallback(')- const fnBody = CANVAS_SRC.slice(fnStart, fnStart + 1500)+ const fnBody = CANVAS_SRC.slice(fnStart, fnStart + 1900)expect(fnBody).toContain('resolveAccountId: (id) => resolveNewNodeAccount(id, project, accounts)')expect(fnBody).toContain('permissionModeFor: (agentId) => projectPermissionMode(project, agentId)')})diff --git a/src/renderer/canvas/handed-off-reopen.source.test.ts b/src/renderer/canvas/handed-off-reopen.source.test.tsindex 0dfb58e7e..5aae4754f 100644--- a/src/renderer/canvas/handed-off-reopen.source.test.ts+++ b/src/renderer/canvas/handed-off-reopen.source.test.ts@@ -42,6 +42,29 @@ describe('handed-off reopen guard in Canvas', () => {expect(unchecked.length).toBe(inGuard.length + 1)})+ it('the one reopen funnel refuses a team tab with the notice, and every path reports the refusal', () => {+ // The decisions are proven in lib/closedHistory, lib/reopenPlan and lib/nodeOwner; what only the+ // source shows is that Canvas's funnel and the two history paths ask them, BEFORE any write.+ const unchecked = between('const reopenProjectUnchecked = useCallback(', CALLBACK_END)+ const refuse = unchecked.indexOf('if (useProjects.getState().getProject(id)?.remote) {')+ expect(refuse).toBeGreaterThan(-1)+ expect(unchecked.indexOf("setNotice({ kind: 'info', text: CLOSED_TEAM_TAB_NOTICE })", refuse)).toBeGreaterThan(refuse)+ expect(unchecked.indexOf('useProjects.getState().reopenProject(id)')).toBeGreaterThan(refuse)+ const human = between('const reopenProject = useCallback(', CALLBACK_END)+ expect(human).toContain('return Promise.resolve(reopenProjectUnchecked(id))')+ expect(human).toContain('ok && reopenProjectUnchecked(id)')+ // ⇧⌘T: a refused plan puts the entry back before its persisted twin would be discarded.+ const last = between('const reopenLastClosedCommand = useCallback(', '}, [executeReopenPlan, writeDisk])')+ const refused = last.indexOf("if (plan.action === 'refuse') {")+ expect(refused).toBeGreaterThan(-1)+ expect(last.indexOf('useReopenHistory.getState().push(entry)', refused)).toBeGreaterThan(refused)+ expect(last.indexOf('discardClosedSession(')).toBeGreaterThan(refused)+ // The sidebar's session restore checks before it consumes the entry.+ const session = between('const reopenClosedSessionCommand = useCallback(', CALLBACK_END)+ expect(session.indexOf('isClosedTeamTab(')).toBeGreaterThan(-1)+ expect(session.indexOf('isClosedTeamTab(')).toBeLessThan(session.indexOf('consumeClosedSession('))+ })+it('the store reopen is called in exactly one place, the unchecked reopen', () => {const calls = src.match(/useProjects\.getState\(\)\.reopenProject\(/g) ?? []expect(calls).toHaveLength(1)diff --git a/src/renderer/lib/closedHistory.test.ts b/src/renderer/lib/closedHistory.test.tsindex c851c6a6d..b9fce951b 100644--- a/src/renderer/lib/closedHistory.test.ts+++ b/src/renderer/lib/closedHistory.test.ts@@ -5,6 +5,8 @@ import {filterClosedProjects,mergeClosedHistory,recentlyClosedProjects,+ isClosedTeamTab,+ CLOSED_TEAM_TAB_NOTICE,stateToReopenSnapshot} from './closedHistory'import type { CanvasNode } from '@renderer/state/workspace'@@ -169,6 +171,30 @@ describe('mergeClosedHistory', () => {const rows = mergeClosedHistory([proj({ id: 'team', closed: true, remote: true, closedAt: 5 })])expect(rows).toHaveLength(0)})++ it('excludes the closed SESSIONS of a closed team tab too (restoring one reopens the tab); an open one keeps them', () => {+ const entry: ClosedSessionEntry = {+ id: 's1', closedAt: 9,+ node: { id: 'n', kind: 'terminal', position: { x: 0, y: 0 }, size: { width: 1, height: 1 }, title: 't', color: '#fff', group: null },+ absolutePosition: { x: 0, y: 0 }+ }+ expect(mergeClosedHistory([proj({ id: 'team', closed: true, remote: true, closedSessions: [entry] })])).toHaveLength(0)+ expect(mergeClosedHistory([proj({ id: 'team', remote: true, closedSessions: [entry] })]).map((r) => r.kind)).toEqual(['session'])+ })+})++describe('closed team tabs', () => {+ it('isClosedTeamTab is a closed relay project only', () => {+ expect(isClosedTeamTab({ closed: true, remote: true })).toBe(true)+ expect(isClosedTeamTab({ remote: true })).toBe(false)+ expect(isClosedTeamTab({ closed: true })).toBe(false)+ expect(isClosedTeamTab(undefined)).toBe(false)+ })+ it('the refusal says what actually brings the tab back', () => {+ expect(CLOSED_TEAM_TAB_NOTICE).toBe(+ 'This team tab was closed on this computer. It opens again when you join the team again (close its other tabs first), or when the team stops sharing the project and shares it again.'+ )+ })})// Issue #531: closing a node used to destroy the ONLY pointer to its transcript (the live sessiondiff --git a/src/renderer/lib/closedHistory.ts b/src/renderer/lib/closedHistory.tsindex 65bbb2744..ee967db96 100644--- a/src/renderer/lib/closedHistory.ts+++ b/src/renderer/lib/closedHistory.ts@@ -206,6 +206,20 @@ export function isReopenableClosedProject(p: { closed?: boolean; unavailable?: breturn !!p.closed && !p.unavailable && !p.remote}+/** A relay tab (a hosted team's project) the user closed on this computer. Its relay session is+ * gone, so anything that reopened it (or restored a node into it) would mount the HOST's node ids+ * on this machine's core: local shells, and an agent cold-resume. Nothing reopens one. */+export function isClosedTeamTab(p: { closed?: boolean; remote?: boolean } | undefined): boolean {+ return !!p?.remote && !!p.closed+}++/** Said instead of reopening a closed team tab. A closed tab stays dismissed while its project+ * stays shared (even across a reconnect of the team's other tabs); what brings it back is joining+ * the team again once none of its tabs is open, or the team unsharing the project and sharing it+ * again (`lib/hostedTeamTabs.ts`). */+export const CLOSED_TEAM_TAB_NOTICE =+ 'This team tab was closed on this computer. It opens again when you join the team again (close its other tabs first), or when the team stops sharing the project and shares it again.'+/*** Narrows the "Recently closed" list by name or folder — both already rendered on the row, and* `cwd` is the row's `title`. Empty/whitespace query = everything, unchanged.@@ -222,6 +236,9 @@ export function filterClosedProjects<T extends { name: string; cwd?: string }>(export function mergeClosedHistory(projects: readonly Project[]): ClosedHistoryRow[] {const rows: ClosedHistoryRow[] = []for (const p of projects) {+ // A closed team tab offers neither itself nor its closed sessions: restoring a session puts the+ // node back into that project and reopens it.+ if (isClosedTeamTab(p)) continueif (isReopenableClosedProject(p)) {rows.push({ kind: 'project', projectId: p.id, closedAt: p.closedAt ?? -1, project: p })}diff --git a/src/renderer/lib/nodeOwner.test.ts b/src/renderer/lib/nodeOwner.test.tsindex 65a1f4f68..9fa04cee6 100644--- a/src/renderer/lib/nodeOwner.test.ts+++ b/src/renderer/lib/nodeOwner.test.ts@@ -22,6 +22,14 @@ describe('nodeOwner', () => {expect(nodeOwner([closedMarked], 'x')?.id).toBe('d')})+ it('a CLOSED team tab owns nothing: the shared node falls back to the handed-off SSH project, whose reopen asks', () => {+ const closedTab = { ...teamTab, closed: true, remote: true }+ expect(nodeOwner([sshProject, closedTab], 'n1')?.id).toBe('ssh-1')+ expect(nodeOwner([closedTab], 'n1')).toBeUndefined()+ // An open team tab still wins, as before.+ expect(nodeOwner([sshProject, { ...teamTab, remote: true }], 'n1')?.id).toBe('p-9')+ })+it('ties go to the first in the list; an unknown node has no owner', () => {expect(nodeOwner([{ id: 'a', nodes: [{ id: 'x' }] }, { id: 'b', nodes: [{ id: 'x' }] }], 'x')?.id).toBe('a')expect(nodeOwner([teamTab], 'nope')).toBeUndefined()diff --git a/src/renderer/lib/nodeOwner.ts b/src/renderer/lib/nodeOwner.tsindex b8800d9ea..bd482b5cb 100644--- a/src/renderer/lib/nodeOwner.ts+++ b/src/renderer/lib/nodeOwner.ts@@ -10,19 +10,23 @@export interface OwnerProject {closed?: booleanhandedOffTo?: unknown+ /** A relay tab (a hosted team's project). */+ remote?: booleannodes: readonly { id: string }[]}/*** The project that owns `nodeId`: an open project before a closed one, and, among those, one not* handed off to a hosted team before one that was; ties go to the first in the list. `undefined`- * when no project holds the node.+ * when no project holds the node. A CLOSED team tab never owns a node: reopening it would mount the+ * host's node ids on this machine's core, so a shared node whose team tab is closed falls back to+ * the handed-off SSH project, whose reopen asks first.*/export function nodeOwner<T extends OwnerProject>(projects: readonly T[], nodeId: string): T | undefined {let best: T | undefinedlet bestRank = Number.POSITIVE_INFINITYfor (const p of projects) {- if (!p.nodes.some((n) => n.id === nodeId)) continue+ if ((p.remote && p.closed) || !p.nodes.some((n) => n.id === nodeId)) continueconst rank = (p.closed ? 2 : 0) + (p.handedOffTo ? 1 : 0)if (rank < bestRank) {best = pdiff --git a/src/renderer/lib/presenceTravel.test.ts b/src/renderer/lib/presenceTravel.test.tsindex 17b1c071a..74021bcb9 100644--- a/src/renderer/lib/presenceTravel.test.ts+++ b/src/renderer/lib/presenceTravel.test.ts@@ -66,6 +66,15 @@ describe('nodeTravel', () => {expect(nodeTravel(shared, 'active', 'n-team')).toEqual({ kind: 'switch', projectId: 'team-tab' })})+ it('a shared node whose team tab is CLOSED travels to the handed-off SSH project (guarded reopen), never the tab', () => {+ const shared: TravelProject[] = [+ { id: 'ssh-1', closed: true, handedOffTo: { at: 1 }, nodes: [{ id: 'n-team' }] },+ { id: 'team-tab', closed: true, remote: true, nodes: [{ id: 'n-team' }] },+ { id: 'active', nodes: [] }+ ]+ expect(nodeTravel(shared, 'active', 'n-team')).toEqual({ kind: 'reopen', projectId: 'ssh-1' })+ })+it('does nothing for an unknown node', () => {expect(nodeTravel(projects, 'active', 'n-ghost')).toEqual({ kind: 'none' })})diff --git a/src/renderer/lib/presenceTravel.ts b/src/renderer/lib/presenceTravel.tsindex d31c7aab6..29b325c29 100644--- a/src/renderer/lib/presenceTravel.ts+++ b/src/renderer/lib/presenceTravel.ts@@ -19,6 +19,8 @@ export interface TravelProject {unavailable?: boolean/** Set on an SSH project handed to a hosted team; that team's tab holds the same node ids. */handedOffTo?: unknown+ /** A relay tab (a hosted team's project); a closed one owns no node (`nodeOwner`). */+ remote?: booleannodes: { id: string }[]}diff --git a/src/renderer/lib/reopenPlan.test.ts b/src/renderer/lib/reopenPlan.test.tsindex 3997d0e1a..eed2f25e9 100644--- a/src/renderer/lib/reopenPlan.test.ts+++ b/src/renderer/lib/reopenPlan.test.ts@@ -53,10 +53,28 @@ describe('planReopen', () => {expect(plan).toEqual({ action: 'skip' })})- it('skips a closed relay (team) tab: a reopen would mount the host nodes on this core', () => {+ it('refuses a closed relay (team) tab: a reopen would mount the host nodes on this core', () => {const projects: PlanReopenProject[] = [{ id: 'team', closed: true, remote: true, nodes: [] }]const plan = planReopen({ kind: 'project', projectId: 'team', closedAt: 1 }, projects, 'p2', new Set(), neverRecreates)- expect(plan).toEqual({ action: 'skip' })+ expect(plan).toEqual({ action: 'refuse', projectId: 'team' })+ })++ it('refuses a nodes entry for a closed team tab BEFORE recreating anything into it', () => {+ // insertStored + reopenProjectAfter would write the nodes into the relay copy and then reopen it.+ const projects: PlanReopenProject[] = [{ id: 'team', closed: true, remote: true, nodes: [] }]+ let recreated = 0+ const plan = planReopen({ kind: 'nodes', projectId: 'team', closedAt: 1, nodes: [snap()] }, projects, 'p2', new Set(), () => {+ recreated+++ return node('x')+ })+ expect(plan).toEqual({ action: 'refuse', projectId: 'team' })+ expect(recreated).toBe(0)+ })++ it('an OPEN team tab still takes a restored node (its relay session is live)', () => {+ const projects: PlanReopenProject[] = [{ id: 'team', remote: true, nodes: [] }]+ const plan = planReopen({ kind: 'nodes', projectId: 'team', closedAt: 1, nodes: [snap()] }, projects, 'p2', new Set(), alwaysRecreates())+ expect(plan).toMatchObject({ action: 'insertStored', projectId: 'team', reopenProjectAfter: false })})it('skips a project entry whose project was permanently deleted since', () => {diff --git a/src/renderer/lib/reopenPlan.ts b/src/renderer/lib/reopenPlan.tsindex 7f016a836..ef890af5d 100644--- a/src/renderer/lib/reopenPlan.ts+++ b/src/renderer/lib/reopenPlan.ts@@ -1,16 +1,20 @@import type { ReopenEntry } from '@renderer/state/reopenHistory'import type { ReopenNodeSnapshot } from './reopenNode'import type { CanvasNode } from '@renderer/state/workspace'+import { isClosedTeamTab } from './closedHistory'/** What `app.reopenLastClosed` (Cmd+Shift+T) should do for ONE popped history entry. Pure* decision only — no store writes, no `setNodes`, no navigation. `Canvas.tsx` executes* whichever variant comes back; `'skip'` means the entry was stale (already reopened another* way, its project was permanently deleted, or every node it held recreated to nothing) and the- * caller should keep popping. */+ * caller should keep popping. `'refuse'` means the entry's project is a CLOSED team tab+ * (`isClosedTeamTab`): nothing may be written into it or reopen it, and the caller keeps the entry+ * and says why. */export type ReopenPlan =| { action: 'reopenProject'; projectId: string }| { action: 'insertActive'; nodes: CanvasNode[] }| { action: 'insertStored'; projectId: string; reopenProjectAfter: boolean; nodes: CanvasNode[] }+ | { action: 'refuse'; projectId: string }| { action: 'skip' }/** The subset of `Project` this decision needs — kept minimal so tests can pass plain fixtures@@ -18,7 +22,7 @@ export type ReopenPlan =export interface PlanReopenProject {id: stringclosed?: boolean- /** A relay tab (a hosted team's project): never reopened from the history. */+ /** A relay tab (a hosted team's project): once closed, never reopened from the history. */remote?: booleannodes: readonly { id: string }[]}@@ -41,15 +45,17 @@ export function planReopen(activeLiveNodeIds: ReadonlySet<string>,recreate: (snapshot: ReopenNodeSnapshot, liveNodeIds: ReadonlySet<string>) => CanvasNode | null): ReopenPlan {+ const project = projects.find((p) => p.id === entry.projectId)+ // A closed team tab: its nodes are the host's sessions, and reopening it (or restoring a node+ // into it, which reopens it) would mount them on this machine's core. Checked before anything is+ // recreated, so nothing is written into it.+ if (isClosedTeamTab(project)) return { action: 'refuse', projectId: entry.projectId }+if (entry.kind === 'project') {- const project = projects.find((p) => p.id === entry.projectId)- // Only stale if it isn't sitting closed right now — already reopened another way, or gone. A- // relay tab is never reopened from here: its nodes are the host's sessions, and a reopen would- // mount them on this machine's core (the team brings its own tabs back).- return project?.closed && !project.remote ? { action: 'reopenProject', projectId: entry.projectId } : { action: 'skip' }+ // Only stale if it isn't sitting closed right now — already reopened another way, or gone.+ return project?.closed ? { action: 'reopenProject', projectId: entry.projectId } : { action: 'skip' }}- const project = projects.find((p) => p.id === entry.projectId)if (!project) return { action: 'skip' } // permanently deleted since the entry was recordedconst isActive = project.id === activeProjectId