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(ssh): "Open here anyway" never resumes the team's conversations a second time
review08eb66ef512f
diff --git a/CLAUDE.md b/CLAUDE.mdindex 1db23dd9d..8b89402d0 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -8480,7 +8480,12 @@ invariants:else's machine), `kanbanWriteNow` and `pushSshSettings` all skip the entry, and the field survivesrestarts (threaded through every `fileToProject` base; a file field of that name is ignored).Every reopen path (Recently closed, ⇧⌘T, `openSshProject`'s endpoint reuse) warns first, and only- "Open here anyway" clears it.+ "Open here anyway" clears it. That answer also marks the project's terminal nodes to skip their+ automatic cold-resume ONCE (`terminal/handed-off-resume.ts`; the node raises `CoState.resumeSkipped`+ and says why): the share killed their SSH sessions, so each would otherwise type `--resume <id>`+ over SSH while the server runs the same conversation. The mark is TRANSIENT on purpose and taken+ by the node's first local mount (warm or cold; never by a relay node), unlike the persisted+ `agentStatus.paused`, which is keyed by a node id the team tab shares.- **The SAS skip lives in ONE writer of `approvedAt`, and `source` gates nothing.** The clientauto-confirm is `autoApprove: approvedAt !== null` (`hosted-join.ts`, for the bookmark recordedwith the code's exact host key); `relay-bookmarks.ts` only validates `source`, it is a label.diff --git a/docs/hosted-team-relay.md b/docs/hosted-team-relay.mdindex ff781f28d..b4745587c 100644--- a/docs/hosted-team-relay.md+++ b/docs/hosted-team-relay.md@@ -352,17 +352,25 @@ SSH project again, warns first:> <name> is now managed by team <team> on <host>. Open it from the team tab, or run "team unshare> <projectId>" on the server first.>-> Open it here anyway? Two copies editing one canvas can overwrite each other.+> Open it here anyway? Two copies editing one canvas can overwrite each other, and its agents would+> start the same conversations the server is running. Its agents are not resumed here automatically.or, for a handover that did not finish:> Sharing <name> with a team did not finish. If the server already took it over, opening it here-> gives one canvas two editors that can overwrite each other.+> gives one canvas two editors that can overwrite each other, and its agents would start the same+> conversations the server is running.>-> Open it here anyway?+> Open it here anyway? Its agents are not resumed here automatically.**Open here anyway** takes the project back: the mark is cleared, and this desktop writes the file-again.+again. Its agent nodes then skip their automatic cold-resume ONCE: the share ended their SSH+sessions, so each would otherwise type `claude --resume <id>` (or its agent's equivalent) over SSH+while the server runs the same conversation, two processes appending to one transcript. Each such+node says so ("Not resumed: this project was shared with a team, and its server may be running this+conversation. Resume it here only once it has stopped there."), and resuming it stays your choice.+The skip is held in memory, never written, so it cannot follow the node id to the team's tab, which+holds the same ids.After a share, the closed SSH project and the team's tab hold the **same node ids** (they are thetmux session names, and the server keeps them). Every "go to node" (a notification, the sessionsdiff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex d07ec05cc..0f46dc4ae 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -382,6 +382,7 @@ import { ShareTeamDialog } from '../components/ShareTeamDialog'import { runShare, type ShareConfirmSummary, type ShareOutcome, type SharePhase } from '../lib/shareSshTeam'import { followSharedProject, shareCanvas, shareProjectDeps } from '../lib/shareTeamCanvas'import { handedOffWarning } from '../lib/handedOff'+import { skipNextColdResumeFor } from '../terminal/handed-off-resume'import { SshProjectDialog } from '../components/SshProjectDialog'import { SshPassphrasePrompt } from '../components/SshPassphrasePrompt'import { transport } from '../terminal/local-transport'@@ -9207,7 +9208,8 @@ export function Canvas() {/** Ask before opening a project this desktop handed to a hosted team: the server's core writes* that canvas now, and opening it here too makes a second writer that overwrites it. True = go* ahead, and going ahead takes the project back — the mark is cleared, so this desktop saves and- * mirrors it again (the caller saves). A project that was never handed off answers true. */+ * mirrors it again (the caller saves), and its agent nodes skip their next automatic resume. A+ * project that was never handed off answers true. */const confirmHandedOffReopen = useCallback(async (id: string): Promise<boolean> => {const marked = useProjects.getState().getProject(id)?.handedOffTo@@ -9248,7 +9250,12 @@ export function Canvas() {onCancel: () => resolve(false)}))- if (ok) useProjects.getState().setHandedOffTo(id, undefined)+ if (ok) {+ useProjects.getState().setHandedOffTo(id, undefined)+ // Its agents would resume the conversations the team's server is running: each one skips+ // its automatic cold-resume once, and says why (terminal/handed-off-resume.ts).+ skipNextColdResumeFor(useProjects.getState().getProject(id)?.nodes ?? [])+ }return ok},[confirmBusy, setConfirm]diff --git a/src/renderer/canvas/handed-off-reopen.source.test.ts b/src/renderer/canvas/handed-off-reopen.source.test.tsindex bebef9115..0dfb58e7e 100644--- a/src/renderer/canvas/handed-off-reopen.source.test.ts+++ b/src/renderer/canvas/handed-off-reopen.source.test.ts@@ -25,7 +25,10 @@ describe('handed-off reopen guard in Canvas', () => {expect(ask).toContain('handedOffWarning(project, label)')expect(ask).toContain("confirmLabel: 'Open here anyway'")expect(ask).toContain('danger: true')- expect(ask).toContain('if (ok) useProjects.getState().setHandedOffTo(id, undefined)')+ expect(ask).toMatch(/if \(ok\) \{\s+useProjects\.getState\(\)\.setHandedOffTo\(id, undefined\)/)+ // …and its agent nodes skip their next automatic resume (the team's server runs those+ // conversations): the decision is proven in terminal/handed-off-resume.test.ts.+ expect(ask).toMatch(/if \(ok\) \{[\s\S]*?skipNextColdResumeFor\(useProjects\.getState\(\)\.getProject\(id\)\?\.nodes \?\? \[\]\)/)// The team label is display only: its lookup fails open to null.expect(ask).toMatch(/try \{\n\s+const list = await window\.nodeTerminal\.relayHosted\?\.bookmarks\(\)/)})diff --git a/src/renderer/lib/handedOff.test.ts b/src/renderer/lib/handedOff.test.tsindex 45096d874..559c15523 100644--- a/src/renderer/lib/handedOff.test.ts+++ b/src/renderer/lib/handedOff.test.ts@@ -6,14 +6,18 @@ describe('handedOffWarning', () => {it('null for a project that was never handed off', () => expect(handedOffWarning(P, null)).toBeNull())it('names the team, the host and the unshare command', () => {const w = handedOffWarning({ ...(P as object), handedOffTo: { hostId: 'H', projectId: 'project-9', at: 1 } } as never, 'Box team')- expect(w).toBe('proj is now managed by team Box team on box. Open it from the team tab, or run "team unshare project-9" on the server first.\n\nOpen it here anyway? Two copies editing one canvas can overwrite each other.')+ expect(w).toBe(+ 'proj is now managed by team Box team on box. Open it from the team tab, or run "team unshare project-9" on the server first.\n\n' ++ 'Open it here anyway? Two copies editing one canvas can overwrite each other, and its agents would start the same conversations the server is running. Its agents are not resumed here automatically.'+ )})it('an unfinished handover says so', () => {expect(handedOffWarning({ ...(P as object), handedOffTo: { at: 1 } } as never, null)).toMatch(/^Sharing proj with a team did not finish\./)})it('the unfinished copy is the whole sentence pair, and ignores any team label', () => {expect(handedOffWarning({ ...(P as object), handedOffTo: { at: 1 } } as never, 'Box team')).toBe(- 'Sharing proj with a team did not finish. If the server already took it over, opening it here gives one canvas two editors that can overwrite each other.\n\nOpen it here anyway?'+ 'Sharing proj with a team did not finish. If the server already took it over, opening it here gives one canvas two editors that can overwrite each other, and its agents would start the same conversations the server is running.\n\n' ++ 'Open it here anyway? Its agents are not resumed here automatically.')})it('an unknown or blank team label falls back to the generic name', () => {diff --git a/src/renderer/lib/handedOff.ts b/src/renderer/lib/handedOff.tsindex 779a8b35e..70dcd5cbd 100644--- a/src/renderer/lib/handedOff.ts+++ b/src/renderer/lib/handedOff.ts@@ -9,13 +9,19 @@ import type { Project } from '@shared/types'* to ask.** A mark with no `hostId` is a handover that never finished: the server may or may not hold the- * project, so the copy says exactly that rather than naming a team that may not exist.+ * project, so the copy says exactly that rather than naming a team that may not exist. Both copies+ * say what opening it here would do to its agents: the server resumed their conversations, so+ * resuming them here too would put two processes on one transcript, and "Open here anyway" skips+ * that automatic resume once.** `teamLabel` is the team's name from this device's bookmark of it, when one is known; anything* else (no bookmark, a blank label) reads as "the hosted team". A finished mark always carries the* server's project id in practice; a hand-edited one without it still names the command, with the* same `<projectId>` placeholder the server's own usage text prints.*/+/** "Open here anyway" skips each agent's automatic resume once (terminal/handed-off-resume.ts). */+const AGENTS_NOT_RESUMED = 'Its agents are not resumed here automatically.'+export function handedOffWarning(p: Pick<Project, 'name' | 'handedOffTo' | 'ssh'>,teamLabel: string | null@@ -25,7 +31,9 @@ export function handedOffWarning(if (!to.hostId) {return (`Sharing ${p.name} with a team did not finish. If the server already took it over, opening it ` +- 'here gives one canvas two editors that can overwrite each other.\n\nOpen it here anyway?'+ 'here gives one canvas two editors that can overwrite each other, and its agents would start ' ++ 'the same conversations the server is running.\n\nOpen it here anyway? ' ++ AGENTS_NOT_RESUMED)}const team = teamLabel?.trim() || 'the hosted team'@@ -34,6 +42,8 @@ export function handedOffWarning(return (`${p.name} is now managed by team ${team} on ${host}. Open it from the team tab, or run ` +`"team unshare ${projectId}" on the server first.\n\n` +- 'Open it here anyway? Two copies editing one canvas can overwrite each other.'+ 'Open it here anyway? Two copies editing one canvas can overwrite each other, and its agents ' ++ 'would start the same conversations the server is running. ' ++ AGENTS_NOT_RESUMED)}diff --git a/src/renderer/nodes/TerminalNode.tsx b/src/renderer/nodes/TerminalNode.tsxindex e04554e97..d42c4b173 100644--- a/src/renderer/nodes/TerminalNode.tsx+++ b/src/renderer/nodes/TerminalNode.tsx@@ -205,6 +205,7 @@ import {LIVENESS_QUERY_MS} from '../terminal/agent-liveness'import { shouldAutoWake, shouldColdResume } from '../terminal/hibernation-policy'+import { skipsColdResume, takeColdResumeSkip } from '../terminal/handed-off-resume'import { coldSelfHealVerdict } from '../terminal/cold-self-heal'import { WakeInputBuffer } from '../terminal/wake-input-buffer'import { FindBar } from '../components/FindBar'@@ -1012,6 +1013,13 @@ interface CoState {* nothing is typed or relaunched — it names the cause and offers an Antigravity node instead.*/geminiRetired: boolean+ /**+ * This node's cold-restore relaunch was skipped once because its project was just taken back from+ * a hosted team ("Open here anyway", `terminal/handed-off-resume.ts`): the team's server may be+ * running the same conversation, and resuming it here too would put two processes on one+ * transcript. A slim banner, like `lostSession`: the shell is alive and nothing was typed.+ */+ resumeSkipped: boolean}const NO_CO: CoState = {letterbox: false,@@ -1022,7 +1030,8 @@ const NO_CO: CoState = {staleCwd: false,lostSession: false,launchTooLongBytes: null,- geminiRetired: false+ geminiRetired: false,+ resumeSkipped: false}const coStates = new Map<string, CoState>()const coSubs = new Map<string, (s: CoState) => void>()@@ -1237,7 +1246,8 @@ function setCo(key: string, patch: Partial<CoState>): void {next.staleCwd === prev.staleCwd &&next.lostSession === prev.lostSession &&next.launchTooLongBytes === prev.launchTooLongBytes &&- next.geminiRetired === prev.geminiRetired+ next.geminiRetired === prev.geminiRetired &&+ next.resumeSkipped === prev.resumeSkipped)returncoStates.set(key, next)@@ -2265,6 +2275,7 @@ export function TerminalNode({}const dismissStaleCwd = (): void => setCo(termKey, { staleCwd: false })const dismissLostSession = (): void => setCo(termKey, { lostSession: false })+ const dismissResumeSkipped = (): void => setCo(termKey, { resumeSkipped: false })const dismissGeminiRetired = (): void => setCo(termKey, { geminiRetired: false })// Canvas owns node creation; a terminal node has no direct line to it (same pattern as the// file-manager's `nodeterm:open-terminal`). The new node lands beside this one, in its frame.@@ -3592,7 +3603,8 @@ export function TerminalNode({lostSession: false,launchTooLongBytes: null,letterbox: false,- geminiRetired: false+ geminiRetired: false,+ resumeSkipped: false})if (!disposed) term.write(`\r\n\x1b[90m[${refusal.message}]\x1b[0m\r\n`)return@@ -3645,6 +3657,8 @@ export function TerminalNode({// cold-restore branch below can raise it) so a respawn that resumes cleanly — or any// warm reattach, which never reaches that branch at all — takes the old banner down.setCo(termKey, { lostSession: false })+ // …and the skipped-resume notice, for the same reason.+ setCo(termKey, { resumeSkipped: false })// Catch up a size change that landed while the spawn was in flight (applyFit skips the// IPC until sessionId is set, and the observer won't re-fire without another change).applyFit()@@ -4028,6 +4042,15 @@ export function TerminalNode({if (data.clearEnv) {updateNodeData(id, { clearEnv: undefined })}+ // A project just taken back from a hosted team ("Open here anyway") skips this relaunch+ // ONCE (see terminal/handed-off-resume.ts). The mark is taken here, warm or cold, so it+ // never outlives this mount; never by a relay tab's node, which shares the node id and is+ // the team's own view of the same session.+ const skipResume = skipsColdResume({+ coldStart,+ canColdRestore,+ marked: session.source !== 'relay' && takeColdResumeSkip(id)+ })// Run a one-shot command on first open (e.g. "gh auth login" or the agent CLI), then// forget it.if (data.initialCommand) {@@ -4051,6 +4074,10 @@ export function TerminalNode({if (outcome === 'line-too-long') setCo(termKey, { launchTooLongBytes: lineBytes(command) })}})+ } else if (skipResume) {+ // Say so rather than leaving a bare shell under an agent badge in silence. Resuming stays+ // the user's explicit choice.+ if (!life.dead) setCo(termKey, { resumeSkipped: true })} else if (coldStart && canColdRestore) {// Cold restart of an agent node: the live agent is gone, so re-launch it. Resume the// prior conversation by its session id when we have one; otherwise start the agent@@ -6629,6 +6656,30 @@ export function TerminalNode({</button></div>)}+ {/* Resume skipped once after "Open here anyway" on a project handed to a hosted team: the+ same slim banner as lostSession, and it yields to the same bigger problems. */}+ {!co.closed &&+ !co.ended &&+ !co.spawnError &&+ !co.offline &&+ !co.staleCwd &&+ co.resumeSkipped &&+ !offscreenDown && (+ <div className="term-node__stalecwd nodrag">+ <span className="term-node__stalecwd-text">+ Not resumed: this project was shared with a team, and its server may be running this+ conversation. Resume it here only once it has stopped there.+ </span>+ <button+ className="term-node__stalecwd-dismiss"+ onClick={dismissResumeSkipped}+ title="Dismiss"+ aria-label="Dismiss"+ >+ ×+ </button>+ </div>+ )}{/* Gemini CLI retired for personal accounts: the same slim banner as lostSession, andyields to the same bigger problems. Two actions — an Antigravity node (Google'sreplacement) beside this one, and Google's migration guide — plus dismiss. */}diff --git a/src/renderer/terminal/handed-off-resume.test.ts b/src/renderer/terminal/handed-off-resume.test.tsnew file mode 100644index 000000000..3cb657aee--- /dev/null+++ b/src/renderer/terminal/handed-off-resume.test.ts@@ -0,0 +1,31 @@+import { afterEach, describe, expect, it } from 'vitest'+import { resetColdResumeSkipsForTests, skipNextColdResumeFor, skipsColdResume, takeColdResumeSkip } from './handed-off-resume'++afterEach(() => resetColdResumeSkipsForTests())++describe('the skip-once mark of a project taken back from a hosted team', () => {+ it('marks the terminal nodes only (a legacy node without a kind is one)', () => {+ skipNextColdResumeFor([{ id: 't', kind: 'terminal' }, { id: 'legacy' } as never, { id: 's', kind: 'sticky' }])+ expect(takeColdResumeSkip('t')).toBe(true)+ expect(takeColdResumeSkip('legacy')).toBe(true)+ expect(takeColdResumeSkip('s')).toBe(false)+ })++ it('is consumed once: the next mount of the same node resumes as usual', () => {+ skipNextColdResumeFor([{ id: 't', kind: 'terminal' }])+ expect(takeColdResumeSkip('t')).toBe(true)+ expect(takeColdResumeSkip('t')).toBe(false)+ })+})++describe('skipsColdResume', () => {+ it('skips only a relaunch that would have happened', () => {+ expect(skipsColdResume({ coldStart: true, canColdRestore: true, marked: true })).toBe(true)+ // Unmarked: the ordinary cold restore.+ expect(skipsColdResume({ coldStart: true, canColdRestore: true, marked: false })).toBe(false)+ // A warm attach relaunches nothing, and neither does a node that could not cold-restore (a+ // relay tab, a paused or armed node, a plain terminal): nothing to skip, nothing to say.+ expect(skipsColdResume({ coldStart: false, canColdRestore: true, marked: true })).toBe(false)+ expect(skipsColdResume({ coldStart: true, canColdRestore: false, marked: true })).toBe(false)+ })+})diff --git a/src/renderer/terminal/handed-off-resume.ts b/src/renderer/terminal/handed-off-resume.tsnew file mode 100644index 000000000..13a706100--- /dev/null+++ b/src/renderer/terminal/handed-off-resume.ts@@ -0,0 +1,34 @@+// "Open here anyway" on a project this desktop handed to a hosted team.+//+// The share ended the project's SSH sessions and the server resumed its agents' conversations on its+// own core. Reopening the SSH project here mounts every node fresh against sessions that are gone, so+// each agent node would cold-restore and type `claude --resume <id>` over SSH: a second process on a+// conversation the server is running, both appending to one transcript. So that reopen marks the+// project's terminal nodes, and each one skips its automatic cold-resume ONCE and says why; resuming+// it here stays the user's explicit choice.+//+// The mark is transient (memory only) on purpose. `agentStatus.paused` would also skip the resume,+// but it is persisted and keyed by node id, and the hosted team's tab holds the very same node ids.+import type { CanvasNodeState } from '@shared/types'++const marked = new Set<string>()++/** Mark the terminal nodes of a project taken back from a hosted team. */+export function skipNextColdResumeFor(nodes: readonly Pick<CanvasNodeState, 'id' | 'kind'>[]): void {+ for (const n of nodes) if ((n.kind ?? 'terminal') === 'terminal') marked.add(n.id)+}++/** Take (and clear) a node's mark. Asked once per local mount that reaches the cold-restore+ * decision, warm or cold, so a mark never outlives the mount it was meant for. */+export function takeColdResumeSkip(nodeId: string): boolean {+ return marked.delete(nodeId)+}++/** Whether this mount skips its cold-restore relaunch: only when it would have relaunched at all. */+export function skipsColdResume(o: { coldStart: boolean; canColdRestore: boolean; marked: boolean }): boolean {+ return o.coldStart && o.canColdRestore && o.marked+}++export function resetColdResumeSkipsForTests(): void {+ marked.clear()+}