From a3bcb2c23265dd6bc571fd7522ca4f6475c1b9a6 Mon Sep 17 00:00:00 2001 From: kshitij <82637225+kshitijk4poor@users.noreply.github.com> Date: Wed, 12 Aug 2026 15:32:29 +0530 Subject: [PATCH] fix(tools): mirror misplaced-arg recovery on the terminal side MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Whole-bug-class sibling of the execute_code fix: terminal(code=...) — the reverse confusion — fell through to command=None and failed with 'Invalid command: expected string, got NoneType', naming neither the stray 'code' argument nor execute_code as the right tool. Mirror the guard in _handle_terminal (verified live: the opaque NoneType error reproduces on main). Mutation-checked: removing the guard fails the new regression test. --- tests/tools/test_code_execution.py | 12 ++++++++++++ tools/terminal_tool.py | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/tests/tools/test_code_execution.py b/tests/tools/test_code_execution.py index 10aab8bf0e..8e60206e38 100644 --- a/tests/tools/test_code_execution.py +++ b/tests/tools/test_code_execution.py @@ -577,6 +577,18 @@ class TestExecuteCodeEdgeCases(unittest.TestCase): self.assertIn("terminal(command=...)", result["error"]) self.assertIn("execute_code(code=...)", result["error"]) + def test_terminal_code_argument_points_to_execute_code(self): + """Mirror recovery: terminal(code=...) names the stray argument and + redirects to execute_code, instead of the opaque + 'Invalid command: expected string, got NoneType'.""" + from tools.terminal_tool import _handle_terminal + result = json.loads(_handle_terminal({"code": "print(1)"}, task_id="test")) + self.assertIn("error", result) + self.assertIn("'code' parameter", result["error"]) + self.assertIn("execute_code(code=...)", result["error"]) + self.assertIn("terminal(command=...)", result["error"]) + self.assertNotIn("NoneType", result["error"]) + def test_empty_code_explains_required_parameter(self): for code in ("", None): with self.subTest(code=code): diff --git a/tools/terminal_tool.py b/tools/terminal_tool.py index 0c1f742f39..16f1a53ecc 100644 --- a/tools/terminal_tool.py +++ b/tools/terminal_tool.py @@ -3786,6 +3786,17 @@ TERMINAL_SCHEMA = { def _handle_terminal(args, **kw): + # Mirror of execute_code's misplaced-argument recovery: models sometimes + # send execute_code's ``code`` argument here. Without this, the call + # falls through to command=None and fails with "Invalid command: + # expected string, got NoneType" — naming neither the stray argument + # nor the right tool. + if "command" not in args and "code" in args: + return tool_error( + "terminal received a 'code' parameter, but it requires a shell " + "command in 'command'. Use execute_code(code=...) for Python; " + "for shell, retry as terminal(command=...)." + ) return terminal_tool( command=args.get("command"), background=args.get("background", False),