Skip to content

fix(sdk): repair malformed arguments for optional Annotated fields - #6613

Merged
VascoSch92 merged 2 commits into
mainfrom
vasco/optional-annotated-repair
Nov 8, 2026
Merged

VascoSch92 merged 2 commits into
mainfrom
vasco/optional-annotated-repair

Conversation

@VascoSch92

@VascoSch92 VascoSch92 commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

HUMAN:

just fixing a bug


AGENT:

Why

fix_malformed_tool_arguments repairs two LLM quirks: list/dict arguments sent as JSON strings, and str arguments sent as arrays of chunks. It decides by the field's expected type, and it unwraps Annotated[X, ...] first, but only at the top level. For an optional field written as Annotated[list[int], Field(...)] | None, the union members are Annotated[...] and None, so the expected origins become [Annotated, NoneType] and neither repair runs. The action then fails validation on input the function is meant to fix.

Summary

Issue Number

Part of #6348 (item: "for Annotated[X, ...] | None the union args are not unwrapped, so the expected origin is Annotated and neither repair applies").

How to Test

uv run pytest tests/sdk/agent/test_fix_malformed_tool_arguments.py

test_optional_annotated_fields_are_repaired fails on main (the arguments come back unchanged) and passes here, returning {"items": [1, 2], "text": "ab"}; the file passes (25).

Type

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

🐳 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:09f03f2-python

Run

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

All tags pushed for this build

ghcr.io/openhands/agent-server:09f03f2-golang-amd64
ghcr.io/openhands/agent-server:09f03f27ec60562337ac344ba26b9bea28040b49-golang-amd64
ghcr.io/openhands/agent-server:vasco-optional-annotated-repair-golang-amd64
ghcr.io/openhands/agent-server:09f03f2-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:09f03f2-golang-arm64
ghcr.io/openhands/agent-server:09f03f27ec60562337ac344ba26b9bea28040b49-golang-arm64
ghcr.io/openhands/agent-server:vasco-optional-annotated-repair-golang-arm64
ghcr.io/openhands/agent-server:09f03f2-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:09f03f2-java-amd64
ghcr.io/openhands/agent-server:09f03f27ec60562337ac344ba26b9bea28040b49-java-amd64
ghcr.io/openhands/agent-server:vasco-optional-annotated-repair-java-amd64
ghcr.io/openhands/agent-server:09f03f2-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:09f03f2-java-arm64
ghcr.io/openhands/agent-server:09f03f27ec60562337ac344ba26b9bea28040b49-java-arm64
ghcr.io/openhands/agent-server:vasco-optional-annotated-repair-java-arm64
ghcr.io/openhands/agent-server:09f03f2-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:09f03f2-python-amd64
ghcr.io/openhands/agent-server:09f03f27ec60562337ac344ba26b9bea28040b49-python-amd64
ghcr.io/openhands/agent-server:vasco-optional-annotated-repair-python-amd64
ghcr.io/openhands/agent-server:09f03f2-python-node-runtime-amd64
ghcr.io/openhands/agent-server:09f03f2-python-arm64
ghcr.io/openhands/agent-server:09f03f27ec60562337ac344ba26b9bea28040b49-python-arm64
ghcr.io/openhands/agent-server:vasco-optional-annotated-repair-python-arm64
ghcr.io/openhands/agent-server:09f03f2-python-node-runtime-arm64
ghcr.io/openhands/agent-server:09f03f2-python-minimal-amd64
ghcr.io/openhands/agent-server:09f03f27ec60562337ac344ba26b9bea28040b49-python-minimal-amd64
ghcr.io/openhands/agent-server:vasco-optional-annotated-repair-python-minimal-amd64
ghcr.io/openhands/agent-server:09f03f2-python-node-runtime-minimal-amd64
ghcr.io/openhands/agent-server:09f03f2-python-minimal-arm64
ghcr.io/openhands/agent-server:09f03f27ec60562337ac344ba26b9bea28040b49-python-minimal-arm64
ghcr.io/openhands/agent-server:vasco-optional-annotated-repair-python-minimal-arm64
ghcr.io/openhands/agent-server:09f03f2-python-node-runtime-minimal-arm64
ghcr.io/openhands/agent-server:09f03f2-python-slim-amd64
ghcr.io/openhands/agent-server:09f03f27ec60562337ac344ba26b9bea28040b49-python-slim-amd64
ghcr.io/openhands/agent-server:vasco-optional-annotated-repair-python-slim-amd64
ghcr.io/openhands/agent-server:09f03f2-python-node-runtime-slim-amd64
ghcr.io/openhands/agent-server:09f03f2-python-slim-arm64
ghcr.io/openhands/agent-server:09f03f27ec60562337ac344ba26b9bea28040b49-python-slim-arm64
ghcr.io/openhands/agent-server:vasco-optional-annotated-repair-python-slim-arm64
ghcr.io/openhands/agent-server:09f03f2-python-node-runtime-slim-arm64
ghcr.io/openhands/agent-server:09f03f2-golang
ghcr.io/openhands/agent-server:09f03f27ec60562337ac344ba26b9bea28040b49-golang
ghcr.io/openhands/agent-server:vasco-optional-annotated-repair-golang
ghcr.io/openhands/agent-server:09f03f2-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:09f03f2-java
ghcr.io/openhands/agent-server:09f03f27ec60562337ac344ba26b9bea28040b49-java
ghcr.io/openhands/agent-server:vasco-optional-annotated-repair-java
ghcr.io/openhands/agent-server:09f03f2-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:09f03f2-python-minimal
ghcr.io/openhands/agent-server:09f03f27ec60562337ac344ba26b9bea28040b49-python-minimal
ghcr.io/openhands/agent-server:vasco-optional-annotated-repair-python-minimal
ghcr.io/openhands/agent-server:09f03f2-python-node-runtime-minimal
ghcr.io/openhands/agent-server:09f03f2-python-slim
ghcr.io/openhands/agent-server:09f03f27ec60562337ac344ba26b9bea28040b49-python-slim
ghcr.io/openhands/agent-server:vasco-optional-annotated-repair-python-slim
ghcr.io/openhands/agent-server:09f03f2-python-node-runtime-slim
ghcr.io/openhands/agent-server:09f03f2-python
ghcr.io/openhands/agent-server:09f03f27ec60562337ac344ba26b9bea28040b49-python
ghcr.io/openhands/agent-server:vasco-optional-annotated-repair-python
ghcr.io/openhands/agent-server:09f03f2-python-node-runtime

