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
perf(mirror): ask for live node ids only when an entry is past EXPIRE_MS
reviewd9d75437baaf
diff --git a/src/core/agent-status-mirror.identity.test.ts b/src/core/agent-status-mirror.identity.test.tsindex 67ae1c973..b00728810 100644--- a/src/core/agent-status-mirror.identity.test.ts+++ b/src/core/agent-status-mirror.identity.test.ts@@ -193,6 +193,18 @@ describe('live mirror — identity survives the state expiry', () => {expect(_snapshot().gone).toBeUndefined()})+ it('does not ask the live-node provider when no entry is past EXPIRE_MS (it scans every project)', async () => {+ recordAgentEvent(ev({ nodeId: 'fresh', state: 'done', sessionId: 'f' }))+ const provider = vi.fn(() => new Set<string>())+ setMirrorLiveNodesProvider(provider)+ await flush()+ expect(provider).not.toHaveBeenCalled()+ expect(Object.keys(read().nodes)).toEqual(['fresh'])+ nowSpy.mockReturnValue(1_000_000 + EXPIRE_MS + 1)+ await flush()+ expect(provider).toHaveBeenCalled()+ })+it('an UNKNOWABLE live set (provider answers undefined, or throws) prunes nothing by existence', async () => {recordAgentEvent(ev({ nodeId: 'a', state: 'done', sessionId: 'a' }))setMirrorLiveNodesProvider(() => undefined)diff --git a/src/core/agent-status-mirror.ts b/src/core/agent-status-mirror.tsindex 59b6112db..7154a72bc 100644--- a/src/core/agent-status-mirror.ts+++ b/src/core/agent-status-mirror.ts@@ -2143,6 +2143,9 @@ export function sessionNameSweepEntries(): {agentId?: stringname?: string}[] {+ // NB: the Server Edition's context-link sweep also reads this list (src/server/context-link.ts,+ // `agentSessions` default), so it too sees only nodes active within EXPIRE_MS — the same set it+ // saw before identity-only entries existed; giving it their session ids is a separate change.return [...state].filter(([, e]) => !e.stateExpired).map(([nodeId, e]) => ({nodeId,sessionId: e.sessionId,@@ -2265,7 +2268,17 @@ export async function flush(): Promise<void> {// identity (so no in-process reader — messaging, triggers, the resync — sees a 6 h-old state),// and an identity past its TTL or for a node that no longer exists is dropped, so the map itself// can't grow without bound.- const liveIds = safeLiveNodes()+ // Ask for the live node set only when some entry is past EXPIRE_MS: only those can be pruned by+ // existence, and the provider scans every project (it runs on every flush otherwise — each event+ // burst plus the 60 s heartbeat).+ let anyExpired = false+ for (const e of state.values()) {+ if (!e.hibernated && now - e.updatedAt > EXPIRE_MS) {+ anyExpired = true+ break+ }+ }+ const liveIds = anyExpired ? safeLiveNodes() : undefinedfor (const [id, e] of state) {const aged = ageEntry(id, e, now, EXPIRE_MS, liveIds)if (!aged) state.delete(id)diff --git a/src/core/workspace-store.ts b/src/core/workspace-store.tsindex 2b08551a5..767ec1791 100644--- a/src/core/workspace-store.ts+++ b/src/core/workspace-store.ts@@ -1513,6 +1513,9 @@ export class WorkspaceStore {* state expiry) whose node was deleted while this process was not watching. A wrong "gone" costs* the phone that node's session id, so every doubt answers `undefined` — the mirror then bounds* the entry by its identity TTL alone. Same three-entry-kind scan as `findNode`.+ * Consequence: ONE permanently unavailable local ref or one never-cached SSH project turns+ * existence pruning off for EVERY project, leaving only the 30-day identity TTL.+ * Parses through `parsedLastWritten`, so a mirror flush re-parses no unchanged project.json.*/knownNodeIds(): Set<string> | undefined {if (!this.index) return undefined@@ -1522,10 +1525,8 @@ export class WorkspaceStore {if (e.project) nodes = e.project.nodeselse if (e.cache) nodes = e.cache.nodeselse if (e.cwd) {- const raw = this.lastWritten.get(projectFilePath(e.cwd))- if (!raw) return undefinedtry {- nodes = (JSON.parse(raw) as ProjectFileV1).nodes+ nodes = this.parsedLastWritten(projectFilePath(e.cwd))?.nodes} catch {return undefined}