-
-
Notifications
You must be signed in to change notification settings - Fork 69.5k
Model fallback ignores reasoning and uses wrong contextWindow/maxTokens #25636
Copy link
Copy link
Closed
Description
OpenClaw version: 2026.2.23
Describe the bug
The generic fallback in resolveModel() has two bugs when constructing a model from provider config:
reasoning: falsehardcoded — ignores the matched model'sreasoningsetting, preventingreasoning.effortfrom being forwarded to the API (e.g., Ollama models withreasoning: true)models[0]for contextWindow/maxTokens — reads from the first model in the provider's array instead of the matched model, causing incorrect context limits when multiple models are configured
Impact: Users running Ollama models with reasoning: true get minimal thinking output (~30 tokens) instead of deep reasoning (200+ tokens). Users with multiple models under a custom provider get wrong context windows.
Steps to reproduce
- Configure Ollama provider with a reasoning-capable model:
{
"models": {
"providers": {
"ollama": {
"baseUrl": "http://localhost:11434/v1",
"api": "openai-responses",
"models": [{
"id": "thinking-model",
"reasoning": true,
"contextWindow": 128000
}]
}
}
},
"agents": {
"defaults": {
"model": { "primary": "ollama/thinking-model" },
"thinkingDefault": "high"
}
}
}- Send a message that requires reasoning
- Check session history or gateway logs
Expected behavior
reasoning.effort: "high"should be included in API request- Model should produce detailed reasoning (200+ tokens)
- Context window should be 128000 (from config)
Actual behavior
- Gateway logs show
thinking=highbutreasoning.effortis not forwarded - Model produces minimal thinking (~30 tokens)
- Context window may be incorrect if multiple models configured
Root cause
src/agents/pi-embedded-runner/model.ts lines 103-115:
const fallbackModel: Model<Api> = normalizeModelCompat({
// ... other fields ...
reasoning: false, // ❌ Hardcoded, ignores matched model config
contextWindow: providerCfg?.models?.[0]?.contextWindow ?? DEFAULT_CONTEXT_TOKENS, // ❌ Wrong model
maxTokens: providerCfg?.models?.[0]?.maxTokens ?? DEFAULT_CONTEXT_TOKENS, // ❌ Wrong model
} as Model<Api>);Proposed fix
Find the matched model by ID and propagate its properties:
const matchedModel = (providerCfg?.models ?? []).find((m) => m.id.trim() === modelId.trim());
const fallbackModel: Model<Api> = normalizeModelCompat({
// ... other fields ...
reasoning: matchedModel?.reasoning ?? false, // ✅ From matched model
contextWindow: matchedModel?.contextWindow ?? DEFAULT_CONTEXT_TOKENS, // ✅ Correct model
maxTokens: matchedModel?.maxTokens ?? DEFAULT_CONTEXT_TOKENS, // ✅ Correct model
} as Model<Api>);Related
- Original report: [Bug]: reasoning.effort not forwarded to Ollama — only minimal thinking despite thinking=high #13575 (closed as stale, but bug persists)
- Previous PR attempt: fix(model): propagate provider model properties in fallback resolution #13626 (auto-closed)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Give feedbackNo fields configured for issues without a type.