Skip to content

Commit 2160b97

Browse files
authored
refactor(config): retire compaction truncateAfterCompaction gate (#115206)
1 parent 35b7d3f commit 2160b97

22 files changed

Lines changed: 162 additions & 202 deletions

‎docs/concepts/compaction.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,11 @@ When `agents.defaults.compaction.maxActiveTranscriptBytes` is set, OpenClaw
110110
triggers normal local compaction before a run if transcript history reaches
111111
that size. This is useful for long-running sessions where provider-side context
112112
management may keep model context healthy while persisted transcript history
113-
keeps growing. It does not split raw bytes; it asks the normal compaction
114-
pipeline to create a semantic summary.
113+
keeps growing. Set a positive byte count or size string such as `"20mb"` to opt
114+
in; `0` or an unset value disables the guard. It does not split raw bytes; it
115+
asks the normal compaction pipeline to create a semantic summary. For Codex
116+
app-server sessions, the same threshold caps native rollout transcripts and
117+
oversized native threads restart fresh.
115118

116119
<Warning>
117120
The byte guard applies to the active SQLite transcript history. Legacy JSONL
@@ -120,7 +123,7 @@ checkpoint artifacts are not the active compaction target.
120123

121124
### Successor transcripts
122125

123-
When `agents.defaults.compaction.truncateAfterCompaction` is enabled, a context engine may return an explicit compacted successor session identity. OpenClaw adopts that successor and records checkpoint metadata against it. The built-in SQLite compactor keeps the current session identity and does not create a second runtime transcript.
126+
A context engine may return an explicit compacted successor session identity. OpenClaw adopts that successor and records checkpoint metadata against it. The built-in SQLite compactor keeps the current session identity and does not create a second runtime transcript.
124127

125128
OpenClaw no longer writes separate `.checkpoint.*.jsonl` copies for new
126129
compactions. Existing legacy checkpoint files can still be used while referenced

‎docs/gateway/config-agents.md‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,7 @@ Delegated consults with a requesting agent keep that requester as their owner. W
610610
postIndexSync: "async", // off | async | await
611611
postCompactionSections: ["Session Startup", "Red Lines"],
612612
model: "openrouter/anthropic/claude-sonnet-4-6", // optional compaction-only model override
613-
truncateAfterCompaction: true, // adopt a context-engine successor when one is returned
614-
maxActiveTranscriptBytes: "20mb", // optional preflight local compaction trigger
613+
maxActiveTranscriptBytes: "20mb", // opt in to preflight local compaction
615614
notifyUser: true, // notices when compaction starts/completes and on memory-flush degradation (default: false)
616615
memoryFlush: {
617616
enabled: true,
@@ -638,8 +637,7 @@ Delegated consults with a requesting agent keep that requester as their owner. W
638637
- `postIndexSync`: post-compaction session-memory reindex mode. Default: `"async"`. Use `"await"` for strongest freshness, `"async"` for lower compaction latency, or `"off"` only when session-memory sync is handled elsewhere.
639638
- `postCompactionSections`: optional AGENTS.md H2/H3 section names to re-inject after compaction. Leave unset or use `[]` to disable.
640639
- `model`: optional `provider/model-id` or bare alias from `agents.defaults.models` for compaction summarization only. Bare aliases resolve before dispatch; configured literal model IDs retain precedence on collisions. Use this when the main session should keep one model but compaction summaries should run on another; when unset, compaction uses the session's primary model.
641-
- `truncateAfterCompaction`: allows a context engine to advance the session to an explicit compacted successor identity. The built-in SQLite compactor keeps the current identity. Default: `false`.
642-
- `maxActiveTranscriptBytes`: optional byte threshold (`number` or strings like `"20mb"`) that triggers normal local compaction before a run when transcript history grows past the threshold. Requires `truncateAfterCompaction`; durable size reduction also requires a context engine that returns a successor identity. Disabled when unset or `0`.
640+
- `maxActiveTranscriptBytes`: byte threshold (`number` or strings like `"20mb"`) that opts in to normal local compaction before a run when transcript history reaches the threshold. For Codex app-server sessions, the same threshold caps native rollout transcripts and oversized native threads restart fresh. Disabled when unset or `0`. When a context engine returns an explicit compacted successor identity, OpenClaw adopts it; the built-in SQLite compactor keeps the current identity.
643641
- `notifyUser`: when `true`, sends brief context-maintenance notices to the user: when compaction starts and completes (for example, "Compacting context..." and "Compaction complete"), and when a pre-compaction memory flush is exhausted so the reply continues in a degraded state (for example, "Memory maintenance temporarily failed; continuing your reply."). Disabled by default to keep these notices silent.
644642
- `memoryFlush`: silent agentic turn before auto-compaction to store durable memories. Set `model` to an exact provider/model such as `ollama/qwen3:8b` when this housekeeping turn should stay on a local model; the override does not inherit the active session fallback chain. `forceFlushTranscriptBytes` forces the flush when transcript size reaches the threshold even if token counters are stale. Skipped when workspace is read-only.
645643

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ Two triggers in the embedded OpenClaw agent:
217217

218218
Two additional guards run outside these two triggers:
219219

220-
- **Preflight local compaction**: set `agents.defaults.compaction.maxActiveTranscriptBytes` (bytes or a string like `"20mb"`) to trigger local compaction before opening the next run once the active transcript reaches that size. Normal semantic compaction still runs. Durable size reduction requires `truncateAfterCompaction` plus a context engine that returns an explicit successor identity.
220+
- **Preflight local compaction**: set `agents.defaults.compaction.maxActiveTranscriptBytes` to a positive byte threshold (bytes or a string like `"20mb"`) to trigger local compaction before opening the next run once the active transcript reaches that size. Normal semantic compaction still runs. For Codex app-server sessions, the same threshold caps native rollout transcripts and oversized native threads restart fresh. Unset or `0` disables the guard.
221221
- **Mid-turn precheck**: set `agents.defaults.compaction.midTurnPrecheck.enabled: true` (default `false`) to add a tool-loop guard. After a tool result is appended and before the next model call, OpenClaw estimates prompt pressure using the same preflight budget logic used at turn start. If context no longer fits, the guard does not compact inline - it raises a structured mid-turn precheck signal, stops the current prompt submission, and lets the outer run loop use the existing recovery path (truncate oversized tool results when that is enough, or trigger the configured compaction mode and retry). Works with both `default` and `safeguard` compaction modes, including provider-backed safeguard compaction. Independent of `maxActiveTranscriptBytes`: the byte-size guard runs before a turn opens, mid-turn precheck runs later, after new tool results are appended.
222222

223223
## Compaction settings
@@ -241,7 +241,7 @@ Set `enabled: false` to disable threshold-driven auto-compaction inside the embe
241241

242242
Manual `/compact` uses `agents.defaults.compaction.keepRecentTokens` (default: `20000`) and keeps that recent-tail cut point.
243243

244-
When `truncateAfterCompaction` is enabled, OpenClaw adopts an explicit successor identity returned by a context engine. The built-in SQLite compactor keeps the current session identity. Branch/restore checkpoint actions use a returned successor when present; legacy pre-compaction checkpoint files remain readable while referenced.
244+
OpenClaw adopts an explicit successor identity returned by a context engine. The built-in SQLite compactor keeps the current session identity. Branch/restore checkpoint actions use a returned successor when present; legacy pre-compaction checkpoint files remain readable while referenced.
245245

246246
## Pluggable compaction providers
247247

‎extensions/codex/src/app-server/run-attempt-connection.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ describe("prepareCodexAttemptConnection", () => {
6868
agents: {
6969
defaults: {
7070
compaction: {
71-
truncateAfterCompaction: true,
7271
maxActiveTranscriptBytes: "1mb",
7372
},
7473
},

‎extensions/codex/src/app-server/run-attempt.context-engine.test.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,6 @@ describe("runCodexAppServerAttempt context-engine lifecycle", () => {
884884
agents: {
885885
defaults: {
886886
compaction: {
887-
truncateAfterCompaction: true,
888887
maxActiveTranscriptBytes: 1_000,
889888
},
890889
},
@@ -1054,7 +1053,6 @@ describe("runCodexAppServerAttempt context-engine lifecycle", () => {
10541053
agents: {
10551054
defaults: {
10561055
compaction: {
1057-
truncateAfterCompaction: true,
10581056
maxActiveTranscriptBytes: "1mb",
10591057
},
10601058
},

‎extensions/codex/src/app-server/run-attempt.test.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4641,7 +4641,6 @@ describe("runCodexAppServerAttempt", () => {
46414641
agents: {
46424642
defaults: {
46434643
compaction: {
4644-
truncateAfterCompaction: true,
46454644
maxActiveTranscriptBytes: "1mb",
46464645
},
46474646
},
@@ -4757,7 +4756,6 @@ describe("runCodexAppServerAttempt", () => {
47574756
agents: {
47584757
defaults: {
47594758
compaction: {
4760-
truncateAfterCompaction: true,
47614759
maxActiveTranscriptBytes: "1mb",
47624760
},
47634761
},

‎extensions/codex/src/app-server/startup-binding.test.ts‎

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,7 @@ describe("Codex app-server startup binding", () => {
7676
binding: await readCodexAppServerBinding(sessionFile),
7777
sessionFile,
7878
agentDir,
79-
config: {
80-
agents: {
81-
defaults: {
82-
compaction: {
83-
truncateAfterCompaction: true,
84-
},
85-
},
86-
},
87-
} as never,
79+
config: undefined,
8880
});
8981

9082
expect(binding?.threadId).toBe("thread-existing");
@@ -122,7 +114,6 @@ describe("Codex app-server startup binding", () => {
122114
agents: {
123115
defaults: {
124116
compaction: {
125-
truncateAfterCompaction: true,
126117
maxActiveTranscriptBytes: "1k",
127118
},
128119
},
@@ -163,7 +154,7 @@ describe("Codex app-server startup binding", () => {
163154
config: {
164155
agents: {
165156
defaults: {
166-
compaction: { truncateAfterCompaction: true, maxActiveTranscriptBytes: "1b" },
157+
compaction: { maxActiveTranscriptBytes: "1b" },
167158
},
168159
},
169160
} as never,
@@ -521,7 +512,6 @@ describe("Codex app-server startup binding", () => {
521512
agents: {
522513
defaults: {
523514
compaction: {
524-
truncateAfterCompaction: true,
525515
maxActiveTranscriptBytes: "1k",
526516
},
527517
},
@@ -553,7 +543,6 @@ describe("Codex app-server startup binding", () => {
553543
agents: {
554544
defaults: {
555545
compaction: {
556-
truncateAfterCompaction: true,
557546
maxActiveTranscriptBytes: "1k",
558547
},
559548
},
@@ -590,7 +579,6 @@ describe("Codex app-server startup binding", () => {
590579
agents: {
591580
defaults: {
592581
compaction: {
593-
truncateAfterCompaction: true,
594582
maxActiveTranscriptBytes: "1k",
595583
},
596584
},
@@ -628,7 +616,6 @@ describe("Codex app-server startup binding", () => {
628616
agents: {
629617
defaults: {
630618
compaction: {
631-
truncateAfterCompaction: true,
632619
maxActiveTranscriptBytes: "1k",
633620
},
634621
},
@@ -666,7 +653,6 @@ describe("Codex app-server startup binding", () => {
666653
agents: {
667654
defaults: {
668655
compaction: {
669-
truncateAfterCompaction: true,
670656
maxActiveTranscriptBytes: "1k",
671657
},
672658
},
@@ -698,7 +684,6 @@ describe("Codex app-server startup binding", () => {
698684
agents: {
699685
defaults: {
700686
compaction: {
701-
truncateAfterCompaction: true,
702687
maxActiveTranscriptBytes: 1_000,
703688
},
704689
},
@@ -744,7 +729,6 @@ describe("Codex app-server startup binding", () => {
744729
agents: {
745730
defaults: {
746731
compaction: {
747-
truncateAfterCompaction: true,
748732
maxActiveTranscriptBytes: "1mb",
749733
},
750734
},
@@ -790,7 +774,6 @@ describe("Codex app-server startup binding", () => {
790774
agents: {
791775
defaults: {
792776
compaction: {
793-
truncateAfterCompaction: true,
794777
maxActiveTranscriptBytes: "1mb",
795778
},
796779
},
@@ -843,7 +826,6 @@ describe("Codex app-server startup binding", () => {
843826
agents: {
844827
defaults: {
845828
compaction: {
846-
truncateAfterCompaction: true,
847829
maxActiveTranscriptBytes: "1mb",
848830
},
849831
},
@@ -887,7 +869,6 @@ describe("Codex app-server startup binding", () => {
887869
agents: {
888870
defaults: {
889871
compaction: {
890-
truncateAfterCompaction: true,
891872
maxActiveTranscriptBytes: "1mb",
892873
},
893874
},
@@ -990,7 +971,6 @@ describe("Codex app-server startup binding", () => {
990971
agents: {
991972
defaults: {
992973
compaction: {
993-
truncateAfterCompaction: true,
994974
maxActiveTranscriptBytes: 1_000,
995975
},
996976
},
@@ -1022,7 +1002,6 @@ describe("Codex app-server startup binding", () => {
10221002
agents: {
10231003
defaults: {
10241004
compaction: {
1025-
truncateAfterCompaction: true,
10261005
maxActiveTranscriptBytes: 1_000,
10271006
},
10281007
},

‎extensions/codex/src/app-server/startup-binding.ts‎

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -439,34 +439,42 @@ export async function rotateOversizedCodexAppServerStartupBinding(params: {
439439
binding.rolloutPath,
440440
);
441441
const compaction = readCompactionConfig(params.config);
442+
const maxBytes = parseCodexAppServerByteLimit(compaction?.maxActiveTranscriptBytes);
442443
const shouldDeferByteGuard =
443-
compaction?.truncateAfterCompaction === true &&
444+
maxBytes !== undefined &&
444445
params.contextEngineActive === true &&
445446
hasContextEngineThreadBootstrapProjection(binding);
446-
if (compaction?.truncateAfterCompaction === true && !shouldDeferByteGuard) {
447-
const maxBytes = parseCodexAppServerByteLimit(compaction.maxActiveTranscriptBytes);
448-
if (maxBytes !== undefined) {
449-
const oversizedFiles = rolloutFiles.filter((file) => file.bytes >= maxBytes);
450-
if (oversizedFiles.length > 0) {
451-
await Promise.all(
452-
rolloutFiles.map(async (file) => {
453-
await file.handle?.close();
454-
}),
455-
);
456-
embeddedAgentLog.warn(
457-
"codex app-server native transcript exceeded active byte limit; starting a fresh thread",
458-
{
459-
threadId: binding.threadId,
460-
maxBytes,
461-
files: oversizedFiles.map((file) => ({ path: file.path, bytes: file.bytes })),
462-
},
463-
);
464-
await params.bindingStore.mutate(params.identity, {
465-
kind: "clear",
447+
if (shouldDeferByteGuard) {
448+
embeddedAgentLog.debug(
449+
"codex app-server deferring native transcript byte guard for context-engine thread bootstrap",
450+
{
451+
threadId: binding.threadId,
452+
engineId: binding.contextEngine?.engineId,
453+
epoch: binding.contextEngine?.projection?.epoch,
454+
fingerprint: binding.contextEngine?.projection?.fingerprint,
455+
},
456+
);
457+
} else if (maxBytes !== undefined) {
458+
const oversizedFiles = rolloutFiles.filter((file) => file.bytes >= maxBytes);
459+
if (oversizedFiles.length > 0) {
460+
await Promise.all(
461+
rolloutFiles.map(async (file) => {
462+
await file.handle?.close();
463+
}),
464+
);
465+
embeddedAgentLog.warn(
466+
"codex app-server native transcript exceeded active byte limit; starting a fresh thread",
467+
{
466468
threadId: binding.threadId,
467-
});
468-
return undefined;
469-
}
469+
maxBytes,
470+
files: oversizedFiles.map((file) => ({ path: file.path, bytes: file.bytes })),
471+
},
472+
);
473+
await params.bindingStore.mutate(params.identity, {
474+
kind: "clear",
475+
threadId: binding.threadId,
476+
});
477+
return undefined;
470478
}
471479
}
472480
const nativeTokenSnapshots = await Promise.all(
@@ -520,20 +528,5 @@ export async function rotateOversizedCodexAppServerStartupBinding(params: {
520528
});
521529
return undefined;
522530
}
523-
if (compaction?.truncateAfterCompaction !== true) {
524-
return binding;
525-
}
526-
if (shouldDeferByteGuard) {
527-
embeddedAgentLog.debug(
528-
"codex app-server deferring native transcript byte guard for context-engine thread bootstrap",
529-
{
530-
threadId: binding.threadId,
531-
engineId: binding.contextEngine?.engineId,
532-
epoch: binding.contextEngine?.projection?.epoch,
533-
fingerprint: binding.contextEngine?.projection?.fingerprint,
534-
},
535-
);
536-
return binding;
537-
}
538531
return binding;
539532
}

‎src/agents/embedded-agent-runner/compact.hooks.test.ts‎

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4178,19 +4178,7 @@ describe("compactEmbeddedAgentSession hooks (ownsCompaction engine)", () => {
41784178
},
41794179
} as never);
41804180

4181-
const result = await compactEmbeddedAgentSession(
4182-
wrappedCompactionArgs({
4183-
config: {
4184-
agents: {
4185-
defaults: {
4186-
compaction: {
4187-
truncateAfterCompaction: true,
4188-
},
4189-
},
4190-
},
4191-
},
4192-
}),
4193-
);
4181+
const result = await compactEmbeddedAgentSession(wrappedCompactionArgs());
41944182

41954183
expect(result.ok).toBe(true);
41964184
expect(result.result?.sessionId).toBe(delegatedSessionId);
@@ -4543,19 +4531,7 @@ describe("compactEmbeddedAgentSession hooks (ownsCompaction engine)", () => {
45434531
sessionId: TEST_SESSION_ID,
45444532
},
45454533
} as never);
4546-
const result = await compactEmbeddedAgentSession(
4547-
wrappedCompactionArgs({
4548-
config: {
4549-
agents: {
4550-
defaults: {
4551-
compaction: {
4552-
truncateAfterCompaction: true,
4553-
},
4554-
},
4555-
},
4556-
},
4557-
}),
4558-
);
4534+
const result = await compactEmbeddedAgentSession(wrappedCompactionArgs());
45594535

45604536
expect(result.ok).toBe(true);
45614537
expect(rotateTranscriptAfterCompactionMock).not.toHaveBeenCalled();

‎src/agents/embedded-agent-runner/replay-history.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ export async function sanitizeSessionHistory(params: {
810810
// stripInvalidThinkingSignatures runs. Pre-compaction kept messages carry signatures
811811
// bound to the original prefix; after compaction the prefix changes and Anthropic
812812
// rejects them. Timestamp comparison with the latest compaction summary identifies
813-
// the affected messages regardless of path (standard or truncateAfterCompaction).
813+
// the affected messages regardless of which compaction path produced them.
814814
const compactionStaleStripped =
815815
signedThinkingProvider || policy.preserveSignatures
816816
? stripStaleThinkingSignaturesForCompactionReplay(sanitizedImages)

0 commit comments

Comments
 (0)