About Multi-Architecture Support

  • Each variant tag (e.g., 09f03f2-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., 09f03f2-python-amd64) are also available if needed

fix_malformed_tool_arguments unwraps a top-level Annotated, but not the
members of a union, so for Annotated[list[int], ...] | None the expected
origin was Annotated and neither the JSON-string nor the chunked-string
repair applied. Unwrap Annotated union members as well.
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@datadog-official

This comment has been minimized.

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-sdk/openhands/sdk/agent
   utils.py2361892%97–99, 104–105, 171, 188–189, 311, 313, 315, 321, 331, 421, 494, 680–681, 686
TOTAL54577851284% 

all-hands-bot
all-hands-bot previously approved these changes Nov 7, 2026
@all-hands-bot
all-hands-bot dismissed their stale review November 7, 2026 22:23

Reposting with the required review body; the prior submission had an empty body.

@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).

Scope

The change touches fix_malformed_tool_arguments in openhands-sdk/openhands/sdk/agent/utils.py, which is agent/tool behavior owned by this repository. It correctly targets the item pinned in #6348 ("for Annotated[X, ...] | None the union args are not unwrapped…"), and no other PR in this repo currently fixes that item.

Verification on head c238d340ce43a4a773fa3c599b6215b569a09473

  • uv run pytest tests/sdk/agent/test_fix_malformed_tool_arguments.py — 25/25 pass. The new test_optional_annotated_fields_are_repaired fails against main's implementation (arguments returned unchanged, matching the issue) and passes here, so the regression test has real failure detection and its expectations come from the issue's pinned case.
  • uv run pytest tests/sdk/agent/ — 998 passed.
  • Origin-computation check across annotation shapes: Annotated[list[int], Field(...)] | None, Optional[Annotated[...]], bare Annotated[str, ...], plain str | None, multi-member unions, nested Annotated, and subscripted generics wrapping Annotated all yield correct origins; existing plain-union members pass through the new conditional unchanged, so only the previously-broken Annotated-member case changes behavior.

Assessment

The fix mirrors the existing top-level Annotated unwrap onto each union member, which is the minimal correct repair. The resulting origins can only make the two intended repairs (_is_chunked_str_field requires str in origins without list/dict; JSON-string decoding requires an explicit list/dict origin) apply where they were previously skipped, so it cannot broaden repairs beyond the intent. The function's only caller is the tool-argument repair path in agent.py; the JSON-schema branch and no public/persisted/REST/OpenAPI surface are touched, so no cross-layer or compatibility work applies. test (3.13), cross-tests, agent-server-tests, and pre-commit all pass on this head.

One CI note, not attributable to this diff: the sdk-tests run on this head exited 1 with zero FAILED tests and no pytest summary — the log ends mid-stream after a passing test, consistent with a runner/infrastructure abort rather than a test failure (main's runs around the same time passed). Workspace execution of the affected suites passes cleanly. Worth a re-run, but not a code defect on this head.

Eval risk (per review guidance, informational): fix_malformed_tool_arguments can now repair more malformed calls for optional annotated fields; this only enables intended repairs and carries no prompt/description changes, so no evaluation evidence is required.

No material correctness, security, compatibility, or acceptance-criterion defects found.

✅ APPROVED

@VascoSch92
VascoSch92 enabled auto-merge (squash) November 7, 2026 22:47
#5796 rejects an MCP server with neither command nor url at config
validation, so {} can no longer reach the runtime and this case fails on
main. Same change as #6606.
@VascoSch92
VascoSch92 merged commit 91e92c6 into main Nov 8, 2026
43 checks passed
@VascoSch92
VascoSch92 deleted the vasco/optional-annotated-repair branch November 8, 2026 19:17
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.

2 participants