Skip to content

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.

fix(workspace-store): the node → project memo also keys on the node arrays (D1)

reviewf125584d193b
diff --git a/src/core/workspace-store.node-project.test.ts b/src/core/workspace-store.node-project.test.ts
index d22cdb7c2..2966968ad 100644
--- a/src/core/workspace-store.node-project.test.ts
+++ b/src/core/workspace-store.node-project.test.ts
@@ -131,3 +131,35 @@ describe('WorkspaceStore.projectIdsForNode — an id in more than one project (M
expect(store.projectIdsForNode('n1')).toEqual(['pa'])
})
})
+
+describe('WorkspaceStore.projectIdsForNode — the memo keys (D1)', () => {
+ // The memo is keyed on the IDENTITY of every input persistedCanvases reads. The node array itself
+ // is one of them: a writer that replaces `entry.project.nodes` / `entry.cache.nodes` on the SAME
+ // entry and project/cache object must still be seen, and so must an in-place re-key of an inline
+ // project's id.
+ type Entry = { id: string; project?: { id: string; nodes: CanvasNodeState[] }; cache?: { nodes: CanvasNodeState[] } }
+ const entriesOf = (store: WorkspaceStore): Entry[] => (store as unknown as { index: { entries: Entry[] } }).index.entries
+
+ it('an inline project whose node array is replaced in place, or whose id is re-keyed in place', async () => {
+ const store = new WorkspaceStore()
+ await store.save(ws([project('inline', undefined, ['n1'])]))
+ expect(store.projectIdsForNode('n1')).toEqual(['inline'])
+ const e = entriesOf(store)[0]
+ e.project!.nodes = [node('n2')]
+ expect(store.projectIdsForNode('n2')).toEqual(['inline'])
+ expect(store.projectIdsForNode('n1')).toEqual([])
+ e.project!.id = 'renamed'
+ expect(store.projectIdsForNode('n2')).toEqual(['renamed'])
+ })
+
+ it('an SSH entry whose cached node array is replaced in place', async () => {
+ const store = new WorkspaceStore()
+ await store.save(ws([project('inline', undefined, ['n1'])]))
+ entriesOf(store).push({ id: 'ssh1', cache: { nodes: [node('s1')] } })
+ expect(store.projectIdsForNode('s1')).toEqual(['ssh1'])
+ const e = entriesOf(store)[1]
+ e.cache!.nodes = [node('s2')]
+ expect(store.projectIdsForNode('s2')).toEqual(['ssh1'])
+ expect(store.projectIdsForNode('s1')).toEqual([])
+ })
+})
diff --git a/src/core/workspace-store.ts b/src/core/workspace-store.ts
index ab2736dc3..3560d11e8 100644
--- a/src/core/workspace-store.ts
+++ b/src/core/workspace-store.ts
@@ -1524,8 +1524,11 @@ export class WorkspaceStore {
* to bump it, and this class changes those inputs from a dozen places — `lastWritten.set`, index
* reassignment, and in-place entry updates (`e.cache = …`, `e.project = …`, `e.id = …` on a
* re-key). Every one of them replaces a reference, so a snapshot comparison sees all of them,
- * including writers added later. It rests on one rule this file already keeps: a project's node
- * array is replaced, never mutated in place.
+ * including writers added later. The snapshot goes down to the node arrays themselves
+ * (`e.project.nodes`, `e.cache.nodes`) and the inline project's own id, so a writer that swaps
+ * `.nodes` or re-keys `.id` on the SAME entry and project/cache object is seen too. What it cannot
+ * see is an array MUTATED in place (a push into `nodes`): the rule this file keeps is that a
+ * project's node array is replaced, never mutated.
*/
projectIdsForNode(nodeId: string): readonly string[] {
const inputs = this.canvasInputs()
@@ -1547,12 +1550,23 @@ export class WorkspaceStore {
}
/** Every input `persistedCanvases` reads, by identity: the index object, and per entry the entry,
- * its id, its inline project, its ssh cache, its cwd and the text last written/read for that
- * cwd's project file. */
+ * its id, its inline project with that project's id and node array, its ssh cache with its node
+ * array, its cwd and the text last written/read for that cwd's project file. A node array is
+ * compared by reference: it must be replaced, never mutated in place (see `projectIdsForNode`). */
private canvasInputs(): unknown[] {
const out: unknown[] = [this.index]
for (const e of this.index?.entries ?? []) {
- out.push(e, e.id, e.project, e.cache, e.cwd, e.cwd ? this.lastWritten.get(projectFilePath(e.cwd)) : undefined)
+ out.push(
+ e,
+ e.id,
+ e.project,
+ e.project?.id,
+ e.project?.nodes,
+ e.cache,
+ e.cache?.nodes,
+ e.cwd,
+ e.cwd ? this.lastWritten.get(projectFilePath(e.cwd)) : undefined
+ )
}
return out
}