Skip to content

Outer compaction pre-check misclassifies tool-heavy sessions as idle #73056

@petesimard

Description

@petesimard

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 fix(agents): skip compaction API call when session has no real messages #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

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleMarked as stale due to inactivity

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions