#16290: fix: add field-level validation for custom LLM provider config
agents
stale
size: M
Cluster:
Wizard Enhancements and Config Fixes
## Summary
- When configuring custom LLM providers (e.g. LiteLLM proxy to Azure OpenAI), omitting the `api` field from the provider config produces an unhelpful runtime error: `No API provider registered for api: undefined`
- This PR adds two layers of protection to catch this early and provide clear guidance:
1. **Zod schema validation**: `ModelProviderSchema` now emits a descriptive error when a provider has models but no `api` field, listing all valid values and suggesting `"openai-completions"` for proxy setups
2. **Runtime default**: `buildInlineProviderModels()` defaults `api` to `"openai-completions"` when neither model nor provider specifies it, preventing the undefined api error at runtime
## Test plan
- [x] New validation test suite (`config.provider-api-validation.test.ts`) — 5 cases covering: missing api warns, api set passes, empty models passes, per-model api passes, partial model api warns
- [x] Updated `model.test.ts` — 1 new test for default behavior, 2 updated expectations for the new default
- [x] All 391 existing config tests pass (59 test files, zero regressions)
- [x] All 16 model tests pass
Closes #6054
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR bundles three related fixes: (1) Zod schema validation that rejects custom LLM provider configs with models but no `api` field, providing a descriptive error listing valid values. (2) Runtime default of `"openai-completions"` in `buildInlineProviderModels()` and `resolveModel()` as defense-in-depth. (3) QMD memory manager concurrency deduplication and timer ordering fix.
- **Schema validation** (`zod-schema.core.ts`): Adds `superRefine` to `ModelProviderSchema` that rejects providers with models but no `api` field. Error message dynamically lists valid API types from `ModelApiSchema`. Note: this validation is **fatal** and blocks gateway startup.
- **Runtime default** (`model.ts`): Both `buildInlineProviderModels` and `resolveModel` now consistently default to `"openai-completions"` when no API is specified. The previous inconsistency (`"openai-responses"` in `resolveModel`) has been corrected.
- **QMD concurrency** (`search-manager.ts`): Adds `QMD_MANAGER_INFLIGHT` promise cache to dedupe concurrent `getMemorySearchManager()` calls, preventing duplicate QMD manager creation.
- **QMD timer ordering** (`qmd-manager.ts`): Reorders `initialize()` to arm the interval timer before the boot update, ensuring periodic updates continue even if boot fails.
- **`ISSUE_29_FIX.md` should be removed** — it's a development notes file committed to the repo root that duplicates information from commit messages and code comments.
<h3>Confidence Score: 3/5</h3>
- PR contains solid functional changes but includes a development artifact file that should be removed before merging.
- The code changes are sound: schema validation is correct, runtime defaults are consistent, concurrency deduplication is properly implemented, and timer ordering fix is a clear improvement. Tests cover the new behavior well. Score is 3 rather than 4 because (1) the ISSUE_29_FIX.md development notes file should not be committed, and (2) the PR scope is broader than the title suggests — it bundles LLM provider validation with unrelated QMD memory manager concurrency fixes.
- `ISSUE_29_FIX.md` should be removed — it is a development artifact that should not be in the repository.
<sub>Last reviewed commit: a21e718</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#16766: fix(model): apply provider baseUrl/headers override to registry-fou...
by dzianisv · 2026-02-15
81.5%
#19020: bugfix(gateway): Handle invalid model provider API config gracefully\…
by funkyjonx · 2026-02-17
80.8%
#2353: fix: ensure api field is set for inline provider models
by sbknana · 2026-01-26
79.1%
#19326: Agents: improve z.ai GLM-5 integration and failover
by gabrielespinheira · 2026-02-17
78.4%
#21977: Preserve provider API for discovered Ollama models
by graysurf · 2026-02-20
77.1%
#16838: fix: include configured fallbacks in model allowlist
by taw0002 · 2026-02-15
76.1%
#23211: fix: include modelByChannel in allowed channels validator
by westerbamos · 2026-02-22
76.0%
#20878: fix: Widen models.input to accept "video" and "audio" modalities
by marcodelpin · 2026-02-19
75.8%
#21638: fix(models): surface models.json validation errors instead of faili...
by aldoeliacim · 2026-02-20
75.8%
#20673: fix #20566: allow unknown fields in provider config
by neipor · 2026-02-19
75.7%