Skip to content

fix: coerce quoted tool arguments on tool_call, Code Mode and Codex dynamic tools - #193200

Merged
obviyus merged 9 commits into
openclaw:mainfrom
ayaangazali:fix/tool-call-quoted-scalars
Nov 17, 2026
Merged

obviyus merged 9 commits into
openclaw:mainfrom
ayaangazali:fix/tool-call-quoted-scalars

Conversation

@ayaangazali

@ayaangazali ayaangazali commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

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 (fix(agents): compact tool search drops arguments and bypasses validation #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:

Thanks @ayaangazali for the original fix and the trace.

Copilot AI balanced review requested due to automatic review settings November 5, 2026 05:07
@clawsweeper

clawsweeper Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Nov 5, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 5, 2026
@clawsweeper

clawsweeper Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Apply 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.

  • Before: Validation rejects the quoted integer and boolean.
  • After: The tool receives limit:1 and includeTools:false and returns one message.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, useful repair with shipped-entry-point evidence and no remaining actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Supplied isolated built-Gateway chat.send evidence exercises dispatch_action, Code Mode, and the real Codex app-server with quoted sessions_history scalars, showing successful execution after the repair and continued rejection of limit:"abc"; the current body records an exact-head rerun after the MCP correction.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Agents encounter validation failures for quoted scalars through deferred and native tool routes despite equivalent direct calls succeeding.
Reason: Consistent execution semantics have concrete value, the repair uses an existing owner, and collaborator obviyus adopted and implemented the direction without introducing a configuration option or public API.

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
Reviewed head: e50e385cb34306c9085800cf7be572670b1a6f87

Before merge

None.

Findings

None.

Agent review details

How this fits together

Tool 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]
Loading

Technical review

Best 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

  • Tool Search input validation and external schemas keeps the original intent (4b9c922: Validate final trusted-tool arguments after policy hooks while preserving MCP/client schema ownership.)
  • Shared native invocation and argument snapshots keeps the original intent (51a27d4: Share host-tool preparation, validation, execution, and result bookkeeping across native harnesses; later snapshot work preserves executed argument custody.)
  • Rejected-input diagnostics changes intended behavior with a stated reason (1c93dbe: Show conservative received-type diagnostics without changing coercion in that diagnostic-only repair.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Sarah Fortune: Raw commit 51a27d4 adds src/agents/harness/tool-invocation.ts:57 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 51a27d44d5b7; files: src/agents/harness/tool-invocation.ts)

PR surface

Source +47, Tests +37. Total +84 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 51 4 +47
Tests 2 43 6 +37
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 94 10 +84

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove merge-risk: 🚨 compatibility: Current PR review selected no merge-risk labels.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Quoted scalar arguments cause avoidable tool failures on specific execution routes while direct calls already accept them.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (8 earlier review cycles)
  • reviewed 2026-11-05T05:26:52.333Z sha 3840a1a :: needs real behavior proof before merge. :: [P3] Resolve the added assertion-safety ratchet violation | [P3] Allocate the added regression test lines
  • reviewed 2026-11-05T19:25:10.325Z sha 6aaa73f :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-05T21:18:15.193Z sha 6aaa73f :: ready, awaiting a maintainer decision. :: none
  • reviewed 2026-11-06T21:32:32.126Z sha e4968bf :: blocked before merge. :: none
  • reviewed 2026-11-06T22:04:07.711Z sha eae41c5 :: ready, awaiting a maintainer decision. :: none
  • reviewed 2026-11-07T01:55:39.262Z sha f66cbe8 :: ready, awaiting a maintainer decision. :: none
  • reviewed 2026-11-17T14:42:52.295Z sha 3db0ca5 :: needs changes before merge. :: [P2] Preserve raw MCP arguments in the native harness
  • reviewed 2026-11-17T14:56:22.289Z sha e50e385 :: needs maintainer review before merge. :: none

Reviewed November 17, 2026, 10:02 AM ET / 15:02 UTC (Revision 9).

@ayaangazali

Copy link
Copy Markdown
Contributor Author

CI note on 6aaa73f: checks-fast-baseline-ratchets is red only on test-lines, and that part isn't from this diff.

Test lines: 6479520; ceiling: 6479500; over by: 20; net delta: +18.

That ceiling already includes this PR's 18-line allocation, so the base was 20 over before these changes. main was 20 over at 1e101d0 too, and by my count it was back at its ceiling at 94bea34, so this should clear on a newer base. assertion-safety passes on this head.

Still on me: the CLI or Gateway trace the review asked for. I'll post it here once I've run it.

@ayaangazali

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 5, 2026
@ayaangazali

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Nov 5, 2026
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.
@obviyus

obviyus commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus

obviyus commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Proof on exact head 3db0ca5 (dist-nodts build) and merge base 654a8a0, real gateway run with isolated state, scripted model, real Codex app-server for the Codex row. One chat.send turn per route.

== base1 sha=654a8a05fb59f10f6cbc85294c095649e619397d
main read             ok    line-1
line-2

[3 more lines in file. Use offset=3 to continue.]
tc   dispatch_action  ERROR Invalid arguments for tool "openclaw:core:sessions_history": limit: expected integer; received "1" (string); includeTools: expected boolean; received "false" (string). Ex
cm   exec             ERROR Error: Invalid arguments for tool "sessions_history": limit: expected integer; received "1" (string); includeTools: expected boolean; received "false" (string). Expected 
cx   sessions_history ERROR Invalid arguments for tool "sessions_history": limit: must be integer; includeTools: must be boolean.
== base2 sha=654a8a05fb59f10f6cbc85294c095649e619397d
main read             ok    line-1
line-2

[3 more lines in file. Use offset=3 to continue.]
tc   dispatch_action  ERROR Invalid arguments for tool "openclaw:core:sessions_history": limit: expected integer; received "1" (string); includeTools: expected boolean; received "false" (string). Ex
tc   dispatch_action  ERROR Invalid arguments for tool "openclaw:core:sessions_history": limit: expected integer; received [redacted] (string). Expected input: { sessionKey: string; includeTools?: b
cm   exec             ERROR Error: Invalid arguments for tool "sessions_history": limit: expected integer; received "1" (string); includeTools: expected boolean; received "false" (string). Expected 
cx   sessions_history ERROR Invalid arguments for tool "sessions_history": limit: must be integer; includeTools: must be boolean.
== cand1 sha=d5e03d266a37d4c0514285ed27b21e8bbbfb237f+worktree
main read             ok    line-1
line-2

[3 more lines in file. Use offset=3 to continue.]
tc   dispatch_action  ok    {"tool":{"id":"openclaw:core:sessions_history","name":"sessions_history","source":"openclaw"},"result":{"content":[{"type":"text","text":"{"sessionKey":"agent:tc:p193200"
cm   exec             ok    {"status":"completed","telemetry":{"catalogSize":62,"sources":{"openclaw":62,"mcp":0,"client":0},"counterScope":"c14e72c9738d066ad0624c84","searchCount":0,"describeCount"
cx   sessions_history ok    {"sessionKey":"agent:cx:p193200","messages":[{"role":"assistant","content":[{"type":"toolCall","id":"call_p193200_codex","name":"sessions_history","arguments":{"sessionKe
== cand2 sha=d5e03d266a37d4c0514285ed27b21e8bbbfb237f+worktree
main read             ok    line-1
line-2

[3 more lines in file. Use offset=3 to continue.]
tc   dispatch_action  ok    {"tool":{"id":"openclaw:core:sessions_history","name":"sessions_history","source":"openclaw"},"result":{"content":[{"type":"text","text":"{"sessionKey":"agent:tc:p193200"
tc   dispatch_action  ERROR Invalid arguments for tool "openclaw:core:sessions_history": limit: expected integer; received [redacted] (string). Expected input: { sessionKey: string; includeTools?: b
cm   exec             ok    {"status":"completed","telemetry":{"catalogSize":62,"sources":{"openclaw":62,"mcp":0,"client":0},"counterScope":"97477042e313822ba7a452ff","searchCount":0,"describeCount"
cx   sessions_history ok    {"sessionKey":"agent:cx:p193200","messages":[{"role":"assistant","content":[{"type":"toolCall","id":"call_p193200_codex","name":"sessions_history","arguments":{"sessionKe
== cand3 sha=3db0ca5b90468b28bd5d74151d34cd891d4f62bb
main read             ok    line-1
line-2

[3 more lines in file. Use offset=3 to continue.]
tc   dispatch_action  ok    {"tool":{"id":"openclaw:core:sessions_history","name":"sessions_history","source":"openclaw"},"result":{"content":[{"type":"text","text":"{"sessionKey":"agent:tc:p193200"
tc   dispatch_action  ERROR Invalid arguments for tool "openclaw:core:sessions_history": limit: expected integer; received [redacted] (string). Expected input: { sessionKey: string; includeTools?: b
cm   exec             ok    {"status":"completed","telemetry":{"catalogSize":62,"sources":{"openclaw":62,"mcp":0,"client":0},"counterScope":"2c85ffea56e90a6d23214d37","searchCount":0,"describeCount"
cx   sessions_history ok    {"sessionKey":"agent:cx:p193200","messages":[{"role":"assistant","content":[{"type":"toolCall","id":"call_p193200_codex","name":"sessions_history","arguments":{"sessionKe

Notes: cand1/cand2 ran commit 5523179 (the fix before the main merge); cand3 is the pushed head. The limit:"abc" control was added after base1, so base1 has no control row.

@obviyus obviyus changed the title fix: tool_call rejects quoted numbers and booleans that direct calls accept fix: coerce quoted tool arguments on tool_call, Code Mode and Codex dynamic tools Nov 17, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Nov 17, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. labels Nov 17, 2026
Codex always supplies validateArguments and skips MCP tools inside it, so coercion must use the same source classifier as the catalog route.
@obviyus

obviyus commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Nov 17, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 17, 2026
@obviyus
obviyus merged commit 40437fa into openclaw:main Nov 17, 2026
144 of 146 checks passed
@obviyus

obviyus commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Thanks @ayaangazali for the fix. This is merged in 40437fa: tool_call, Code Mode and Codex dynamic tools now accept quoted numbers and booleans ("1", "false") for OpenClaw tools the same way direct tool calls do, using the same validator. MCP and client tools still receive their raw arguments.

RomneyDa added a commit that referenced this pull request Nov 17, 2026
…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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 18, 2026
…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]>
RomneyDa pushed a commit that referenced this pull request Nov 19, 2026
…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)
RomneyDa pushed a commit that referenced this pull request Nov 19, 2026
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants