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(context-link): carry one-way reader through team sync and the edge menu (#852)

review617000561fee
diff --git a/CLAUDE.md b/CLAUDE.md
index fce44e5f0..6a65b1300 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -4911,7 +4911,12 @@ bridges enter live state only via `appendBridgeEdges`) and the server
discovery note a new link sends; losing access sends nothing, like removing a link. Note: the
premise "every submit triggers a full read" does not hold — nothing reads on submit; the linked
agent reads only when it decides to run the skill/shim. What one-way removes is the other side's
- PERMISSION and its discovery note.
+ PERMISSION and its discovery note. **Team sync carries it too**: an `edge-upsert` of kind
+ `bridge` keeps `reader` through the diff, the shape gate, the reflector's sanitize and the peer's
+ apply (`edgeFields`/`sameEdge` in `shared/canvas-mutations.ts`), and a flip alone is a change. A
+ three-id copy there never cast a flip and landed a cast one-way link on the peer as both-read,
+ which the peer then saved and published back. A malformed reader on the wire REFUSES the op
+ (never dropped — dropping widens), and a rope never carries one.
**Note links:** a sticky note can be connected to ANY terminal node (one-way, sticky →
terminal). On connect, agent sessions get a one-shot idle-gated push of the note text
(`buildNotePushMessage`, single-line, truncated at 2000 chars); plain terminals get no
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 073b26953..a59392e89 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -603,7 +603,7 @@ import { answerHostedRequest, type HostedAnswer } from '../lib/hostedOwner'
import { headRequest, type QueuedRequest } from '../lib/hostedPendingQueue'
import { useHostedPending } from '../state/hostedPending'
import { hostedInfoFor, isHostedReadOnly, useHostedTeams } from '../state/hostedTeams'
-import { appendBridgeEdges, bridgeToEdge, buildContextLinkNote, contextLinkForEdge, buildNotePushMessage, classifyLink, edgeToBridge, gainedReaders, hiddenLinkIds, linkIdsCoveredByRopes, linkReadPairs, pairKey, planBridges, withLinkReader, type LinkEndpoint } from '../lib/noteLink'
+import { appendBridgeEdges, bridgeToEdge, buildContextLinkNote, contextLinkForEdge, buildNotePushMessage, classifyLink, edgeToBridge, gainedReaders, hiddenLinkIds, isCurrentLinkDirection, linkIdsCoveredByRopes, linkReadPairs, pairKey, planBridges, withLinkReader, type LinkEndpoint } from '../lib/noteLink'
import {
deliveriesToRetire,
launchesToFire,
@@ -3454,7 +3454,9 @@ export function Canvas() {
publishableScene(
{
nodes: flowToNodeStates(flow, retainInitial),
- bridges: bridges.map(toBridgeLink),
+ // Bridges keep their one-way `reader` (issue #852): a peer applies what is cast, and a
+ // three-id bridge would widen a one-way link back to both-read on every teammate.
+ bridges: bridges.map(edgeToBridge),
ropes: ropes.map(toBridgeLink)
},
ephIds
@@ -4382,7 +4384,7 @@ export function Canvas() {
// gate above keys on (`mutationKey` leaves the kind out).
const prevBridges = linkEdgesRef.current
const prevRopes = controlEdgesRef.current
- const base = { bridges: prevBridges.map(toBridgeLink), ropes: prevRopes.map(toBridgeLink) }
+ const base = { bridges: prevBridges.map(edgeToBridge), ropes: prevRopes.map(toBridgeLink) }
const next = applyEdgeMutationToScene(base, mutation)
// Nothing to do — a remove for an edge we do not have, or the edge we already hold (every
// Server Edition tab re-casts a server-written edge): no setState, no markDirty, no save.
@@ -4397,9 +4399,13 @@ export function Canvas() {
}
if (next.bridges !== base.bridges) {
// No `type`: a bridge carries none in state — `displayEdges` makes every link `floating`.
- const edges = next.bridges.map(
- (b) => keep(prevBridges, b) ?? { id: b.id, source: b.source, target: b.target }
- )
+ // A bridge is also kept only while its one-way `reader` (issue #852) is unchanged: a peer
+ // flipping the direction must reach this canvas, not be swallowed as "same three ids".
+ const edges = next.bridges.map((b) => {
+ const held = keep(prevBridges, b)
+ if (!held) return bridgeToEdge(b)
+ return edgeToBridge(held).reader === b.reader ? held : { ...bridgeToEdge(b), selected: held.selected }
+ })
linkEdgesRef.current = edges
setLinkEdges(edges)
}
@@ -4732,7 +4738,7 @@ export function Canvas() {
const a = titleOf(link.source)
const b = titleOf(link.target)
const option = (label: string, reader: string | null) => {
- const active = (current.reader ?? null) === reader
+ const active = isCurrentLinkDirection(current, reader)
return {
label: `${active ? '✓ ' : ''}${label}`,
onClick: () => setReader(reader),
diff --git a/src/renderer/canvas/canvas-sync-ordering.source.test.ts b/src/renderer/canvas/canvas-sync-ordering.source.test.ts
index 58930b772..d384afa34 100644
--- a/src/renderer/canvas/canvas-sync-ordering.source.test.ts
+++ b/src/renderer/canvas/canvas-sync-ordering.source.test.ts
@@ -94,7 +94,9 @@ describe('render-time readers pair the rendered nodes with the rendered epoch',
// already names the incoming project while this render's `nodes` are still the outgoing one's.
// The context-link map (which authorizes context reads) must not pair A's links with B's id.
it('the context-link sync takes the rendered epoch', () => {
- expect(src).toContain('useContextLinkSync({ projectId: renderedProjectId, nodes, edges: linkEdges })')
+ expect(src).toContain('useContextLinkSync({ projectId: renderedProjectId, nodes, edges: linkBridges })')
+ // …built from the RENDERED linkEdges (one-way readers ride edge.data, issue #852).
+ expect(src).toContain('const linkBridges = useMemo(() => linkEdges.map(edgeToBridge), [linkEdges])')
expect(src).not.toContain('useContextLinkSync({ projectId: nodesProjectIdRef.current')
})
diff --git a/src/renderer/canvas/context-link-direction.source.test.ts b/src/renderer/canvas/context-link-direction.source.test.ts
index e28b5f433..c500f9806 100644
--- a/src/renderer/canvas/context-link-direction.source.test.ts
+++ b/src/renderer/canvas/context-link-direction.source.test.ts
@@ -15,14 +15,14 @@ describe('one-way context links — Canvas wiring (source pins)', () => {
it('never rebuilds a bridge edge field-by-field (that drops the reader)', () => {
expect(src).not.toMatch(/\(\{ id: b\.id, source: b\.source, target: b\.target \}\)/)
expect(src).not.toMatch(/linkEdgesRef\.current\.map\(\(e\) => \(\{ id: e\.id, source: e\.source, target: e\.target \}\)\)/)
- expect(src).toContain('setLinkEdges((project.bridges ?? []).map(bridgeToEdge))')
+ expect(src).toContain('const loadedBridges: Edge[] = (project.bridges ?? []).map(bridgeToEdge)')
expect(src).toContain('linkEdgesRef.current.map(edgeToBridge)')
expect(src).toContain('liveBridges: linkEdgesRef.current.map(edgeToBridge)')
- expect(src).toContain('setLinkEdges(plan.bridges.map(bridgeToEdge))')
+ expect(src).toContain('const bridges: Edge[] = plan.bridges.map(bridgeToEdge)')
})
it('publishes the link map from reader-carrying bridges', () => {
- expect(src).toMatch(/useContextLinkSync\(\{ projectId: nodesProjectIdRef\.current, nodes, edges: linkBridges \}\)/)
+ expect(src).toMatch(/useContextLinkSync\(\{ projectId: renderedProjectId, nodes, edges: linkBridges \}\)/)
})
it('draws the arrowhead on the reading side only for a one-way link', () => {
@@ -58,4 +58,17 @@ describe('one-way context links — Canvas wiring (source pins)', () => {
expect(body).toContain('contextLinkForEdge(')
expect(body).toContain('controlEdgesRef.current')
})
+
+ it('team sync casts and applies bridges WITH their reader (a flip must not widen on a peer)', () => {
+ // No bridge list may be flattened to three ids on its way to or from the wire.
+ expect(src).not.toMatch(/bridges\.map\(toBridgeLink\)/)
+ expect(src).not.toMatch(/prevBridges\.map\(toBridgeLink\)/)
+ const pub = src.slice(src.indexOf('const publishableLater = useCallback('))
+ expect(pub.slice(0, 2500)).toContain('bridges: bridges.map(edgeToBridge)')
+ const apply = src.slice(src.indexOf('if (isEdgeMutation(mutation)) {'))
+ const body = apply.slice(0, 4000)
+ expect(body).toContain('bridges: prevBridges.map(edgeToBridge)')
+ // A held bridge is reused only while its reader is unchanged.
+ expect(body).toContain('edgeToBridge(held).reader === b.reader')
+ })
})
diff --git a/src/renderer/lib/noteLink.test.ts b/src/renderer/lib/noteLink.test.ts
index 4fbb5a90f..f79c75c8b 100644
--- a/src/renderer/lib/noteLink.test.ts
+++ b/src/renderer/lib/noteLink.test.ts
@@ -13,7 +13,8 @@ import {
bridgeToEdge,
contextLinkForEdge,
edgeToBridge,
- linkReadPairs
+ linkReadPairs,
+ isCurrentLinkDirection
} from './noteLink'
import type { CanvasNodeState } from '@shared/types'
@@ -488,3 +489,23 @@ describe('contextLinkForEdge (issue #852 review P2b)', () => {
})
})
+
+// The edge menu's ✓ (issue #852). A malformed reader authorizes nobody, so it must not read as
+// "both read" — that ticked and DISABLED the one option that repairs the link.
+describe('isCurrentLinkDirection', () => {
+ const base = { id: 'x', source: 'a', target: 'b' }
+ it('ticks both-read only for a reader-less bridge', () => {
+ expect(isCurrentLinkDirection(base, null)).toBe(true)
+ expect(isCurrentLinkDirection({ ...base, reader: 'a' }, null)).toBe(false)
+ expect(isCurrentLinkDirection({ ...base, reader: 'a' }, 'a')).toBe(true)
+ expect(isCurrentLinkDirection({ ...base, reader: 'a' }, 'b')).toBe(false)
+ })
+ it('ticks nothing for a malformed reader (null / non-string / names neither endpoint)', () => {
+ for (const reader of [null, 7, 'zzz'] as unknown as string[]) {
+ const bad = { ...base, reader }
+ expect(isCurrentLinkDirection(bad, null)).toBe(false)
+ expect(isCurrentLinkDirection(bad, 'a')).toBe(false)
+ expect(isCurrentLinkDirection(bad, 'b')).toBe(false)
+ }
+ })
+})
diff --git a/src/renderer/lib/noteLink.ts b/src/renderer/lib/noteLink.ts
index 0bb725e2a..1eeeb521b 100644
--- a/src/renderer/lib/noteLink.ts
+++ b/src/renderer/lib/noteLink.ts
@@ -49,6 +49,14 @@ export function edgeToBridge(e: Pick<Edge, 'id' | 'source' | 'target' | 'data'>)
return data && hasReader(data) ? { ...b, reader: data.reader as string } : b
}
+/** Is `reader` (null = both read) the link's CURRENT direction, for the edge menu's ✓? Keyed on the
+ * reader's PRESENCE, not `reader ?? null`: a present-but-malformed reader (`null`, a number, a
+ * string naming neither endpoint) authorizes NOBODY, so it must not be shown as "both read" — that
+ * would tick and disable the one choice that repairs it. Such a link ticks no option at all. */
+export function isCurrentLinkDirection(bridge: BridgeLink, reader: string | null): boolean {
+ return reader === null ? !hasReader(bridge) : hasReader(bridge) && bridge.reader === reader
+}
+
function hasReader(o: { reader?: unknown }): boolean {
return 'reader' in o && o.reader !== undefined
}
diff --git a/src/shared/canvas-mutations.test.ts b/src/shared/canvas-mutations.test.ts
index b2d236cb7..014bcdc3c 100644
--- a/src/shared/canvas-mutations.test.ts
+++ b/src/shared/canvas-mutations.test.ts
@@ -547,3 +547,56 @@ describe('applyCanvasMutation — parent-first order (the downgrade contract)',
expect(ids(applyCanvasMutation([n('b'), n('a')], { op: 'upsert', node: n('c') }))).toEqual(['b', 'a', 'c'])
})
})
+
+// Issue #852: a context link's one-way `reader` is part of the edge on the wire. Every hop of team
+// sync (diff → shape gate → reflector sanitize → peer apply) used to carry only the three ids, so a
+// direction flip was never cast, and a freshly cast one-way link landed on the peer as both-read —
+// which the peer then saved and published back, widening who may read on every canvas.
+describe('one-way context links (#852) through team sync', () => {
+ const oneWay = (reader: string): BridgeLink => ({ id: 'x', source: 'a', target: 'b', reader })
+ const scene = (bridges: BridgeLink[]) => ({ nodes: [], bridges, ropes: [] })
+
+ it('a direction flip diffs to an edge-upsert carrying the reader', () => {
+ expect(diffToMutations(scene([e('x')]), scene([oneWay('a')]))).toEqual([
+ { op: 'edge-upsert', kind: 'bridge', edge: oneWay('a') }
+ ])
+ expect(diffToMutations(scene([oneWay('a')]), scene([e('x')]))).toEqual([
+ { op: 'edge-upsert', kind: 'bridge', edge: e('x') }
+ ])
+ expect(diffToMutations(scene([oneWay('a')]), scene([oneWay('a')]))).toEqual([])
+ })
+
+ it('flip → cast → reflect → peer apply leaves the peer one-way, not both-read', () => {
+ const peer = [e('x')]
+ const [cast] = diffToMutations(scene([e('x')]), scene([oneWay('b')]))
+ expect(isCanvasMutation(cast)).toBe(true)
+ const clean = sanitizeCanvasMutation(cast as CanvasMutation)!
+ const out = applyEdgeMutation(peer, 'bridge', clean)
+ expect(out).not.toBe(peer)
+ expect(out).toEqual([oneWay('b')])
+ // …and back to both-read clears it on the peer.
+ const back = sanitizeCanvasMutation({ op: 'edge-upsert', kind: 'bridge', edge: e('x') })!
+ expect(applyEdgeMutation(out, 'bridge', back)).toEqual([e('x')])
+ })
+
+ it('a held one-way bridge re-cast unchanged keeps identity', () => {
+ const list = [oneWay('a')]
+ expect(applyEdgeMutation(list, 'bridge', { op: 'edge-upsert', kind: 'bridge', edge: oneWay('a') })).toBe(list)
+ })
+
+ it('refuses a malformed reader rather than dropping it (dropping would widen the link)', () => {
+ const bad = (reader: unknown) =>
+ isCanvasMutation({ op: 'edge-upsert', kind: 'bridge', edge: { ...e('x'), reader } })
+ expect(bad('a')).toBe(true)
+ expect(bad(7)).toBe(false)
+ expect(bad('')).toBe(false)
+ expect(bad('r'.repeat(129))).toBe(false)
+ // A rope has no direction.
+ expect(isCanvasMutation({ op: 'edge-upsert', kind: 'rope', edge: oneWay('a') })).toBe(false)
+ })
+
+ it('never lets a reader onto a rope, even past the gate', () => {
+ const [out] = applyEdgeMutation([], 'rope', { op: 'edge-upsert', kind: 'rope', edge: oneWay('a') })
+ expect(out).toEqual(e('x'))
+ })
+})
diff --git a/src/shared/canvas-mutations.ts b/src/shared/canvas-mutations.ts
index 9bc0764d7..f9a4d98de 100644
--- a/src/shared/canvas-mutations.ts
+++ b/src/shared/canvas-mutations.ts
@@ -107,11 +107,17 @@ function checkMutation(value: unknown, sized: boolean): value is CanvasMutation
if (m.op === 'edge-remove') return isEdgeKind(m.kind) && isRefId(m.id) && fits(value)
if (m.op === 'edge-upsert') {
if (!isEdgeKind(m.kind)) return false
- const edge = m.edge as { id?: unknown; source?: unknown; target?: unknown } | undefined
+ const edge = m.edge as { id?: unknown; source?: unknown; target?: unknown; reader?: unknown } | undefined
if (!edge || typeof edge !== 'object') return false
// All three ids are ADDRESSES — an edge with a truncated endpoint would attach to the wrong
// node on every peer — so they are rejected rather than capped, exactly like a node id.
if (!isRefId(edge.id) || !isRefId(edge.source) || !isRefId(edge.target)) return false
+ // A one-way context link's reader (issue #852) is an address too. A malformed one REFUSES the
+ // op rather than being dropped: dropping it would turn a one-way link into a both-read one on
+ // every peer — widening who may read, the unsafe direction. Ropes never carry one.
+ if ('reader' in edge && edge.reader !== undefined) {
+ if (m.kind !== 'bridge' || !isRefId(edge.reader)) return false
+ }
return fits(m)
}
if (m.op !== 'upsert') return false
@@ -149,8 +155,7 @@ export function sanitizeCanvasMutation(m: CanvasMutation, keepLaunch = false): C
if (m.op === 'remove') return withStamp({ op: 'remove', id: m.id }, m)
if (m.op === 'edge-remove') return withStamp({ op: 'edge-remove', kind: m.kind, id: m.id }, m)
if (m.op === 'edge-upsert') {
- const { id, source, target } = m.edge
- return withStamp({ op: 'edge-upsert', kind: m.kind, edge: { id, source, target } }, m)
+ return withStamp({ op: 'edge-upsert', kind: m.kind, edge: edgeFields(m.kind, m.edge) }, m)
}
return sanitizeInboundMutation(m, keepLaunch)
}
@@ -316,6 +321,19 @@ export function applyOwnCanvasMutation(
return next
}
+/** The fields an edge op defines: its three ids, plus — for a context link (`bridge`) only — the
+ * one-way `reader` (issue #852). Anything else a cast carries is dropped. The reader MUST travel:
+ * a peer that received only three ids would hold the link as both-read and publish that back. */
+function edgeFields(kind: CanvasEdgeKind, e: BridgeLink): BridgeLink {
+ const out: BridgeLink = { id: e.id, source: e.source, target: e.target }
+ return kind === 'bridge' && typeof e.reader === 'string' ? { ...out, reader: e.reader } : out
+}
+
+/** Same edge for sync purposes: endpoints AND one-way reader — a direction flip is a change. */
+function sameEdge(a: BridgeLink, b: BridgeLink): boolean {
+ return a.source === b.source && a.target === b.target && a.reader === b.reader
+}
+
/**
* Apply one EDGE mutation to one of a project's edge lists, returning a NEW array when it changes
* anything (the input is never mutated). A mutation for the other kind — or for a node — and one
@@ -340,13 +358,13 @@ export function applyEdgeMutation(
const next = edges.filter((e) => e.id !== m.id)
return next.length === edges.length ? edges : next
}
- const edge: BridgeLink = { id: m.edge.id, source: m.edge.source, target: m.edge.target }
+ const edge = edgeFields(kind, m.edge)
const idx = edges.findIndex((e) => e.id === edge.id)
if (idx === -1) return [...edges, edge]
// The edge we already hold, unchanged: same reference, so a duplicate cast (every Server Edition
// tab re-casts a server-written edge) costs a receiver no setState, no markDirty, no save.
const held = edges[idx]
- if (held.source === edge.source && held.target === edge.target) return edges
+ if (sameEdge(held, edge)) return edges
const next = edges.slice()
next[idx] = edge
return next
@@ -407,7 +425,7 @@ function diffEdges(
const prevById = new Map(prev.map((e) => [e.id, e]))
for (const edge of next) {
const before = prevById.get(edge.id)
- if (!before || before.source !== edge.source || before.target !== edge.target) {
+ if (!before || !sameEdge(before, edge)) {
upserts.push({ op: 'edge-upsert', kind, edge })
}
}