Skip to content

fix: preserve compact plugin tool argument types for Codex - #157734

Merged
jalehman merged 3 commits into
mainfrom
fix/openai-compact-tool-schema-refs
Sep 25, 2026
Merged

jalehman merged 3 commits into
mainfrom
fix/openai-compact-tool-schema-refs

Conversation

@jalehman

@jalehman jalehman commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Related: #156957. Related implementation context: #81238, #139431, and #132442.

What Problem This Solves

Fixes complex plugin tool arguments appearing as unknown in Codex when shared schema definitions are expanded beyond its declaration-compaction budget.

User Impact

Agents retain useful nested argument types for compact, reference-bearing plugin tools. The change is in shared OpenAI-provider normalization, not a Knowledge-specific exception. Other providers and unsupported shapes keep the existing expansion path. No configuration or migration is required.

Why This Change Was Made

Expanding a shared definition at each use can turn a small schema into one large enough for Codex to discard nested types. Preserve eligible root $defs / definitions references for OpenAI-provider normalization, while retaining inlining for unresolved or scoped references, malformed definition tables, root unions, OpenAPI components, nullable reference nodes, and incompatible provider profiles/keywords. References confined to unused definition tables do not activate preservation.

The reference helper is extracted from the existing normalizer to keep the fix within the repository line cap; both baseline changes shrink existing exceptions. This PR contains only the host fix, not the Knowledge plugin's ingestion work.

The review follow-up restores host coercion for preserved references without expanding the model-facing schema. Union checks retain root context and TypeBox refinements; recursive data locations remain independent. Unsupported identifier/scoped-definition shapes keep the existing inlining path.

Compatibility detail: bundled MCP materialization still uses provider-neutral inlining. Direct OpenAI Responses payload conversion also still inlines references at its later provider-neutral conversion boundary, with both strict modes verified. This patch does not switch every outgoing OpenAI API request to reference-bearing schemas.

Evidence

Review-feedback correction — 46ce73c

  • Before/after regression: the new focused tests failed 7 and passed 47 before repair. The normalizeToolParameterSchema → validateToolCall → validateToolArguments boundary now converts referenced JSON-stringified arrays/objects and nested primitives without mutating the compact schema or original arguments.
  • Final focused proof: 109 tests passed across five suites in 4.384 s wrapper wall: llm-core validation, parameter normalization, OpenAI tool-schema/reuse, and schema projection. Individual modified suites passed 36 tests in 2.09 s and 23 tests in 1.90 s, respectively (pnpm test with --maxWorkers=1).
  • Selected checks passed, exit 0: formatting, core types, all 25 test-type graphs, lint (0 warnings/errors), dead exports and import cycles. Candidate hashes were verified inside the Testbox execution. The combined install/probe/test/check command took 27m53s, not an individual test runtime.
  • Real app-server registration: Codex 0.155.1 accepted a synthetic tool through normalization, projectCodexDynamicTools, createCodexDynamicToolSpecs and thread/start. Root references/definitions survived. Registered schema: 2,120 bytes; inline form: 5,077 bytes. Fresh credential-free HOME/CODEX_HOME; no inference request.
  • Autoreview completed with documented dispositions. The INDEX-only finding was resolved by staging the full correction. A later TypeBox refinement-loss defect was fixed by wrapping original union branches in allOf instead of spreading them; a negative control and regression cover it. The final production review requested root-identifier/nested-definition coercion support in two P2 findings. Both are rejected: the unchanged preservation gate excludes these shapes, the existing inliner handles them, and two normalize-to-tool-call regressions prove prior coercion still works. This is not a zero-findings report.

Limits: registration acceptance is not renderer or external OpenAI inference proof; neither was run. Codex's schema-size limits remain. The reproduced regression affects embedded-host coercion, not the separate Codex bridge validator. Hosted PR CI for this commit passed on 2026-09-25: 140 successful jobs, 20 skipped, no failures; openclaw/ci-gate and applicable security/dependency checks succeeded.

