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 remote tab the store deleted still resolves offline
reviewdcf871db8117
diff --git a/src/renderer/session/offline-relay-session.test.ts b/src/renderer/session/offline-relay-session.test.tsindex 4cbbd191e..d503a6422 100644--- a/src/renderer/session/offline-relay-session.test.ts+++ b/src/renderer/session/offline-relay-session.test.ts@@ -318,6 +318,21 @@ describe('an unbound REMOTE project resolves to the offline relay session', () =expect(() => bindProjectToSession(TEAM_ALPHA, OFFLINE_RELAY_SESSION_ID)).toThrow()})+ 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)+ disposeSession(relay.id)+ useProjects.setState({ projects: [localProject()] }) // TEAM_ALPHA leaves the store+ expect(sessionForProject(TEAM_ALPHA).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.+ expect(sessionForProject(LOCAL_ONE).id).toBe('local')+ // An id that was never bound remote stays local.+ expect(sessionForProject('project-never-seen').id).toBe('local')+ })+it('(e) sessionCount() does not count the sentinel', () => {expect(sessionForProject(TEAM_ALPHA).id).toBe(OFFLINE_RELAY_SESSION_ID)expect(sessionCount()).toBe(1)@@ -413,6 +428,31 @@ describe('ported repro scenarios: a team tab without a live binding creates nothexpect(localApi.pty.create).not.toHaveBeenCalled()})+ // Found while enumerating: `teamTabStoreOps.removeTab` (a host that stops sharing a project)+ // deletes the tab from the STORE and unbinds it. When it was the only open tab the welcome screen+ // keeps its nodes mounted, and an id the store no longer holds would read as "not remote".+ it('the host stops sharing the only open team tab (store delete) while its nodes are mounted', async () => {+ useProjects.setState({ projects: [teamTabProject()], activeProjectId: TEAM_ALPHA })+ const relay = createSession('relay', fakeApi('host'), 'e2ehost')+ bindProjectToSession(TEAM_ALPHA, relay.id)+ await mount()+ creates = []+ outcomes = []+ await act(async () => {+ unbindProject(TEAM_ALPHA)+ useProjects.getState().deleteProject(TEAM_ALPHA)+ })+ await settle()+ expect(useProjects.getState().activeProjectId).toBe('')+ expect(useProjects.getState().getProject(TEAM_ALPHA)).toBeUndefined()+ expect(localCreatesOfTeamNodes()).toEqual([])+ expect(outcomes.map((o) => [o.session, o.result])).toEqual([+ [OFFLINE_RELAY_SESSION_ID, 'rejected'],+ [OFFLINE_RELAY_SESSION_ID, 'rejected']+ ])+ expect(localApi.pty.create).not.toHaveBeenCalled()+ })+it('a local project is untouched: its nodes keep the local session', async () => {useProjects.setState({projects: [diff --git a/src/renderer/session/session.ts b/src/renderer/session/session.tsindex e1a13dd92..4c8f38720 100644--- a/src/renderer/session/session.ts+++ b/src/renderer/session/session.ts@@ -50,6 +50,12 @@ export const OFFLINE_RELAY_SESSION_ID = 'relay-offline'let offlineApiFactory: (() => NodeTerminalApi) | null = null/** The offline session, built lazily on first use, once per registry. */let offline: Entry | null = null+/** Project ids bound to a session while the projects store marked them `remote`. A remote tab can+ * 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. */+const KNOWN_REMOTE = new Set<string>()/** The per-session store instances. `createPresenceSession` is memoized BY API IDENTITY, so the* one-store-per-core guarantee needs no source branch here: the local session's api is@@ -152,6 +158,7 @@ export function resetSessionsForTest(): void {activeId = nullremoteSeq = 0offline = null+ KNOWN_REMOTE.clear()}/** Register (or, with `null`, drop) the builder of the offline relay session's api. Production@@ -234,6 +241,7 @@ export function sessionCount(): number {export function bindProjectToSession(projectId: string, sessionId: string): void {if (!SESSIONS.has(sessionId)) throw new Error(`[session] no session ${sessionId}`)PROJECT_BINDINGS.set(projectId, sessionId)+ if (useProjects.getState().getProject(projectId)?.remote) KNOWN_REMOTE.add(projectId)}/** Unbind ONE project (a hosted team stopped sharing it, or the user closed that one of the team's@@ -277,9 +285,11 @@ export function boundSessionForProject(projectId: string): WorkspaceSession | nu* — its session was disposed (the last team tab closed) or its binding dropped — resolves to the* OFFLINE relay session, never the local one: its node ids live on another machine, and a node* still mounted under the local session would create them on this desktop's core (bug F). Every- * core-bound call on the offline session rejects. A stale binding is pruned. An id the store does- * not know (a deleted project, '' on the welcome screen) is not evidence of anything remote and- * resolves local, as does a remote project when no offline factory is registered. */+ * core-bound call on the offline session rejects. A stale binding is pruned. A remote tab the store+ * has since deleted (a host that stopped sharing it) still resolves offline if it was bound while+ * remote in this run; any other id the store does not know ('' on the welcome screen) is not+ * evidence of anything remote and resolves local, as does a remote project when no offline factory+ * is registered. */export function sessionForProject(projectId: string): WorkspaceSession {const bound = boundSessionForProject(projectId)if (bound) return bound@@ -287,11 +297,14 @@ export function sessionForProject(projectId: string): WorkspaceSession {return off ? off.session : localOrActiveSession()}-/** The offline session's entry when `projectId` is a REMOTE project of the projects store — the- * one rule `sessionForProject` and `presenceForProject` share. The caller has already found no- * live binding. `null` for any other id, or when no offline factory is registered. */+/** The offline session's entry when `projectId` is a REMOTE project — `remote` in the projects+ * store, or (once the store no longer holds it) bound while it was (`KNOWN_REMOTE`) — the one rule+ * `sessionForProject` and `presenceForProject` share. The caller has already found no live binding.+ * `null` for any other id, or when no offline factory is registered. */function offlineForUnboundRemote(projectId: string): Entry | null {- if (!projectId || !useProjects.getState().getProject(projectId)?.remote) return null+ if (!projectId) return null+ const stored = useProjects.getState().getProject(projectId)+ if (!(stored ? stored.remote : KNOWN_REMOTE.has(projectId))) return nullreturn offlineEntry()}