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(workspace): only an owner client's load hands out a pending adoption
reviewf56d7af49bcd
diff --git a/src/core/workspace-store.adopt.test.ts b/src/core/workspace-store.adopt.test.tsindex 7deb025d3..317ad9775 100644--- a/src/core/workspace-store.adopt.test.ts+++ b/src/core/workspace-store.adopt.test.ts@@ -171,7 +171,10 @@ describe('WorkspaceStore.adoptFolder', () => {describe('a renderer that loaded before the adoption', () => {const save = (ws: Workspace): Promise<unknown> => Promise.resolve(fake.handlers[IPC.workspaceSave](ws))- const load = (): Promise<Workspace> => Promise.resolve(fake.handlers[IPC.workspaceLoad]() as Workspace)+ // The load handler takes the caller's client id first (it is registered with its sender).+ const OWNER = 1+ const load = (sender = OWNER): Promise<Workspace> =>+ Promise.resolve(fake.handlers[IPC.workspaceLoad](sender) as Workspace)it('cannot drop the adopted project with its stale autosave; once a renderer has loaded it, it can', async () => {store.registerIpc()@@ -188,6 +191,22 @@ describe('WorkspaceStore.adoptFolder', () => {await save(withA) // a renderer that HAS seen it and saves without it is deleting itexpect(indexIds()).toEqual(['p-a'])})++ it('a load by a client that cannot save (a relay peer, a hosted guest) does not hand the adoption out', async () => {+ fake.isOwnerClient = (id: number) => id === OWNER+ store.registerIpc()+ const stale = await load(OWNER) // the owner's tab, loaded before the bootstrap+ const withA: Workspace = { ...stale, activeProjectId: 'p-a', projects: [emptyProject('p-a', 'mu-a', folder('mu-a'))] }+ await save(withA)+ const r = await store.adoptFolder(folder('mu-b'), { home: dir })+ const guest = await load(7) // a teammate joins and loads: it sees the project, but it can never save+ expect(guest.projects.map((p) => p.id)).toContain(r.projectId)+ await save(withA) // the owner's stale tab autosaves+ expect(indexIds()).toEqual(['p-a', r.projectId])+ await load(OWNER) // the owner's tab reloads: now its saves speak for the project+ await save(withA)+ expect(indexIds()).toEqual(['p-a'])+ })})it('a closed adopted project is reopened when adopted again', async () => {diff --git a/src/core/workspace-store.ts b/src/core/workspace-store.tsindex 7ce539643..5c9f21fd2 100644--- a/src/core/workspace-store.ts+++ b/src/core/workspace-store.ts@@ -369,7 +369,8 @@ export class WorkspaceStore {* workspace and `saveNow` rebuilds the index from it, so a browser tab opened before a headless* adoption would otherwise delete the adopted entry on its next autosave. A renderer can only* delete a project it has loaded, so an entry no renderer has seen is never treated as deleted:- * the renderer save path re-appends it (`withPendingAdoptions`) until a renderer load hands it out.+ * the renderer save path re-appends it (`withPendingAdoptions`) until an OWNER client's load+ * hands it out (a client that cannot save cannot be the one whose save would drop it).*/private pendingAdoptions = new Set<string>()/** The content authority, when this process runs one (Server Edition hosting a team). */@@ -389,11 +390,17 @@ export class WorkspaceStore {}registerIpc(): void {- platform().handle(IPC.workspaceLoad, async () => {+ platform().handleWithSender(IPC.workspaceLoad, async (senderId: number) => {const workspace = await this.load()// The renderer now holds these, so from here on its saves speak for them. Only the ids this// load actually returned: an adoption that landed while the load was in flight stays pending.- for (const p of workspace.projects) this.pendingAdoptions.delete(p.id)+ // And only for a client that CAN save: a relay peer or a hosted-team guest reaches this same+ // handler but is refused `workspace:save`, so its load proves nothing about the owner's tabs,+ // and clearing on it let the first teammate to join hand a stale owner tab the right to drop+ // the shared project. A platform that cannot tell (a test double) counts every caller.+ if (platform().isOwnerClient?.(senderId) !== false) {+ for (const p of workspace.projects) this.pendingAdoptions.delete(p.id)+ }return workspace})platform().handle(IPC.workspaceSave, (workspace: Workspace, opts?: WorkspaceSaveOptions) =>