Commands, redacted registration result, and correction scope
node scripts/run-vitest.mjs packages/llm-core/src/validation.test.ts packages/ai/src/providers/agent-tools-parameter-schema.test.ts packages/ai/src/providers/openai-tool-schema.test.ts packages/ai/src/providers/openai-tool-schema-reuse.test.ts src/agents/tool-schema-projection.test.ts --maxWorkers=1
node scripts/check-changed.mjs --base e2d2e9fdb86983dc0722aa0da51aa53f5f71bc32 -- packages/llm-core/src/validation.ts packages/llm-core/src/validation.test.ts packages/ai/src/providers/agent-tools-parameter-schema.test.ts

Redacted actual registration result:

{"serverVersion":"0.155.1","method":"thread/start","accepted":true,"registeredSchemaBytes":2120,"inlineSchemaBytes":5077,"rootRefsAndDefinitionsRetained":true,"credentials":"none","inferenceRequested":false,"rendererProof":false}

Pinned source inspected directly: schema preparation and compaction.

Correction scope: three files; production +114/−28 (net +86), tests +244. Necessary growth is reference resolution, root-bound validator caching and recursion context in the existing owner. No second projection, dependency change, protocol/schema bump or baseline expansion. The 64-KiB limit, nullable policy, final validation and TypeBox recovery remain intact.

An initial remote check used a stale comparator; final proof uses the pinned PR merge base above. An intermediate overbroad typecheck was cancelled, not counted as passing; all 25 graphs completed in the final check. Both task Testboxes are stopped. The local formatting hook lacked worktree dependencies; its documented recovery was used only after separate formatting proof and matching candidate hashes.

Original pre-feedback verification at the previous PR head
  • New compact-schema regression: 19 tests passed. Measured command: pnpm test packages/ai/src/providers/agent-tools-parameter-schema.test.ts --maxWorkers=1; 2.52 s wall, 891 ms Vitest duration.
  • Final focused verification: 177 tests passed across six suites: agent-tools-parameter-schema (19), openai-tool-schema + openai-tool-schema-reuse (30), tool-schema-projection (20), and agent-tools.schema + bundled MCP materialization (108).
  • Bundled MCP materialization: 36 tests passed, including the existing local-reference and root-union regressions from the earlier MCP fixes.
  • Synthetic probe through the real convertResponsesToolPayload entry point verified both strict modes retain nested field types and keep outgoing references inlined.
  • The regression demonstrates the expanded synthetic schema exceeding 5,000 bytes while its normalized/projected reference-bearing form stays below the budget. The sibling Codex source confirms the 5,000-byte compaction threshold and support for rendering root definition references.

Autoreview: the first independent pass identified two reproduced gate defects (unused definitions and malformed definition tables); both were fixed with regressions demonstrated failing before and passing after. Its strict-reference-sibling concern was checked against the real downstream payload converter: both strict modes inline references, covered by new payload regressions. A second independent review completed on the revised patch and accepted the strict-mode disposition. It reported one P2 concern about unused definitions alongside a live reference. That finding is rejected with downstream evidence: Codex prepares schemas by pruning unreachable definitions before compaction, and its regression explicitly covers a live reference plus an unused definition. The reviewer did not have that downstream source. This is a completed review with a documented rejected finding, not a zero-findings verdict.

Checks: core typecheck and all 25 test-typecheck shards passed; revised files passed fresh core/package typechecking, formatting, and targeted lint. node scripts/check-changed.mjs passed its checks through the dead-export scans, then failed on the existing eslint(max-lines) violation in unchanged src/agents/workspace.test.ts:1215 (1,017 counted lines, limit 1,000). Verified that file has no diff; this PR does not alter it. Later checks in that command did not run.

Evidence limits: no fresh external OpenAI API request or Rust Codex renderer test is included in this run. The TypeScript regression checks schema structure/projection and size, not the renderer itself. Remaining Codex compaction/render limits still apply to sufficiently large schemas; this is not a general removal of those limits. A concurrent final-suite run hit the worker compiler guard (Source changed during compiled subprocess invocation: pnpm-lock.yaml); lockfile content is unchanged. After the competing preparation commands ended, direct sequential replay of the affected agents-core files passed all 108 tests. This PR does not claim to fix that harness race. Hosted CI timing is pending.

Original implementation by @jalehman; this review follow-up was made at their request.

Work sessions

@clawsweeper

clawsweeper Bot commented Sep 24, 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.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 25, 2026
@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 25, 2026, 5:55 PM ET / 21:55 UTC (Revision 3).

ClawSweeper review

What this changes

