Repository navigation
fix: coerce quoted tool arguments on tool_call, Code Mode and Codex dynamic tools - #193200
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
|
Codex review: needs maintainer review before merge. What this changesApply direct-call argument coercion to validated OpenClaw tools invoked through Tool Search, Code Mode, and native harnesses. Example: Call sessions_history with limit:"1" and includeTools:"false" through dispatch_action.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a real argument-coercion inconsistency that remains on current main. The prior MCP finding is resolved, and no new correctness or security findings remain; required CI has not cleared. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherTool Search and native harnesses receive model arguments, prepare and validate them, execute host tools, and return tool results; the shared agent-core validator already handles coercion for direct calls. flowchart TD
A[Model tool arguments] --> B[Tool Search or native harness]
B --> C[Shared argument coercion]
C --> D[Policy hooks and final validation]
D --> E[OpenClaw tool execution]
B --> F[MCP arguments preserved]
E --> G[Tool results]
Technical reviewBest possible solution: Land the shared coercion repair once required checks clear, retaining final validation and external-tool schema ownership. Do we have a high-confidence way to reproduce the issue? Current-main source exposes the missing normalization, and supplied built-Gateway before/after traces demonstrate the route inconsistency; this read-only review ran no target code. Is this the best way to solve the issue? The patch is the smallest complete repair: reuse the existing coercion owner at the two shared boundaries, preserve invalid-input diagnostics, and leave MCP/client arguments under their existing owners. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 46982ac40764. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +47, Tests +37. Total +84 across 5 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (8 earlier review cycles)
Reviewed November 17, 2026, 10:02 AM ET / 15:02 UTC (Revision 9). |
|
CI note on 6aaa73f: That ceiling already includes this PR's 18-line allocation, so the base was 20 over before these changes. Still on me: the CLI or Gateway trace the review asked for. I'll post it here once I've run it. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
tool_call, Code Mode and harness dynamic-tool calls (Codex, Agents API) now run the agent loop's validateToolArguments coercion before their own schema checks, so "1"/"false" reach trusted tools as they do on direct calls. MCP and client tools keep their raw arguments.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Proof on exact head 3db0ca5 (dist-nodts build) and merge base 654a8a0, real Notes: cand1/cand2 ran commit 5523179 (the fix before the main merge); cand3 is the pushed head. The |
Codex always supplies validateArguments and skips MCP tools inside it, so coercion must use the same source classifier as the catalog route.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Thanks @ayaangazali for the fix. This is merged in 40437fa: |
…93200) Reuse direct-loop argument coercion for validated OpenClaw tool-search and harness execution. Preserve MCP argument bytes and existing invalid-input diagnostics. (cherry picked from commit 40437fa) Co-authored-by: Ayaan Zaidi <[email protected]> Co-authored-by: RomneyDa <[email protected]>
…ynamic tools (openclaw#193200) ## What Problem This Solves Root cause: src/agents/tool-search-runtime.ts:407 (`executeEntry`) and src/agents/harness/tool-invocation.ts:58 pass model arguments straight to a strict schema check, while direct agent-loop calls first run the shared coercion owner `validateToolArguments` (packages/agent-core/src/agent-loop-tool-execution.ts:54). So `"1"` / `"false"` that a direct call accepts are rejected on `tool_call` (`dispatch_action`), Code Mode, and Codex dynamic tools (`extensions/codex/src/app-server/dynamic-tool-catalog.ts:263`). Related: openclaw#166133 ## What changed - One helper, `coerceToolExecutionArguments` in `src/agents/agent-tools.execution-validation.ts`, calls the existing `validateToolArguments` owner. Input the schema still rejects is passed through unchanged, so each route's own validator and error text stay as they are. - `ToolSearchRuntime.executeEntry` uses it for every validated OpenClaw entry. That covers `tool_call` and Code Mode (`runtime.call`) together. The `coerceInput` option this PR first added is gone. - `runAgentHarnessToolInvocation` uses it after argument preparation, for OpenClaw-sourced tools on routes that validate arguments. That covers Codex dynamic tools and the Agents API. It uses the same `classifyAgentToolSource` the catalog uses, so Codex MCP tools keep their raw arguments even though Codex passes a validator callback for them too. - MCP and client tools keep their raw arguments, as before. Their schemas belong to their own servers (openclaw#114461). This builds on @ayaangazali's commits, which found the `tool_call` gap. The test-line allocation file and the agent-loop test are dropped. Coverage now lives in the existing runtime and harness suites, one regression per route boundary. ## Evidence Full capture: openclaw#193200 (comment) Real built Gateway (`ocx build --dist`, `gateway run`) with isolated state. A scripted OpenAI-compatible model sends the same quoted scalars down each route in one `chat.send` turn. The Codex route uses the real bundled Codex app-server with a local ChatGPT-backend fixture. Base is merge base 90e7da0. Each side ran twice. | route | base | this PR | |---|---|---| | direct `read` `{limit:"2"}` | 2 lines returned | unchanged | | `dispatch_action` -> `sessions_history` `{limit:"1", includeTools:"false"}` | `Invalid arguments ... limit: expected integer; received "1" (string)` | returns 1 message | | Code Mode `sessions_history({limit:"1", includeTools:"false"})` | `invalid_input`, `failureCode=input_contract` | `{messages:1, truncated:true}` | | Codex dynamic tool `sessions_history` (same args) | `Invalid arguments for tool "sessions_history": limit: must be integer; includeTools: must be boolean.` | returns 1 message | | control: `dispatch_action` `{limit:"abc"}` | rejected | still rejected before execution | Unit: `tool-search-runtime.test.ts` (quoted integer on `runtime.call`; MCP input stays raw) and `harness/tool-invocation.test.ts` (quoted scalars on a validated OpenClaw tool are coerced; an MCP tool's are not). The coercion cases fail on the base and pass here. Head e50e385 was re-run end to end after the MCP fix (cand4 in results). Items in the same signature cluster that this PR does not fix: - openclaw#172572 is DeepSeek union flattening in `provider-tools.ts`. That is a different root. - openclaw#177505 is a model inventing properties and actions, plus a retry-budget question. That is a different root. - openclaw#194865 is Code Mode declarations that show provider-projected string literals. With this PR, a call that follows that guidance (`"true"`) is coerced and accepted, but the declaration text itself is unchanged. Thanks @ayaangazali for the original fix and the trace. Co-authored-by: Ayaan Zaidi <[email protected]>
…ynamic tools (#193200) ## What Problem This Solves Root cause: src/agents/tool-search-runtime.ts:407 (`executeEntry`) and src/agents/harness/tool-invocation.ts:58 pass model arguments straight to a strict schema check, while direct agent-loop calls first run the shared coercion owner `validateToolArguments` (packages/agent-core/src/agent-loop-tool-execution.ts:54). So `"1"` / `"false"` that a direct call accepts are rejected on `tool_call` (`dispatch_action`), Code Mode, and Codex dynamic tools (`extensions/codex/src/app-server/dynamic-tool-catalog.ts:263`). Related: #166133 ## What changed - One helper, `coerceToolExecutionArguments` in `src/agents/agent-tools.execution-validation.ts`, calls the existing `validateToolArguments` owner. Input the schema still rejects is passed through unchanged, so each route's own validator and error text stay as they are. - `ToolSearchRuntime.executeEntry` uses it for every validated OpenClaw entry. That covers `tool_call` and Code Mode (`runtime.call`) together. The `coerceInput` option this PR first added is gone. - `runAgentHarnessToolInvocation` uses it after argument preparation, for OpenClaw-sourced tools on routes that validate arguments. That covers Codex dynamic tools and the Agents API. It uses the same `classifyAgentToolSource` the catalog uses, so Codex MCP tools keep their raw arguments even though Codex passes a validator callback for them too. - MCP and client tools keep their raw arguments, as before. Their schemas belong to their own servers (#114461). This builds on @ayaangazali's commits, which found the `tool_call` gap. The test-line allocation file and the agent-loop test are dropped. Coverage now lives in the existing runtime and harness suites, one regression per route boundary. ## Evidence Full capture: #193200 (comment) Real built Gateway (`ocx build --dist`, `gateway run`) with isolated state. A scripted OpenAI-compatible model sends the same quoted scalars down each route in one `chat.send` turn. The Codex route uses the real bundled Codex app-server with a local ChatGPT-backend fixture. Base is merge base 654a8a0. Each side ran twice. | route | base | this PR | |---|---|---| | direct `read` `{limit:"2"}` | 2 lines returned | unchanged | | `dispatch_action` -> `sessions_history` `{limit:"1", includeTools:"false"}` | `Invalid arguments ... limit: expected integer; received "1" (string)` | returns 1 message | | Code Mode `sessions_history({limit:"1", includeTools:"false"})` | `invalid_input`, `failureCode=input_contract` | `{messages:1, truncated:true}` | | Codex dynamic tool `sessions_history` (same args) | `Invalid arguments for tool "sessions_history": limit: must be integer; includeTools: must be boolean.` | returns 1 message | | control: `dispatch_action` `{limit:"abc"}` | rejected | still rejected before execution | Unit: `tool-search-runtime.test.ts` (quoted integer on `runtime.call`; MCP input stays raw) and `harness/tool-invocation.test.ts` (quoted scalars on a validated OpenClaw tool are coerced; an MCP tool's are not). The coercion cases fail on the base and pass here. Head e50e385 was re-run end to end after the MCP fix (cand4 in results). Items in the same signature cluster that this PR does not fix: - #172572 is DeepSeek union flattening in `provider-tools.ts`. That is a different root. - #177505 is a model inventing properties and actions, plus a retry-budget question. That is a different root. - #194865 is Code Mode declarations that show provider-projected string literals. With this PR, a call that follows that guidance (`"true"`) is coerced and accepted, but the declaration text itself is unchanged. Thanks @ayaangazali for the original fix and the trace. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 40437fa) Backport review: Coerce only classified OpenClaw tools using the existing argument validator; raw MCP tool arguments remain unchanged. Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit e8eb16303c0e055c3c8d2f6e6ebb45ded2381b2e)
…00679) (cherry picked from commit 7a55c60) Backport review: Required companion to #193200; retain private host invocation symbols across argument coercion so Code Mode collector replay remains functional. Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit b0e18e92d74deb8b334a6210595d045c7222e8ab)
What Problem This Solves
Root cause: src/agents/tool-search-runtime.ts:407 (
executeEntry) and src/agents/harness/tool-invocation.ts:58 pass model arguments straight to a strict schema check, while direct agent-loop calls first run the shared coercion ownervalidateToolArguments(packages/agent-core/src/agent-loop-tool-execution.ts:54). So"1"/"false"that a direct call accepts are rejected ontool_call(dispatch_action), Code Mode, and Codex dynamic tools (extensions/codex/src/app-server/dynamic-tool-catalog.ts:263).Related: #166133
What changed
coerceToolExecutionArgumentsinsrc/agents/agent-tools.execution-validation.ts, calls the existingvalidateToolArgumentsowner. Input the schema still rejects is passed through unchanged, so each route's own validator and error text stay as they are.ToolSearchRuntime.executeEntryuses it for every validated OpenClaw entry. That coverstool_calland Code Mode (runtime.call) together. ThecoerceInputoption this PR first added is gone.runAgentHarnessToolInvocationuses it after argument preparation, for OpenClaw-sourced tools on routes that validate arguments. That covers Codex dynamic tools and the Agents API. It uses the sameclassifyAgentToolSourcethe catalog uses, so Codex MCP tools keep their raw arguments even though Codex passes a validator callback for them too.This builds on @ayaangazali's commits, which found the
tool_callgap. The test-line allocation file and the agent-loop test are dropped. Coverage now lives in the existing runtime and harness suites, one regression per route boundary.Evidence
Full capture: #193200 (comment)
Real built Gateway (
ocx build --dist,gateway run) with isolated state. A scripted OpenAI-compatible model sends the same quoted scalars down each route in onechat.sendturn. The Codex route uses the real bundled Codex app-server with a local ChatGPT-backend fixture. Base is merge base 654a8a0. Each side ran twice.read{limit:"2"}dispatch_action->sessions_history{limit:"1", includeTools:"false"}Invalid arguments ... limit: expected integer; received "1" (string)sessions_history({limit:"1", includeTools:"false"})invalid_input,failureCode=input_contract{messages:1, truncated:true}sessions_history(same args)Invalid arguments for tool "sessions_history": limit: must be integer; includeTools: must be boolean.dispatch_action{limit:"abc"}Unit:
tool-search-runtime.test.ts(quoted integer onruntime.call; MCP input stays raw) andharness/tool-invocation.test.ts(quoted scalars on a validated OpenClaw tool are coerced; an MCP tool's are not). The coercion cases fail on the base and pass here. Head e50e385 was re-run end to end after the MCP fix (cand4 in results).Items in the same signature cluster that this PR does not fix:
provider-tools.ts. That is a different root."true") is coerced and accepted, but the declaration text itself is unchanged.Thanks @ayaangazali for the original fix and the trace.