← Back to PRs

#12220: fix: forward-compat models now respect user-configured contextWindow

by Batuhan4 open 2026-02-09 01:22 View on GitHub →
agents stale
## Problem When a user configures `contextWindow: 1000000` for `claude-opus-4-6` in their `openclaw.json` (to use Opus 4.6's 1M context window), the forward-compat model resolution ignores this value and inherits `contextWindow: 200000` from the `claude-opus-4-5` template. This causes Pi's auto-compaction to trigger at ~184K tokens (200K - 16K reserve) instead of the expected ~984K, effectively negating the user's configuration. ## Root Cause `resolveAnthropicOpus46ForwardCompatModel()` clones the template model (Opus 4.5) and only overrides `id` and `name`. It doesn't check if the user has configured model-specific properties like `contextWindow` or `maxTokens` in `openclaw.json`. The same issue exists in `resolveOpenAICodexGpt53FallbackModel()`. ## Fix Both forward-compat functions now: 1. Accept the `OpenClawConfig` as an optional parameter 2. Look up user-configured model properties from `cfg.models.providers` via a new `resolveInlineModelOverrides()` helper 3. Merge any user overrides (`contextWindow`, `maxTokens`, `reasoning`, `input`) on top of the template model This ensures that when a user explicitly configures properties for a forward-compat model, those values take precedence over the template defaults. ## Tests Added 2 new test cases: - `applies user-configured contextWindow to anthropic forward-compat model` — verifies Opus 4.6 gets 1M context from config instead of 200K from template - `applies user-configured contextWindow to codex forward-compat model` — verifies same behavior for Codex gpt-5.3 All 12 tests pass. <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR updates Pi embedded runner model resolution so forward-compat model fallbacks (Anthropic Opus 4.6 and OpenAI Codex GPT‑5.3) can apply model-specific overrides from `openclaw.json` (e.g. `contextWindow`, `maxTokens`, `reasoning`, `input`) on top of the cloned template model. It adds a small helper to extract inline overrides from `cfg.models.providers` and extends the forward-compat resolver functions to accept an optional `OpenClawConfig`. Two unit tests are added to verify `contextWindow` from user config is applied for both Anthropics’s Opus 4.6 and Codex GPT‑5.3 fallback paths. <h3>Confidence Score: 3/5</h3> - This PR is close to safe, but config-driven overrides may fail to apply in common configurations due to normalization/whitespace matching issues. - Core approach is small and well-tested, but the override lookup currently depends on exact provider key/id formatting in user config; if provider keys are not already normalized (or if ids contain incidental whitespace), the main promised behavior change may not occur. Fixing the matching logic should make the change reliable. - src/agents/pi-embedded-runner/model.ts <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs