Skip to content

fix(sessions): use model contextWindow instead of agent contextTokens in session listing - #15726

Closed
lailoo wants to merge 1 commit into
openclaw:mainfrom
lailoo:fix/sessions-context-tokens-fallback-15705
Closed

lailoo wants to merge 1 commit into
openclaw:mainfrom
lailoo:fix/sessions-context-tokens-fallback-15705

Conversation

@lailoo

@lailoo lailoo commented Feb 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #15705. Also addresses #15697.

The sessionsCommand fallback chain for configContextTokens incorrectly prioritized cfg.agents.defaults.contextTokens (the agent max buffer setting) over the model's actual context window. When users set a large buffer value (e.g. 1M), session listings showed inflated context windows and misleading token percentages.\n\n## Root Cause\n\nIn src/commands/sessions.ts, the fallback chain was:\n\ntypescript\nconst configContextTokens =\n cfg.agents?.defaults?.contextTokens ?? // agent buffer (e.g. 1M)\n lookupContextTokens(resolved.model) ?? // model's actual contextWindow\n DEFAULT_CONTEXT_TOKENS; // 200k\n\n\ncfg.agents.defaults.contextTokens is the agent's max buffer setting, not the model's context window. Because ?? only falls through on null/undefined, a configured value (e.g. 1_000_000) always wins, even when the model's actual context window is known.\n\n## Fix\n\nRemove cfg.agents.defaults.contextTokens from the fallback chain:\n\ntypescript\nconst configContextTokens =\n lookupContextTokens(resolved.model) ?? DEFAULT_CONTEXT_TOKENS;\n\n\n## Before / After\n\nBefore (agent buffer = 1M, model = MiniMax-M2.5-Omni with 204k context):\n\ndirect +15555550123 30m ago MiniMax-M2.5-Omni 60k/1000k (6%)\n\n\nAfter:\n\ndirect +15555550123 30m ago MiniMax-M2.5-Omni 60k/200k (30%)\n\n\n## Test Plan\n\n- Updated existing e2e test assertions to reflect correct fallback behavior\n- Added regression test verifying agents.defaults.contextTokens does not leak into display\n- All 4 tests pass: pnpm vitest run src/commands/sessions.e2e.test.ts --config vitest.e2e.config.ts

Greptile Overview

Greptile Summary

This PR updates sessionsCommand to derive the displayed context window from model metadata (lookupContextTokens(resolved.model)) and fall back to DEFAULT_CONTEXT_TOKENS, rather than incorrectly preferring cfg.agents.defaults.contextTokens (agent buffer size). The sessions e2e tests are updated accordingly and add a regression assertion to ensure agents.defaults.contextTokens does not affect the JSON/table display when the model context window is unknown.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk.
  • The change is narrowly scoped to a single fallback chain in sessionsCommand and aligns the displayed context window with model metadata, preventing misleading token percentages. Test updates and an explicit regression test cover the behavior change for both table and JSON outputs.
  • No files require special attention

Last reviewed commit: 058ef3f

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added stale Marked as stale due to inactivity and removed stale Marked as stale due to inactivity labels Feb 21, 2026
@steipete

Copy link
Copy Markdown
Contributor

Closing as AI-assisted stale-fix triage.

Linked issue #15705 ("fix(sessions): Use model contextWindow instead of agent contextTokens in session listing") is currently closed and was closed on 2026-02-14T02:11:08Z with state reason completed.
Given that issue is closed, this fix PR is no longer needed in the active queue and is being closed as stale.

If this specific implementation is still needed on current main, please reopen #15726 (or open a new focused fix PR) and reference #15705 for fast re-triage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(sessions): Use model contextWindow instead of agent contextTokens in session listing

2 participants