Skip to content

[Bug]: Auto-compaction overflow recovery not triggering - no retry after token limit error #5433

@MillionthOdin16

Description

@MillionthOdin16

Bug Report

Description
Auto-compaction overflow recovery is not working. When a model request exceeds the context window, the documented flow should be:

  1. Model returns token limit error
  2. Auto-compaction triggers
  3. Original request is retried with compacted context

What Actually Happens:
The request fails with HTTP 400 and no auto-compaction or retry occurs. compactionCount remains 0.

Reproduction Steps

  1. Session accumulates context (93 lines in transcript, contextTokens: 204,800)
  2. Request is sent that exceeds model context limit
  3. Error returned: HTTP 400: Invalid request: Your request exceeded model token limit: 262144 (requested: 276742)
  4. Session shows compactionCount: 0 — no compaction ran
  5. No retry attempted

Actual Behavior

  • Error: exceeded model token limit: 262144 (requested: 276742)
  • compactionCount: 0 (checked in sessions.json)
  • No retry with compacted context
  • Session transcript shows no "type":"compaction" entries

Expected Behavior

Per documentation (/concepts/compaction.md):

"When a session nears or exceeds the model's context window, OpenClaw triggers auto-compaction and may retry the original request using the compacted context."

Expected flow:

  1. Error detected
  2. Auto-compaction runs
  3. Request retried with compacted context
  4. compactionCount increments

Configuration

agents:
  defaults:
    compaction:
      mode: "safeguard"
    contextPruning:
      mode: "off"

Session Details

  • Session ID: 446dd781-76a1-4bb8-bed3-d53e7038b75d
  • Session key: agent:default:telegram:dm:5437910345
  • Model at error: kimi-code/kimi-for-coding (262,144 context window)
  • Transcript lines: 93
  • contextTokens: 204,800
  • compactionCount: 0

Notes

  1. Error shows limit 262,144 which is kimi-for-coding's context window, even though session model shows glm-4.7 (200,000 limit). This suggests a fallback model switch occurred.
  2. Documentation references Pi runtime compaction settings like reserveTokens and keepRecentTokens, but these are not exposed in OpenClaw config. Overflow recovery may depend on these settings.
  3. The overflow recovery flow is documented but not executing — appears to be a bug in the retry logic.

Environment

  • OS: Linux 5.15.0-305.176.4.el9uek.aarch64 (arm64)
  • Node: v22.20.0
  • OpenClaw: dev channel, version 2026.1.29
  • Config: agents.defaults.compaction.mode: "safeguard"

Documentation Reference

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions