Skip to content

Commit 13b4d49

Browse files
committed
fix(sessions): preserve compacted transcript structure
1 parent a0429dc commit 13b4d49

11 files changed

Lines changed: 599 additions & 53 deletions

src/cli/program/register.status-health-sessions.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,18 @@ describe("registerStatusHealthSessionsCommands", () => {
332332
});
333333

334334
it("rejects other unsupported inherited parent list options for compact", async () => {
335-
await runCli(["sessions", "--all-agents", "--limit", "25", "compact", "agent:work:main"]);
335+
await runCli([
336+
"sessions",
337+
"--all-agents",
338+
"--limit",
339+
"25",
340+
"--verbose",
341+
"compact",
342+
"agent:work:main",
343+
]);
336344

337345
expect(runtime.error).toHaveBeenCalledWith(expect.stringContaining("--all-agents"));
346+
expect(runtime.error).toHaveBeenCalledWith(expect.stringContaining("--verbose"));
338347
expect(runtime.exit).toHaveBeenCalledWith(1);
339348
expect(sessionsCompactCommand).not.toHaveBeenCalled();
340349
});

src/cli/program/register.status-health-sessions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,13 +411,15 @@ export function registerStatusHealthSessionsCommands(program: Command) {
411411
allAgents?: boolean;
412412
active?: string;
413413
limit?: string;
414+
verbose?: boolean;
414415
}
415416
| undefined;
416417
const unsupportedParentOptions = [
417418
parentOpts?.store !== undefined ? "--store" : undefined,
418419
parentOpts?.allAgents ? "--all-agents" : undefined,
419420
parentOpts?.active !== undefined ? "--active" : undefined,
420421
parentOpts?.limit !== undefined ? "--limit" : undefined,
422+
parentOpts?.verbose ? "--verbose" : undefined,
421423
].filter((flag): flag is string => flag !== undefined);
422424
if (unsupportedParentOptions.length > 0) {
423425
const plural = unsupportedParentOptions.length > 1 ? "options" : "option";

src/commands/sessions-compact.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ describe("sessionsCompactCommand", () => {
8080
expect(joinedArgs(runtime.error)).toContain("summarize interrupted");
8181
});
8282

83+
it("exits non-zero when the gateway response omits explicit success", async () => {
84+
callGatewayCli.mockResolvedValue({ key: "agent:main:main", compacted: false });
85+
const runtime = createRuntime();
86+
87+
await sessionsCompactCommand({ key: "agent:main:main" }, runtime);
88+
89+
expect(runtime.exit).toHaveBeenCalledWith(1);
90+
expect(joinedArgs(runtime.error)).toContain("Compaction failed");
91+
});
92+
8393
it("exits non-zero and surfaces the error when the RPC throws", async () => {
8494
callGatewayCli.mockRejectedValue(new Error("gateway unreachable"));
8595
const runtime = createRuntime();

src/commands/sessions-compact.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,9 @@ export async function sessionsCompactCommand(
9999
return;
100100
}
101101

102-
// An explicit ok:false means the gateway accepted the request but the
103-
// compaction itself did not complete (for example an interrupted summarize
104-
// run). Surface it as a failure instead of letting the process exit 0.
105-
const failed = result?.ok === false;
102+
// Success is explicit. A malformed or version-skewed payload must not turn
103+
// into the same exit-0 message as a genuine no-op compaction.
104+
const failed = result?.ok !== true;
106105

107106
if (opts.json) {
108107
writeRuntimeJson(runtime, result);

0 commit comments

Comments
 (0)