← Back to PRs

#16290: fix: add field-level validation for custom LLM provider config

by superlowburn open 2026-02-14 15:48 View on GitHub →
agents stale size: M
## 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