Skip to content

Commit f73c54e

Browse files
committed
fix(sessions): reclaim legacy compact backups
1 parent cb3986a commit f73c54e

3 files changed

Lines changed: 18 additions & 8 deletions

File tree

‎src/config/sessions/artifacts.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@ export function isSessionArchiveArtifactName(fileName: string): boolean {
3939
);
4040
}
4141

42-
/** Returns true for retained reset/delete transcript archives counted by the session budget. */
42+
/** Returns true for retained archives and disposable legacy compact backups pruned at high water. */
4343
export function isRetainedSessionTranscriptArchiveName(fileName: string): boolean {
44-
return hasArchiveSuffix(fileName, "deleted") || hasArchiveSuffix(fileName, "reset");
44+
return (
45+
hasArchiveSuffix(fileName, "deleted") ||
46+
hasArchiveSuffix(fileName, "reset") ||
47+
hasArchiveSuffix(fileName, "bak")
48+
);
4549
}
4650

4751
/** Returns true for migration rollback archives retained beside their legacy source. */

‎src/config/sessions/disk-budget.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ export async function hasRetainedSessionTranscriptArchives(storePath: string): P
317317
return files.some((file) => isRetainedSessionTranscriptArchiveName(file.name));
318318
}
319319

320-
/** Removes oldest retained reset/delete archives, remeasuring physical usage after each file. */
320+
/** Removes oldest retained archives and legacy compact backups, remeasuring after each file. */
321321
export async function pruneSessionTranscriptArchivesToHighWater(params: {
322322
excludeNames?: ReadonlySet<string>;
323323
highWaterBytes: number;

‎src/config/sessions/session-history-eviction.test.ts‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,16 @@ describe("SQLite historical session disk budget", () => {
143143
expect(sessionExists(sessionId)).toBe(false);
144144
});
145145

146-
it("removes counted archives before evicting searchable history", async () => {
146+
it.each([
147+
{
148+
archiveName: "already-extracted.jsonl.deleted.2026-01-01T00-00-00.000Z",
149+
kind: "deleted transcript archive",
150+
},
151+
{
152+
archiveName: `legacy-compact.jsonl.bak.2026-01-01T00-00-00.000Z.${"a".repeat(32)}.zst`,
153+
kind: "legacy compact backup",
154+
},
155+
])("removes a $kind before evicting searchable history", async ({ archiveName }) => {
147156
await createHistoricalTranscript({
148157
content: "keep searchable history",
149158
nextSessionId: "archive-live",
@@ -152,10 +161,7 @@ describe("SQLite historical session disk budget", () => {
152161
updatedAt: 1,
153162
});
154163
database().walMaintenance.checkpoint();
155-
const oldArchive = path.join(
156-
tempDir,
157-
"already-extracted.jsonl.deleted.2026-01-01T00-00-00.000Z",
158-
);
164+
const oldArchive = path.join(tempDir, archiveName);
159165
fs.writeFileSync(oldArchive, Buffer.alloc(256 * 1024));
160166
const before = await measureSessionPhysicalDiskUsage(storePath);
161167

0 commit comments

Comments
 (0)