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(session): a Team Access fallback tab is a relay tab
reviewccc291d90748
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsxindex 6c2642749..f1002dd2f 100644--- a/src/renderer/canvas/Canvas.tsx+++ b/src/renderer/canvas/Canvas.tsx@@ -503,7 +503,7 @@ import {shouldShowExplorerPinHint,writeSeenExplorerPinHint} from '../lib/explorerPinHint'-import { sameSshEndpoint, setKanbanPublishHook, setStoredCanvasPublishHook, useProjects } from '../state/projects'+import { addRelayTab, sameSshEndpoint, setKanbanPublishHook, setStoredCanvasPublishHook, useProjects } from '../state/projects'import { useAgentStatus, recordsTurnInterrupt } from '../state/agentStatus'import { usePendingPause, startPendingPauseWatcher } from '../state/pendingPause'import {@@ -5600,7 +5600,10 @@ export function Canvas() {}return { id: reconnectProjectId } // reconnect: reuse the existing tab, don't spawn one}- : (name) => useProjects.getState().addProject(name),+ : // The host shared nothing to adopt: an EMPTY relay tab — `remote`, like every relay tab,+ // or it would be saved as a local project carrying the host's node ids and resolve to+ // the LOCAL session once its relay session is gone.+ (name) => addRelayTab(name),// First connect adopts the host's shared project (its nodes, fresh id). On reconnect the// existing tab (with its nodes) is reused via addProject above, so no adopt lever is passed.adoptProject: reconnectProjectId@@ -10103,8 +10106,9 @@ export function Canvas() {// 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.+ // relay session is gone, and its nodes could never start — `sessionForProject` answers the offline+ // relay session for it (before that existed it fell 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): boolean => {if (useProjects.getState().getProject(id)?.remote) {diff --git a/src/renderer/lib/hostedTeamTabStore.ts b/src/renderer/lib/hostedTeamTabStore.tsindex 10caca513..69c430b49 100644--- a/src/renderer/lib/hostedTeamTabStore.ts+++ b/src/renderer/lib/hostedTeamTabStore.ts@@ -2,7 +2,7 @@// registry. Kept out of Canvas so the placeholder and the removal run under a test against the// real store.-import { useProjects } from '../state/projects'+import { addRelayTab, useProjects } from '../state/projects'import { bindProjectToSession, unbindProject } from '../session/session'import { openSuccessor, type TeamTabOps } from './hostedTeamTabs'@@ -20,14 +20,9 @@ export function teamTabStoreOps(teamOf: (projectId: string) => string | undefineadoptProject: (p) => useProjects.getState().adoptProject(p),// A relay tab like the team's others (`remote`): the save filter drops it, so a restart never// finds one on disk (a boot reconnect would otherwise add a second beside it), and whatever asks- // whether a project is a relay tab (the codex probe) says yes. Added like any project first, so- // it takes the store's name cap and does not take the screen.- addPlaceholder: (label) => {- const store = useProjects.getState()- const relay = { ...store.addProject(label), remote: true }- store.replaceProject(relay)- return relay- },+ // whether a project is a relay tab (the codex probe) says yes. `addRelayTab` takes the store's+ // name cap and does not take the screen.+ addPlaceholder: (label) => addRelayTab(label),// The STORE delete, never Canvas's `deleteProject` (which ends the host's sessions through the// relay transport): a hosted tab leaves this desktop only. When the removed tab was active, the// store hands the active slot to whatever slid into it; only when that is a closed project (ordiff --git a/src/renderer/session/offline-relay-session.test.ts b/src/renderer/session/offline-relay-session.test.tsindex d503a6422..a8070f1b3 100644--- a/src/renderer/session/offline-relay-session.test.ts+++ b/src/renderer/session/offline-relay-session.test.ts@@ -22,7 +22,7 @@ import { join } from 'node:path'import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import type { CanvasNodeState, NodeTerminalApi, Project, PtyCreateOptions } from '@shared/types'import { E_DISCONNECTED } from '../../shared/rpc'-import { useProjects } from '../state/projects'+import { addRelayTab, useProjects } from '../state/projects'import {OFFLINE_RELAY_SESSION_ID,activeSessionApi,@@ -321,13 +321,18 @@ describe('an unbound REMOTE project resolves to the offline relay session', () =it('a remote tab the store has since deleted still resolves offline; a never-remote one stays local', () => {const relay = createSession('relay', fakeApi('host'), 'e2ehost')bindProjectToSession(TEAM_ALPHA, relay.id) // remote in the store at bind time- // Team Access's fallback tab (`addProject(label)`, not marked remote) bound to the same session.- bindProjectToSession(LOCAL_ONE, relay.id)+ // Team Access's fallback tab (the host shared nothing to adopt), bound to the same session. It+ // is an EMPTY relay tab, `remote` like every relay tab (`addRelayTab`, what Canvas passes as the+ // first-connect `addProject`): the host's nodes reach it over canvas sync.+ const fallback = addRelayTab("Ayşe's Mac")+ bindProjectToSession(fallback.id, relay.id)disposeSession(relay.id)- useProjects.setState({ projects: [localProject()] }) // TEAM_ALPHA leaves the store+ expect(sessionForProject(fallback.id).id).toBe(OFFLINE_RELAY_SESSION_ID)+ useProjects.setState({ projects: [localProject()] }) // TEAM_ALPHA and the fallback leave the storeexpect(sessionForProject(TEAM_ALPHA).id).toBe(OFFLINE_RELAY_SESSION_ID)+ expect(sessionForProject(fallback.id).id).toBe(OFFLINE_RELAY_SESSION_ID)expect(presenceForProject(TEAM_ALPHA)).toBe(getSessionStores(OFFLINE_RELAY_SESSION_ID).presence)- // The store's answer wins while it holds the project: never remote ⇒ local.+ // A local project the store holds stays local (local projects are never bound).expect(sessionForProject(LOCAL_ONE).id).toBe('local')// An id that was never bound remote stays local.expect(sessionForProject('project-never-seen').id).toBe('local')@@ -500,6 +505,20 @@ describe('source pins', () => {}})+ // Canvas's first-connect `addProject` (the host shared nothing to adopt) must make a RELAY tab:+ // a plain `useProjects.getState().addProject(name)` is a local project — saved to this machine's+ // workspace with the host's node ids, and LOCAL again once its relay session is gone.+ it('Canvas creates the Team Access fallback tab with addRelayTab', () => {+ const canvas = read('../canvas/Canvas.tsx')+ const a = canvas.indexOf('const mountRemoteMirror = useCallback(')+ const b = canvas.indexOf('adoptProject: reconnectProjectId', a)+ expect(a).toBeGreaterThan(-1)+ expect(b).toBeGreaterThan(a)+ const deps = canvas.slice(a, b)+ expect(deps).toContain('(name) => addRelayTab(name)')+ expect(deps).not.toContain('.addProject(')+ })+it('offline-relay-session.ts registers the factory at module load', () => {expect(read('offline-relay-session.ts')).toMatch(/^setOfflineRelayApiFactory\(offlineRelayApi\)$/m)})diff --git a/src/renderer/session/relay-tab.test.ts b/src/renderer/session/relay-tab.test.tsindex 5abbb69ad..99b754d88 100644--- a/src/renderer/session/relay-tab.test.ts+++ b/src/renderer/session/relay-tab.test.ts@@ -19,7 +19,7 @@ import {setOfflineRelayApiFactory,OFFLINE_RELAY_SESSION_ID,} from './session'-import { useProjects } from '../state/projects'+import { addRelayTab, useProjects } from '../state/projects'import { LocalTransport } from '../terminal/local-transport'import { planActiveProjectDials } from '../lib/sshAttachments'import type { NodeTerminalApi, Project, Workspace } from '@shared/types'@@ -125,6 +125,35 @@ describe('openRelayTab (connect → tab → mount)', () => {expect(sessionCount()).toBe(1) // only local remains})+ it('a Team Access tab whose host shared nothing is a RELAY tab: never saved, offline (never local) once disposed', async () => {+ // The host's workspace is empty, so openRelayTab takes the fallback: `deps.addProject(label)`,+ // which Canvas wires to `addRelayTab` on a first connect.+ const { api } = fakeBridgedApi()+ const close = vi.fn()+ const handle: RelayApiHandle = { api, ready: () => Promise.resolve(), close }+ const { deps } = makeDeps({ handle, addProject: addRelayTab })+ const offlineApi = { marker: 'offline-relay' } as unknown as NodeTerminalApi+ setOfflineRelayApiFactory(() => offlineApi)+ try {+ const tab = await openRelayTab('conn-1', "Ayşe's Mac", deps)+ const project = useProjects.getState().getProject(tab.projectId)+ expect(project?.remote).toBe(true)+ expect(sessionForProject(tab.projectId).id).toBe(tab.sessionId)+ // Never written to THIS machine's workspace: a reload must not bring it back as a LOCAL+ // project carrying the host's node ids (the disk writer skips `remote` too).+ expect(useProjects.getState().toWorkspace().projects.map((p) => p.id)).not.toContain(tab.projectId)+ tab.dispose()+ expect(close).toHaveBeenCalledTimes(1)+ const s = sessionForProject(tab.projectId)+ expect(s.id).toBe(OFFLINE_RELAY_SESSION_ID)+ expect(s.source).toBe('relay')+ expect(boundSessionForProject(tab.projectId)).toBeNull()+ } finally {+ setOfflineRelayApiFactory(null)+ useProjects.setState({ projects: [], activeProjectId: '' })+ }+ })+it('a disposed tab whose project is REMOTE in the store resolves to the offline relay session, never local', async () => {const { api } = fakeBridgedApi()const handle: RelayApiHandle = { api, ready: () => Promise.resolve(), close: vi.fn() }diff --git a/src/renderer/session/relay-tab.ts b/src/renderer/session/relay-tab.tsindex 155e3f3ae..8df9b17bd 100644--- a/src/renderer/session/relay-tab.ts+++ b/src/renderer/session/relay-tab.ts@@ -41,9 +41,9 @@ const APPROVAL_TIMEOUT_MS = 60_000export interface RelayTabDeps {/** The preload relay surface — only `onClosed` is needed here (to catch a pre-approval drop). */relayClient: Pick<RelayClientApi, 'onClosed'>- /** Add an EMPTY project tab (`useProjects.getState().addProject`) → the new project's id. The- * fallback when the host shared nothing (no scoped project) and the reconnect lever (Canvas- * overrides it to reuse the existing project id in place). */+ /** Add an EMPTY relay tab (`addRelayTab` — marked `remote`, never a plain local project) → the+ * new project's id. The fallback when the host shared nothing (no scoped project) and the+ * reconnect lever (Canvas overrides it to reuse the existing project id in place). */addProject: (label: string) => { id: string }/** Adopt the host's shared project as a tab (`useProjects.getState().adoptProject`) → fresh* project id, node ids kept. Used on FIRST connect to populate the tab with the host's actualdiff --git a/src/renderer/session/session.ts b/src/renderer/session/session.tsindex 4c8f38720..4b2e78c26 100644--- a/src/renderer/session/session.ts+++ b/src/renderer/session/session.ts@@ -54,7 +54,9 @@ let offline: Entry | null = null* leave the store while its nodes are still mounted — a host that stops sharing the only open team* tab deletes it from the store, and the welcome screen keeps its nodes in React Flow — and an id* the store no longer holds must still not resolve local. The store's own answer wins whenever it- * still holds the project. Runtime only, like the bindings. */+ * still holds the project. Runtime only, like the bindings. Needs no cap: it holds one entry per+ * DISTINCT remote project id bound in this app run (a handful of relay / team tabs), and a+ * reconnect re-binds the same id. */const KNOWN_REMOTE = new Set<string>()/** The per-session store instances. `createPresenceSession` is memoized BY API IDENTITY, so the@@ -309,7 +311,8 @@ function offlineForUnboundRemote(projectId: string): Entry | null {}/** The projects bound to a live session whose api IS `api`, i.e. the tabs one relay connection- * serves. An unbound project merely falls back to the local session, so the local api binds none. */+ * serves. Bindings only: an unbound project — local, or a remote one resolving to the offline+ * relay session — is bound to no api, so neither the local api nor the offline one binds any. */export function projectIdsBoundToApi(api: NodeTerminalApi): string[] {const out: string[] = []for (const [projectId, sessionId] of PROJECT_BINDINGS) {diff --git a/src/renderer/state/projects.ts b/src/renderer/state/projects.tsindex 29afbafc1..3b752478d 100644--- a/src/renderer/state/projects.ts+++ b/src/renderer/state/projects.ts@@ -1131,6 +1131,21 @@ export const useProjects = create<ProjectsState>((set, get) => ({}}))+/**+ * Add an EMPTY relay tab: a project for a connection whose host shared nothing that could be adopted+ * (a Team Access tab's fallback, a hosted team's placeholder). Marked `remote` like every relay tab,+ * because it IS one: the host's nodes reach it over canvas sync, so it must never be saved into this+ * machine's workspace (`toWorkspace` filters `remote`) nor, once its relay session is gone, resolve+ * to the local session (session.ts `sessionForProject`). Added like any project first, so it takes+ * the store's name cap and does not take the screen.+ */+export function addRelayTab(label: string): Project {+ const store = useProjects.getState()+ const relay = { ...store.addProject(label), remote: true }+ store.replaceProject(relay)+ return relay+}+// Codex launch caps must know a relay tab when they see one: its sessions run on ANOTHER machine's// codex, which this machine's probe never saw (see `codexApprovalCaps`). Registered here rather// than imported there, because this store imports workspace.ts, which imports codexCli.ts.