Skip to content

fix(sdk): refuse a non-object discriminated-union input with a ValidationError - #5798

Merged
enyst merged 2 commits into
mainfrom
claude/umbrella-bug-fixes-tgz9ai-secrets-non-object
Oct 22, 2026
Merged

enyst merged 2 commits into
mainfrom
claude/umbrella-bug-fixes-tgz9ai-secrets-non-object

Conversation

@enyst

@enyst enyst commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

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

 DiscriminatedUnionMixin._validate_subtype(input)
   dict or existing model → existing kind dispatch
   scalar / list / null   → Pydantic validation error
                              └─ HTTP 422 at body.secrets.<NAME>

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
  • New tests fail on main with 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. Also tests/sdk/utils tests/sdk/event tests/sdk/security pass (1380 passed).
  • Map proof (private AGENT_SERVER_VERIFY_HOME, --fresh --repeat 2):
    • main (--checkout at 6a298a4): F04.create-secrets-plain xfail, xfail; F08.secrets-bad-value xfail, xfail.
    • this branch: both xpass, xpass.
    • after removing the markers: control-agent-server map check reports no problems; map run --file F04 --only F04.create-secrets-plain --fresh and map run --file F08 --only F08.secrets-bad-value --fresh pass.
  • uv run pre-commit run --files <changed files> passes.

Video/Screenshots

n/a

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

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

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python-slim amd64, arm64 python-node-runtime Link
python-minimal amd64, arm64 python-node-runtime Link
python amd64, arm64 python-node-runtime Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:972fc78-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-972fc78-python \
  ghcr.io/openhands/agent-server:972fc78-python

All tags pushed for this build

ghcr.io/openhands/agent-server:972fc78-golang-amd64
ghcr.io/openhands/agent-server:972fc7888600132e180f8f16d16a738426cb4320-golang-amd64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-secrets-non-object-golang-amd64
ghcr.io/openhands/agent-server:972fc78-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:972fc78-golang-arm64
ghcr.io/openhands/agent-server:972fc7888600132e180f8f16d16a738426cb4320-golang-arm64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-secrets-non-object-golang-arm64
ghcr.io/openhands/agent-server:972fc78-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:972fc78-java-amd64
ghcr.io/openhands/agent-server:972fc7888600132e180f8f16d16a738426cb4320-java-amd64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-secrets-non-object-java-amd64
ghcr.io/openhands/agent-server:972fc78-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:972fc78-java-arm64
ghcr.io/openhands/agent-server:972fc7888600132e180f8f16d16a738426cb4320-java-arm64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-secrets-non-object-java-arm64
ghcr.io/openhands/agent-server:972fc78-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:972fc78-python-amd64
ghcr.io/openhands/agent-server:972fc7888600132e180f8f16d16a738426cb4320-python-amd64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-secrets-non-object-python-amd64
ghcr.io/openhands/agent-server:972fc78-python-node-runtime-amd64
ghcr.io/openhands/agent-server:972fc78-python-arm64
ghcr.io/openhands/agent-server:972fc7888600132e180f8f16d16a738426cb4320-python-arm64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-secrets-non-object-python-arm64
ghcr.io/openhands/agent-server:972fc78-python-node-runtime-arm64
ghcr.io/openhands/agent-server:972fc78-python-minimal-amd64
ghcr.io/openhands/agent-server:972fc7888600132e180f8f16d16a738426cb4320-python-minimal-amd64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-secrets-non-object-python-minimal-amd64
ghcr.io/openhands/agent-server:972fc78-python-node-runtime-minimal-amd64
ghcr.io/openhands/agent-server:972fc78-python-minimal-arm64
ghcr.io/openhands/agent-server:972fc7888600132e180f8f16d16a738426cb4320-python-minimal-arm64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-secrets-non-object-python-minimal-arm64
ghcr.io/openhands/agent-server:972fc78-python-node-runtime-minimal-arm64
ghcr.io/openhands/agent-server:972fc78-python-slim-amd64
ghcr.io/openhands/agent-server:972fc7888600132e180f8f16d16a738426cb4320-python-slim-amd64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-secrets-non-object-python-slim-amd64
ghcr.io/openhands/agent-server:972fc78-python-node-runtime-slim-amd64
ghcr.io/openhands/agent-server:972fc78-python-slim-arm64
ghcr.io/openhands/agent-server:972fc7888600132e180f8f16d16a738426cb4320-python-slim-arm64
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-secrets-non-object-python-slim-arm64
ghcr.io/openhands/agent-server:972fc78-python-node-runtime-slim-arm64
ghcr.io/openhands/agent-server:972fc78-golang
ghcr.io/openhands/agent-server:972fc7888600132e180f8f16d16a738426cb4320-golang
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-secrets-non-object-golang
ghcr.io/openhands/agent-server:972fc78-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:972fc78-java
ghcr.io/openhands/agent-server:972fc7888600132e180f8f16d16a738426cb4320-java
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-secrets-non-object-java
ghcr.io/openhands/agent-server:972fc78-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:972fc78-python-minimal
ghcr.io/openhands/agent-server:972fc7888600132e180f8f16d16a738426cb4320-python-minimal
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-secrets-non-object-python-minimal
ghcr.io/openhands/agent-server:972fc78-python-node-runtime-minimal
ghcr.io/openhands/agent-server:972fc78-python-slim
ghcr.io/openhands/agent-server:972fc7888600132e180f8f16d16a738426cb4320-python-slim
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-secrets-non-object-python-slim
ghcr.io/openhands/agent-server:972fc78-python-node-runtime-slim
ghcr.io/openhands/agent-server:972fc78-python
ghcr.io/openhands/agent-server:972fc7888600132e180f8f16d16a738426cb4320-python
ghcr.io/openhands/agent-server:claude-umbrella-bug-fixes-tgz9ai-secrets-non-object-python
ghcr.io/openhands/agent-server:972fc78-python-node-runtime

About Multi-Architecture Support

  • Each variant tag (e.g., 972fc78-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., 972fc78-python-amd64) are also available if needed

…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
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014MKndVj7XWvRQmvW9w2bDg
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-sdk/openhands/sdk/utils
   models.py1733083%42–43, 84, 86, 94–98, 254–256, 259, 262, 266, 276, 314, 322, 325–326, 329, 380–381, 383–385, 387, 391, 393, 397
TOTAL50019841283% 

@enyst
enyst marked this pull request as ready for review October 13, 2026 23:42
@enyst
enyst requested a review from all-hands-bot October 13, 2026 23:42

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_input guards only the non-dict / non-instance case and delegates to the pydantic handler, so a string, number, null, or boolean now produces a ValidationError (model_type) instead of reaching data.pop("kind").
  • Independently reproduced the base behavior at 6a298a48: Animal.model_validate("plain") raises AttributeError: 'str' object has no attribute 'pop' ('int', 'NoneType', 'bool' likewise); a list raises TypeError. On this head all five inputs raise ValidationError at the correct loc.
  • 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_type checks 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 Schema and REST 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

@enyst
enyst merged commit efec2c3 into main Oct 22, 2026
59 of 60 checks passed
@enyst
enyst deleted the claude/umbrella-bug-fixes-tgz9ai-secrets-non-object branch October 22, 2026 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: A secret value that is not an object returns 500 "'str'/'int' object has no attribute 'pop'"

3 participants