openclaw - 💡(How to fix) Fix compaction: absolute token thresholds break when switching models with different context windows

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…

Error Message

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.

Fix Action

Fix / Workaround

Workaround (current)

Code Example

{
  "softThresholdTokens": "40%",
  "reserveTokens": "4%",
  "keepRecentTokens": "2%",
  "reserveTokensFloor": "3%"
}
RAW_BUFFERClick to expand / collapse

Problem

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

ParameterTypeDeepSeek (1M)GLM-5.1 (200K)
softThresholdTokens (400K)absolute40%200% 💥
reserveTokens (40K)absolute4%20%
keepRecentTokens (20K)absolute2%10%
reserveTokensFloor (30K)absolute3%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

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