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(messaging): a NaN clock could silence a sender, and an unvalidated id could collide two conversations

Claude Code633a8e6a7db5
diff --git a/src/core/agents/agent-message-decide.ts b/src/core/agents/agent-message-decide.ts
index f2b8d7343..417d8738b 100644
--- a/src/core/agents/agent-message-decide.ts
+++ b/src/core/agents/agent-message-decide.ts
@@ -18,7 +18,18 @@ import { MIN_TOKEN_AWARE_REVISION } from './hooks/managed-script'
* the policy without either.
*/
-export type NotPermittedReason = 'switch-off' | 'cross-project' | 'self-send' | 'unsupported-edition'
+/**
+ * `unaddressable-node-id` is deliberately its own word rather than a shade of `cross-project`: an
+ * id outside `isSafeNodeId` may well be listed in the sender's OWN project file (nothing validates
+ * ids on the load path), so calling it a project-scope failure would be a false statement about
+ * why it was refused — and it needs a different action from the human. See `agent-message-scope.ts`.
+ */
+export type NotPermittedReason =
+ | 'switch-off'
+ | 'cross-project'
+ | 'self-send'
+ | 'unsupported-edition'
+ | 'unaddressable-node-id'
/** Which signal satisfied the delivery receipt (Task 3.4). */
export type ReceiptSignal = 'newTurn' | 'working'
diff --git a/src/core/agents/agent-message-flow.test.ts b/src/core/agents/agent-message-flow.test.ts
index 2d13e0178..715a67bf0 100644
--- a/src/core/agents/agent-message-flow.test.ts
+++ b/src/core/agents/agent-message-flow.test.ts
@@ -17,6 +17,7 @@ import {
import { decidePreProbe, RETRYABLE } from './agent-message-decide'
import { deliverAgentMessage, type DeliveryDeps } from './agent-message'
import { MANAGED_SCRIPT_REVISION } from './hooks/managed-script'
+import { isSafeNodeId } from '../remote-safety'
import type { MirrorEntry } from '../agent-status-mirror'
const T0 = 1_700_000_000_000
@@ -90,6 +91,23 @@ describe('the per-pair rate limit', () => {
expect(pairKey('a', 'b')).not.toBe(pairKey('b', 'a'))
})
+ it('an id CONTAINING the separator would collide two conversations — and is refused upstream', () => {
+ // The uniqueness test above cannot see this: no id in its set can contain a NUL, so the shape
+ // moves one layer down instead of dying. Here it is, exhibited rather than asserted away — and
+ // then the validator that makes the premise true, refusing exactly the ids that cause it.
+ const SEP = String.fromCharCode(0)
+ expect(pairKey(`x${SEP}y`, 'z')).toBe(pairKey('x', `y${SEP}z`))
+ noteSent(`x${SEP}y`, 'z', T0)
+ // …a live mis-throttle: a conversation nobody has had is refused for 9999 ms.
+ expect(wait(checkPairRate('x', `y${SEP}z`, T0 + 1))).toBe(PAIR_MIN_INTERVAL_MS - 1)
+ // Node ids are not validated on the project.json load path, so the premise is enforced at the
+ // authorization boundary instead — `resolveDeliveryScope`, over this predicate.
+ expect(isSafeNodeId(`x${SEP}y`)).toBe(false)
+ expect(isSafeNodeId('x y')).toBe(false)
+ expect(isSafeNodeId('v/1')).toBe(false)
+ expect(isSafeNodeId('term-mabc-3')).toBe(true)
+ })
+
it('a CHECK never starts a window — only a delivered message does', () => {
// Otherwise a delivery refused for any other reason (a busy target, an unverified identity —
// the two commonest refusals there are) would burn the budget it never used, and the caller
@@ -275,6 +293,32 @@ describe('eviction — the entries go away, not just the verdicts', () => {
expect(flowStats().senders).toBe(0)
})
+ it('a NON-FINITE clock reading empties both maps instead of freezing them', () => {
+ // Every comparison in the sweep is FALSE for NaN, so without the guard the entry is immortal —
+ // and the two budgets then fail in opposite directions: the pair limiter's `retryAfterMs` is
+ // NaN (which `decidePreProbe` reads as "no limit", so it fails open) while the fan-out cap
+ // keeps returning a real number forever, silencing the sender for the rest of the run.
+ for (let i = 0; i < FANOUT_PER_TURN; i++) noteSent('a', `dst-${i}`, T0 + i)
+ expect(wait(checkFanOut('a', T0 + 10))).toBe(FANOUT_RETRY_AFTER_MS)
+ expect(wait(checkFanOut('a', Number.NaN))).toBeNull()
+ expect(flowStats()).toEqual({ pairs: 0, senders: 0 })
+ // …and the budget is genuinely released rather than merely reported open once.
+ expect(wait(checkFanOut('a', T0 + 11))).toBeNull()
+ expect(wait(checkPairRate('a', 'dst-0', T0 + 11))).toBeNull()
+ })
+
+ it('an INFINITE reading is safe too, though not because of that guard', () => {
+ // Measured, not assumed: +Infinity is dropped by the staleness arm and -Infinity by the future
+ // arm, so swapping `!Number.isFinite` for `Number.isNaN` is an EQUIVALENT mutation. NaN is the
+ // one value both comparisons are false for, which is what the previous test pins.
+ noteSent('a', 'b', T0)
+ expect(wait(checkPairRate('a', 'b', Number.POSITIVE_INFINITY))).toBeNull()
+ expect(flowStats()).toEqual({ pairs: 0, senders: 0 })
+ noteSent('a', 'b', T0)
+ expect(wait(checkPairRate('a', 'b', Number.NEGATIVE_INFINITY))).toBeNull()
+ expect(flowStats()).toEqual({ pairs: 0, senders: 0 })
+ })
+
it('resetMessageFlow really empties both maps', () => {
noteSent('a', 'b', T0)
resetMessageFlow()
diff --git a/src/core/agents/agent-message-flow.ts b/src/core/agents/agent-message-flow.ts
index 402194b3e..ca5744755 100644
--- a/src/core/agents/agent-message-flow.ts
+++ b/src/core/agents/agent-message-flow.ts
@@ -39,8 +39,10 @@ import type { AgentMessageOutcome } from './agent-message-decide'
* refuses every future delivery with a number nobody can wait out. That is the failure mode this
* module refuses to have, so every path that could produce it fails OPEN: entries are evicted on
* read (`sweep`), a clock that jumps BACKWARDS drops the entry instead of parking it in the
- * future, and a fan-out budget whose reset signal never arrives expires on its own after
- * `TURN_STALE_MS`.
+ * future, a NON-FINITE clock reading drops everything (every comparison is false for `NaN`, which
+ * would otherwise make an entry immortal — and would silence the fan-out budget while the pair
+ * budget failed open, the worst of both), and a fan-out budget whose reset signal never arrives
+ * expires on its own after `TURN_STALE_MS`.
*
* Nothing here reads the clock, the filesystem or a socket; `now` is injected exactly as it is in
* `decideDelivery`, so the whole thing is testable without fake timers.
@@ -76,6 +78,13 @@ export const TURN_STALE_MS = 5 * 60_000
* existing — and something enormous would tell a caller to abandon a budget that clears the moment
* its turn ends. The per-pair interval is the honest lower bound: nothing this sender does can land
* sooner than that anyway.
+ *
+ * KNOWN COST, stated so it is not a surprise: in the degenerate case where `noteNewTurn` never
+ * arrives, a caller that obeys this floor exactly spends `TURN_STALE_MS / FANOUT_RETRY_AFTER_MS`
+ * = 30 refused attempts before the staleness backstop opens the budget. Those 30 are cheap for the
+ * host (pre-probe, no pane, no ssh) and expensive for the caller (30 tool calls). The alternative —
+ * reporting the true wait — is not available: the number does not exist while the reset is a turn
+ * boundary rather than a clock event.
*/
export const FANOUT_RETRY_AFTER_MS = PAIR_MIN_INTERVAL_MS
@@ -96,6 +105,20 @@ export type FlowCheck = { ok: true } | { ok: false; limit: FlowLimit; outcome: R
* A raw NUL in a source file makes git, grep and ripgrep skip the ENTIRE file in silence. This
* repo has been bitten twice (commit 4c0e8c3); the plan this task comes from was written with a raw
* one and was itself invisible to grep until it was caught.
+ *
+ * -- THE KEY IS INJECTIVE ONLY OVER IDS THAT PASS `isSafeNodeId`, AND THAT IS A PRECONDITION ------
+ *
+ * An id that CONTAINS the separator collides two different conversations: with S for the separator,
+ * `pairKey('x'+S+'y', 'z')` and `pairKey('x', 'y'+S+'z')` are the same string, and the second
+ * conversation is then throttled by the first. `isSafeNodeId` (`[A-Za-z0-9._-]`, so no NUL, no
+ * space, no slash) is what makes the premise true, and `resolveDeliveryScope` enforces it at the
+ * AUTHORIZATION BOUNDARY rather than here: a limiter is the wrong place to decide whether an id is
+ * addressable at all, and enforcing it in two places would leave one of them untested in practice.
+ *
+ * A DIRECT caller of this module that has not gone through `resolveDeliveryScope` — PR 5's verbs,
+ * PR 7's queue — must validate first. Nothing in the type system says so, which is why the test
+ * asserts the collision EXISTS and asserts the validator refuses exactly the ids that cause it: a
+ * precondition pinned by execution instead of by this paragraph.
*/
export function pairKey(src: string, dst: string): string {
return `${src}\u0000${dst}`
@@ -159,8 +182,28 @@ const senderTurns = new Map<string, TurnBudget>()
* step was large — an agent silenced for an hour by a time correction, with no way to wait it out.
* Dropping it over-sends by at most one message per pair. That is the direction this module always
* takes.
+ *
+ * A NON-FINITE `now` gets the same treatment, and it is not a hypothetical tidy-up: EVERY comparison
+ * below is false for `NaN`, so without this line an entry becomes immortal — and the two budgets
+ * then fail in OPPOSITE directions, which is the worst of both. The pair limiter fails open by
+ * accident (its `retryAfterMs` is `NaN`, and `decidePreProbe` refuses on `retryAfterMs > 0`, which
+ * `NaN` is not), while a fan-out budget already at the cap returns a real `FANOUT_RETRY_AFTER_MS`
+ * forever — a permanently silent sender that only a `newTurn` can rescue, which is exactly the
+ * failure this module claims not to have. Unreachable while `now` is `Date.now()`; the guard costs
+ * one comparison and makes the claim true instead of true-by-luck.
+ *
+ * NaN is the only value this line is load-bearing for, and the test says so: `+Infinity` is already
+ * dropped by the staleness arm and `-Infinity` by the future arm below. It is written as
+ * `!Number.isFinite` rather than `Number.isNaN` because that is the intent — a clock reading that
+ * is not a position on the number line — and because a mutation swapping the two is EQUIVALENT
+ * rather than a defect the sweep would let through.
*/
function sweep(now: number): void {
+ if (!Number.isFinite(now)) {
+ pairLastSentAt.clear()
+ senderTurns.clear()
+ return
+ }
for (const [key, at] of pairLastSentAt)
if (at > now || now - at >= PAIR_MIN_INTERVAL_MS) pairLastSentAt.delete(key)
for (const [id, b] of senderTurns)
diff --git a/src/core/agents/agent-message-scope.test.ts b/src/core/agents/agent-message-scope.test.ts
index 1db4237fc..44bb5e54a 100644
--- a/src/core/agents/agent-message-scope.test.ts
+++ b/src/core/agents/agent-message-scope.test.ts
@@ -93,7 +93,9 @@ describe('resolveDeliveryScope', () => {
it('resolves a DUPLICATE node id to the sender’s own project', () => {
// A cloned `project.json` gives two projects the same node id — this repo has shipped that bug
- // once. The sender addresses the node it can see, and the ambiguity never reaches a pane.
+ // once. The sender addresses the node it can see. This is a ROUTING answer only: sessions are
+ // keyed by the bare node id, so the two ids still name one pane, and no resolver can change
+ // that from here.
const cloned: ScopeProject[] = [
{ id: 'p-alpha', nodes: [{ id: 'a-1' }, { id: 'dup' }] },
{ id: 'p-clone', nodes: [{ id: 'c-1' }, { id: 'dup' }] }
@@ -124,6 +126,75 @@ describe('resolveDeliveryScope', () => {
})
})
+describe('an id the app could never have made is refused before anything else', () => {
+ // Node ids come off `.nodeterm/project.json` and the load path validates nothing, so this is the
+ // only place on the messaging path that asks. Two things break without it: the pair limiter's
+ // key stops being injective (its separator is a NUL), and tmux session names FOLD, because
+ // `sessionName()` sanitises rather than refuses — declared `v/1` and `v_1` are one session.
+ const SEP = String.fromCharCode(0)
+ const unsafe = ['a 1', `a${SEP}1`, 'v/1', '../etc', '..', '', 'a$1', 'x'.repeat(129)]
+
+ it.each(unsafe)('refuses %j as a TARGET', (id) => {
+ const scope = resolveDeliveryScope([{ id: 'p', nodes: [{ id: 'a-1' }, { id }] }], 'a-1', id)
+ expect(scope).toEqual({ kind: 'refused', reason: 'unaddressable-node-id', targetFound: true })
+ })
+
+ it.each(unsafe)('refuses %j as a SOURCE', (id) => {
+ const scope = resolveDeliveryScope([{ id: 'p', nodes: [{ id }, { id: 'a-1' }] }], id, 'a-1')
+ expect(scope.kind).toBe('refused')
+ expect((scope as { reason: string }).reason).toBe('unaddressable-node-id')
+ })
+
+ it('refuses it even when BOTH nodes are listed in the same project — this is not a scope failure', () => {
+ // Which is exactly why the word is its own: such an id can be sitting in the sender's own
+ // project file, so calling it `cross-project` would be a false statement about the reason.
+ const both = [{ id: 'p', nodes: [{ id: 'a 1' }, { id: 'a 2' }] }]
+ expect(resolveDeliveryScope(both, 'a 1', 'a 2').kind).toBe('refused')
+ expect(resolveDeliveryScope(both, 'a-1', 'a-2')).toEqual({
+ kind: 'refused',
+ reason: 'cross-project',
+ targetFound: false
+ })
+ })
+
+ it('is decided BEFORE the self-send arm — an unaddressable id is not a self-send', () => {
+ // Both refusals are terminal, so this is about the WORD: "that is not a node id" and "you may
+ // not message yourself" need different actions from whoever reads it.
+ expect(resolveDeliveryScope([{ id: 'p', nodes: [{ id: 'a 1' }] }], 'a 1', 'a 1')).toEqual({
+ kind: 'refused',
+ reason: 'unaddressable-node-id',
+ targetFound: true
+ })
+ })
+
+ it('the two ids that would FOLD to one tmux session are both refused', () => {
+ const folding = [{ id: 'p', nodes: [{ id: 'v/1' }, { id: 'v_1' }] }]
+ // `v_1` is a legal id; `v/1` is the one that sanitises onto it, and it never gets that far.
+ expect(resolveDeliveryScope(folding, 'v_1', 'v/1')).toEqual({
+ kind: 'refused',
+ reason: 'unaddressable-node-id',
+ targetFound: true
+ })
+ })
+
+ it('the ids the app actually emits are all still admitted', () => {
+ // The check must not cost a legitimate population: `nextId()` emits `<prefix>-<base36>-<n>`
+ // and `uuid()` hex-with-dashes.
+ const real = ['term-mabc-3', 'claude-mb1x2y-11', '3f9a1c22-7b0e-4a11-9f00-0c1d2e3f4a5b', 'a.b_c-1']
+ for (const id of real) {
+ const scope = resolveDeliveryScope([{ id: 'p', nodes: [{ id: 'src-1' }, { id }] }], 'src-1', id)
+ expect(scope, id).toEqual({ kind: 'same-project', projectId: 'p' })
+ }
+ })
+
+ it('carries through decideDelivery as its own notPermitted reason, and is terminal', () => {
+ const scope = resolveDeliveryScope([{ id: 'p', nodes: [{ id: 'a-1' }] }], 'a-1', 'a 2')
+ const outcome = decideDelivery(facts({ notPermitted: scopeRefusal(scope) }))
+ expect(outcome).toEqual({ kind: 'notPermitted', reason: 'unaddressable-node-id' })
+ expect(RETRYABLE.notPermitted).toBe(false)
+ })
+})
+
describe('scopeRefusal feeds decideDelivery, and the refusal is terminal', () => {
it('a cross-project target is notPermitted{cross-project} and is NOT retryable', () => {
const scope = resolveDeliveryScope(projects, 'a-1', 'b-1')
diff --git a/src/core/agents/agent-message-scope.ts b/src/core/agents/agent-message-scope.ts
index 416dafd0a..984ebe041 100644
--- a/src/core/agents/agent-message-scope.ts
+++ b/src/core/agents/agent-message-scope.ts
@@ -1,3 +1,4 @@
+import { isSafeNodeId } from '../remote-safety'
import type { NotPermittedReason } from './agent-message-decide'
/**
@@ -15,12 +16,17 @@ import type { NotPermittedReason } from './agent-message-decide'
* exists to fix on the source side, where it surfaced as a lost capability rather than as the wrong
* canvas answering.
*
- * The fix is NOT to travel to the target's project. `send` is declared outside `needsLiveCanvas`
- * precisely so it never can: travelling would yank the human's view to another tab on a background
- * agent's say-so, and `setActive` on the way would clear that node's unread badge — a delivery
- * silently erasing the signal a human relies on (G5). So this resolver takes the projects store and
- * NOTHING else. There is no parameter for a live node list, which is a guarantee a test can check
- * by running it: a node the live canvas has but the store has not is refused, not admitted.
+ * Nor is the fix to travel to the target's project, and THIS resolver is what makes that
+ * impossible: it takes the projects store and NOTHING else. There is no parameter for a live node
+ * list, so there is nothing to travel toward — a guarantee a test can check by running it, since a
+ * node the live canvas has but the store has not is refused rather than admitted.
+ *
+ * `needsLiveCanvas` is a different guarantee and must not be confused with this one: Canvas routes
+ * by SOURCE (`routeControlSource(projects, activeId, sourceNodeId)`), so declaring `send`/`reply`
+ * store-answered stops a travel to the SENDER's project — the one an off-canvas orchestrator would
+ * otherwise trigger on every message it sent. Both matter, for different halves of the pair, and
+ * either alone would leave a way for a background agent to yank the human's view and clear an
+ * unread badge on the way (G5).
*
* ── THREE SURFACES ──────────────────────────────────────────────────────────────────────────────
*
@@ -34,21 +40,27 @@ import type { NotPermittedReason } from './agent-message-decide'
* ── WHICH WAY IT FAILS ──────────────────────────────────────────────────────────────────────────
*
* CLOSED, because the thing being authorised is a write into someone else's terminal. Anything this
- * cannot positively resolve to a single shared project is refused: a source that belongs to no
- * project the store knows, a target that resolves nowhere, a target in a project the store has but
- * the sender does not share. `notPermitted` is not retryable, so a refusal here is terminal — which
- * is correct for a boundary and would be wrong for a timing problem, and none of these are timing
- * problems.
+ * cannot positively resolve to a single shared project is refused: an id outside `isSafeNodeId`, a
+ * source that belongs to no project the store knows, a target that resolves nowhere, a target in a
+ * project the store has but the sender does not share. `notPermitted` is not retryable, so a
+ * refusal here is terminal — which is correct for a boundary and would be wrong for a timing
+ * problem, and none of these are timing problems.
*/
/** The little this needs from a project — a structural subset of both `Project` and the store's
- * serialized `ProjectFileV1`, so either can be passed without adaptation. */
+ * serialized `ProjectFileV1`, so either can be passed without adaptation.
+ *
+ * `nodes` is required rather than optional on purpose, and the caller owns that: a synthesised
+ * array with `nodes` absent throws here instead of failing closed. Every real `Project` has it. */
export interface ScopeProject {
id: string
nodes: readonly { id: string }[]
}
-export type ScopeRefusal = Extract<NotPermittedReason, 'self-send' | 'cross-project'>
+export type ScopeRefusal = Extract<
+ NotPermittedReason,
+ 'self-send' | 'cross-project' | 'unaddressable-node-id'
+>
export type DeliveryScope =
| { kind: 'same-project'; projectId: string }
@@ -64,18 +76,49 @@ export type DeliveryScope =
/**
* Resolve a (source, target) pair to the project they share, or to the refusal that stops it.
*
- * `self-send` is checked first and is the same rule, in the same words, that the manual
- * `onConnect` already applies to a canvas edge — a node may not be wired to itself. It is decided
- * before project membership because it is true regardless of where either id lives, including when
- * neither lives anywhere.
+ * ── THE ID ITSELF IS CHECKED FIRST, AND NOTHING ELSE ON THIS PATH DOES IT ───────────────────────
+ *
+ * Node ids come out of `.nodeterm/project.json` and `fileToProject` validates NOTHING — the repo
+ * says so at `node-identity-policy.ts:128` and `hook-server.ts:282`. `isSafeNodeId` exists and is
+ * applied at `PtyManager.create()`, which is not the load path this resolver reads. Two concrete
+ * consequences, and both are why the check is here rather than deeper:
+ *
+ * - **The pair limiter's key stops being injective.** Its separator is a NUL, so an id CONTAINING
+ * one collides two different conversations and each throttles the other (`agent-message-flow.ts`
+ * spells out the shape). `isSafeNodeId`'s charset — `[A-Za-z0-9._-]` — is exactly what makes
+ * that impossible.
+ * - **tmux session names FOLD.** `sessionName()` sanitises rather than refuses, so declared ids
+ * `v/1` and `v_1` name ONE session. An id that cannot be sanitised into a different node's
+ * session is the only kind worth admitting.
+ *
+ * Refused as `unaddressable-node-id`, not as `cross-project`: such an id may be listed in the
+ * sender's own project, so the scope word would be a false statement about why it was refused.
+ *
+ * `self-send` is the same rule, in the same words, that the manual `onConnect` already applies to a
+ * canvas edge — a node may not be wired to itself. It is decided before project membership because
+ * it is true regardless of where either id lives, including when neither lives anywhere.
*
* Note that this is the OUTER guard, not the only one: `decidePreProbe` carries its own self-send
* backstop so that no future caller can forget this one. Both produce the identical
* `notPermitted{reason:'self-send'}`, which the test asserts by running them.
*
- * A duplicate node id across two projects (a cloned `project.json` — this repo has shipped that
- * bug once) resolves to the SOURCE's project when the source's project is one of them: the sender
- * addresses the node it can see, and the ambiguity never reaches the pane.
+ * ── A DUPLICATE NODE ID IS RESOLVED, NOT DISAMBIGUATED ──────────────────────────────────────────
+ *
+ * A duplicate id across two projects (a cloned `project.json` — this repo has shipped that bug
+ * once) resolves to the SOURCE's project when the source's project is one of them: the sender
+ * addresses the node it can see.
+ *
+ * That is a routing answer, NOT an isolation guarantee, and the earlier claim here that "the
+ * ambiguity never reaches the pane" was false. A session's only key is the bare node id
+ * (`PtyManager.byPersistKey`, `paneOwner(persistKey)`, tmux `nt-<nodeId>`); no project id appears
+ * anywhere in that namespace and nothing de-duplicates ids when a second project carrying them is
+ * opened. So a `project.json` that merely LISTS another project's node id resolves `same-project`
+ * here and lands in that node's one global pane — verified by execution, not reasoned about.
+ *
+ * This resolver cannot close that: the ambiguity is in the session namespace, not in the scope
+ * question. What it can do is refuse the ids that make it worse, which is the check above.
+ * **PR 5's delivery call must run `isSafeNodeId(targetNodeId)` before `paneOwner`** — a direct
+ * caller that skips this resolver gets neither guard.
*
* `closed` and `unavailable` projects are deliberately NOT filtered out. A closed project's tmux
* sessions keep running and are re-adopted on the next start — that is the whole premise of
@@ -89,6 +132,8 @@ export function resolveDeliveryScope(
): DeliveryScope {
const has = (p: ScopeProject, id: string): boolean => p.nodes.some((n) => n.id === id)
const targetFound = projects.some((p) => has(p, targetNodeId))
+ if (!isSafeNodeId(sourceNodeId) || !isSafeNodeId(targetNodeId))
+ return { kind: 'refused', reason: 'unaddressable-node-id', targetFound }
if (sourceNodeId === targetNodeId) return { kind: 'refused', reason: 'self-send', targetFound }
const owner = projects.find((p) => has(p, sourceNodeId))
if (owner && has(owner, targetNodeId)) return { kind: 'same-project', projectId: owner.id }
diff --git a/src/renderer/lib/controlRouting.test.ts b/src/renderer/lib/controlRouting.test.ts
index 105024598..e08eea95e 100644
--- a/src/renderer/lib/controlRouting.test.ts
+++ b/src/renderer/lib/controlRouting.test.ts
@@ -74,9 +74,10 @@ describe('needsLiveCanvas', () => {
})
it('is false for send and reply — a delivery must never travel the camera', () => {
- // Travelling to the target's project would hijack the human's view on a background agent's
- // say-so, and the `setActive` on the way would clear that node's unread badge — a message
- // silently erasing the signal a human relies on. A delivery goes to a pane; it needs no canvas.
+ // Routing here is by SOURCE, so what this stops is a trip to the SENDER's project — which an
+ // off-canvas orchestrator would otherwise trigger on every message it sent, hijacking the
+ // human's view and clearing an unread badge via `setActive` on the way (G5). Never travelling
+ // to the TARGET's project is a different guarantee, and it belongs to `resolveDeliveryScope`.
expect(needsLiveCanvas('send')).toBe(false)
expect(needsLiveCanvas('reply')).toBe(false)
})
diff --git a/src/renderer/lib/controlRouting.ts b/src/renderer/lib/controlRouting.ts
index e0388b598..08718de41 100644
--- a/src/renderer/lib/controlRouting.ts
+++ b/src/renderer/lib/controlRouting.ts
@@ -72,12 +72,17 @@ export function routeControlSource(
* keeps a background agent's polling from yanking the user's view to another project tab on every
* call.
*
- * `send`/`reply` are here for a stronger reason than politeness. A delivery goes to a tmux PANE,
- * not to a canvas, so travelling to the target's project buys nothing — and it costs twice: it
- * hijacks the human's view on a background agent's say-so, and the `setActive` on the way clears
- * that node's unread badge, so a message silently erases the signal a human relies on. The target
- * is therefore resolved off the store (`resolveDeliveryScope`), which is also the only source of
- * truth that can see nodes outside the active tab at all.
+ * `send`/`reply` are here for a stronger reason than politeness, and it is worth being precise
+ * about WHICH travel this prevents: routing here is by SOURCE
+ * (`routeControlSource(projects, activeId, sourceNodeId)`), so what the declaration stops is a trip
+ * to the SENDER's project — which an off-canvas orchestrator would otherwise trigger on every
+ * message it sent, hijacking the human's view on a background agent's say-so and clearing that
+ * node's unread badge via `setActive` on the way (G5). A delivery goes to a tmux PANE, not to a
+ * canvas, so it needs no live canvas at either end.
+ *
+ * The other half — never travelling to the TARGET's project — is not this function's doing. It
+ * comes from `resolveDeliveryScope` (`src/core/agents/agent-message-scope.ts`) taking the
+ * serialized store and having no live-node parameter at all, so there is nothing to travel toward.
*
* INERT AS OF THIS COMMIT: neither verb is in `ControlVerb` yet, so `parseControlRequest` refuses
* both before any of this is reached (asserted by running it, in `canvas-control-core.test.ts`).