Skip to content

fix(codex): reject malformed native tool arguments - #124649

Merged
sallyom merged 2 commits into
openclaw:mainfrom
PollyBot13:fix/native-tool-schema-validation
Aug 17, 2026
Merged

sallyom merged 2 commits into
openclaw:mainfrom
PollyBot13:fix/native-tool-schema-validation

Conversation

@PollyBot13

@PollyBot13 PollyBot13 commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Related: #111704

What Problem This Solves

Native Codex dynamic tool calls could execute even when their arguments violated the JSON schema shown to Codex. In the published 2026.8.1-beta.2 package, session_status({ sessionKey: 47 }) succeeded even though sessionKey is declared as a string.

Published-package reproduction: #111704 (comment)

Why This Change Was Made

PR #114461 validates the compact Tool Search path, but native Codex dynamic tools use a separate bridge. This change validates OpenClaw-owned native-tool arguments against the exact normalized schema projected to Codex, after before_tool_call rewrites and before any side effect.

The implementation:

  • keeps the public four-argument tool-execution contract and Plugin SDK surface unchanged
  • carries a call-scoped private validation control in the standard fourth update slot, where the existing policy wrapper consumes it before execution
  • preserves ordinary update callbacks and the finalized abort/approval wrapper chain
  • excludes external MCP-owned tools, whose server remains responsible for validation
  • bounds returned validation details by count and length

Regression coverage includes wrong types, missing and extra properties, primitive roots, normalized empty-object and repaired type: null schemas, direct and deferred surfaces, hook rewrites, same-name tools with different schemas, external MCP ownership, approval metadata, cancellation, and the fully finalized four-argument adapter path that exposed the earlier P1.

User Impact

Malformed native Codex tool calls now return a structured validation error instead of reaching execution or silently using tool-specific fallback behavior. Valid calls, ordinary update callbacks, and external MCP tools retain their existing behavior.

Evidence

Exact packaged and public head: 7d62c1549377a98bcee394b4e915616abecf9370

Current-head validation:

  • exact-head GitHub CI passed, including lint, type, build, boundary, security, and test shards
  • Codex extension suite passed: 143 tests
  • shared schema normalization suite passed: 67 tests
  • exact-head autoreview completed with no findings
  • local offline ClawSweeper found no actionable issue

Exact-head packaged-runtime proof:

  • image: sha256:921b8efab8ade0f813cff2583c9311b5be54cc203189052508182509d5a3526c
  • image version: OpenClaw 2026.8.1 (7d62c15)
  • bundled extension: codex
  • model: openai/gpt-5.6-sol
  • native runtime: OpenAI Codex using ChatGPT authentication
  • no fallback, source-tree mount, production OpenClaw state, workspace mount, container socket, or channel credentials

Malformed native call argument:

47

Result:

Invalid arguments for tool "session_status": sessionKey: must be string.

The turn completed with one session_status call, one tool failure, and no successful tool execution.

Valid control:

{}

The same exact-head runtime returned live session status identifying OpenClaw 2026.8.1 (7d62c15) and the OpenAI Codex runtime. The turn completed with one session_status call, zero failures, and session_status listed as successfully executed.

The sanitized evidence bundle contains the turn summaries, malformed/valid native trace, image identity, and secret scan. Session and run identifiers, quota text, timestamps, and raw authentication material were omitted. TruffleHog scanned the captured envelopes, stderr logs, and sanitized artifacts with zero verified or unverified secrets. The auth-bearing disposable container was removed after capture.

Key artifact hashes:

  • proof summary: d3d28a91d883564540121795c62d1a9b008aa9f91e633c49cd2133354262cd37
  • native trace: c5b845244230a9b56d8d7caab0b1e59ee29e773946e58bece48cb51fb2c0b9eb
  • malformed turn: a03f6f70bfaef8de99efdcaf3594dfdfa2914349787cb2e0f95cf69a53a7b0a3
  • valid control: 294f4ad126b94b982247be205d153cf79ad8dc0c93971a09f265e531ebd82430
  • image identity: 4a80c2bea202573a4a8dbb0df4a56ac26cd1a0bfede3146cd80bec225419da80
  • secret scan: 1b32917d75e78c13c5752af7898e3b0d039bc886bae2d8412df048d0dc1cfafd

AI-assisted: Codex helped implement and review this change. The author reviewed the diff, resolved the normalized-schema, validation-bounding, abort-lifecycle, adapter-transport, provider-ownership, and public-SDK-scope findings, and ran the validation above.

@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling extensions: codex size: M triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Aug 16, 2026
@PollyBot13

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

To use Codex here, create a Codex account and connect to github.

@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Aug 16, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 16, 2026
@clawsweeper

clawsweeper Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 16, 2026, 10:32 PM ET / August 17, 2026, 02:32 UTC.

