Repository navigation
[codex] Preserve recent tail for empty manual compact - #79297
Conversation
|
Codex review: needs real behavior proof before merge. Summary Reproducibility: yes. from source inspection: current main rewrites the latest manual compaction boundary to the compaction entry itself, and the PR's SessionManager scenario constructs the empty/no-op compaction case where that drops the kept tail. I did not run tests because this review is read-only. Real behavior proof Next step before merge Security Review detailsBest possible solution: Land a narrow fix that preserves manual checkpoint hardening for real summaries while leaving Pi's kept tail intact for blank or no-input compactions, with regression coverage and redacted after-fix runtime proof. Do we have a high-confidence way to reproduce the issue? Yes, from source inspection: current main rewrites the latest manual compaction boundary to the compaction entry itself, and the PR's SessionManager scenario constructs the empty/no-op compaction case where that drops the kept tail. I did not run tests because this review is read-only. Is this the best way to solve the issue? Yes, the proposed direction is the narrowest maintainable fix I found: skip boundary hardening only when the saved summary is blank or there were no input messages before the kept tail, while preserving existing hardening for real manual compactions. What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against c1c3e79a9d67. Re-review progress:
|
9596eff to
16e023a
Compare
16e023a to
ad7e4e8
Compare
Summary
Manual
/compactis unsafe in current OpenClaw when Pi prepares a compaction with no messages to summarize. This PR keeps manual compaction boundary hardening from rewriting those empty/no-op compactions into hard checkpoints, preserving the useful recent tail instead.Observed Behavior
A Telegram Pi session had real conversation history. Running
/compactproduced a checkpoint summary saying no conversation content was provided. The active session then dropped to only the empty compaction summary, losing the useful prior chat context.Root Cause
Pi compaction can return a valid preparation with
messagesToSummarize: 0when the actual transcript is below itskeepRecentTokensthreshold. It still calls the summarizer, so the model receives empty<conversation>tags and writes a no-content summary.OpenClaw then hardens manual compaction by rewriting
firstKeptEntryIdto the compaction entry itself, so rebuilt context starts at the empty summary and drops the kept recent messages.Culprit Commit
f4fcaa09a358347e9715067e1058c00b0f4567a1(feat(gateway): add compaction checkpoints, #62146) addedsrc/agents/pi-embedded-runner/manual-compaction-boundary.tsand wired manual compaction to callhardenManualCompactionBoundary()insrc/agents/pi-embedded-runner/compact.ts.That hardener changed manual compaction's
firstKeptEntryIdto the compaction entry id itself.Impact
Manual
/compactcan erase usable session context in edge cases. Auto compaction is less dangerous because it does not call the manual hardener, so it may keep recent messages even if the summary is bad. This is not caused by the recent sort-selection performance commits.Fix
Do not harden a manual compaction when the saved summary is blank or when the compaction input has no summarizable messages before the kept tail. In those cases, preserve Pi's recent tail instead of rewriting the boundary.
Verification
pnpm test src/agents/pi-embedded-runner/manual-compaction-boundary.test.ts -- --reporter=verbosepnpm exec oxfmt --check --threads=1 src/agents/pi-embedded-runner/manual-compaction-boundary.ts src/agents/pi-embedded-runner/manual-compaction-boundary.test.tsgit diff --check -- src/agents/pi-embedded-runner/manual-compaction-boundary.ts src/agents/pi-embedded-runner/manual-compaction-boundary.test.ts CHANGELOG.mdpnpm tsgo:corepnpm tsgo:core:testReal behavior proof
/compacton a Pi-backed gateway session with no summarizable messages must not turn an empty summary into a hard checkpoint that drops the recent conversation tail.pnpm tsxlive script that seeded a Pi session with a fresh user/assistant tail, startednode scripts/run-node.mjs gateway --port <loopback-port> --bind loopback --allow-unconfigured, called the realsessions.compactgateway RPC, then rebuilt session context from disk.<conversation>, but the compaction entry preserved Pi's originalfirstKeptEntryId; rebuilt context still included the fresh user question and assistant answer after the empty compaction summary.