Skip to content

Commit 3d669c7

Browse files
authored
fix(sessions): maxDiskBytes 0 no longer deletes all session history (#119422)
* fix(sessions): treat maxDiskBytes 0 as disabled disk budget * fix(sessions): treat zero maxDiskBytes as disabled budget and document the contract
1 parent 1b5dbd3 commit 3d669c7

6 files changed

Lines changed: 59 additions & 5 deletions

File tree

‎docs/gateway/config-agents.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ See [Multi-Agent Sandbox & Tools](/tools/multi-agent-sandbox-tools) for preceden
12601260
- Short-lived gateway model-run probe sessions use fixed `24h` retention, but cleanup is pressure-gated: it only removes stale strict model-run probe rows when session-entry maintenance/cap pressure is reached. Only strict explicit probe keys matching `agent:*:explicit:model-run-<uuid>` are eligible; normal direct, group, thread, cron, hook, heartbeat, ACP, and sub-agent sessions do not inherit this 24h retention. When model-run cleanup runs, it runs before the broader `pruneAfter` stale-entry cleanup and `maxEntries` cap.
12611261
- Legacy `rotateBytes` is rejected by the current schema; `openclaw doctor --fix` removes it from older configs.
12621262
- `resetArchiveRetention`: age-based retention for reset/deleted transcript archives. By default, archives remain until disk-budget eviction; set a duration to opt into wall-clock deletion, or `false` to disable it explicitly.
1263-
- `maxDiskBytes`: optional sessions-directory disk budget. In `warn` mode it logs warnings; in `enforce` mode it removes oldest artifacts/sessions first.
1263+
- `maxDiskBytes`: optional sessions-directory disk budget. In `warn` mode it logs warnings; in `enforce` mode it removes oldest artifacts/sessions first. Set `false`, `0`, or `"0"` to disable the budget entirely.
12641264
- `highWaterBytes`: optional target after budget cleanup. Defaults to `80%` of `maxDiskBytes`.
12651265
- **`threadBindings`**: global defaults for thread-bound session features.
12661266
- `enabled`: master switch for supported channel thread bindings

‎docs/reference/session-management-compaction.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Per agent, on the Gateway host (resolved via `src/config/sessions.ts`):
5050
| `pruneAfter` | `"30d"` | stale-entry age cutoff |
5151
| `maxEntries` | `500` | cap on session entries |
5252
| `resetArchiveRetention` | keep (no age cutoff) | age cutoff for `*.reset.*`/`*.deleted.*` transcript archives; a duration opts into deletion |
53-
| `maxDiskBytes` | `10gb` | per-agent sessions disk budget; `false` disables |
53+
| `maxDiskBytes` | `10gb` | per-agent sessions disk budget; `false`, `0`, or `"0"` disables |
5454
| `highWaterBytes` | 80% of `maxDiskBytes` | target after budget cleanup |
5555

5656
Reset advances the live `sessionKey -> sessionId` mapping but keeps the previous SQLite session, transcript, trajectory, and search rows. That history remains searchable under the same session key; ordinary entry and session lists show only the new live mapping. Retained reset history is bounded by the disk budget, not by `resetArchiveRetention`, which only ages archive artifacts. Explicit deletion is different: it writes and verifies a compressed transcript archive (`*.jsonl.deleted.<timestamp>.zst` when zstd is available) before removing the deleted session's rows.

‎src/config/schema.help.automation.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export const AUTOMATION_FIELD_HELP: Record<string, string> = {
8181
"session.maintenance.resetArchiveRetention":
8282
"Age-based retention for archived transcripts (`*.reset.<timestamp>` and `*.deleted.<timestamp>`). Defaults to keeping archives until the disk budget evicts them oldest-first; set a duration (for example `30d`) to opt into wall-clock deletion, or `false` to disable it explicitly.",
8383
"session.maintenance.maxDiskBytes":
84-
"Per-agent sessions-directory disk budget (for example `500mb`). Defaults to `10gb`; when exceeded, warn mode reports pressure and enforce mode performs oldest-first cleanup (archived transcripts before live sessions). Set `false` to disable.",
84+
'Per-agent sessions-directory disk budget (for example `500mb`). Defaults to `10gb`; when exceeded, warn mode reports pressure and enforce mode performs oldest-first cleanup (archived transcripts before live sessions). Set `false`, `0`, or `"0"` to disable.',
8585
"session.maintenance.highWaterBytes":
8686
"Target size after disk-budget cleanup (high-water mark). Defaults to 80% of maxDiskBytes; set explicitly for tighter reclaim behavior on constrained disks.",
8787
cron: "Global scheduler settings for stored automations, run concurrency, delivery fallback, and run-session retention. Keep defaults unless you are scaling automation volume or integrating external webhook receivers.",

‎src/config/sessions/store-maintenance.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,13 @@ function resolveMaxDiskBytes(maintenance?: SessionMaintenanceConfig): number | n
102102
return DEFAULT_SESSION_MAX_DISK_BYTES;
103103
}
104104
try {
105-
return parseByteSize(normalized, { defaultUnit: "b" });
105+
const bytes = parseByteSize(normalized, { defaultUnit: "b" });
106+
// A zero or negative budget is not a usable cap; treat it the same as an
107+
// explicit disable so maintenance does not delete every session artifact.
108+
if (bytes <= 0) {
109+
return null;
110+
}
111+
return bytes;
106112
} catch {
107113
// A malformed explicit value must not opt the user into destructive
108114
// budget cleanup they never chose; disable the budget instead.

‎src/config/sessions/store.pruning.test.ts‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import crypto from "node:crypto";
33
import fs from "node:fs/promises";
44
import path from "node:path";
55
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
6+
import { saveLegacySessionStore as saveSessionStore } from "../../infra/state-migrations.legacy-session-store.js";
67
import { beginSessionWorkAdmission } from "../../sessions/session-lifecycle-admission.js";
8+
import { withTempDir } from "../../test-helpers/temp-dir.js";
79
import { createFixtureSuite } from "../../test-utils/fixture-suite.js";
810
import { normalizeSessionDeliveryState } from "../../utils/delivery-context.shared.js";
911
import { enforceSessionDiskBudget } from "./disk-budget.js";
@@ -987,6 +989,52 @@ describe("resolveMaintenanceConfigFromInput", () => {
987989
expect(maintenance.highWaterBytes).toBeNull();
988990
});
989991

992+
it("disables the disk budget when maxDiskBytes is 0", () => {
993+
const maintenance = resolveMaintenanceConfigFromInput({ maxDiskBytes: 0 });
994+
995+
expect(maintenance.maxDiskBytes).toBeNull();
996+
expect(maintenance.highWaterBytes).toBeNull();
997+
});
998+
999+
it("disables the disk budget when maxDiskBytes is the string '0'", () => {
1000+
const maintenance = resolveMaintenanceConfigFromInput({ maxDiskBytes: "0" });
1001+
1002+
expect(maintenance.maxDiskBytes).toBeNull();
1003+
expect(maintenance.highWaterBytes).toBeNull();
1004+
});
1005+
1006+
it("retains session history when a zero maxDiskBytes disables the budget", async () => {
1007+
await withTempDir({ prefix: "openclaw-zero-disk-budget-" }, async (dir) => {
1008+
const storePath = path.join(dir, "sessions.json");
1009+
const transcriptPath = path.join(dir, "old-session.jsonl");
1010+
await fs.writeFile(transcriptPath, JSON.stringify({ role: "user", content: "hello" }));
1011+
const store: Record<string, SessionEntry> = {
1012+
"agent:main:subagent:old-worker": {
1013+
sessionId: "old-session",
1014+
updatedAt: 1,
1015+
transcriptPath,
1016+
},
1017+
};
1018+
await saveSessionStore(storePath, store, { skipMaintenance: true });
1019+
1020+
const maintenance = resolveMaintenanceConfigFromInput({ maxDiskBytes: 0 });
1021+
const result = await enforceSessionDiskBudget({
1022+
store,
1023+
storePath,
1024+
maintenance: {
1025+
maxDiskBytes: maintenance.maxDiskBytes,
1026+
highWaterBytes: maintenance.highWaterBytes,
1027+
},
1028+
warnOnly: false,
1029+
});
1030+
1031+
expect(maintenance.maxDiskBytes).toBeNull();
1032+
expect(maintenance.highWaterBytes).toBeNull();
1033+
expect(result).toBeNull();
1034+
await expect(fs.access(transcriptPath)).resolves.toBeUndefined();
1035+
});
1036+
});
1037+
9901038
it("force-gates the unset model-run prune default to the cap-eviction threshold", () => {
9911039
const defaultMaintenance = resolveMaintenanceConfigFromInput({ maxEntries: 50 });
9921040
expect(resolveSessionEntryMaintenanceHighWater(50)).toBe(75);

‎src/config/types.base.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ export type SessionMaintenanceConfig = {
263263
/**
264264
* Per-agent sessions-directory disk budget (e.g. "500mb"). Default: "10gb".
265265
* When exceeded, warn (mode=warn) or enforce oldest-first cleanup
266-
* (mode=enforce). Set `false` to disable the budget entirely.
266+
* (mode=enforce). Set `false`, `0`, or `"0"` to disable the budget entirely.
267267
*/
268268
maxDiskBytes?: number | string | false;
269269
/**

0 commit comments

Comments
 (0)