ClawSweeper review

What this changes

The PR validates OpenClaw-owned native Codex dynamic-tool arguments against their projected JSON schema after preparation and policy hooks, returning bounded failures before execution.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

The repair follows the correct OpenClaw execution boundary and has focused coverage plus reported exact-head packaged proof. Keep it open for a direct Codex runtime/protocol source check that this read-only environment could not perform.

Priority: P1
Reviewed head: 7d62c1549377a98bcee394b4e915616abecf9370

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The repair has focused owner-boundary coverage and credible exact-head packaged-runtime evidence, with a maintainer-side Codex contract check remaining.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body provides exact-head packaged-runtime malformed-versus-valid native-call outcomes showing no execution for invalid input and execution for a valid control.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body provides exact-head packaged-runtime malformed-versus-valid native-call outcomes showing no execution for invalid input and execution for a valid control.
Evidence reviewed 5 items Current main gap: Current main coerces native call input and invokes the tool without validating it against the projected schema.
Final execution boundary: The branch carries a private validator through the existing fourth execution slot; the shared wrapper applies it after finalization and before source-tool execution.
Adjacent validation design: Tool Search already validates final hook-adjusted arguments through a core-only execution scope; it is not a Plugin SDK export.
Findings None None.
Security None None.

How this fits together

The Codex extension projects OpenClaw tools to Codex and routes native tool calls through shared preparation, policy, abort, and capability wrappers. This change enforces the projected schema immediately before OpenClaw-owned tool execution.

flowchart LR
  A[Codex native tool call] --> B[Dynamic-tool bridge]
  B --> C[Argument preparation]
  C --> D[Policy and approval wrapper]
  D --> E{Schema valid?}
  E -->|No| F[Bounded tool error]
  E -->|Yes| G[Abort and capability wrappers]
  G --> H[Tool execution]
Loading

Before merge

  • Resolve merge risk (P2) - Malformed native calls that previously reached tool-specific fallback behavior will intentionally become structured failures.
  • Resolve merge risk (P1) - The shared execution-wrapper change needs direct Codex contract confirmation before merge.
  • Complete next step (P2) - The active PR already owns the repair; direct Codex-source verification is the remaining merge gate.
Agent review details

Security

None.

PR surface

Source +119, Tests +337, Other 0. Total +456 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 4 127 8 +119
Tests 6 366 29 +337
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 11 494 38 +456

Review metrics

Metric Value Why it matters
Production versus regression coverage production +126/-7; tests and test support +367/-30; generated baseline +1/-1 Most additions are focused regression coverage, while the production change extends the shared execution boundary.

Stored data model

Persistent data-model change detected: persistent cache schema: extensions/codex/src/app-server/dynamic-tools.ts, serialized state: extensions/codex/src/app-server/dynamic-tools.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #111704
Summary: This PR is the candidate repair for the native Codex branch of the declared-schema validation gap.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Confirm the Codex boundary (recommended)
    Inspect the matching Codex dynamic-tool protocol/runtime source and retain the final-wrapper regressions before merge.
  2. Accept the behavior change
    Merge with the intentional change that malformed native calls fail before tool-specific fallback execution.

Technical review

Best possible solution:

Keep validation private to the Codex bridge, retain its final policy-wrapper position, and confirm the native Codex input contract from the sibling source before merging.

Do we have a high-confidence way to reproduce the issue?

Yes: current main reaches tool execution without a schema check, and the branch has focused wrong-type, primitive-root, hook-rewrite, direct, and deferred regressions.

Is this the best way to solve the issue?

Unclear: validation after preparation and hook finalization is the right owner boundary, but the required direct Codex runtime/protocol check could not be completed here.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 6c027ad5e1f1.

Labels

Label justifications:

  • P1: Malformed native Codex calls can currently reach OpenClaw tool execution without model-actionable schema feedback.
  • merge-risk: 🚨 compatibility: The patch intentionally changes malformed-call behavior and touches common hook, callback, and abort composition.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body provides exact-head packaged-runtime malformed-versus-valid native-call outcomes showing no execution for invalid input and execution for a valid control.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides exact-head packaged-runtime malformed-versus-valid native-call outcomes showing no execution for invalid input and execution for a valid control.

Evidence

What I checked:

