← Back to PRs

#9822: fix: allow local/custom model providers for sub-agent inference

by stammtobias91 open 2026-02-05 18:31 View on GitHub →
agents stale
## Summary Fixes #7211. When a local model provider (Ollama or any OpenAI-compatible endpoint) is explicitly configured in `models.providers`, session model overrides pointing to those providers were silently rejected because the models did not appear in the piSdk model catalog. This caused `sessions_spawn` with `model: 'ollama/qwen2.5:7b'` (or any custom provider) to return `modelApplied: true` but actually fall back to the default Anthropic model at inference time. ## Root Cause Two code paths validated session model overrides against the model catalog without considering explicitly configured providers: 1. **`buildAllowedModelSet()`** (`model-selection.ts`): When `allowAny=true` (no explicit model allowlist), only catalog-discovered models were included in `allowedKeys`. Models from `cfg.models.providers` entries (e.g. Ollama, LM Studio, custom OpenAI-compatible endpoints) were missing. 2. **`createModelSelectionState()`** (`auto-reply/reply/model-selection.ts`): When a stored model override was not in `allowedKeys`, it was silently reset to the default model — even when the override pointed to a model from an explicitly configured provider. ## Fix - **`buildAllowedModelSet`**: In `allowAny` mode, also add model keys from `cfg.models.providers` so configured provider models are recognized as valid. - **`createModelSelectionState`**: Before resetting a session override, check if the override's provider is explicitly configured. If so, keep the override instead of resetting to default. Both changes are backwards-compatible: behavior is unchanged for hosted providers and for users with explicit model allowlists (the allowlist path already handled configured providers correctly). ## Test Added `model-selection.build-allowed-model-set-includes-configured-provider-models.test.ts` covering: - Ollama provider models included in `allowAny` mode - Custom-named providers (e.g. `local`) included in `allowAny` mode - Graceful handling of providers without `models` array ## Reproduction Config (from #7211) ```json5 { models: { mode: "merge", providers: { local: { baseUrl: "http://127.0.0.1:11434/v1", apiKey: "ollama-local", api: "openai-responses", models: [{ id: "qwen2.5:7b", name: "Qwen 2.5 7B", ... }] } } } } ``` Before this fix: `sessions_spawn(model: 'local/qwen2.5:7b')` → `modelApplied: true` but inference used `claude-opus-4-5`. After this fix: inference correctly uses the local model via the configured endpoint. <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR fixes session model overrides for local/custom providers by expanding the allowed-model key set and by preventing auto-reset of overrides when the override’s provider is explicitly configured in `cfg.models.providers`. Concretely: - `src/agents/model-selection.ts` extends `buildAllowedModelSet()` so that in `allowAny` mode it also includes model IDs declared under `models.providers.*.models[]`, not just catalog-discovered entries. - `src/auto-reply/reply/model-selection.ts` updates `createModelSelectionState()` to preserve/accept stored session overrides when the override’s provider is configured, even if the model key is missing from the curated catalog. - Adds a Vitest file to cover configured-provider models being present in `allowAny` mode and the “providers without models array” edge case. <h3>Confidence Score: 3/5</h3> - This PR is likely safe to merge after addressing a couple of correctness issues in provider-configuration detection and test imports. - Core logic change is small and covered by tests, but the configured-provider detection in `createModelSelectionState` appears to assume provider config keys are already normalized, which isn’t guaranteed, and the new test’s import path may not resolve depending on the repo’s module resolution settings. - src/auto-reply/reply/model-selection.ts, src/agents/model-selection.build-allowed-model-set-includes-configured-provider-models.test.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