Skip to content

[codex] Preserve recent tail for empty manual compact - #79297

Merged
scoootscooob merged 1 commit into
openclaw:mainfrom
scoootscooob:codex/fix-manual-compaction-tail
May 8, 2026
Merged

scoootscooob merged 1 commit into
openclaw:mainfrom
scoootscooob:codex/fix-manual-compaction-tail

Conversation

@scoootscooob

@scoootscooob scoootscooob commented May 8, 2026 •

Copy link
Copy Markdown
Member

Summary

Manual /compact is 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 /compact produced 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: 0 when the actual transcript is below its keepRecentTokens threshold. 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 firstKeptEntryId to 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) added src/agents/pi-embedded-runner/manual-compaction-boundary.ts and wired manual compaction to call hardenManualCompactionBoundary() in src/agents/pi-embedded-runner/compact.ts.

That hardener changed manual compaction's firstKeptEntryId to the compaction entry id itself.

Impact

Manual /compact can 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=verbose
  • pnpm exec oxfmt --check --threads=1 src/agents/pi-embedded-runner/manual-compaction-boundary.ts src/agents/pi-embedded-runner/manual-compaction-boundary.test.ts
  • git diff --check -- src/agents/pi-embedded-runner/manual-compaction-boundary.ts src/agents/pi-embedded-runner/manual-compaction-boundary.test.ts CHANGELOG.md
  • pnpm tsgo:core
  • pnpm tsgo:core:test

Real behavior proof

  • Behavior or issue addressed: Manual /compact on 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.
  • Real environment tested: Local macOS OpenClaw gateway from this PR branch, isolated temporary OpenClaw home/state, loopback gateway, Pi session storage, and a local OpenAI-compatible provider shim that returned an empty streamed compaction summary.
  • Exact steps or command run after this patch: Ran a pnpm tsx live script that seeded a Pi session with a fresh user/assistant tail, started node scripts/run-node.mjs gateway --port <loopback-port> --bind loopback --allow-unconfigured, called the real sessions.compact gateway RPC, then rebuilt session context from disk.
  • Evidence after fix: Terminal transcript:
compactRpcReturnedCompacted: true
providerSawEmptyConversation: true
compactionFirstKeptPreserved: true
compactionDidNotSelfBoundary: true
contextRolesPreserveTail: true
contextContainsFreshQuestion: true
contextContainsFreshAnswer: true
providerCalls: 1
summaryLength: 0
tokensAfter: 20
roles: ["compactionSummary","user","assistant"]
  • Observed result after fix: The gateway completed manual compact while the provider saw an empty <conversation>, but the compaction entry preserved Pi's original firstKeptEntryId; rebuilt context still included the fresh user question and assistant answer after the empty compaction summary.
  • What was not tested: No known gaps.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels May 8, 2026
@scoootscooob
scoootscooob marked this pull request as ready for review May 8, 2026 07:15
@clawsweeper

clawsweeper Bot commented May 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Summary
The PR updates manual compaction boundary hardening so blank or no-input manual compactions keep Pi's recent tail, adds two regression tests, and adds a changelog fix entry.

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
Needs real behavior proof before merge: The PR body lists tests/typechecks but no after-fix real Telegram/CLI/session proof; add redacted terminal output, logs, a screenshot, or a recording in the PR body so ClawSweeper can re-review automatically, or ask a maintainer to comment @clawsweeper re-review.

Next step before merge
Maintainer review is needed because the PR has protected maintainer routing and the contributor still needs to provide after-fix real behavior proof before merge.

Security
Cleared: The diff only changes compaction transcript logic, tests, and changelog text; it does not add dependencies, CI changes, secret handling, permissions, downloads, or new execution surfaces.

Review details

Best 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:

  • scoootscooob: Merged PR feat(gateway): add compaction checkpoints #62146 added compaction checkpoints, manual-compaction-boundary.ts, and the manual compaction hardening call path now affected by this bug. (role: introduced behavior; confidence: high; commits: f4fcaa09a358; files: src/agents/pi-embedded-runner/manual-compaction-boundary.ts, src/agents/pi-embedded-runner/compact.ts, src/gateway/session-compaction-checkpoints.ts)
  • steipete: Recent commits touched the same manual compaction boundary and adjacent transcript-maintenance path, including honoring manual keepRecentTokens and avoiding session manager opens. (role: recent maintainer; confidence: high; commits: 7920f8d4fdeb, f7fe6ad55eb0; files: src/agents/pi-embedded-runner/manual-compaction-boundary.ts, src/agents/pi-embedded-runner/compact.ts)
  • shakkernerd: Recent work in compact.ts adjusted compaction contributor selection and embedded-run snapshot handling near this path. (role: adjacent owner; confidence: medium; commits: 7d4011862ab3, 5655c2b0666d; files: src/agents/pi-embedded-runner/compact.ts)

Remaining risk / open question:

  • The PR lacks after-fix real behavior proof from a Telegram, CLI, gateway, or transcript run; the body only lists test/typecheck/format commands.
  • The branch is behind current main by 16 commits, so maintainers should rebase or re-check the touched surface before merge.
  • The protected maintainer label requires explicit maintainer handling even though the code diff is small.

Codex review notes: model gpt-5.5, reasoning high; reviewed against c1c3e79a9d67.

Re-review progress:

@scoootscooob
scoootscooob force-pushed the codex/fix-manual-compaction-tail branch 3 times, most recently from 9596eff to 16e023a Compare May 8, 2026 07:59
@scoootscooob
scoootscooob force-pushed the codex/fix-manual-compaction-tail branch from 16e023a to ad7e4e8 Compare May 8, 2026 08:00
@scoootscooob
scoootscooob merged commit 09f83bf into openclaw:main May 8, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant