diff --git a/src/gateway/session-compaction-checkpoints.test.ts b/src/gateway/session-compaction-checkpoints.test.ts index 7271b1c7fb1..bba73ffed64 100644 --- a/src/gateway/session-compaction-checkpoints.test.ts +++ b/src/gateway/session-compaction-checkpoints.test.ts @@ -79,6 +79,8 @@ describe("session-compaction-checkpoints", () => { expect(sessionManagerOpenSpy).not.toHaveBeenCalled(); expect(snapshot).not.toBeNull(); + expect(snapshot?.agentId).toBe(DEFAULT_AGENT_ID); + expect(snapshot?.sourceSessionId).toBe(session.getSessionId()); expect(snapshot?.leafId).toBe(leafId); expect(snapshot?.sessionFile).not.toBe(sessionFile); expect(snapshot?.sessionFile).toContain("sqlite-transcript://"); @@ -119,7 +121,14 @@ describe("session-compaction-checkpoints", () => { agentId: DEFAULT_AGENT_ID, sessionId: snapshot!.sessionId, }), - ).toBe(true); + ).toBe(false); + expect( + hasSqliteSessionTranscriptSnapshot({ + agentId: DEFAULT_AGENT_ID, + sessionId: session.getSessionId(), + snapshotId: snapshot!.sessionId, + }), + ).toBe(false); } finally { sessionManagerOpenSpy.mockRestore(); } @@ -161,6 +170,8 @@ describe("session-compaction-checkpoints", () => { expect(sessionManagerOpenSpy).not.toHaveBeenCalled(); expect(snapshot).not.toBeNull(); + expect(snapshot?.agentId).toBe(DEFAULT_AGENT_ID); + expect(snapshot?.sourceSessionId).toBe(sessionId); expect(snapshot?.sessionId).not.toBe(sessionId); expect(snapshot?.leafId).toBe(leafId); expect(snapshot?.sessionFile).not.toBe(sessionFile); diff --git a/src/gateway/session-compaction-checkpoints.ts b/src/gateway/session-compaction-checkpoints.ts index ab481077aef..267a2ec4911 100644 --- a/src/gateway/session-compaction-checkpoints.ts +++ b/src/gateway/session-compaction-checkpoints.ts @@ -31,6 +31,8 @@ const MAX_COMPACTION_CHECKPOINTS_PER_SESSION = 25; export const MAX_COMPACTION_CHECKPOINT_SNAPSHOT_BYTES = 64 * 1024 * 1024; export type CapturedCompactionCheckpointSnapshot = { + agentId: string; + sourceSessionId: string; sessionId: string; sessionFile?: string; leafId: string; @@ -289,6 +291,8 @@ export async function captureCompactionCheckpointSnapshotAsync(params: { }, }); return { + agentId: snapshotAgentId, + sourceSessionId: sourceHeader.id, sessionId: snapshotSessionId, sessionFile: snapshotFile, leafId, @@ -298,7 +302,18 @@ export async function captureCompactionCheckpointSnapshotAsync(params: { export async function cleanupCompactionCheckpointSnapshot( snapshot: CapturedCompactionCheckpointSnapshot | null | undefined, ): Promise { - void snapshot; + if (!snapshot) { + return; + } + deleteSqliteSessionTranscriptSnapshot({ + agentId: snapshot.agentId, + sessionId: snapshot.sourceSessionId, + snapshotId: snapshot.sessionId, + }); + deleteSqliteSessionTranscript({ + agentId: snapshot.agentId, + sessionId: snapshot.sessionId, + }); } export async function persistSessionCompactionCheckpoint(params: {