Repository navigation
fix(sdk): repair malformed arguments for optional Annotated fields - #6613
Conversation
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.
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
This comment has been minimized.
This comment has been minimized.
Reposting with the required review body; the prior submission had an empty body.
all-hands-bot
left a comment
There was a problem hiding this comment.
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 newtest_optional_annotated_fields_are_repairedfails againstmain'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[...]], bareAnnotated[str, ...], plainstr | None, multi-member unions, nestedAnnotated, and subscripted generics wrappingAnnotatedall yield correct origins; existing plain-union members pass through the new conditional unchanged, so only the previously-brokenAnnotated-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
HUMAN:
just fixing a bug
AGENT:
Why
fix_malformed_tool_argumentsrepairs 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 unwrapsAnnotated[X, ...]first, but only at the top level. For an optional field written asAnnotated[list[int], Field(...)] | None, the union members areAnnotated[...]andNone, 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
Annotatedon each union member before taking its origin, the same way the top-level annotation is already unwrapped.OptionalAnnotatedAction) without thexfailmarker.Issue Number
Part of #6348 (item: "for
Annotated[X, ...] | Nonethe union args are not unwrapped, so the expected origin is Annotated and neither repair applies").How to Test
test_optional_annotated_fields_are_repairedfails onmain(the arguments come back unchanged) and passes here, returning{"items": [1, 2], "text": "ab"}; the file passes (25).Type
🐳 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:09f03f2-pythonRun
All tags pushed for this build
About Multi-Architecture Support
09f03f2-python) is a multi-arch manifest supporting both amd64 and arm6409f03f2-python-amd64) are also available if needed