Repository navigation
fix(sdk): refuse a non-object discriminated-union input with a ValidationError - #5798
Conversation
…tionError
DiscriminatedUnionMixin._validate_subtype called data.pop("kind") on any
input, so a string, number, null or bool raised an AttributeError that
escaped pydantic validation. On the Agent Server a non-object secret value
(a plain string in the create body; a number, null or bool on
POST .../secrets) answered 500. Non-dict inputs now go straight to the
pydantic handler, which reports a model_type ValidationError (422).
Drops the known-bug markers of F04.create-secrets-plain and
F08.secrets-bad-value.
Fixes #5791
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014MKndVj7XWvRQmvW9w2bDg
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014MKndVj7XWvRQmvW9w2bDg
all-hands-bot
left a comment
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Review: PR #5798 — refuse a non-object discriminated-union input with a ValidationError
Scope. The change belongs in this repository. It fixes a genuine root cause in the SDK's DiscriminatedUnionMixin._validate_subtype (openhands-sdk/openhands/sdk/utils/models.py) and adds the agent-server regression coverage for the REST paths that surface it. The repository's own triage evidence (issue #5791, ready-for-dev; the verify-agent-server F04/F08 feature map) endorses 422 rejection for the create body, so the product direction is settled and no maintainer decision is needed.
Verification (current head 972fc7888600132e180f8f16d16a738426cb4320).
- Fix confirmed:
_is_object_inputguards only the non-dict / non-instance case and delegates to the pydantic handler, so a string, number,null, or boolean now produces aValidationError(model_type) instead of reachingdata.pop("kind"). - Independently reproduced the base behavior at
6a298a48:Animal.model_validate("plain")raisesAttributeError: 'str' object has no attribute 'pop'('int','NoneType','bool'likewise); a list raisesTypeError. On this head all five inputs raiseValidationErrorat the correctloc. - The new tests (
tests/sdk/utils/test_discriminated_union.py,tests/agent_server/test_conversation_router.py) assert observable behavior (422 +loc == ["body", "secrets", "PLAIN"], service not called) and are real regression protection: they fail on base with the pre-fix exception. - Focused suites pass locally:
tests/sdk/utils,tests/sdk/event,tests/sdk/security(1266 passed, 7 skipped, 12 xfailed) and the three cited test files (133 passed). - The feature-map prose and the
--expect 422/model_attributes_typechecks in F04 and F08 now match the implemented behavior. - Current-head CI is fully green (sdk-tests, agent-server-tests, cross-tests, REST API (OpenAPI), security, pre-commit, etc.).
Check OpenAPI SchemaandREST API (OpenAPI)pass, so there is no public-schema drift.
Non-blocking note (informational, no change requested). The plain-string asymmetry the PR documents is real on this head: POST /api/conversations/{id}/secrets still coerces "NAME": "value" via convert_string_secrets, while the create body now returns 422. The issue's triage selected rejection for the create body and the create schema (dict[str, SecretSource]) never accepted plain strings, so this is consistent with the agreed contract, not a defect. If maintainers later want parity, the alternative is the string coercion described in the PR, which would also widen the secrets OpenAPI schema and flip the F04 map expectation.
No material correctness, security, or compatibility defect found on the current head.
✅ APPROVED
HUMAN:
This PR proposes a fix for a bug uncovered during the first full agentic run of
verify-agent-server.AGENT:
Why
A scalar where a discriminated-union object was required escaped validation as an AttributeError and became HTTP 500.
Summary
Delegate non-object inputs to Pydantic before accessing
kind. The shared fix covers secrets, tools, events, policies and analyzers; HTTP tests assert that rejected secret payloads neither start nor modify a conversation.Source: models.py.
Issue Number
Fixes #5791
How to Test
Previously recorded verification
AttributeError: '<type>' object has no attribute 'pop'and pass here:uv run pytest tests/sdk/utils/test_discriminated_union.py tests/agent_server/test_conversation_router.py tests/agent_server/test_models.py. Alsotests/sdk/utils tests/sdk/event tests/sdk/securitypass (1380 passed).AGENT_SERVER_VERIFY_HOME,--fresh --repeat 2):--checkoutat 6a298a4):F04.create-secrets-plainxfail,xfail;F08.secrets-bad-valuexfail,xfail.xpass,xpass.control-agent-server map checkreports no problems;map run --file F04 --only F04.create-secrets-plain --freshandmap run --file F08 --only F08.secrets-bad-value --freshpass.uv run pre-commit run --files <changed files>passes.Video/Screenshots
n/a
Type
Notes
Create requests continue to reject plain-string secrets; the update-secrets endpoint still coerces strings to
StaticSecret. That deliberate asymmetry is retained from triage; widening create input remains the alternative described by the author. #5770 separately fixes mutation of dict inputs. Umbrella: #5653.Visual explanation by Codex using HumanLayer show-me.
🐳 Agent Server images for this PR — GHCR package, pull/run commands, and all pushed tags (click to expand)
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdkpython-node-runtimepython-node-runtimepython-node-runtimegolang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:972fc78-pythonRun
All tags pushed for this build
About Multi-Architecture Support
972fc78-python) is a multi-arch manifest supporting both amd64 and arm64972fc78-python-amd64) are also available if needed