Likely related people:

  • sallyom: Authored the final raw-argument preparation correction and is assigned in the supplied timeline. (role: recent area contributor; confidence: high; commits: 7d62c1549377; files: extensions/codex/src/app-server/dynamic-tools.ts)
  • steipete: Current-main blame and history connect this person to the Codex dynamic-tool bridge and pre-execution path. (role: long-running adjacent owner; confidence: high; commits: 4f92cab8b434, 2afa9de43853; files: extensions/codex/src/app-server/dynamic-tools.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Inspect the matching sibling Codex protocol/runtime source before merge.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (13 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-16T17:00:27.834Z sha 0cb758da230123c04408e9e0e37cb8ccbf6b4668 :: needs changes before merge. :: [P1] Reuse the generic final-argument validation seam
  • reviewed 2026-08-16T17:38:53.458Z sha 394e16c8e90b84b173a815fc10be2e298b90c1c4 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-16T17:57:00.653Z sha 1412ecf0e4c1dfbedfc3deb50251ce9f91241ab4 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-16T18:42:37.161Z sha 7cf3578e154be37888bf16c0b9c9cf066fba0996 :: needs real behavior proof before merge. :: [P0] Bound schema-validation errors before returning them to Codex | [P1] Get approval before publishing the validation seam
  • reviewed 2026-08-16T19:24:15.137Z sha 3c906802512ab724699753f6df0f96b463c295b5 :: needs real behavior proof before merge. :: [P1] Preserve validation through the abort wrapper
  • reviewed 2026-08-16T21:49:22.346Z sha 06c2c5cc647c37501de92eb0d5b8bc4eb884c159 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-17T01:20:28.575Z sha d9b5b4779422cd6eca34754f50c165af309ec17c :: needs real behavior proof before merge. :: [P1] Defer primitive-root validation until after policy hooks
  • reviewed 2026-08-17T01:49:56.840Z sha 7d62c15 :: needs real behavior proof before merge. :: none

@PollyBot13

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Current head 9491d1999ed739a9e6041886e4ae1a64ec743952 addresses the projected-schema validation finding and adds normalized/repaired-schema execution regressions. The PR body now includes the fresh packaged-runtime proof and artifact hashes.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 16, 2026
@clawsweeper

clawsweeper Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@PollyBot13

Copy link
Copy Markdown
Contributor Author

Current head a9857a20bfeb7de3a8c3311df6f6c03011faa4c0 also fixes the branch-owned hosted-CI findings: permissive runtime-contract test doubles now declare additionalProperties: true, and the unused type import is removed. Local rerun: 233 affected Codex tests passed, extension production type-check passed, targeted lint clean.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 16, 2026
@PollyBot13

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Current head 31412a6646689c353e5ddcae9473da9842cba8ef addresses the abort-lifecycle P1 by reapplying the shared run-abort race after projected-schema validation is injected into an already-finalized tool. New regression: a never-settling non-cooperative tool now settles promptly on run cancellation. Validation: 151 bridge tests, 45 hook-integration tests, 30 abort-wrapper tests, extension type-check, lint, and formatting all pass.

@clawsweeper

clawsweeper Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 16, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 16, 2026
@sallyom sallyom self-assigned this Aug 17, 2026
@sallyom
sallyom force-pushed the fix/native-tool-schema-validation branch from 06c2c5c to d9b5b47 Compare August 17, 2026 01:13
@sallyom

sallyom commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Pushed a small signed-off maintainer fix in d9b5b477942: Codex native tools now run prepareArguments on the raw input before validation, preserving the existing optional-argument compatibility path and the preparer method receiver. Added regression coverage for null preparation.

Local ClawSweeper offline and autoreview are clean; focused tests pass (212/212).

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 17, 2026
@sallyom
sallyom force-pushed the fix/native-tool-schema-validation branch from d9b5b47 to 7d62c15 Compare August 17, 2026 01:43
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 17, 2026
@sallyom

sallyom commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Maintainer Codex-contract check complete for OpenClaw HEAD 7d62c1549377a98bcee394b4e915616abecf9370, against openai/codex SHA 8b2c84ddccafe40dc0dc09f9f52bcbdc9dc45d66.

Codex defines dynamic-tool arguments as arbitrary JsonValue, parses and forwards them without schema validation, and sends them unchanged through the app-server request (protocol, runtime, app server). Its response contract explicitly supports host-returned success: false with explanatory content (response). OpenClaw's private validation carrier is consumed at the final policy-wrapper boundary before source execution and is not forwarded as the tool callback.

Verdict: host-side final-argument validation matches the Codex contract; there is no Codex protocol, public API, or config change. The direct-source P1 confirmation is resolved, and the intentional malformed-call tightening is accepted.

@sallyom

sallyom commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Merge-ready at 7d62c1549377. This is the best fix at the correct Codex bridge/final-execution owner boundary. Valid calls remain unchanged; malformed native calls now intentionally fail before execution, with no public API, config, protocol, or persistence changes. Direct Codex-source inspection confirms the host-side validation contract. Focused tests and packaged proof pass, local autoreview is clean, hosted ClawSweeper has no findings, and exact-head CI is green.

@sallyom

sallyom commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling extensions: codex merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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