Bug
MODEL_CACHE uses a last-write-wins strategy when multiple providers register the same model ID with different context windows. There is no warning or conflict resolution — the last provider to load silently overwrites the previous value.
Example
The built-in anthropic provider correctly registers claude-opus-4-6 with a 1M context window. The opencode provider (from @mariozechner/pi-coding-agent) then overwrites it with 200K — and the values for Opus 4.6 and Sonnet 4.5 are actually swapped in that provider.
Because MODEL_CACHE silently accepts the last write, the wrong values propagate to session context limit calculations, causing:
- Opus 4.6 sessions to compact prematurely (200K limit instead of 1M)
- Sonnet 4.5 sessions to overflow (1M belief instead of ~200K, API rejects at ~195K)
Relevant Code
// reply-B_4pVbIX.js ~line 4188
if (typeof m.contextWindow === "number" && m.contextWindow > 0)
MODEL_CACHE.set(m.id, m.contextWindow);
No conflict check, no logging, no provider priority.
Suggestion
When a model ID is already in MODEL_CACHE with a different contextWindow, OpenClaw should either:
- Log a warning — so users can diagnose context window mismatches
- Prefer the larger value — safer default (premature compaction is worse than slightly delayed compaction)
- Use provider priority — e.g., the native provider for a model should win over third-party providers
Workaround
Using modelOverrides in the conflicting provider's models.json entry to patch values post-load:
{
"providers": {
"opencode": {
"modelOverrides": {
"claude-opus-4-6": { "contextWindow": 1000000 },
"claude-sonnet-4-5": { "contextWindow": 200000 }
}
}
}
}
Bug
MODEL_CACHEuses a last-write-wins strategy when multiple providers register the same model ID with different context windows. There is no warning or conflict resolution — the last provider to load silently overwrites the previous value.Example
The built-in
anthropicprovider correctly registersclaude-opus-4-6with a 1M context window. Theopencodeprovider (from@mariozechner/pi-coding-agent) then overwrites it with 200K — and the values for Opus 4.6 and Sonnet 4.5 are actually swapped in that provider.Because
MODEL_CACHEsilently accepts the last write, the wrong values propagate to session context limit calculations, causing:Relevant Code
No conflict check, no logging, no provider priority.
Suggestion
When a model ID is already in MODEL_CACHE with a different
contextWindow, OpenClaw should either:Workaround
Using
modelOverridesin the conflicting provider'smodels.jsonentry to patch values post-load:{ "providers": { "opencode": { "modelOverrides": { "claude-opus-4-6": { "contextWindow": 1000000 }, "claude-sonnet-4-5": { "contextWindow": 200000 } } } } }