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(team): an adopt keeps owed only what the adopted scene still holds
reviewbec0b3eb94d8
diff --git a/docs/team-presence.md b/docs/team-presence.mdindex 84ff78cd6..94d9124ec 100644--- a/docs/team-presence.md+++ b/docs/team-presence.md@@ -464,17 +464,25 @@ They are in the vocabulary now, and everything around them is the node machinerypeer's `edge-remove` would delete the link on our canvas too. The publisher holds such an`edge-upsert` inside the emit that refused the node (and on every later emit while the node's lastcast stays refused — `refusedNodeIds()`), keeps it owed, and casts it in the same batch as the node,- after it, on the first emit in which the node goes through. That holds across adopts too: an adopt- (every peer op, every project load) takes the scene on screen, which already contains the refused- node and the held edge, so the adopted baseline keeps the PREVIOUS baseline's entry for the owed- node and every edge touching it (`adoptBaseline`) — otherwise the node would re-diff only when it- next changed, and the edge would never differ from the baseline again and never be cast. The hold- is in the publisher, not a filter on the scene: dropping an edge the baseline already holds would- diff as an `edge-remove` — the same delete, cast by us. It is conservative: an edge to a node whose- EARLIER version the peer has also waits. What it does not cover: a baseline taken while the solo- gate is closed (`shouldPublish` false) is not rebased, so an owed item swallowed there syncs only- when it next changes; the gate closes on an open publisher only when a hosted role drops to- read-only.+ after it, on the first emit in which the node goes through. That holds across a peer's op too: the+ adopt that applies it takes the scene on screen, which already contains the refused node and the+ held edge, so the adopted baseline keeps the PREVIOUS baseline's entry for an owed node that scene+ still holds and for every edge in it touching one (`adoptBaseline`) — otherwise the node would+ re-diff only when it next changed, and the edge would never differ from the baseline again and+ never be cast. Only what the adopted scene still holds: one publisher serves every local project,+ so a project switch adopts ANOTHER project's scene, and re-emitting an owed node it lacks would+ cast a `remove` of the old project's node under the new project's id (and a peer's delete, which+ also arrives as an adopt, would be echoed back). The hold is in the publisher, not a filter on the+ scene: dropping an edge the baseline already holds would diff as an `edge-remove` — the same+ delete, cast by us. It is conservative: an edge to a node whose EARLIER version the peer has also+ waits. What it does not cover: (1) a baseline taken while the solo gate is closed (`shouldPublish`+ false) is not rebased, so an owed item swallowed there syncs only when it next changes — the gate+ closes on an open publisher only when a hosted role drops to read-only; (2) a round trip to+ another project with any emit there (A → B → A): the emit in B forgets the owed node (it is not on+ B's canvas), and the load that returns to A adopts A's whole scene, so a held edge is not cast+ after the node is trimmed until the edge itself changes; (3) a `remove` that was itself refused (no+ active project) and then adopted over is not retried. None of the three is a regression — the+ publisher behaved the same way before holds existed.- **"This note is too large" is said only for a node upsert.** An edge op is refused only for amalformed or over-long id, so the sentence would name a cause nobody measured; the refusal islogged instead.diff --git a/src/shared/canvas-publish.test.ts b/src/shared/canvas-publish.test.tsindex 406547961..4e9aada5c 100644--- a/src/shared/canvas-publish.test.ts+++ b/src/shared/canvas-publish.test.ts@@ -562,6 +562,55 @@ describe('an adopt does not swallow what is still owed', () => {expect(c.sent.slice(cast).map(label)).toEqual(['edge-remove:b1', 'remove:n'])})+ // One publisher serves every local project, and a project switch ADOPTS the incoming project's+ // scene. An owed node of the project we left is absent from that scene; keeping its previous entry+ // in the new baseline would diff as a `remove` (and its edge as an `edge-remove`), cast under the+ // NEW project's id — a rule-4 tombstone for that id on every client, and a pending entry here that+ // deafens us to peers' edits of it in the project it actually lives in.+ it('a project switch casts nothing for the old project’s owed node', () => {+ const bad = new Set<string>()+ const c = refusing(bad)+ const p = createCanvasPublisher(c.send)+ p.publish(scene([node('s'), node('t')], [link('b1', 's', 't')])) // project A, all cast+ bad.add('s')+ p.publish(scene([node('s', 9), node('t')], [link('b1', 's', 't')])) // s grows past the cap+ const cast = c.sent.length+ p.adopt(scene([node('x')])) // switch to project B+ p.publish(scene([node('x', 1)])) // the first edit in B+ expect(c.sent.slice(cast).map(label)).toEqual(['upsert:x'])+ })++ // The peer deleted the owed node (and its link); applying their op and adopting the result must not+ // echo their remove back at them.+ it('a peer’s remove of an owed node is not echoed back', () => {+ const bad = new Set<string>()+ const c = refusing(bad)+ const p = createCanvasPublisher(c.send)+ p.publish(scene([node('s'), node('t')], [link('b1', 's', 't')]))+ bad.add('s')+ p.publish(scene([node('s', 9), node('t')], [link('b1', 's', 't')]))+ const cast = c.sent.length+ p.adopt(scene([node('t')])) // the peer's remove of s (and b1) applied locally+ p.publish(scene([node('t')])) // the [nodes] effect fires+ expect(c.sent.slice(cast)).toEqual([])+ })++ // Same rule for an EDGE the adopted scene dropped: the peer removed the link of an owed node (not+ // the node); keeping the link's previous entry would echo their edge-remove back at them.+ it('a peer’s remove of an owed node’s edge is not echoed back', () => {+ const bad = new Set<string>()+ const c = refusing(bad)+ const p = createCanvasPublisher(c.send)+ p.publish(scene([node('s'), node('t')], [link('b1', 's', 't')]))+ bad.add('s')+ p.publish(scene([node('s', 9), node('t')], [link('b1', 's', 't')]))+ const cast = c.sent.length+ p.adopt(scene([node('s', 9), node('t')])) // the peer's edge-remove of b1 applied locally+ p.publish(scene([node('s', 9), node('t')]))+ expect(c.sent.slice(cast)).toEqual([])+ expect(p.refusedNodeIds()).toEqual(new Set(['s'])) // s itself is still owed+ })+it('an adopt with nothing owed stays lazy', () => {const c = collect()const p = createCanvasPublisher(c.send)diff --git a/src/shared/canvas-publish.ts b/src/shared/canvas-publish.tsindex 4ad06f2e2..7fce7833f 100644--- a/src/shared/canvas-publish.ts+++ b/src/shared/canvas-publish.ts@@ -55,7 +55,8 @@ export interface CanvasPublisher {publish(next: CanvasSnapshot, opts?: { throttle?: boolean }): void/** Take `next` as the new baseline WITHOUT sending — the loop guard (a peer's mutation, or a* programmatic project load). The next diff against it is empty, except for what is still owed- * (a refused node and the edges held for it), which stays owed — see `adoptBaseline`. */+ * and still on the adopted scene (a refused node and the edges held for it), which stays owed —+ * see `adoptBaseline`. */adopt(next: CanvasSnapshot): void/** Send any coalesced drag frame immediately (drag settle / unmount). */flush(): void@@ -186,6 +187,14 @@ export function createCanvasPublisher(* older version where it did. Dropping them outright instead would lose that older version, and a* later local delete of the node would diff to nothing.*+ * Only for what the ADOPTED scene still holds: an owed node present in it, and edges in it that+ * touch one. An owed node the scene no longer holds is not ours to re-emit — a project switch+ * adopts ANOTHER project's scene (one publisher serves every local project), where keeping the old+ * entry would cast a `remove` of the previous project's node under the new project's id; and a+ * peer's delete arrives here as an adopt, where it would echo their remove back. The same goes for+ * an edge the adopted scene dropped. The cost: a REMOVE that was itself refused (no active project)+ * and then adopted over is not retried — which the publisher never did before this rule either.+ ** Only while something is owed — and then the previous baseline is resolved now, one serialize per* adopt, because the adopted thunk must be rebased against the baseline AS OF this adopt. With* nothing owed an adopt is exactly what it was: a thunk stored unresolved.@@ -198,10 +207,12 @@ export function createCanvasPublisher(const owed = new Set(owedNodes)const prev = baseline()const keepOwed = (next: CanvasScene): CanvasScene => {+ const here = new Set(next.nodes.filter((n) => owed.has(n.id)).map((n) => n.id))+ if (!here.size) return nextconst keys = new Set<string>()- for (const id of owed) keys.add('n:' + id)- for (const e of [...prev.bridges, ...prev.ropes, ...next.bridges, ...next.ropes]) {- if (owed.has(e.source) || owed.has(e.target)) keys.add('e:' + e.id)+ for (const id of here) keys.add('n:' + id)+ for (const e of [...next.bridges, ...next.ropes]) {+ if (here.has(e.source) || here.has(e.target)) keys.add('e:' + e.id)}return rebaseRefused(prev, next, keys)}