openclaw - ✅(Solved) Fix Outer compaction pre-check misclassifies tool-heavy sessions as idle [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#73056Fetched 2026-04-28 06:28:05
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Participants
Timeline (top)
cross-referenced ×1

Root Cause

Because this guard only sees the raw session.messages slice (after limitHistoryTurns()), it has no preparation / turnPrefixMessages context to consult. steipete's split-turn fix for the inner safeguard was not mirrored here.

Fix Action

Fix / Workaround

#44138 was closed as fixed by the messagesToSummarize + turnPrefixMessages check in src/agents/pi-hooks/compaction-safeguard.ts:727 (shipped in 2026.3.22). That fix is present in 2026.4.15 — verified at dist/model-context-tokens-z5hvDVkk.js:4558-4561 of the published bundle.

PR fix notes

PR #73092: fix(compaction): bypass idle skip at token threshold

Description (problem / solution / changelog)

Summary

  • Pass fresh persisted token usage into manual /compact runs
  • Let over-threshold sessions continue past the outer no-real-conversation pre-check, even if the limited slice is tool-heavy
  • Keep idle/heartbeat-only sessions skipping when token usage is absent or below threshold

Fixes #73056

Validation

  • node scripts/run-vitest.mjs run --config test/vitest/vitest.agents.config.ts src/agents/pi-embedded-runner/compact.hooks.test.ts
  • node scripts/run-vitest.mjs run --config test/vitest/vitest.auto-reply-reply.config.ts src/auto-reply/reply/commands-compact.test.ts
  • pnpm exec oxfmt --check --threads=1 src/agents/pi-embedded-runner/compact.ts src/agents/pi-embedded-runner/compact.hooks.test.ts src/auto-reply/reply/commands-compact.ts src/auto-reply/reply/commands-compact.test.ts

Changed files

  • src/agents/pi-embedded-runner/compact.hooks.test.ts (modified, +50/-0)
  • src/agents/pi-embedded-runner/compact.ts (modified, +31/-1)
  • src/auto-reply/reply/commands-compact.test.ts (modified, +10/-2)
  • src/auto-reply/reply/commands-compact.ts (modified, +3/-2)

Code Example

Compaction skipped: no real conversation messages yet • Context 236k/200k (118%)
RAW_BUFFERClick to expand / collapse

Symptom

Manual /compact on a long, tool-heavy Discord-thread session reports:

Compaction skipped: no real conversation messages yet • Context 236k/200k (118%)

The session is clearly not idle — context is at 118%.

Why this is a separate issue from #44138

#44138 was closed as fixed by the messagesToSummarize + turnPrefixMessages check in src/agents/pi-hooks/compaction-safeguard.ts:727 (shipped in 2026.3.22). That fix is present in 2026.4.15 — verified at dist/model-context-tokens-z5hvDVkk.js:4558-4561 of the published bundle.

But the message above comes from a different code path: the outer pre-check that runs before the Pi SDK builds a preparation object.

  • Bundle: dist/compact-Fl3cALvc.js:910containsRealConversationMessages(session.messages)
  • Helper: dist/model-context-tokens-z5hvDVkk.js:3726isRealConversationMessage
  • Origin: CHANGELOG entry for #36451 — "Agents/compaction safeguard pre-check: skip embedded compaction before entering the Pi SDK when a session has no real conversation messages."

Because this guard only sees the raw session.messages slice (after limitHistoryTurns()), it has no preparation / turnPrefixMessages context to consult. steipete's split-turn fix for the inner safeguard was not mirrored here.

Failure mode

isRealConversationMessage accepts a toolResult only if a meaningful user message exists within the previous 20 entries. On long sessions where most recent activity is Read/Grep/Bash tool-call sequences, the trimmed window can land on a stretch of toolResult / heartbeat entries with no user message inside the 20-message lookback. Every entry then fails the test and the user sees the skip even though the session is at 118% of context and had plenty of real conversation upstream.

Repro shape

  • Long-running Discord-thread session, mostly tool calls (Read/Grep/Bash) interleaved with brief user prompts.
  • /compactCompaction skipped: no real conversation messages yet • Context 236k/200k (118%).
  • Sending a fresh plain-text user turn and re-running /compact succeeds.

Suggested fix direction

Mirror the intent of the inner-safeguard fix in the outer pre-check. Two options:

  1. Pass turnPrefixMessages (or equivalent prefix context) into the outer guard so it has the same view the inner safeguard now has.
  2. Bypass the outer pre-check entirely when the estimated token count is over the configured compaction threshold — a session at 118% of context window should never be short-circuited as "idle".

Option 2 is the conservative one and eliminates the misclassification risk without touching message-classification heuristics.

Environment

  • openclaw 2026.4.15
  • Channel: Discord thread session
  • Trigger: manual /compact

extent analysis

TL;DR

The issue can be resolved by bypassing the outer pre-check when the estimated token count exceeds the configured compaction threshold.

Guidance

  • Review the containsRealConversationMessages function in dist/compact-Fl3cALvc.js:910 to understand how it determines the presence of real conversation messages.
  • Consider implementing option 2 from the suggested fix direction, which involves bypassing the outer pre-check when the estimated token count is over the threshold.
  • Evaluate the impact of mirroring the inner-safeguard fix in the outer pre-check, as described in option 1 of the suggested fix direction.
  • Test the fix by reproducing the issue with a long-running Discord-thread session and verifying that compaction is no longer skipped when the context is above the threshold.

Example

No code snippet is provided due to the complexity of the issue and the need for a thorough review of the existing codebase.

Notes

The suggested fix direction provides two options, but option 2 is considered more conservative and eliminates the misclassification risk without touching message-classification heuristics.

Recommendation

Apply workaround: Bypass the outer pre-check entirely when the estimated token count is over the configured compaction threshold, as this approach is more conservative and reduces the risk of misclassification.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix Outer compaction pre-check misclassifies tool-heavy sessions as idle [1 pull requests, 1 participants]