openclaw - 💡(How to fix) Fix Session status displays stale contextTokens (128K) when agents.defaults.contextTokens overrides to 1M [1 comments, 2 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#78039Fetched 2026-05-06 06:17:41
View on GitHub
Comments
1
Participants
2
Timeline
2
Reactions
3
Author
Timeline (top)
closed ×1commented ×1

When a custom model is defined under models.providers.<provider>.models[] with contextWindow: 1000000, and agents.defaults.contextTokens is set to 1000000, the session status card still displays 128k context — even though the runtime correctly uses 1M.

Root Cause

The context window cache uses a "take minimum" policy in applyDiscoveredContextWindows():

const existing = params.cache.get(model.id);
if (existing === void 0 || contextTokens < existing) params.cache.set(model.id, contextTokens);

Load order:

  1. applyConfiguredContextWindows() runs first → sets the model to 1000000 from user config
  2. applyDiscoveredContextWindows() runs second → overwrites with 128000 because the provider plugin's forward-compat model builder hardcodes contextWindow: 128000 for unknown model IDs, and 128K < 1M satisfies the min-wins condition

The runtime correctly uses 1M because resolveContextTokensForModel() checks contextTokensOverride (from agents.defaults.contextTokens) before the cache lookup.

Code Example

const existing = params.cache.get(model.id);
if (existing === void 0 || contextTokens < existing) params.cache.set(model.id, contextTokens);

---

const contextTokens = resolvePositiveNumber(entry?.contextTokens)   // ← stored 128K from session creation
  ?? resolvePositiveNumber(transcriptUsage?.contextTokens)
  ?? resolvePositiveNumber(resolveContextTokensForModel({ ... }));  // ← never reached
RAW_BUFFERClick to expand / collapse

Description

When a custom model is defined under models.providers.<provider>.models[] with contextWindow: 1000000, and agents.defaults.contextTokens is set to 1000000, the session status card still displays 128k context — even though the runtime correctly uses 1M.

Root Cause

The context window cache uses a "take minimum" policy in applyDiscoveredContextWindows():

const existing = params.cache.get(model.id);
if (existing === void 0 || contextTokens < existing) params.cache.set(model.id, contextTokens);

Load order:

  1. applyConfiguredContextWindows() runs first → sets the model to 1000000 from user config
  2. applyDiscoveredContextWindows() runs second → overwrites with 128000 because the provider plugin's forward-compat model builder hardcodes contextWindow: 128000 for unknown model IDs, and 128K < 1M satisfies the min-wins condition

The runtime correctly uses 1M because resolveContextTokensForModel() checks contextTokensOverride (from agents.defaults.contextTokens) before the cache lookup.

How the Status Display Gets 128K

The session status card resolves context tokens as:

const contextTokens = resolvePositiveNumber(entry?.contextTokens)   // ← stored 128K from session creation
  ?? resolvePositiveNumber(transcriptUsage?.contextTokens)
  ?? resolvePositiveNumber(resolveContextTokensForModel({ ... }));  // ← never reached

Since entry.contextTokens is set at session creation (using the cached 128K), it never falls through to the override.

Impact

  • Display-only bug — runtime correctly uses configured context window
  • Confusing for users who set custom context windows and see the wrong number in /status
  • openclaw models list correctly shows 977k for the model

Possible Fixes

  1. Preferred: In applyDiscoveredContextWindows(), don't overwrite if a configured value already exists (configured > discovered priority)
  2. Alternative: Re-run configured context windows after discovered ones so user config always wins
  3. Status display fix: Have the status card use resolveContextTokensForModel() with the override, matching what the runtime actually uses

Reproduction

  1. Add a custom model under models.providers.<provider>.models[] with contextWindow: 1000000 for a model ID not in the provider's built-in catalog
  2. Set agents.defaults.contextTokens: 1000000
  3. Restart gateway, start new session
  4. /status → shows 128k instead of 1M
  5. openclaw models list → correctly shows 977k

Environment

  • OpenClaw 2026.5.4 (325df3e)

extent analysis

TL;DR

The most likely fix is to modify applyDiscoveredContextWindows() to prioritize configured values over discovered ones.

Guidance

  • Review the applyDiscoveredContextWindows() function to ensure it does not overwrite configured context window values with discovered ones.
  • Verify that the resolveContextTokensForModel() function is correctly using the contextTokensOverride from agents.defaults.contextTokens.
  • Consider re-running configured context windows after discovered ones to ensure user config always takes priority.
  • Update the status card to use resolveContextTokensForModel() with the override to match the runtime's behavior.

Example

const existing = params.cache.get(model.id);
if (existing === void 0 || (contextTokens > existing && !params.configured)) {
  params.cache.set(model.id, contextTokens);
}

This example code snippet demonstrates how to modify applyDiscoveredContextWindows() to prioritize configured values.

Notes

The provided fix only addresses the display issue and does not affect the runtime's correct usage of the configured context window.

Recommendation

Apply the workaround by modifying applyDiscoveredContextWindows() to prioritize configured values, as this approach directly addresses the root cause of the issue.

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 - 💡(How to fix) Fix Session status displays stale contextTokens (128K) when agents.defaults.contextTokens overrides to 1M [1 comments, 2 participants]