#12220: fix: forward-compat models now respect user-configured contextWindow
agents
stale
Cluster:
Context Window and Model Updates
## 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
#10831: fix(agents): set Opus 4.6 context window to 1M in forward-compat fa...
by slawt · 2026-02-07
90.6%
#13119: fix: add forward-compat for google-antigravity claude-opus-4-6 models
by sdb001 · 2026-02-10
84.9%
#6053: fix: use 400K context window instead of 200K if the model allows (g...
by icedac · 2026-02-01
82.4%
#11882: fix: accept openai-codex/gpt-5.3-codex model refs
by jackberger03 · 2026-02-08
81.5%
#18697: fix: include forward-compat models in model catalog for allowlist val…
by dmitry-orabey · 2026-02-17
80.9%
#19533: fix: allow forward-compat models in buildAllowedModelSet
by Anthony-g-dev · 2026-02-17
80.7%
#20747: feat(copilot): support Claude models with correct context windows (...
by yuf1011 · 2026-02-19
80.2%
#16891: fix(models): generic opus-4-6 forward-compat for all providers
by battman21 · 2026-02-15
80.0%
#11089: feat(compaction): support customInstructions and model override for...
by p697 · 2026-02-07
79.7%
#14508: fix(models): allow forward-compat models in allowlist check
by jonisjongithub · 2026-02-12
79.5%