#23299: fix(status): show runtime model context limit instead of stale session value
commands
size: XS
Cluster:
Context Window Fixes
## Summary
- **Problem:** When a session uses a runtime model different from the default (e.g. default is MiniMax M2.5 at 200k, runtime is google/gemini-3-pro-preview at 1M), the status display shows the default model's context limit instead of the runtime model's.
- **Why:** In \`buildSessionRows\`, \`entry?.contextTokens\` (set at session creation time for the default model) was checked before \`lookupContextTokens(model)\` (which resolves the actual runtime model's context window). When the model changes at runtime, the stored session value is stale.
- **What changed:** Swapped the priority so \`lookupContextTokens(resolvedModel)\` is checked first, falling back to \`entry?.contextTokens\` only if the lookup doesn't know the model.
- **What did NOT change:** The \`defaults\` section in the overview still shows the configured default model and its context. Per-session model resolution (\`resolveSessionModelRef\`) is unchanged.
## Change Type (select all)
- [x] Bug fix
- [ ] Feature
- [ ] Refactor
- [ ] Docs
- [ ] Security hardening
- [ ] Chore/infra
## Scope (select all touched areas)
- [ ] Gateway / orchestration
- [ ] Skills / tool execution
- [ ] Auth / tokens
- [ ] Memory / storage
- [ ] Integrations
- [ ] API / contracts
- [x] UI / DX
- [ ] CI/CD / infra
## Linked Issue/PR
- Closes #23122
## User-visible / Behavior Changes
- \`openclaw status\` Sessions table now shows the correct context limit for the runtime model, not the stale value from session creation
## Security Impact (required)
- New permissions/capabilities? \`No\`
- Secrets/tokens handling changed? \`No\`
- New/changed network calls? \`No\`
- Command/tool execution surface changed? \`No\`
- Data access scope changed? \`No\`
## Repro + Verification
### Steps
1. Configure a default model (e.g. MiniMax M2.5, 200k context)
2. Start a session and override the model to one with a different context window (e.g. google/gemini-3-pro-preview, 1M context)
3. Run \`openclaw status\`
### Expected
- Session row shows 1M context limit (matching runtime model)
### Actual (before fix)
- Session row shows 200k context limit (from default model, stored at session creation)
## Evidence
Before (line 134-135 in \`status.summary.ts\`):
\`\`\`typescript
const contextTokens =
entry?.contextTokens ?? lookupContextTokens(model) ?? configContextTokens ?? null;
\`\`\`
After:
\`\`\`typescript
const contextTokens =
lookupContextTokens(model) ?? entry?.contextTokens ?? configContextTokens ?? null;
\`\`\`
\`lookupContextTokens(model)\` uses the resolved runtime model, giving the correct context window. The stale \`entry?.contextTokens\` only applies as fallback for unknown/custom models.
## Human Verification (required)
- Verified scenarios: Confirmed \`resolveSessionModelRef\` correctly resolves runtime model; \`lookupContextTokens\` returns correct value for known models
- Edge cases checked: Unknown/custom models still fall back to stored value or config default
- What I did **not** verify: Live gateway testing with model override
## Compatibility / Migration
- Backward compatible? \`Yes\`
- Config/env changes? \`No\`
- Migration needed? \`No\`
## Failure Recovery (if this breaks)
If \`lookupContextTokens\` returns an unexpected value, the display would show wrong context but has no functional impact (display-only). Fallback chain preserved.
## Risks and Mitigations
Low risk — single line priority change in fallback chain, with existing fallbacks preserved.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Fixed stale context limit display in `openclaw status` by prioritizing runtime model lookup over session-stored value.
**Key Changes:**
- Swapped fallback priority in `status.summary.ts:135` from `entry?.contextTokens ?? lookupContextTokens(model)` to `lookupContextTokens(model) ?? entry?.contextTokens`
- Now shows correct context limit (1M) when runtime model differs from default (200k)
- `resolveSessionModelRef` correctly resolves runtime model from `entry.model`, so `lookupContextTokens(model)` gets the right value
**Issues Found:**
- `src/commands/sessions.ts:265` still uses the old priority order and should be updated for consistency
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge with one minor inconsistency to fix
- The fix correctly addresses the stale context limit display issue by prioritizing runtime model lookup. The logic is sound - `resolveSessionModelRef` gets the runtime model, then `lookupContextTokens` returns its context window. However, there's an identical pattern in `sessions.ts:265` that wasn't updated, creating an inconsistency where the two commands may show different context limits for the same session.
- Check `src/commands/sessions.ts:265` - needs the same priority swap for consistency
<sub>Last reviewed commit: 6c49fda</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#23279: fix: show correct context limit in status when runtime model differs
by Imccccc · 2026-02-22
86.1%
#17414: fix(sessions): refresh contextTokens when model override changes
by michaelbship · 2026-02-15
84.5%
#18886: fix(status): prefer configured contextTokens over model metadata
by BinHPdev · 2026-02-17
84.0%
#15726: fix(sessions): use model contextWindow instead of agent contextToke...
by lailoo · 2026-02-13
81.7%
#16478: fix(gateway): fall back to lookupContextTokens on model switch
by colddonkey · 2026-02-14
80.1%
#21731: Fix: clear stale session runtime model on /new, /reset, and session...
by AIflow-Labs · 2026-02-20
79.9%
#21932: fix(tui): eliminate stale model indicator lag in TUI
by graysurf · 2026-02-20
78.5%
#19412: fix(status): prefer configured contextTokens over session entry
by rafaelipuente · 2026-02-17
78.2%
#16609: fix: resolve session store race condition and contextTokens updates
by battman21 · 2026-02-14
78.2%
#23113: fix: show actual runtime version after update/restart when service ...
by BryanTegomoh · 2026-02-22
78.1%