Skip to content

compaction: absolute token thresholds break when switching models with different context windows #87136

Description

@luzhidong

Problem

Four compaction parameters use absolute token counts, not relative percentages of the context window:

Parameter Type DeepSeek (1M) GLM-5.1 (200K)
softThresholdTokens (400K) absolute 40% 200% 💥
reserveTokens (40K) absolute 4% 20%
keepRecentTokens (20K) absolute 2% 10%
reserveTokensFloor (30K) absolute 3% 15%

Meanwhile, contextThreshold (0.75) and maxHistoryShare (0.8) correctly use ratios that scale with the context window.

Impact

When switching a session from a 1M-token model (e.g. deepseek-v4-pro) to a 200K-token model (e.g. zai/glm-5.1), softThresholdTokens=400000 exceeds the entire 200K context window. This causes immediate memory flush on every turn, preventing the context from ever building up — effectively rendering LCM unusable.

Every model change with a different context window requires manually editing the JSON config and restarting the gateway. This is error-prone and creates a silent footgun.

Proposed Fix

Allow percentage strings for these parameters (similar to how contextThreshold works):

{
  "softThresholdTokens": "40%",
  "reserveTokens": "4%",
  "keepRecentTokens": "2%",
  "reserveTokensFloor": "3%"
}

Resolved at runtime against the active model's context window. Backward-compatible: integer values keep the current behavior.

Workaround (current)

Manual JSON edit + gateway restart per model switch. Not sustainable.

Environment

  • openclaw 2026.5.20 (e510042)
  • macOS, Node 24

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions