#13626: fix(model): propagate provider model properties in fallback resolution
agents
size: S
trusted-contributor
experienced-contributor
Cluster:
Model Configuration Fixes
## Summary
Fixes #13575
The generic fallback in `resolveModel()` had two bugs when constructing a model from provider config:
1. **`reasoning: false` hardcoded** — ignored the matched model's `reasoning` setting, preventing `reasoning.effort` from being forwarded to the API (e.g. Ollama models with `reasoning: true`)
2. **`models[0]` for contextWindow/maxTokens** — read from the first model in the provider's array instead of the matched model, causing incorrect context limits when multiple models are configured
The fix finds the matched model by ID from the provider config and propagates all its properties (`reasoning`, `input`, `cost`, `contextWindow`, `maxTokens`, `name`, `api`) instead of using hardcoded defaults or the first model in the array.
## Test plan
- [x] Add test: fallback does not bleed contextWindow from unrelated `models[0]`
- [x] Add test: fallback propagates reasoning from matched provider model
- [x] Add test: fallback uses correct model when provider has multiple models
- [x] All 3 new tests fail before the fix, pass after
- [x] All 13 tests pass (`npx vitest run src/agents/pi-embedded-runner/model.test.ts`)
- [x] `pnpm build && pnpm check` clean
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
Fixed two bugs in the generic fallback path of `resolveModel()` when constructing models from provider config:
- **`reasoning` propagation**: Previously hardcoded to `false`, now reads from matched model config (e.g., Ollama models with `reasoning: true`)
- **`contextWindow`/`maxTokens` selection**: Previously read from `models[0]` regardless of which model was requested, now reads from the matched model
Added comprehensive test coverage for all three scenarios (unmatched model using defaults, matched model with reasoning, multiple models selecting the correct one). The fix properly finds the matched model by trimmed ID and propagates all its properties (`reasoning`, `input`, `cost`, `contextWindow`, `maxTokens`, `name`, `api`). Previous review comments about trimming inconsistencies have been addressed in follow-up commits.
<h3>Confidence Score: 5/5</h3>
- Safe to merge with no blocking issues
- The implementation correctly fixes both documented bugs with proper test coverage. All three new tests target the exact scenarios described in the PR (bleeding contextWindow, reasoning propagation, multiple model selection). Previous review concerns about trimming have been addressed. The logic is straightforward and the changes are minimal and focused.
- No files require special attention
<!-- 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
85.9%
#11349: fix(agents): do not filter fallback models by models allowlist
by liuxiaopai-ai · 2026-02-07
84.7%
#23816: fix(agents): model fallback skipped during session overrides and pr...
by ramezgaberiel · 2026-02-22
83.5%
#3322: fix: merge provider config api into registry model
by nulone · 2026-01-28
83.4%
#9905: fix: require provider prefix for models set without alias (#5790)
by petter-b · 2026-02-05
83.4%
#23136: fix: lookupContextTokens should handle provider/model refs
by patchguardio · 2026-02-22
83.1%
#13188: fix: add cross-provider fallback when primary provider is rate-limited
by 1bcMax · 2026-02-10
82.9%
#22064: fix(failover): bypass models allowlist for configured fallback models
by winston-bepresent · 2026-02-20
82.8%
#15632: fix: use provider-qualified key in MODEL_CACHE for context window l...
by linwebs · 2026-02-13
82.7%
#16838: fix: include configured fallbacks in model allowlist
by taw0002 · 2026-02-15
82.5%