[Serve] Fail fast on invalid fields in deployment and autoscaling configs - #62016
[Serve] Fail fast on invalid fields in deployment and autoscaling configs#62016javierdejesusda wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
The pull request effectively addresses the problem of silently ignored misconfigurations in Serve deployment and autoscaling configs by introducing extra="forbid" to relevant Pydantic models. This change significantly improves the developer experience by providing immediate feedback on invalid fields. The addition of comprehensive unit tests for all updated schemas, including regression tests for forward-compatible schemas, ensures the robustness and correctness of the changes. The fix for dict-to-model validation in DeploymentSchema is also a critical improvement, ensuring that extra="forbid" is applied even when configurations are provided as plain dictionaries.
1f34972 to
6a15e60
Compare
…figs Add extra="forbid" to Pydantic config schemas so that unrecognized fields raise a ValidationError immediately instead of being silently ignored. This addresses a usability issue where users could accidentally place fields like max_ongoing_requests inside autoscaling_config (instead of at the deployment level), and the misconfiguration would be silently swallowed. Schemas changed: - AutoscalingConfig, GangSchedulingConfig, RequestRouterConfig (config.py) - DeploymentSchema, RayActorOptionsSchema, gRPCOptionsSchema (schema.py) Deliberately unchanged (forward-compatible by design): - HTTPOptionsSchema, ServeDeploySchema, ServeApplicationSchema Also adds a before-validator to DeploymentSchema that validates dict inputs for autoscaling_config and request_router_config against their typed models, catching extra fields even when configs arrive as plain dicts from YAML. The dicts are intentionally kept as-is (not replaced with model instances) because downstream code relies on isinstance(field, dict) checks. Fixes ray-project#61439 Signed-off-by: javierdejesusda <javier.dejesusj9@gmail.com>
6a15e60 to
ed65af7
Compare
Signed-off-by: javierdejesusda <javier.dejesusj9@gmail.com>
|
This pull request has been automatically marked as stale because it has not had You can always ask for help on our discussion forum or Ray's public slack channel. If you'd like to keep this open, just leave any comment, and the stale label will be removed. |
|
Keeping this PR active — it is ready for maintainer review. Current state:
Summary of changes since the original submission:
@abrarsheikh — this directly implements the broader schema validation you asked for in #61529. Happy to iterate on the approach if there is a preferred direction for the microcheck failure. |

Why are these changes needed?
When users provide a faulty Serve deployment config (e.g., placing
max_ongoing_requestsinsideautoscaling_configinstead of at the deployment level), the misconfiguration is silently ignored and the default value is used instead. This leads to hard-to-debug production issues.As noted by @abrarsheikh in #61529:
This PR adds
extra="forbid"to all Serve config Pydantic models that are not explicitly forward-compatible, so unrecognized fields raise aValidationErrorimmediately.Changes
Config models updated (
extra="forbid"added):AutoscalingConfig(config.py) — previously silently accepted unknown fieldsGangSchedulingConfig(config.py)RequestRouterConfig(config.py)DeploymentSchema(schema.py) — extended existingmodel_configRayActorOptionsSchema(schema.py)ServeApplicationSchema(schema.py)gRPCOptionsSchema(schema.py)Deliberately unchanged (forward-compatible by design):
HTTPOptionsSchema— has explicit "allows extra parameters for forward-compatibility" noteServeDeploySchema— same forward-compatibility noteDict-to-model validation fix:
The
autoscaling_configfield onDeploymentSchemais typed asUnion[Dict, AutoscalingConfig], which means Pydantic matches any dict asDictfirst, bypassingAutoscalingConfigvalidation entirely. Extended the existingvalidate_gang_scheduling_configvalidator to also convertautoscaling_configandrequest_router_configdicts into their typed model equivalents before validation, ensuringextra="forbid"applies to dict inputs from YAML configs.Tests:
test_extra_fields_invalid_*tests (they previously asserted extras were accepted; now assertValidationError)HTTPOptionsSchemaandServeDeploySchemastill accept extrasRelated issue number
Fixes #61439
Supersedes stale #61529
Checks