fix: cap effective session context window by known model limit#39859
fix: cap effective session context window by known model limit#39859xdanger wants to merge 11 commits into
Conversation
Greptile SummaryThis PR fixes Key observations:
Confidence Score: 4/5
Last reviewed commit: cb318fa |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 46f30c0d52
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Addressed the current review feedback in What changed:
Local validation run:
I also reran a local |
e4c6ce8 to
2ddb4dd
Compare
|
Rebased onto current Addressed both review comments:
Local verification passed:
All review threads are resolved. Ready for /prepare-pr once the refreshed CI run is green. |
|
CI is green again. Follow-ups since the last note:
Ready for /prepare-pr. |
…window-cap # Conflicts: # .github/workflows/ci.yml # .secrets.baseline
|
Synced with latest Ready for /prepare-pr. |
|
/prepare-pr |
…window-cap # Conflicts: # .secrets.baseline
|
This pull request has been automatically marked as stale due to inactivity. |
|
Codex review: needs real behavior proof before merge. Workflow note: Future ClawSweeper reviews update this same comment in place. How this review workflow works
Summary Reproducibility: yes. source-level. Current main still has override-first shared resolver, session-store, and status-summary paths, so a configured override above a known model window can still be persisted or reported before the smaller model limit is considered. PR rating Rank-up moves:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. Real behavior proof Risk before merge
Maintainer options:
Next step before merge Security Review findings
Review detailsBest possible solution: Refresh or replace this with a current-main fix that reuses the existing provider-aware lookup, clamps only when a known model window exists, updates session/status duplicate paths, and includes focused tests plus redacted real behavior proof. Do we have a high-confidence way to reproduce the issue? Yes, source-level. Current main still has override-first shared resolver, session-store, and status-summary paths, so a configured override above a known model window can still be persisted or reported before the smaller model limit is considered. Is this the best way to solve the issue? No. The min-cap direction is right, but this stale diff is not the best current solution until it is rebased around the current provider-aware resolver contracts and covers the session/status bypasses it claims to fix. Label justifications:
Full review comments:
Overall correctness: patch is incorrect What I checked:
Likely related people:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 7f4bd454febf. |
|
ClawSweeper PR egg 🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat. Where did the egg go?
|
|
This pull request has been automatically marked as stale due to inactivity. |
|
ClawSweeper 🐠 reef update Thanks for the contribution. The source branch was not safely writable by ClawSweeper, so it opened a replacement PR and kept the credit trail visible. Why replacement: ClawSweeper could not update the source PR branch directly; GitHub did not grant sufficient push rights to the bot for that branch.
fish notes: model gpt-5.5, reasoning high; reviewed against 0ef2869. |
Fixes #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.