Fix: Fix revision commit endpoints silently discard unknown fields in…#4345
Conversation
… data Signed-off-by: justin212407 <charlesjustin2124@gmail.com>
|
@justin212407 is attempting to deploy a commit to the agenta projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThis PR enforces strict Pydantic validation across revision data models by adding ChangesStrict validation enforcement
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR tightens validation for workflow revision data payloads so unknown fields are rejected instead of silently discarded during commit operations.
Changes:
- Adds
extra="forbid"to SDKWorkflowRevisionData. - Adds a server-side strict
WorkflowRevisionDatawrapper. - Adds an application revision regression test for stale
ag_configpayloads returning 422.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
sdks/python/agenta/sdk/models/workflows.py |
Makes SDK workflow revision data reject unknown fields. |
api/oss/src/core/workflows/dtos.py |
Makes server workflow revision data reject unknown fields. |
api/oss/tests/pytest/acceptance/applications/test_application_variants_and_revisions.py |
Adds an acceptance test for application revision commit validation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@jp-agenta Could you review these changes once you are free? |
Signed-off-by: justin212407 <charlesjustin2124@gmail.com>
Signed-off-by: justin212407 <charlesjustin2124@gmail.com>
Signed-off-by: justin212407 <charlesjustin2124@gmail.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
Comments suppressed due to low confidence (2)
api/oss/src/core/testsets/dtos.py:160
extra="forbid"onTestsetRevisionDatachanges request validation behavior for/testsets/revisions/commit(unknown keys underdatawill now return 422 instead of being ignored). Please add/adjust acceptance tests to cover this new rejection path, so clients get a clear, stable error contract and we don’t regress back to silently dropping fields.
class TestsetRevisionData(BaseModel):
model_config = ConfigDict(extra="forbid")
testcase_ids: Optional[List[UUID]] = None
testcases: Optional[List[Testcase]] = None
api/oss/src/core/queries/dtos.py:146
- With
extra="forbid"onQueryRevisionData, unknown keys underdatawill now be rejected with 422 for/queries/revisions/commit. Add acceptance test coverage for this failure mode (assert status 422 and that the response mentions the offending key) to lock in the intended behavior and avoid future silent-drop regressions.
class QueryRevisionData(BaseModel):
model_config = ConfigDict(extra="forbid")
formatting: Optional[Formatting] = None
filtering: Optional[Filtering] = None
windowing: Optional[Windowing] = None
Signed-off-by: justin212407 <charlesjustin2124@gmail.com>
Signed-off-by: justin212407 <charlesjustin2124@gmail.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (3)
sdks/python/agenta/sdk/models/workflows.py:135
- The PR description claims a new acceptance test
test_commit_application_revision_rejects_unknown_data_fieldwas added, but it is not present inapi/oss/tests/pytest/acceptance/applications/test_application_variants_and_revisions.pyin this branch. Please add the described test (or update the PR description) so the stricterextra="forbid"behavior is protected against regressions.
class WorkflowRevisionData(BaseModel):
model_config = ConfigDict(extra="forbid")
uri: Optional[str] = None
url: Optional[str] = None
headers: Optional[Dict[str, Union[str, Reference]]] = None
runtime: Optional[Literal["python", "typescript", "javascript"]] = None
script: Optional[str] = None
schemas: Optional[JsonSchemas] = None
parameters: Optional[Data] = None
api/oss/src/core/testsets/dtos.py:160
- This changes
TestsetRevisionDatavalidation to reject unknown keys (extra="forbid"), which will make/testsets/revisions/commit(and any other endpoints consuming this DTO) return 422 for stale payload shapes. Please add an acceptance/regression test that exercises the commit endpoint with an unknown field and asserts the 422 error contains the offending key, to prevent reintroducing silent drops.
class TestsetRevisionData(BaseModel):
model_config = ConfigDict(extra="forbid")
testcase_ids: Optional[List[UUID]] = None
testcases: Optional[List[Testcase]] = None
api/oss/src/core/workflows/dtos.py:71
- The PR description says
extra="forbid"is set onWorkflowRevisionDatain this file, but the only explicitConfigDict(extra="forbid")is onWorkflowRevisionCommitData(which is not used byWorkflowRevisionCommit.data). If the goal is to make commit endpoints reject unknown fields via the server-side DTO, please apply the config on the actualWorkflowRevisionDatatype used by the commit/request models (or update the description to match the implementation).
class WorkflowRevisionData(BaseWorkflowRevisionData):
pass
WorkflowRevisionCommitData = WorkflowRevisionData
class WorkflowRevisionCommitData(BaseWorkflowRevisionData):
model_config = ConfigDict(extra="forbid")
Signed-off-by: justin212407 <charlesjustin2124@gmail.com>
|
this one got a little messy with all the commits opening the new one with the right changes. |
|
Hey I have made the new PR here - #4415. Please check this out. |
Although Pydantic v2 inherits model_config from WorkflowRevisionData, declaring extra="forbid" explicitly on ApplicationRevisionData and EvaluatorRevisionData (both API and SDK) makes the strict-validation contract grep-friendly and matches the per-domain expectation in Agenta-AI#4315. Also drop the now-unused ConfigDict import from workflows/dtos.py; WorkflowRevisionData inherits its strict config from the SDK base. Picked up from PR Agenta-AI#4415. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
What changed: Set
model_config = ConfigDict(extra="forbid")on every*RevisionDataDTO so revision-commit endpoints reject unknown top-level fields underdatainstead of silently dropping them. Pydantic now returns HTTP 422 naming the offending field.Strict configuration applied to all six revision-commit domains:
BaseWorkflowRevisionDatasdks/python/agenta/sdk/models/workflows.py—WorkflowRevisionDataapi/oss/src/core/applications/dtos.py—ApplicationRevisionDatasdks/python/agenta/sdk/models/workflows.py—ApplicationRevisionDataapi/oss/src/core/evaluators/dtos.py—EvaluatorRevisionDatasdks/python/agenta/sdk/models/workflows.py—EvaluatorRevisionDataapi/oss/src/core/testsets/dtos.py—TestsetRevisionDatasdks/python/agenta/sdk/models/testsets.py—TestsetRevisionDataapi/oss/src/core/queries/dtos.py—QueryRevisionDataapi/oss/src/core/environments/dtos.py—EnvironmentRevisionDataAlthough Pydantic v2 inherits
model_configfrom a strict parent, the explicit declarations onApplicationRevisionDataandEvaluatorRevisionDatamake the contract grep-friendly per domain.Why: Fixes #4315.
POST /{applications,workflows,evaluators,testsets,queries,environments}/revisions/commitused to accept unknown top-level fields insidedata(e.g. the legacyag_configwrapper) and silently discard them while returning HTTP 200 withcount: 1. Users got a false success signal and lost their payload.Additional changes
_normalize_configuration_for_legacy_pathsfromapi/oss/src/core/embeds/service.py. That helper injected a top-levelconfigurationkey into embed-resolution payloads, whichextra="forbid"would have rejected atWorkflowsService.resolve_workflow_revision. Legacyconfiguration.parameters.*shapes are no longer supported — the canonicalparameters.*path is the only one.Behavior change
data: {"ag_config": {...}}→ HTTP 200,count: 1, storeddata: {}.ag_confignamed in the validation error.This is a breaking change for any client still sending stale envelope shapes. Detection is straightforward: callers match on the 422 and migrate.
Testing
New SDK unit tests —
sdks/python/oss/tests/pytest/unit/test_revision_data_extra_forbid.py:WorkflowRevisionDataaccepts known fields, rejectsag_configand other unknowns.TestsetRevisionDataacceptstestcase_ids, rejectscsvdata.New acceptance tests —
api/oss/tests/pytest/acceptance/test_revision_commit_extra_forbid.py:/revisions/commitendpoints.datafield and asserts the response is 422 with the offending field named in the error body.Verified locally with
curl:{ "detail": [ { "type": "extra_forbidden", "loc": ["body", "application_revision_commit", "data", "ag_config"], "msg": "Extra inputs are not permitted", "input": { "prompt": { "messages": [{"role": "system", "content": "sys"}] } } } ] }Valid payloads with
data: {"parameters": {...}}continue to return HTTP 200 withcount: 1.Related issues
data#4315 — Revisions commit endpoints silently discard unknown fields indataunsupported#4173, POST /testsets/revisions/{id}/upload silently fails when testset_id is not set on the commit #4176 — sibling silent-failure-on-write bugs