fix: disable Pi auto-compaction when safeguard mode is active#73839
Conversation
Greptile SummaryThis PR extends
Confidence Score: 3/5Not safe to merge until the CliCompactionDeps interface is updated; the missing compactionMode field causes a TypeScript compile error on the CLI path. One P1 finding: the CliCompactionDeps type was not updated to reflect the new compactionMode parameter, which will produce a TypeScript excess-property error at the cli-compaction call site. The fix is a one-line change but blocks the build. src/agents/command/cli-compaction.ts — CliCompactionDeps.applyPiAutoCompactionGuard type is missing the compactionMode field
|
| /** When "safeguard", OpenClaw owns the compaction lifecycle and Pi auto-compaction | ||
| * must be disabled to prevent threshold conflicts (see #73003). */ | ||
| compactionMode?: string; |
There was a problem hiding this comment.
Use the existing
AgentCompactionMode type instead of string
src/config/types.agent-defaults.ts already exports AgentCompactionMode = "default" | "safeguard". Using the narrow union type here (and in applyPiAutoCompactionGuard's signature) would catch invalid mode strings at compile time and make it obvious that "off" is not a real compaction mode value.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/pi-settings.ts
Line: 128-130
Comment:
**Use the existing `AgentCompactionMode` type instead of `string`**
`src/config/types.agent-defaults.ts` already exports `AgentCompactionMode = "default" | "safeguard"`. Using the narrow union type here (and in `applyPiAutoCompactionGuard`'s signature) would catch invalid mode strings at compile time and make it obvious that `"off"` is not a real compaction mode value.
How can I resolve this? If you propose a fix, please make it concise.|
Codex review: needs changes before merge. Summary Reproducibility: yes. Current-main source shows safeguard mode is not passed into the Pi auto-compaction guard, and the PR body supplies a Testbox probe showing the enabled-versus-disabled runtime switch. Real behavior proof Next step before merge Security Review findings
Review detailsBest possible solution: Restore the unrelated changelog escape change, keep the narrow safeguard guard implementation, rerun the affected checks, and land it as the fix for the linked safeguard compaction bug. Do we have a high-confidence way to reproduce the issue? Yes. Current-main source shows safeguard mode is not passed into the Pi auto-compaction guard, and the PR body supplies a Testbox probe showing the enabled-versus-disabled runtime switch. Is this the best way to solve the issue? Yes for the functional bug: extending the existing guard preserves default-mode Pi behavior while disabling the competing Pi lifecycle when OpenClaw owns safeguard compaction. The only safer adjustment is to revert the unrelated changelog escape change. Full review comments:
Overall correctness: patch is incorrect Acceptance criteria:
What I checked:
Likely related people:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 8b9b849b19c4. Re-review progress:
|
d8792c9 to
a2e2cb7
Compare
a2e2cb7 to
460615f
Compare
…aw#73003) When compaction.mode = "safeguard", OpenClaw's compaction is permanently blocked by Pi SDK's internal auto-compaction. The two systems operate on different thresholds and do not coordinate, causing consecutive already_compacted_recently failures and uncontrolled session growth. Extend shouldDisablePiAutoCompaction() to recognize safeguard mode in addition to context engines that own compaction. Pass compactionMode from both call sites (attempt.ts, cli-compaction.ts). Fixes openclaw#73003
460615f to
d554201
Compare
|
Merged via squash.
Thanks @bradhallett! |
Summary
Fixes #73003
When
compaction.mode = "safeguard", OpenClaw's safeguard compaction is permanently blocked by Pi SDK's internal auto-compaction. The two systems operate on different thresholds with no coordination, causing consecutivealready_compacted_recentlyfailures and uncontrolled session growth.Root Cause
shouldDisablePiAutoCompaction()only disables Pi auto-compaction when a context engine declaresownsCompaction === true. Safeguard mode has no context engine, so Pi auto-compaction remains active and conflicts with OpenClaw's own compaction lifecycle.Changes
src/agents/pi-settings.ts— ExtendshouldDisablePiAutoCompaction()to acceptcompactionModeand returntruewhen"safeguard". Thread the new param throughapplyPiAutoCompactionGuard().src/agents/pi-embedded-runner/run/attempt.ts— PasscompactionModefrom config to the guard.src/agents/command/cli-compaction.ts— Same for the CLI compaction path.src/agents/pi-settings.test.ts— Add 13 new tests:shouldDisablePiAutoCompaction: 6 tests (false by default, true for safeguard, true for ownsCompaction, both, false for other modes)applyPiAutoCompactionGuard: 3 tests (disables for safeguard, no-op for default, unsupported without setCompactionEnabled)Test plan
vitest run src/agents/pi-settings.test.ts— 50/50 pass (25 existing + 25 new across 2 shards)already_compacted_recentlycascade described in [Bug]: Safeguard compaction permanently blocked by Pi SDK auto-compaction (consecutive failures) #73003Real behavior proof
agent.state.messagesunderneath OpenClaw and trigger thealready_compacted_recentlycascade from [Bug]: Safeguard compaction permanently blocked by Pi SDK auto-compaction (consecutive failures) #73003.tbx_01kqxfh7kn5qnzcx5q623k9hkmon.github/workflows/ci-check-testbox.yml, with a fresh checkout and a temp config usingagents.defaults.compaction.mode = "safeguard"andplugins.load.paths = []so the local Lossless Claw/context-engine setup is not involved.a2e2cb7204709973c90455ce5a59a7d4143deea7tojalehman/clawdbot:test/pr-73839-real-proof, then ran a Testbox script that fetched bothorigin/mainand that PR head and executed the same probe against the real OpenClaw/PicreatePreparedEmbeddedPiSettingsManager,applyPiAutoCompactionGuard, andDefaultResourceLoader.reload()path./tmp/pr73839-real-proof-testbox.log:main, safeguard mode is active but Pi auto-compaction remains enabled through the guard/reload path. On the PR head, the same clean Testbox setup resolves safeguard mode, disables Pi auto-compaction, and keeps it disabled afterDefaultResourceLoader.reload()plus guard re-application. That verifies the patch changes the real runtime behavior that caused OpenClaw safeguard compaction to fight Pi's auto-compaction.already_compacted_recentlycascade end-to-end; the Testbox proof targets the direct real runtime switch that prevents Pi's competing compaction path from being armed in safeguard mode.