From c238d340ce43a4a773fa3c599b6215b569a09473 Mon Sep 17 00:00:00 2001 From: VascoSch92 Date: Sat, 7 Nov 2026 23:02:39 +0100 Subject: [PATCH 1/2] fix(sdk): repair malformed arguments for optional Annotated fields 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. --- openhands-sdk/openhands/sdk/agent/utils.py | 6 +++++- .../agent/test_fix_malformed_tool_arguments.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/openhands-sdk/openhands/sdk/agent/utils.py b/openhands-sdk/openhands/sdk/agent/utils.py index 245a6ddbff9..461c936f7b3 100644 --- a/openhands-sdk/openhands/sdk/agent/utils.py +++ b/openhands-sdk/openhands/sdk/agent/utils.py @@ -190,7 +190,11 @@ def fix_malformed_tool_arguments( origin = get_origin(expected_type) if origin is Union or origin is types.UnionType: - type_args = get_args(expected_type) + # Unwrap Annotated members too, e.g. Annotated[list[int], ...] | None + type_args = [ + get_args(arg)[0] if get_origin(arg) is Annotated else arg + for arg in get_args(expected_type) + ] expected_origins = [get_origin(arg) or arg for arg in type_args] else: expected_origins = [origin or expected_type] diff --git a/tests/sdk/agent/test_fix_malformed_tool_arguments.py b/tests/sdk/agent/test_fix_malformed_tool_arguments.py index 96ded7d157f..57c5311fbb1 100644 --- a/tests/sdk/agent/test_fix_malformed_tool_arguments.py +++ b/tests/sdk/agent/test_fix_malformed_tool_arguments.py @@ -57,6 +57,13 @@ class StrOrListAction(Action): value: str | list[str] = Field(description="A str-or-list field") +class OptionalAnnotatedAction(Action): + """Optional fields whose inner type carries ``Annotated`` metadata.""" + + items: Annotated[list[int], Field(description="Optional list")] | None = None + text: Annotated[str, Field(description="Optional string")] | None = None + + class _NestedActionForMalformedArgs(Action): """Action with nested structures for testing JSON decoding. @@ -383,3 +390,11 @@ def test_str_or_list_field_list_passthrough(): action = StrOrListAction.model_validate(fixed_data) assert action.value == ["a", "b", "c"] + + +def test_optional_annotated_fields_are_repaired(): + data = {"items": "[1, 2]", "text": ["a", "b"]} + + fixed = fix_malformed_tool_arguments(data, OptionalAnnotatedAction) + + assert fixed == {"items": [1, 2], "text": "ab"} From 09f03f27ec60562337ac344ba26b9bea28040b49 Mon Sep 17 00:00:00 2001 From: VascoSch92 Date: Sun, 8 Nov 2026 20:08:36 +0100 Subject: [PATCH 2/2] test(sdk): drop the invalid-entry MCP case made obsolete by #5796 #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. --- tests/sdk/conversation/test_local_conversation_mcp.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/sdk/conversation/test_local_conversation_mcp.py b/tests/sdk/conversation/test_local_conversation_mcp.py index d8c7c661024..84594e7b0d0 100644 --- a/tests/sdk/conversation/test_local_conversation_mcp.py +++ b/tests/sdk/conversation/test_local_conversation_mcp.py @@ -297,7 +297,6 @@ def _failed_servers(caplog: pytest.LogCaptureFixture) -> list[str]: "broken", [ pytest.param(UNRESPONSIVE_SERVER, id="never-answers"), - pytest.param({}, id="invalid-entry"), pytest.param({"command": "missing-mcp-server-command"}, id="missing-command"), ], )