Skip to content

Commit 340da9f

Browse files
committed
fix(sessions): satisfy test-types, knip export scan, and docs map
1 parent 3842dcb commit 340da9f

4 files changed

Lines changed: 7 additions & 18 deletions

File tree

docs/docs_map.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2492,7 +2492,7 @@ Do not edit it by hand; run `pnpm docs:map:gen`.
24922492
- H2: Home
24932493
- H2: What flows into the main session
24942494
- H2: Memory across resets and conversations
2495-
- H2: A rolling session, not an immortal one
2495+
- H2: A rolling session with durable history
24962496
- H2: When you want isolation instead
24972497
- H2: Related
24982498

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { getSessionKysely } from "./session-accessor.sqlite-scope.js";
2020
import {
2121
enforceSqliteSessionHistoryDiskBudget,
2222
kickSessionHistoryDiskBudgetMaintenance,
23-
resetSessionHistoryBudgetKicksForTests,
2423
inspectSqliteSessionHistoryDiskBudget,
2524
} from "./session-history-eviction.js";
2625
import { resolveSqliteTargetFromSessionStorePath } from "./session-sqlite-target.js";
@@ -294,7 +293,6 @@ describe("kickSessionHistoryDiskBudgetMaintenance", () => {
294293
it("throttles repeat kicks and skips warn mode entirely", async () => {
295294
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-session-history-kick-"));
296295
const storePath = path.join(tempDir, "sessions.json");
297-
resetSessionHistoryBudgetKicksForTests();
298296
const maintenance = {
299297
mode: "warn",
300298
maxDiskBytes: 1,
@@ -325,7 +323,6 @@ describe("kickSessionHistoryDiskBudgetMaintenance", () => {
325323
// Give the fire-and-forget pass a tick to settle; an under-budget store
326324
// must leave every session untouched.
327325
await new Promise((resolve) => setTimeout(resolve, 50));
328-
resetSessionHistoryBudgetKicksForTests();
329326
closeOpenClawAgentDatabasesForTest();
330327
fs.rmSync(tempDir, { recursive: true, force: true });
331328
});

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,10 @@ function createPhysicalBudgetResult(params: {
6363
};
6464
}
6565

66-
export type SessionHistoryDiskBudgetInspection = {
67-
diskBudget: SessionDiskBudgetSweepResult | null;
68-
wouldMutate: boolean;
69-
};
70-
7166
/** Reports the same physical total enforce mode compares, without projecting logical row bytes. */
7267
export async function inspectSqliteSessionHistoryDiskBudget(
7368
params: SessionHistoryDiskBudgetParams,
74-
): Promise<SessionHistoryDiskBudgetInspection> {
69+
): Promise<{ diskBudget: SessionDiskBudgetSweepResult | null; wouldMutate: boolean }> {
7570
const { highWaterBytes, maxDiskBytes } = params.maintenance;
7671
if (maxDiskBytes == null || highWaterBytes == null) {
7772
return { diskBudget: null, wouldMutate: false };
@@ -107,7 +102,7 @@ export async function inspectSqliteSessionHistoryDiskBudget(
107102
return { diskBudget, wouldMutate: candidates.length > 0 };
108103
}
109104

110-
export function collectProtectedHistoricalSessionIds(params: {
105+
function collectProtectedHistoricalSessionIds(params: {
111106
database: OpenClawAgentDatabase;
112107
storePath: string;
113108
}): Set<string> {
@@ -207,10 +202,6 @@ const budgetKickStateByStore = new Map<
207202
{ lastCheckAt: number; running: boolean; pendingForce: boolean }
208203
>();
209204

210-
export function resetSessionHistoryBudgetKicksForTests(): void {
211-
budgetKickStateByStore.clear();
212-
}
213-
214205
/** Fire-and-forget budget pass from the ordinary entry-write maintenance seam. */
215206
export function kickSessionHistoryDiskBudgetMaintenance(params: {
216207
agentId?: string;

src/config/sessions/store.session-lifecycle-mutation.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,17 +203,18 @@ describe("session store lifecycle mutations", () => {
203203
const sessionIds = ["delete-history-one", "delete-history-two", "delete-history-three"];
204204
await replaceSessionEntry(
205205
{ sessionKey, storePath },
206-
{ sessionId: sessionIds[0], updatedAt: 1 },
206+
{ sessionId: "delete-history-one", updatedAt: 1 },
207207
);
208208
for (const [index, sessionId] of sessionIds.entries()) {
209209
await replaceSqliteTranscriptEvents({ sessionId, sessionKey, storePath }, [
210210
createSearchableTranscriptEvent(sessionId, `deleteforever generation ${index + 1}`),
211211
]);
212-
if (index < sessionIds.length - 1) {
212+
const nextSessionId = sessionIds[index + 1];
213+
if (nextSessionId) {
213214
await resetSessionEntryLifecycle({
214215
storePath,
215216
target: { canonicalKey: sessionKey, storeKeys: [sessionKey] },
216-
buildNextEntry: () => ({ sessionId: sessionIds[index + 1], updatedAt: index + 2 }),
217+
buildNextEntry: () => ({ sessionId: nextSessionId, updatedAt: index + 2 }),
217218
});
218219
}
219220
}

0 commit comments

Comments
 (0)