diff --git a/packages/app/src/panels/agent-panel.tsx b/packages/app/src/panels/agent-panel.tsx index 1eaaacccc..4b0844855 100644 --- a/packages/app/src/panels/agent-panel.tsx +++ b/packages/app/src/panels/agent-panel.tsx @@ -908,7 +908,7 @@ function ChatAgentContent({ } return; } - if (!isConnected || !hasSession) { + if (!isPaneFocused || !isConnected || !hasSession) { return; } if ( @@ -969,6 +969,7 @@ function ChatAgentContent({ ensureAgentIsInitialized, hasSession, isConnected, + isPaneFocused, missingAgentState.kind, serverId, ]); diff --git a/packages/app/src/utils/agent-directory-reconciliation.test.ts b/packages/app/src/utils/agent-directory-reconciliation.test.ts index ca9e9ba03..cb52bf69d 100644 --- a/packages/app/src/utils/agent-directory-reconciliation.test.ts +++ b/packages/app/src/utils/agent-directory-reconciliation.test.ts @@ -183,4 +183,32 @@ describe("agent directory reconciliation", () => { usage: { inputTokens: 20, outputTokens: 8 }, }); }); + + it("preserves usage when a stale buffered upsert omits it", () => { + const result = reconcileAgentDirectory({ + previous: new Map(), + snapshot: [ + { + ...entry("agent", "idle"), + agent: { + ...snapshot("agent", "idle"), + updatedAt: "2026-07-12T12:00:00.000Z", + lastUsage: { inputTokens: 10, outputTokens: 5 }, + }, + }, + ], + deltas: [ + { + kind: "upsert", + agent: { + ...snapshot("agent", "running"), + updatedAt: "2026-07-12T11:00:00.000Z", + }, + project: entry("agent", "idle").project, + }, + ], + }); + + expect(result.entries[0]?.agent.lastUsage).toEqual({ inputTokens: 10, outputTokens: 5 }); + }); }); diff --git a/packages/app/src/utils/agent-directory-update-policy.ts b/packages/app/src/utils/agent-directory-update-policy.ts index a802ae3b9..4d14f101b 100644 --- a/packages/app/src/utils/agent-directory-update-policy.ts +++ b/packages/app/src/utils/agent-directory-update-policy.ts @@ -15,6 +15,7 @@ export function acceptAgentDirectoryUpdate( incoming: T, ): T { if (!current || timestamp(incoming.updatedAt) >= timestamp(current.updatedAt)) return incoming; + if (incoming.lastUsage === undefined) return current; if (equal(incoming.lastUsage, current.lastUsage)) return current; return { ...current, lastUsage: incoming.lastUsage }; }