The branch preserves eligible shared definitions in OpenAI-facing plugin tool schemas and teaches host argument validation to coerce values through those references.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep this PR open. Current main still expands the references that this branch preserves, and the latest commit addresses the prior host-coercion finding. The real Codex registration probe confirms a compact schema was accepted, but does not show whether Codex displays the nested argument types whose loss prompted the fix.

Priority: P2
Reviewed head: 46ce73c424a0e6789e94b879370660a9140756c7

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch and boundary regressions are useful, but registration evidence stops short of the reported Codex type-display outcome.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Evidence reviewed 10 items Introduced compact-reference path: The introduced OpenAI-provider gate preserves eligible root definitions instead of expanding them; other profiles retain the inlining path.
Preservation boundary: The new gate requires a root object, valid definition tables, and resolvable root references; scoped and unsupported reference shapes fall back to inlining.
Prior finding addressed in source: The new validator resolves root references during coercion and retains root-aware union validation. The earlier reviewed head had the base validation blob, while the current head has a changed blob and new normalization-to-tool-call regressions.
Findings None None.
Security None None.

How this fits together

OpenClaw normalizes plugin tool schemas for the selected model before projecting them into Codex dynamic tool declarations or direct OpenAI requests. Model-emitted arguments then pass through host validation before a tool runs.

flowchart LR
  A[Plugin tool schema] --> B[Provider normalization]
  B --> C[Codex tool projection]
  C --> D[Codex declaration]
  D --> E[Model tool call]
  E --> F[Host argument validation]
  F --> G[Tool execution]
Loading

Before merge

  • Complete next step (P2) - Add redacted Codex output showing that the registered compact tool declaration retains the affected nested argument types before merge.
  • Resolve review confidence - ClawSweeper must reach high confidence before merge readiness is known.
Agent review details

Security

None.

PR surface

Source +161, Tests +425, Other -1. Total +585 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 3 458 297 +161
Tests 2 425 0 +425
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 1 2 -1
Total 7 884 299 +585

Review metrics

Metric Value Why it matters
Production and regression growth production +161 net lines; tests +425 lines The production growth comes from extracting reference handling and adding root-aware coercion; the tests cover both schema projection and argument validation.

Technical review

Best possible solution:

Retain compact references for Codex-compatible tool schemas while preserving direct OpenAI inlining and host coercion, then show the resulting nested argument types in Codex output.

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

Yes, current-main inlining and Codex's 5,000-byte compaction policy give a high-confidence source-level path using the PR's synthetic schema. I did not execute the untrusted branch in this read-only review.

Is this the best way to solve the issue?

Yes, the patch changes the existing normalization and validation owners and keeps the documented provider fallbacks. The user-visible Codex declaration outcome still needs direct observation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 800bf8e10e7c.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, 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: This is a bounded tool-schema fix with limited user impact and no established urgent regression.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • liuhao1024: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • giodl73-repo: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Capture a redacted real Codex declaration or renderer trace showing the nested plugin argument types after registration.

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 (2 earlier review cycles)
  • reviewed 2026-09-25T00:00:16.288Z sha 46f144f :: needs maintainer review before merge. :: none
  • reviewed 2026-09-25T13:34:52.220Z sha a393359 :: blocked before merge. :: [P2] Preserve coercion for reference-backed tool arguments

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 25, 2026
Resolve eligible root definitions during host argument coercion while keeping model-facing schemas compact. Preserve root-aware union validation, recursive data traversal, and TypeBox refinements.

Addresses ClawSweeper feedback on #157734.

Co-authored-by: jalehman <[email protected]>
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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 Sep 25, 2026
@jalehman
jalehman merged commit ea1de33 into main Sep 25, 2026
222 checks passed
@jalehman
jalehman deleted the fix/openai-compact-tool-schema-refs branch September 25, 2026 22:08
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 26, 2026
…157734)

* fix: preserve compact plugin tool argument types for Codex

* fix: preserve coercion for referenced tool arguments

Resolve eligible root definitions during host argument coercion while keeping model-facing schemas compact. Preserve root-aware union validation, recursive data traversal, and TypeBox refinements.

Addresses ClawSweeper feedback on openclaw#157734.

Co-authored-by: jalehman <[email protected]>

---------

Co-authored-by: roboclaw-bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL 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.

2 participants