[5641] fix(sdk): return 422 for invalid self-managed connections - #5732
[5641] fix(sdk): return 422 for invalid self-managed connections#5732Linxiushen wants to merge 3 commits into
Conversation
|
@Linxiushen is attempting to deploy a commit to the agenta projects Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe agent handler converts agent template validation failures into HTTP 422 responses. A dedicated error class identifies invalid template values. Tests cover invalid self-managed connections and invalid composition defaults. ChangesAgent template validation
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant AgentRequest
participant AgentHandler
participant AgentTemplate
AgentRequest->>AgentHandler: Submit agent template parameters
AgentHandler->>AgentTemplate: Call from_params
AgentTemplate-->>AgentHandler: Raise ValidationError
AgentHandler-->>AgentRequest: Return HTTP 422 validation error
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 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.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 214e51b7-f9ed-4ce3-b001-b62b29e6cb36
📒 Files selected for processing (3)
sdks/python/agenta/sdk/agents/dtos.pysdks/python/agenta/sdk/agents/handler.pysdks/python/oss/tests/pytest/unit/test_invoke_real_handlers_negotiation_routing.py
There was a problem hiding this comment.
🧹 Nitpick comments (1)
sdks/python/oss/tests/pytest/unit/test_invoke_real_handlers_negotiation_routing.py (1)
288-301: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider asserting the response body, not only the status code.
The test only checks
resp.status_code == 500. Add an assertion onresp.json()(for example, confirming the response does not surface the rawAgentTemplateValidationErrorshape used for the 422 case) to guard against a future regression where an invalid composition default is misclassified as a client error instead of an internal one.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 9702cd20-05bd-4493-82c4-eeb4c514831e
📒 Files selected for processing (2)
sdks/python/agenta/sdk/agents/handler.pysdks/python/oss/tests/pytest/unit/test_invoke_real_handlers_negotiation_routing.py
🚧 Files skipped from review as they are similar to previous changes (1)
- sdks/python/agenta/sdk/agents/handler.py
|
Addressed the latest review suggestion in |
Summary
Closes #5641.
Invalid agent connection values are parsed inside the agent handler, after FastAPI request-model validation. The resulting Pydantic
ValidationErrortherefore reached the workflow normalizer without a client-error status and was returned as HTTP 500.This change catches validation only around
AgentTemplate.from_params()and converts it to a typedAgentTemplateValidationErrorwith status 422. The narrow boundary keeps downstream/internal Pydantic failures visible as server errors while preserving the original field-level validation message for callers.Testing
Verified locally
24 passed:oss/tests/pytest/unit/test_invoke_real_handlers_negotiation_routing.py14 passed:oss/tests/pytest/unit/agents/test_agent_composition_seam.pyruff format --checkwith the CI-pinned Ruff 0.15.12ruff checkwith the CI-pinned Ruff 0.15.12Added or updated tests
Added a regression through the real FastAPI
/invokeroute. It submitsconnection: {mode: self_managed, slug: unused}, asserts HTTP 422 and the typed error URI, and verifies the original validation message is preserved.QA follow-up
Confirm the same request returns 422 in a deployed staging workflow service after the next build.
Demo
Checklist