From 898fd0482a401c1703a7305b067b9ba334f7aae9 Mon Sep 17 00:00:00 2001 From: Ayaan Zaidi Date: Thu, 16 Apr 2026 09:20:37 +0530 Subject: [PATCH] fix(agents): preserve cli session metadata before transcript persist (#67490) --- src/agents/agent-command.ts | 1 + src/commands/agent.cli-provider.test.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/agents/agent-command.ts b/src/agents/agent-command.ts index 3ffcfc8d168..1ea6946eb96 100644 --- a/src/agents/agent-command.ts +++ b/src/agents/agent-command.ts @@ -1042,6 +1042,7 @@ async function agentCommandInternal( fallbackModel, result, }); + sessionEntry = sessionStore[sessionKey] ?? sessionEntry; } if (result.meta.executionTrace?.runner === "cli") { diff --git a/src/commands/agent.cli-provider.test.ts b/src/commands/agent.cli-provider.test.ts index b7db92c427e..e17d8268c49 100644 --- a/src/commands/agent.cli-provider.test.ts +++ b/src/commands/agent.cli-provider.test.ts @@ -176,6 +176,14 @@ describe("agentCommand CLI provider handling", () => { sessionId: "cli-session-123", provider: "google-gemini-cli", model: "gemini-3.1-pro-preview", + compactionCount: 2, + usage: { + input: 12, + output: 4, + cacheRead: 3, + cacheWrite: 0, + total: 19, + }, }, executionTrace: { winnerProvider: "google-gemini-cli", @@ -191,6 +199,12 @@ describe("agentCommand CLI provider handling", () => { const saved = readSessionStore<{ sessionFile?: string }>(store); const sessionFile = saved[sessionKey]?.sessionFile; expect(sessionFile).toBeTruthy(); + expect(saved[sessionKey]).toMatchObject({ + compactionCount: 2, + inputTokens: 12, + outputTokens: 4, + cacheRead: 3, + }); const messages = await readSessionMessages(sessionFile!); expect(messages).toHaveLength(2);