#17604: fix(context): use getAvailable() to prevent cross-provider model ID collision in MODEL_CACHE
agents
stale
size: XS
Cluster:
Model Configuration Fixes
## Summary
`lookupContextTokens()` in `src/agents/context.ts` uses `modelRegistry.getAll()` which returns models from **all** built-in providers — including unconfigured ones. When multiple providers define the same model ID (e.g. `claude-sonnet-4-5`) with different `contextWindow` values, the last provider iterated overwrites the correct value in `MODEL_CACHE`.
## Fix
Switch from `getAll()` to `getAvailable()`, which filters to only providers with configured authentication. This prevents unconfigured providers from polluting the cache with incorrect context window values.
## Impact
- `/status` now shows correct context window
- Token budget calculations use accurate context size
- Session `contextTokens` field persisted correctly
## Testing
- Existing `context.test.ts` passes (2/2 tests)
- Build passes cleanly
Fixes #17586
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Fixes a cross-provider model ID collision in `MODEL_CACHE` by switching from `modelRegistry.getAll()` to `modelRegistry.getAvailable()` in `src/agents/context.ts`. When multiple providers define the same model ID (e.g. `claude-sonnet-4-5`) with different `contextWindow` values, `getAll()` would let unconfigured providers overwrite the correct value. Using `getAvailable()` filters to only providers with configured authentication, ensuring accurate context window values.
- Minimal one-line change that aligns with how `list.registry.ts` already distinguishes between "all models" (for display) and "available models" (for functional use)
- Both `getAll()` and `getAvailable()` return `Model<Api>[]`, so the existing type cast and downstream iteration logic remain correct
- Existing `context.test.ts` tests cover `applyConfiguredContextWindows` (which runs after the cache is populated) but not the cache population itself — this is acceptable since the fix is a straightforward API swap with the same return type
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge — it's a minimal, well-targeted one-line fix that uses the correct API for filtering to configured providers.
- The change is a single method call swap from getAll() to getAvailable(), both of which return the same type. The fix directly addresses the documented bug (cross-provider model ID collision) and is consistent with how the rest of the codebase uses getAvailable() for functional/operational purposes. No new code paths, no behavioral changes for correctly-configured providers, and the surrounding error handling remains intact.
- No files require special attention.
<sub>Last reviewed commit: d2eed6e</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#14744: fix(context): key MODEL_CACHE by provider/modelId to prevent collis...
by lailoo · 2026-02-12
88.9%
#15632: fix: use provider-qualified key in MODEL_CACHE for context window l...
by linwebs · 2026-02-13
88.3%
#23136: fix: lookupContextTokens should handle provider/model refs
by patchguardio · 2026-02-22
84.2%
#17414: fix(sessions): refresh contextTokens when model override changes
by michaelbship · 2026-02-15
81.5%
#18721: fix: prefer configured contextTokens over model catalog in status d...
by MisterGuy420 · 2026-02-17
81.3%
#12195: fix(agents): sync config fallback for lookupContextTokens cold-star...
by mcaxtr · 2026-02-09
81.1%
#6053: fix: use 400K context window instead of 200K if the model allows (g...
by icedac · 2026-02-01
80.2%
#13626: fix(model): propagate provider model properties in fallback resolution
by mcaxtr · 2026-02-10
79.9%
#16478: fix(gateway): fall back to lookupContextTokens on model switch
by colddonkey · 2026-02-14
79.1%
#15726: fix(sessions): use model contextWindow instead of agent contextToke...
by lailoo · 2026-02-13
78.5%