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(relay): a joined tab records the host's agent status in its own session store
review121411c36273
diff --git a/src/renderer/session/relay-agent-status.test.ts b/src/renderer/session/relay-agent-status.test.tsnew file mode 100644index 000000000..05973a633--- /dev/null+++ b/src/renderer/session/relay-agent-status.test.ts@@ -0,0 +1,236 @@+// A relay session's own agent-status subscription (bug D), run against REAL stores: a fresh keyless+// agent-status session per test, fed through a fake api whose `onAgentStatus` keeps the listener so+// the test can fire the host's events at it.+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import type { NormalizedAgentEvent } from '@shared/agents/normalize'+import type { NodeTerminalApi } from '@shared/types'+import { createAgentStatusSession, STALE_WORKING_MS, type AgentNodeStatus } from '../state/agentStatus'+import { applyAgentEvent } from '../state/applyAgentEvent'+import { useAgentNodes } from '../state/agentNodes'+import { playSfx } from '../lib/sfx'+import { wireRelayAgentStatus } from './relay-agent-status'++// The chime is an interrupt the relay path must never raise. The wiring does not import it; the+// spy makes a future import that plays it fail here.+vi.mock('../lib/sfx', () => ({ playSfx: vi.fn() }))++const N = 'term-node-a'++const ev = (over: Partial<NormalizedAgentEvent> = {}): NormalizedAgentEvent => ({+ nodeId: N,+ agentId: 'claude',+ kind: 'state',+ ...over+})++const working = ev({ state: 'working', newTurn: true, task: 'hello', sessionId: 's1' })+const doneEvent = ev({ state: 'done', lastMessage: 'all green' })++/** A relay api whose only member is `onAgentStatus`: it keeps the listener and hands back a spy. */+function fakeApi() {+ let cb: ((e: NormalizedAgentEvent) => void) | null = null+ const unsub = vi.fn()+ const api: Pick<NodeTerminalApi, 'onAgentStatus'> = {+ onAgentStatus: vi.fn((listener: (e: NormalizedAgentEvent) => void) => {+ cb = listener+ return unsub+ })+ }+ const fire = (e: NormalizedAgentEvent): void => {+ if (!cb) throw new Error('nothing subscribed')+ cb(e)+ }+ return { api, unsub, fire }+}++let status: ReturnType<typeof createAgentStatusSession>+const entry = (id = N) => status.store.getState().byId[id]++beforeEach(() => {+ status = createAgentStatusSession(undefined)+})++afterEach(() => {+ vi.useRealTimers()+ vi.unstubAllGlobals()+ vi.clearAllMocks()+})++describe('wireRelayAgentStatus', () => {+ it('an event lands in the session store through applyAgentEvent', () => {+ const { api, fire } = fakeApi()+ const stop = wireRelayAgentStatus(api, status, { hasFocus: () => false })+ expect(api.onAgentStatus).toHaveBeenCalledTimes(1)+ fire(working)+ expect(entry()?.state).toBe('working')+ expect(entry()?.agentId).toBe('claude')+ expect(entry()?.sessionId).toBe('s1')+ // The account the hook names is another machine's (the host's), so it is recorded as remote.+ fire(ev({ state: 'working', account: { configDir: '/home/u/.claude', accountId: null, known: false } }))+ expect(entry()?.account?.remote).toBe(true)+ stop()+ })++ it('a finish marks unread when the window is not focused on that node', () => {+ const { api, fire } = fakeApi()+ const stop = wireRelayAgentStatus(api, status, { hasFocus: () => false })+ // Active in this store, but the window has no focus: still unread (Canvas's `watching` rule).+ status.store.getState().setActive(N, true)+ fire(working)+ fire(doneEvent)+ const unread = entry()?.unread+ expect(entry()?.state).toBe('done')+ expect(unread).toBe(true)+ // Focused, but on ANOTHER node: a needs-input on this one is unread too.+ const focused = createAgentStatusSession(undefined)+ const other = fakeApi()+ const stopOther = wireRelayAgentStatus(other.api, focused, { hasFocus: () => true })+ focused.store.getState().setActive('term-node-b', true)+ other.fire(ev({ state: 'blocked', pendingId: 'p-1' }))+ expect(focused.store.getState().byId[N]?.unread).toBe(true)+ stop()+ stopOther()+ })++ it('a finish on the focused active node stays read', () => {+ const { api, fire } = fakeApi()+ const stop = wireRelayAgentStatus(api, status, { hasFocus: () => true })+ status.store.getState().setActive(N, true)+ fire(working)+ fire(doneEvent)+ expect(entry()?.state).toBe('done')+ expect(entry()?.unread).toBe(false)+ stop()+ })++ it('never acks, sounds or notifies', () => {+ const ackSpy = vi.fn()+ const local = { ackDone: vi.fn(), notify: vi.fn() }+ vi.stubGlobal('window', { nodeTerminal: local })+ status = createAgentStatusSession(undefined, ackSpy)+ const { api, fire } = fakeApi()+ // Focused on the node: the branch where Canvas acks a watched finish.+ const stop = wireRelayAgentStatus(api, status, { hasFocus: () => true })+ status.store.getState().setActive(N, true)+ fire(working)+ fire(ev({ state: 'blocked', pendingId: 'p-1' }))+ fire(ev({ state: 'working' }))+ fire(doneEvent)+ // And unfocused: the branch where Canvas chimes and notifies.+ status.store.getState().setActive(N, false)+ fire(ev({ state: 'working', newTurn: true }))+ fire(doneEvent)+ expect(entry()?.unread).toBe(true)+ expect(ackSpy).not.toHaveBeenCalled()+ expect(local.ackDone).not.toHaveBeenCalled()+ expect(local.notify).not.toHaveBeenCalled()+ expect(playSfx).not.toHaveBeenCalled()+ // Reading it is the store's own business: the wiring adds no ack of its own and nothing reaches+ // the local api. (The store's ack callback itself is what agentStatusForApi leaves out for a+ // relay api — see agentStatus-session.test.ts.)+ status.store.getState().clearUnread(N)+ expect(entry()?.unread).toBe(false)+ expect(ackSpy).toHaveBeenCalledTimes(1) // the store's own, from clearUnread — none from the wiring+ expect(local.ackDone).not.toHaveBeenCalled()+ expect(local.notify).not.toHaveBeenCalled()+ stop()+ })++ it('teardown unsubscribes, clears the store, and ignores late events', () => {+ const { api, unsub, fire } = fakeApi()+ const stop = wireRelayAgentStatus(api, status, { hasFocus: () => false })+ status.store.getState().setActive(N, true)+ fire(working)+ fire(doneEvent)+ expect(entry()?.unread).toBe(true)+ stop()+ expect(unsub).toHaveBeenCalledTimes(1)+ expect(status.store.getState().byId).toEqual({})+ expect(status.store.getState().activeId).toBeNull()+ // A late frame (the RpcClient delivered it after the drop) writes nothing.+ fire(doneEvent)+ expect(status.store.getState().byId).toEqual({})+ // A second teardown is a no-op.+ stop()+ expect(unsub).toHaveBeenCalledTimes(1)+ })++ it('the stale-working sweep runs on the session store', () => {+ vi.useFakeTimers()+ vi.setSystemTime(new Date('2026-11-01T10:00:00Z'))+ const { api, fire } = fakeApi()+ const stop = wireRelayAgentStatus(api, status, { hasFocus: () => false, sweepMs: 1000 })+ fire(working)+ vi.setSystemTime(Date.now() + STALE_WORKING_MS + 1)+ // Nothing has swept yet: the decay below is the interval's.+ expect(entry()?.state).toBe('working')+ vi.advanceTimersByTime(1000)+ expect(entry()?.state).toBeUndefined()+ stop()+ // The interval is released with the subscription.+ expect(vi.getTimerCount()).toBe(0)+ })++ it('the same events yield the same state as the Canvas path', () => {+ vi.useFakeTimers()+ vi.setSystemTime(new Date('2026-11-01T10:00:00Z'))+ useAgentNodes.setState({+ byId: {},+ activityById: {},+ lastActivityAt: {},+ positions: {},+ sizes: {},+ expanded: {},+ selectedId: null,+ autoHideFinished: false+ })+ const account = { configDir: '/home/u/.claude', accountId: null, known: false }+ const events: NormalizedAgentEvent[] = [+ ev({ state: 'working', newTurn: true, task: 'hello', sessionId: 's1', account }), // prompt+ ev({ state: 'working', sessionId: 's1' }), // tool+ ev({ state: 'blocked', pendingId: 'p-1', sessionId: 's1' }), // permission request+ ev({ state: 'working', sessionId: 's1' }), // approved, the turn resumes+ ev({ state: 'done', lastMessage: 'first turn done', sessionId: 's1' }),+ ev({ state: 'working', newTurn: true, task: '/loop 5m check the build', sessionId: 's1' }),+ ev({ state: 'done', lastMessage: 'build green', sessionId: 's1' }),+ ev({ kind: 'session', sessionPhase: 'end', sessionId: 's1' })+ ]+ // A: the Canvas listener's writes on an unfocused window — the reducer against the default-shaped+ // stores, then `markUnread` whenever it answered an alert (its `!watching` branch).+ const a = createAgentStatusSession(undefined)+ // B: the relay wiring, same window.+ const b = createAgentStatusSession(undefined)+ const { api, fire } = fakeApi()+ const stop = wireRelayAgentStatus(api, b, { hasFocus: () => false })+ for (const e of events) {+ const r = applyAgentEvent(a.store, useAgentNodes, e, { observationRemote: false })+ if (r.alert) a.store.getState().markUnread(r.nodeId)+ fire(e)+ vi.setSystemTime(Date.now() + 1000)+ }+ const A = a.store.getState()+ const B = b.store.getState()+ // The one designed difference: the relay records every observed account as another machine's.+ expect(A.byId[N]?.account?.remote).toBe(false)+ expect(B.byId[N]?.account?.remote).toBe(true)+ expect(stripAccountRemote(B.byId)).toEqual(stripAccountRemote(A.byId))+ // The sequence exercised what it claims to: a recorded unread, a loop, and the session end.+ expect(B.byId[N]?.unread).toBe(true)+ expect(B.byId[N]?.sessionEnded).toBe(true)+ stop()+ })+})++/** The byId table with only `account.remote` removed — everything else must match exactly. */+function stripAccountRemote(byId: Record<string, AgentNodeStatus>): Record<string, AgentNodeStatus> {+ const out: Record<string, AgentNodeStatus> = {}+ for (const [id, v] of Object.entries(byId)) {+ if (!v.account) {+ out[id] = v+ continue+ }+ const { remote: _remote, ...account } = v.account+ out[id] = { ...v, account }+ }+ return out+}diff --git a/src/renderer/session/relay-agent-status.ts b/src/renderer/session/relay-agent-status.tsnew file mode 100644index 000000000..c9e93030f--- /dev/null+++ b/src/renderer/session/relay-agent-status.ts@@ -0,0 +1,65 @@+// wireRelayAgentStatus — a relay session's own subscription to its host's agent status (bug D).+//+// A team tab (a desktop joined to a Server Edition team, or a Team Access relay tab) never showed+// RUNNING / NEEDS YOU / unread: the only `agent:status` subscriber was Canvas's listener on the LOCAL+// api, writing the DEFAULT store. Each relay session now subscribes ITS OWN api's `onAgentStatus`+// for the session's lifetime and feeds the same reducer Canvas uses (`applyAgentEvent`) into the+// session's own keyless store (`getSessionStores(id).agentStatus`). Routing is by api, never by a+// project lookup: two relay sessions may serve the same project id.+//+// What the relay path deliberately does NOT do, compared with Canvas's listener:+// • no ack — reading a remote session's finish clears unread on this desktop only; nothing is sent+// back to the host (no `ackDone`, no `agent:unread-clear` subscription);+// • no sound and no OS notification — the badge and the unread dot are the whole signal;+// • no subagent cards (`nodes = null`) and no `onSubagentActivity` subscription.+// What it keeps: the unread mark for BOTH alert kinds unless this window is focused on that node+// (Canvas's `watching` rule), and the 60 s stale-working sweep, run on this session's store.++import type { NodeTerminalApi } from '@shared/types'+import type { AgentStatusSession } from '../state/agentStatus'+import { applyAgentEvent } from '../state/applyAgentEvent'++/** The Canvas sweep interval for the default store's stale-working decay. */+const SWEEP_MS = 60_000++export interface RelayAgentStatusDeps {+ /** Whether this window has focus. Default: `document.hasFocus()` (false without a document). */+ hasFocus?: () => boolean+ /** How often the stale-working sweep runs. Default 60 s, the Canvas interval. */+ sweepMs?: number+}++/** Subscribe `api.onAgentStatus` into `status` until the returned teardown runs. */+export function wireRelayAgentStatus(+ api: Pick<NodeTerminalApi, 'onAgentStatus'>,+ status: AgentStatusSession,+ deps: RelayAgentStatusDeps = {}+): () => void {+ const hasFocus = deps.hasFocus ?? (() => typeof document !== 'undefined' && document.hasFocus())+ const store = status.store+ // Set by the teardown. A frame the RpcClient delivers after the session went offline or was+ // disposed must write nothing, and neither may a sweep tick that was already queued.+ let disposed = false++ const unsubscribe = api.onAgentStatus((e) => {+ if (disposed) return+ const { nodeId, alert } = applyAgentEvent(store, null, e, { observationRemote: true })+ if (!alert) return+ // Canvas's `watching` gate: unread unless the user is actively in this node's terminal.+ const watching = hasFocus() && store.getState().activeId === nodeId+ if (!watching) store.getState().markUnread(nodeId)+ })++ const sweep = setInterval(() => {+ if (!disposed) store.getState().sweepStaleWorking()+ }, deps.sweepMs ?? SWEEP_MS)++ return () => {+ if (disposed) return+ disposed = true+ unsubscribe()+ clearInterval(sweep)+ // An offline or disposed tab reads unknown: its status described a host it no longer hears.+ store.setState({ byId: {}, activeId: null })+ }+}diff --git a/src/renderer/session/relay-tab.test.ts b/src/renderer/session/relay-tab.test.tsindex 99b754d88..522ff81bd 100644--- a/src/renderer/session/relay-tab.test.ts+++ b/src/renderer/session/relay-tab.test.ts@@ -46,10 +46,13 @@ function fakeRelayClient() {/** A bridged relay api whose `pty.create` is a spy — this is what `LocalTransport(api)` must hit.* `presenceUnsub` is what the session's held presence teardown calls (onSync's unsubscribe), so a- * drop that "runs the presence teardown" is observable in node env. */+ * drop that "runs the presence teardown" is observable in node env. `agentStatusUnsub` is the same+ * for the session's agent-status subscription (`onAgentStatus`). */function fakeBridgedApi(ws: Workspace = { version: 2, activeProjectId: '', projects: [] }) {const ptyCreate = vi.fn().mockResolvedValue({ sessionId: 's1', fresh: false })const presenceUnsub = vi.fn()+ const agentStatusUnsub = vi.fn()+ const onAgentStatus = vi.fn(() => agentStatusUnsub)const workspaceLoad = vi.fn().mockResolvedValue(ws)const api = {marker: 'relay-bridged',@@ -60,8 +63,9 @@ function fakeBridgedApi(ws: Workspace = { version: 2, activeProjectId: '', projeonSync: vi.fn(() => presenceUnsub),onPeer: vi.fn(() => () => {}),},+ onAgentStatus,} as unknown as NodeTerminalApi- return { api, ptyCreate, presenceUnsub, workspaceLoad }+ return { api, ptyCreate, presenceUnsub, workspaceLoad, onAgentStatus, agentStatusUnsub }}function makeDeps(over: Partial<RelayTabDeps> & { handle: RelayApiHandle }): {@@ -125,6 +129,20 @@ describe('openRelayTab (connect → tab → mount)', () => {expect(sessionCount()).toBe(1) // only local remains})+ it("subscribes its own api's agent status before the workspace load, and a dispose releases it", async () => {+ const { api, onAgentStatus, agentStatusUnsub, workspaceLoad } = fakeBridgedApi()+ const handle: RelayApiHandle = { api, ready: () => Promise.resolve(), close: vi.fn() }+ const { deps } = makeDeps({ handle })+ const tab = await openRelayTab('conn-1', "Ayşe's Mac", deps)+ // Subscribed on the session's OWN api, before the first await after the session exists, so the+ // RpcClient's early frames reach it.+ expect(onAgentStatus).toHaveBeenCalledTimes(1)+ expect(onAgentStatus.mock.invocationCallOrder[0]).toBeLessThan(workspaceLoad.mock.invocationCallOrder[0])+ expect(agentStatusUnsub).not.toHaveBeenCalled()+ tab.dispose()+ expect(agentStatusUnsub).toHaveBeenCalledTimes(1)+ })+it('a Team Access tab whose host shared nothing is a RELAY tab: never saved, offline (never local) once disposed', async () => {// The host's workspace is empty, so openRelayTab takes the fallback: `deps.addProject(label)`,// which Canvas wires to `addRelayTab` on a first connect.@@ -309,7 +327,7 @@ describe('openRelayTab (connect → tab → mount)', () => {describe('handleRelayDrop (Stage 4 Task 7 — involuntary drop → greyed reconnectable tab)', () => {it('marks the bound project unavailable + runs the presence teardown ONCE, never removes it', async () => {- const { api, presenceUnsub } = fakeBridgedApi()+ const { api, presenceUnsub, agentStatusUnsub } = fakeBridgedApi()const close = vi.fn()const handle: RelayApiHandle = { api, ready: () => Promise.resolve(), close }const { deps } = makeDeps({ handle })@@ -322,6 +340,7 @@ describe('handleRelayDrop (Stage 4 Task 7 — involuntary drop → greyed reconn// dead socket was closed, but the PROJECT is kept and stays bound to a 'relay' source.expect(setProjectUnavailable).toHaveBeenCalledWith(tab.projectId, true)expect(presenceUnsub).toHaveBeenCalledTimes(1)+ expect(agentStatusUnsub).toHaveBeenCalledTimes(1) // an offline tab hears no more agent statusexpect(close).toHaveBeenCalledTimes(1)expect(sessionForProject(tab.projectId).source).toBe('relay') // still reconnectable in placeexpect(sessionForProject(tab.projectId).status).toBe('offline')@@ -330,6 +349,7 @@ describe('handleRelayDrop (Stage 4 Task 7 — involuntary drop → greyed reconn// Idempotent: a redundant drop (a revoke racing the FIN) re-runs no teardown.handleRelayDrop(tab, { setProjectUnavailable })expect(presenceUnsub).toHaveBeenCalledTimes(1)+ expect(agentStatusUnsub).toHaveBeenCalledTimes(1)expect(close).toHaveBeenCalledTimes(1)})})diff --git a/src/renderer/session/relay-tab.ts b/src/renderer/session/relay-tab.tsindex 5912e22b8..e7cafae48 100644--- a/src/renderer/session/relay-tab.ts+++ b/src/renderer/session/relay-tab.ts@@ -19,6 +19,7 @@ import { buildRelayApi, type RelayApiHandle } from '../bridge/relay-api'import { E_DISCONNECTED } from '../../shared/rpc'import { onLocalRelayClose } from '../bridge/relay-local-close'import { sanitizeRelayProject } from './relay-ssh'+import { wireRelayAgentStatus } from './relay-agent-status'import { closedReasonMessage, RelayApprovalError } from '../lib/hostedTeam'import { attachHostedOwner } from '../lib/hostedOwner'import { useHostedTeams, type HostedTeamInfo } from '../state/hostedTeams'@@ -131,8 +132,13 @@ export async function openRelayTab(const session = createSession('relay', handle.api, label)if (hostedInfo) useHostedTeams.getState().set(session.id, hostedInfo)// The teardowns the tab owes on disconnect (obligation 1): the presence subscription this session- // just opened, and the relay socket. Both run exactly once in disposeSession.+ // just opened, its agent-status subscription, and the relay socket. All run exactly once, in+ // disposeSession or takeSessionOffline.holdSessionTeardown(session.id, getSessionStores(session.id).presence.connect())+ // The host's agent status, into THIS session's own store (bug D) — subscribed by this session's+ // api, never through a project lookup (two sessions may serve one project id). Before any await,+ // so the RpcClient's early buffer flushes into it.+ holdSessionTeardown(session.id, wireRelayAgentStatus(handle.api, getSessionStores(session.id).agentStatus))holdSessionTeardown(session.id, () => handle.close())// Populate the tab from the host's workspace, which the relay boundary already SCOPED to the onediff --git a/src/renderer/state/agentStatus-session.test.ts b/src/renderer/state/agentStatus-session.test.tsindex 9429337f9..b81eeb8a4 100644--- a/src/renderer/state/agentStatus-session.test.ts+++ b/src/renderer/state/agentStatus-session.test.ts@@ -115,6 +115,30 @@ describe('agentStatusForApi — one store per core, keyed by api identity', () =expect(localStorage.getItem('nodeterm.agentStatus')).toBeNull()})+ it('a non-local api never acks a read: clearUnread after done calls no api.ackDone', async () => {+ const { agentStatusForApi } = await import('./agentStatus')+ const ackDone = vi.fn()+ const api = { marker: 'relay', ackDone } as unknown as NodeTerminalApi+ const { store } = agentStatusForApi(api)+ store.getState().setState('nt-x', 'done', 'claude')+ store.getState().markUnread('nt-x')+ store.getState().clearUnread('nt-x')+ // Read on this desktop only (product decision 1): nothing goes back to that core.+ expect(store.getState().byId['nt-x']?.unread).toBe(false)+ expect(ackDone).not.toHaveBeenCalled()+ })++ it('the default instance still acks a read to the local api', async () => {+ const ackDone = vi.fn()+ const api = { marker: 'preload', ackDone } as unknown as NodeTerminalApi+ vi.stubGlobal('window', { nodeTerminal: api })+ const { agentStatusForApi } = await import('./agentStatus')+ const { store } = agentStatusForApi(api)+ store.getState().setState('nt-y', 'done', 'claude')+ store.getState().clearUnread('nt-y')+ expect(ackDone).toHaveBeenCalledWith('nt-y')+ })+it('window.nodeTerminal resolves to the default (persisted) instance — the WeakMap seed', async () => {const api = { marker: 'preload' } as unknown as NodeTerminalApivi.stubGlobal('window', { nodeTerminal: api })diff --git a/src/renderer/state/agentStatus.ts b/src/renderer/state/agentStatus.tsindex 09e2b2369..e7776e4f3 100644--- a/src/renderer/state/agentStatus.ts+++ b/src/renderer/state/agentStatus.ts@@ -1262,10 +1262,11 @@ const instanceByApi = new WeakMap<NodeTerminalApi, AgentStatusSession>()export function agentStatusForApi(api: NodeTerminalApi): AgentStatusSession {const existing = api ? instanceByApi.get(api) : undefinedif (existing) return existing- // Keyless — remote status is never persisted (4a) — but the done-read ack routes to THAT core's- // api (a remote/relay core acks on its own host), so reading a finished remote session dismisses- // its phone activity too. A nullish api (node-env tests) gets no ack.- const session = createAgentStatusSession(undefined, api ? (id) => api.ackDone(id) : undefined)+ // Keyless — remote status is never persisted (4a) — and with NO done-read ack: reading a remote+ // session's finish clears unread on this desktop only (product decision 1). Nothing is sent back+ // to that core (no `ackDone`, no `agent:ack-done`), so the host's own read state — its notch,+ // its paired phone's Live Activity — stays as it was.+ const session = createAgentStatusSession(undefined, undefined)if (api) instanceByApi.set(api, session)return session}diff --git a/test/acceptance/hosted-relay-agent-status.test.ts b/test/acceptance/hosted-relay-agent-status.test.tsindex 7cf57ff4e..abc57714c 100644--- a/test/acceptance/hosted-relay-agent-status.test.ts+++ b/test/acceptance/hosted-relay-agent-status.test.ts@@ -2,10 +2,10 @@* ACCEPTANCE (bug D): on a team tab, agent status reaches the tab's OWN relay session store.** A desktop joined to a Server Edition team over the E2EE relay never showed RUNNING / NEEDS YOU /- * unread on its agent nodes. The host sends `agent:status`, the joiner's relay RpcClient receives- * it, and nothing on the joiner listens: the only subscriber is Canvas's listener on the LOCAL- * `window.nodeTerminal`, which writes the DEFAULT agent-status store. The relay session's own store- * (`SessionStores.agentStatus`) is never written.+ * unread on its agent nodes. The host sent `agent:status`, the joiner's relay RpcClient received+ * it, and nothing on the joiner listened: the only subscriber was Canvas's listener on the LOCAL+ * `window.nodeTerminal`, which writes the DEFAULT agent-status store, so the relay session's own+ * store (`SessionStores.agentStatus`) was never written.** The chain, end to end, with every layer REAL except the relay carrier (an in-memory FrameTransport* that also plays the host's request handlers for the requests a hosted tab sends at open):@@ -14,8 +14,9 @@* → the hosted relay peer's sink, filtered by `wrapSinkForRole` (owner, and viewer)* → the joiner's `buildRelayApi({hosted:true})` RpcClient → `openRelayTab` session + stores*- * The tests marked `it.fails` state the intended behavior and fail until the fix lands; the- * default-store test already holds (today nothing writes) and must keep holding after it.+ * Each relay session subscribes its own api's `onAgentStatus` (`wireRelayAgentStatus`, wired in+ * `openRelayTab`) into its own store; the default-store test pins that none of it leaks into the+ * local user's store or its persisted keys.** Runs in the NODE environment with a real jsdom window installed by hand (`installDom`), not in* vitest's jsdom environment: that one loads modules through Vite's client transform, which@@ -267,7 +268,7 @@ const working = { hook_event_name: 'UserPromptSubmit', session_id: 's1', prompt:const done = { hook_event_name: 'Stop', session_id: 's1', last_assistant_message: 'done.' }describe('hosted team tab: agent status reaches the relay session', () => {- it.fails('a host hook event reaches each relay session store', async () => {+ it('a host hook event reaches each relay session store', async () => {h.hook(working)await settle()expect(relayStore(h.owner.tab).getState().byId[NODE]?.state).toBe('working')@@ -291,11 +292,11 @@ describe('hosted team tab: agent status reaches the relay session', () => {expect(setItem.mock.calls.filter(([k]) => String(k).startsWith('nodeterm.agentStatus'))).toEqual([])})- it.fails('reading a finished relay session acks nothing on the host', async () => {+ it('reading a finished relay session acks nothing on the host', async () => {h.hook(working)h.hook(done)await settle()- expect(relayStore(h.viewer.tab).getState().byId[NODE]?.unread).toBe(true) // fails today: nothing wrote it+ expect(relayStore(h.viewer.tab).getState().byId[NODE]?.unread).toBe(true)expect(relayStore(h.owner.tab).getState().byId[NODE]?.unread).toBe(true)relayStore(h.viewer.tab).getState().clearUnread(NODE)relayStore(h.owner.tab).getState().clearUnread(NODE)@@ -309,7 +310,7 @@ describe('hosted team tab: agent status reaches the relay session', () => {expect(relayStore(h.owner.tab).getState().byId[NODE]?.unread).toBe(false)})- it.fails('after a relay drop the tab reads unknown and later events write nothing', async () => {+ it('after a relay drop the tab reads unknown and later events write nothing', async () => {h.hook(working)await settle()expect(relayStore(h.viewer.tab).getState().byId[NODE]?.state).toBe('working')