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(subagents): carry the activity clock across a supersede, and forget the old key's entry
reviewbac8bacc2ee8
diff --git a/src/core/subagent-replay.test.ts b/src/core/subagent-replay.test.tsindex 4d5062e69..090e36ea0 100644--- a/src/core/subagent-replay.test.ts+++ b/src/core/subagent-replay.test.ts@@ -80,6 +80,17 @@ describe('Claude native subagents (core/claude-subagent-lifecycle.ts)', () => {replay.record({ ...start, toolUseId: 'a1', supersedes: 'toolu_1' }, 150)expect(replay.snapshot(200).map((e) => [e.toolUseId, e.subagentStartedAt])).toEqual([['a1', 100]])})+ it('a supersede moves the replaced card\'s last activity to the new key and drops the old entry', () => {+ const replay = new SubagentReplay()+ replay.record({ ...start, toolUseId: 'toolu_1' }, 100)+ replay.touch('toolu_1', 140)+ replay.record({ ...start, toolUseId: 'a1', supersedes: 'toolu_1' }, 150)+ expect(replay.snapshot(200)).toEqual([expect.objectContaining({ toolUseId: 'a1', subagentLastActivityAt: 140 })])+ // A later start that reuses the old key must not inherit the orphaned activity time.+ replay.record({ ...start, toolUseId: 'toolu_1' }, 300)+ const reused = replay.snapshot(300).find((e) => e.toolUseId === 'toolu_1')+ expect(reused?.subagentLastActivityAt).toBeUndefined()+ })it('a repeated start of a running card corrects its label and keeps its start time', () => {const replay = new SubagentReplay()replay.record({ ...start, toolUseId: 'a1', taskLabel: 'guess' }, 100)diff --git a/src/core/subagent-replay.ts b/src/core/subagent-replay.tsindex 55ca76bde..01fed6a64 100644--- a/src/core/subagent-replay.ts+++ b/src/core/subagent-replay.ts@@ -19,8 +19,17 @@ export class SubagentReplay {const key = this.key(event)// A native card REPLACING the card its tool call drew (core/claude-subagent-lifecycle.ts):// the replayed card keeps the original start time under the new key.- const replaced = event.supersedes ? this.starts.get(this.key({ ...event, toolUseId: event.supersedes })) : undefined- if (event.supersedes) this.starts.delete(this.key({ ...event, toolUseId: event.supersedes }))+ // Its last sign of life moves with it (a time cannot double the way streamed text would), and+ // `forget` drops the old key's activity entry too — a bare `starts.delete` orphaned it.+ const oldKey = event.supersedes && event.supersedes !== event.toolUseId+ ? this.key({ ...event, toolUseId: event.supersedes })+ : undefined+ const replaced = oldKey ? this.starts.get(oldKey) : undefined+ const replacedLast = oldKey ? this.lastActivity.get(oldKey) : undefined+ if (oldKey) this.forget(oldKey)+ if (replaced && replacedLast !== undefined) {+ this.lastActivity.set(key, Math.max(replacedLast, this.lastActivity.get(key) ?? 0))+ }const running = this.starts.get(key)if (running) {// A repeated start of a running card corrects what it shows, never when it started.diff --git a/src/renderer/state/agentNodes.native.test.ts b/src/renderer/state/agentNodes.native.test.tsindex b12de4c16..1639e57ad 100644--- a/src/renderer/state/agentNodes.native.test.ts+++ b/src/renderer/state/agentNodes.native.test.ts@@ -8,6 +8,7 @@ const reset = (): void =>useAgentNodes.setState({byId: {},activityById: {},+ lastActivityAt: {},positions: {},sizes: {},expanded: {},@@ -53,6 +54,26 @@ describe('start(…, supersedes) — a native card replacing the card its tool cexpect(st.byId.a123).toMatchObject({ startedAt: 2, label: 'fixed' })})+ it("carries the sweep's clock: the replaced card's last activity and a replayed seed both count", () => {+ const s = useAgentNodes.getState()+ s.start('toolu_1', { parentNodeId: 'n1', startedAt: 1000 })+ useAgentNodes.setState({ lastActivityAt: { toolu_1: 5000 } })+ s.start('a123', { parentNodeId: 'n1' }, 'toolu_1')+ expect(useAgentNodes.getState().lastActivityAt).toEqual({ a123: 5000 })+ // A reload replay of the superseding start seeds a newer time; the clock never goes backwards.+ s.start('a123', { parentNodeId: 'n1', lastActivityAt: 9000 })+ s.start('a123', { parentNodeId: 'n1', lastActivityAt: 2000 })+ expect(useAgentNodes.getState().lastActivityAt).toEqual({ a123: 9000 })+ expect(useAgentNodes.getState().byId.a123).not.toHaveProperty('lastActivityAt')+ })++ it('a replayed superseding start seeds its clock even when nothing was carried', () => {+ const s = useAgentNodes.getState()+ s.start('toolu_1', { parentNodeId: 'n1', startedAt: 1000 })+ s.start('a123', { parentNodeId: 'n1', lastActivityAt: 7000 }, 'toolu_1')+ expect(useAgentNodes.getState().lastActivityAt).toEqual({ a123: 7000 })+ })+it('an unknown superseded key is a plain start', () => {useAgentNodes.getState().start('a123', { parentNodeId: 'n1', startedAt: 7 }, 'gone')expect(useAgentNodes.getState().byId.a123).toMatchObject({ state: 'working', startedAt: 7 })