feat: enhance model validation and error handling#243
Open
kerwin2046 wants to merge 8 commits into
Open
Conversation
- Added validation for provider models and models.json structure to ensure correct data format. - Implemented error reporting for invalid configurations, allowing for partial model loading despite configuration errors. - Updated ModelsData interface to include optional configError field for better error tracking.
feat: enhance model validation and error handling
- Added validation for provider models and models.json structure to ensure correct data format. - Implemented error reporting for invalid configurations, allowing for partial model loading despite configuration errors. - Updated ModelsData interface to include optional configError field for better error tracking.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug: models.json schema validation is all-or-nothing — one invalid model entry silently drops ALL custom providers
Reproduction:
Root cause:
ModelConfig.load() in pi-coding-agent uses Typebox schema validation on the entire models.json file. If ANY single field across ANY provider violates the schema (e.g., Type.String({ minLength: 1 }) rejects ""), the whole file is discarded and ModelConfig returns an empty providers Map. ModelRuntime.rebuildProviders() then has no custom providers to register, so modelRuntime.getAvailable() returns only builtins — silently.
The relevant code path:
models.json → ModelConfig.load() → validateModelsConfig.Check(parsed) → false → new ModelConfig(new Map(), error)
↘ true → new ModelConfig(parsedProviders)
Why it's insidious:
Fix (pi-web side, defense-in-depth):