The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
fix(llm): reject invalid tool arguments
Iams4kura8eedb3d3deed
diff --git a/src/llm/providers/openai_compat.py b/src/llm/providers/openai_compat.pyindex a497eea2f..e1da6069e 100644--- a/src/llm/providers/openai_compat.py+++ b/src/llm/providers/openai_compat.py@@ -22,12 +22,17 @@ def _to_openai_tool_call_param(tool_call: ToolCall,) -> ChatCompletionMessageToolCallParam:"""Convert a domain tool call to the OpenAI request schema."""+ try:+ arguments = json.dumps(tool_call.arguments, allow_nan=False)+ except (TypeError, ValueError) as exc:+ raise ValueError("OpenAI tool call arguments must be valid JSON") from exc+return {"id": tool_call.id,"type": "function","function": {"name": tool_call.name,- "arguments": json.dumps(tool_call.arguments),+ "arguments": arguments,},}diff --git a/tests/test_provider_tools.py b/tests/test_provider_tools.pyindex e0bea308b..bdba6866d 100644--- a/tests/test_provider_tools.py+++ b/tests/test_provider_tools.py@@ -145,12 +145,36 @@ def test_openai_compatible_provider_serializes_assistant_tool_calls({"role": "tool", "content": "result", "tool_call_id": "call_1"},]- client.completions.params = None+ submitted_params = client.completions.paramswith pytest.raises(ValueError, match="tool messages require a tool_call_id"):provider.generate(LLMInput(messages=[Message(role=Role.TOOL, content="unlinked result")]))- assert client.completions.params is None+ assert client.completions.params is submitted_params++ for invalid_arguments in ({"score": float("nan")}, {"value": object()}):+ with pytest.raises(+ ValueError,+ match="tool call arguments must be valid JSON",+ ):+ provider.generate(+ LLMInput(+ messages=[+ Message(+ role=Role.ASSISTANT,+ content="",+ tool_calls=[+ ToolCall(+ id="call_invalid",+ name="score",+ arguments=invalid_arguments,+ )+ ],+ )+ ]+ )+ )+ assert client.completions.params is submitted_paramsdef test_openai_provider_can_be_constructed_without_credentials(monkeypatch):