fix: cap effective session context window by known model limit#152
Open
BingqingLyu wants to merge 11 commits into
Open
fix: cap effective session context window by known model limit#152BingqingLyu wants to merge 11 commits into
BingqingLyu wants to merge 11 commits into
Conversation
…window-cap # Conflicts: # .github/workflows/ci.yml # .secrets.baseline
…window-cap # Conflicts: # .secrets.baseline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes openclaw#39857
Summary
resolveContextTokensForModel()could return an override value even when OpenClaw already knew the selected model's smaller context window./status, so OpenClaw would over-report the effective context window for the active model.min(override, modelWindow); provider aliases are also normalized before reading configured model windows.Problem
This was a correctness bug in the effective context-window resolver, not just a display nit.
Before this PR, the resolver could treat
agents.defaults.contextTokens(or another context override) as authoritative even when the selected model's real window was already known and smaller.That meant OpenClaw could persist and report a context window that the active model does not actually have.
Affected paths include places that read the resolved
contextTokens, such as:/statusExample
If a user sets:
agents.defaults.contextTokens: 1048000and then uses a model whose known context window is smaller, OpenClaw could previously keep reporting
1048000instead of the model's real effective limit.The correct result is the smaller effective window.
Fix
The functional change is intentionally narrow:
cfg.models.providers, normalize provider names first so aliases likebedrockstill match configured entries likeamazon-bedrockWhy this is safe
This is fail-safe and correctness-preserving:
Validation
bunx vitest run src/agents/context.test.ts src/agents/models-config.merge.test.tsbunx vitest run src/plugins/loader.test.tspnpm checkScope note
A few later commits in this PR are CI-only follow-ups caused by
mainmoving during review. The product fix itself remains limited to effective context-window resolution and regression coverage for that bug.