Skip to content

fix(tools): keep deeply nested tool schemas callable - #164836

Merged
steipete merged 11 commits into
openclaw:mainfrom
RXQ6:fix/tool-schema-depth-budget
Oct 11, 2026
Merged

steipete merged 11 commits into
openclaw:mainfrom
RXQ6:fix/tool-schema-depth-budget

Conversation

@RXQ6

@RXQ6 RXQ6 commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Closes #141306
Related: #153713, #153700, #153701, #153743, #155475

What Problem This Solves

Fixes: a deeply nested MCP or plugin tool input schema crashes agent preparation with RangeError: Maximum call stack size exceeded, including native Ollama and llama.cpp's grammar preparation path.

User Impact

The tool remains callable. Subschemas beyond 128 nested schema levels become permissive {} schemas, with a one-time warning naming the tool. Validation beyond that cutoff is unavailable; tool authors should keep schemas shallow. There is no new configuration option.

Why This Change Was Made

One package-owned budget now protects schema normalization, reference expansion, provider inspection, and JSON projection. Named tool boundaries retain bounded parameters for execution. Projection preserves literal data, mutable source freshness, and once-per-payload getter/toJSON behavior. Truncated tools use the existing OpenAI strict-mode fallback.

Live testing showed that 512 was still unsafe: TypeBox overflowed while compiling a generated validator, and managed llama.cpp overflowed its native grammar reference resolver. The shared limit is therefore 128, verified through both downstream consumers. A cold-main-thread regression protects the validator boundary that Vitest's larger worker stack missed. It replaces the former Gemini cold-process fixture.

This updates @RXQ6's contributor branch by merging main (aa311a4b2864361cac66571412a9ad9df6e60a24), preserving all contributor commits and replacing depth rejection/quarantine with the maintainer-selected truncation policy. Main's consolidated normalizers remain canonical. The separate plugin-config PR #160438 is closed; #155475 includes additional deep-literal comparison work and is not fully superseded here.

Production: +421/-120 (net +301). Test/support: +458/-68 (net +390). Documentation: +6 lines. Net production growth remains necessary for the shared traversal, native JSON serialization tracking, and strict-mode/cache provenance; duplicate schema-key tables and obsolete rejection/quarantine paths were removed.

Evidence

Live candidate: 0311e4428a103cded08185ca1b5ac83cf08280d2. Real embedded CLI entry point: pnpm openclaw --profile <isolated-profile> agent --local --agent main --session-id <fresh-id> --message 'Call deep_schema_echo exactly once and omit metadata' --json --timeout 300, with isolated state/config and the built checkout. The synthetic MCP-style plugin has a required shallow message and optional metadata containing 5,000 nested object schemas.

Backend Current-main baseline Candidate Candidate wall time
Native Ollama qwen3:8b (/api/chat) RangeError before dispatch 1 successful tool call, 0 failures 20.551s
Managed llama.cpp b10809, Qwen3 8B (GBNF path) RangeError before dispatch 1 successful tool call, 0 failures; HTTP 200 21.124s

Baseline main was pinned at c6d71fae0ed1c0f7968c8d05c410345246af235b; both depth-2 controls executed successfully. Candidate persisted tool results contain the exact expected DEEP_SCHEMA_TOOL_CALLED:... markers and details.depth: 5000, with exactly one warning naming deep_schema_echo per run. Owned managed servers shut down cleanly.

The exact final cold validator fixture fails on main with RangeError in 0.635s; it also fails at the discarded 512 budget in TypeBox's new Function, and passes at 128. The focused 156-test suite passed, followed by all changed test files and the additional serialization/cache/SDK regressions. Latest per-file commands use node scripts/run-vitest.mjs <file> --maxWorkers=1:

Changed test file Result Wall time
packages/ai/src/providers/tool-schema-depth.test.ts 20 passed 29.506s
src/plugin-sdk/provider-tools.test.ts 20 passed 7.462s
src/agents/agent-tools.schema.test.ts 15 passed 14.924s
packages/ai/src/providers/clean-for-gemini.test.ts passed 3.320s

The cold validator requires a fresh main-thread stack; compiled-worker preparation dominates that file's wall time. No Gateway is booted by these tests.

pnpm build passed in 5m 4.1s. Targeted lint, core/package/agent-root/plugin-SDK test typechecks, formatting/diff sanity, and the assertion-safety, max-lines, line-cap, test-timeout-race, test-mock-exports, config-docs, and plugin-inventory checks passed. Prompt snapshots were regenerated with 0 token delta.

Independent Codex autoreview: scoped-clean at P2 and above on this head after resolving projection/cache/provider-copy provenance findings. ClawSweeper reviewed this exact head on October 11 at 06:42 UTC: no code findings, live proof sufficient. Its remaining before-merge item is attribution of the CI failures below.

CI disposition

Exact-head CI failed; openclaw/ci-gate is red. Lint, types, security-fast, ratchets, and 28 Node test jobs passed. Run wall time: 765s. Failed jobs: worker fixtures 133s, Codex extension bundle 679s. GitHub tested merge 5c58293c1955cf062904dfb5318c2118e9a98a37 with newer main 1fbfd4a567276df895a1547ac923da9f3fba9985.

The SQLite worker-fixture failure is proven inherited. Main commit 8267c24051ff adds Solid to shared Vitest plugins. Generated projects use extends:false, copy the plugins, and omit the Node environment, so Solid defaults to jsdom. The exact CI main base reproduces the same cp.execFile.mock.calls[0][1] error after successful SQLite snapshot creation (42.36s); adding only environment:'node' makes that focused case pass (71.38s). The probe was reverted. The original PR checkout passes all 30 worker-artifact tests (131.21s). Scheduled main CI independently records the same failure in job 114410630280. This separate main fixture repair is not mixed into the schema change.

The Codex steering/cleanup failure is proven inherited. Independent Linux / Node 24.19 Testbox runs reproduced the same missing acceptance callback and cleanup deadlines on baseline main and later main; the failing fixture, harness, no-tool dispatch guard, steering owner, and runtime setup match this PR’s tested merge. The fixture disables model tools and returns an empty tool surface before schema preparation. The earlier macOS replays remain passing controls, not proof of a fix.

Both inherited failures have separate main repairs: fd0fc628ec2d9 (fix(test): retain Node environment in subprocess probes) for the SQLite worker fixture, and 26d63bea6c827 (test(codex): keep steering receipt proofs independent of wall time) for Codex steering. Maintainer landing uses the native inherited-failure admin exception for those two jobs and their aggregate openclaw/ci-gate; exact-head CI remains failed. No CI rerun, source push, or branch rewrite was made solely to obtain green.

@clawsweeper

clawsweeper Bot commented Oct 4, 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. 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: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 4, 2026
@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR keeps deeply nested tools callable by replacing subschemas beyond 128 levels with permissive schemas and warning about reduced validation.

Example: Call deep_schema_echo with message="proof" while its optional metadata schema contains 5,000 nested objects.

  • Before: Agent preparation fails with RangeError before the tool executes.
  • After: The tool executes successfully, deep subschemas become {}, and one warning names the affected tool.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Strong shipped-entry-point evidence supports a coherent, owner-approved repair with no new actionable code finding; failed required CI still prevents ordinary landing.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The exact reviewed head is reported exercising the shared schema owner through the real embedded CLI with a 5,000-level plugin schema on native Ollama and managed llama.cpp; both runs execute the tool successfully with one named warning, against failing baselines and successful shallow controls.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A deeply nested MCP or plugin input schema prevents an agent turn from preparing or executing its tools.
Reason: The repair restores demonstrated tool execution, and the area owner's commits explicitly select truncation over rejection and accept reduced validation.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this PR open: it provides a useful, owner-approved repair that current main lacks, with no new code findings; the required CI gate still has an unattributed Codex failure.

Priority: P2
Reviewed head: 0311e4428a103cded08185ca1b5ac83cf08280d2

Before merge

  • Complete next step - Attribute the Codex steering-acceptance and cleanup failure in the matching hosted environment; repair it here only if this diff causes it, otherwise establish the baseline evidence required for the native inherited-failure exception.

Findings

None.

Agent review details

How this fits together

MCP and plugin tool schemas enter shared AI normalization, provider projection, and argument validation; bounded schemas leave for model requests and tool execution.

flowchart LR
  A[MCP and plugin tools] --> B[Shared schema budget]
  B --> C[Provider normalization]
  C --> D[Model request projection]
  D --> E[Model tool call]
  E --> F[Argument validation]
  F --> G[Tool execution]
Loading

Technical review

Best possible solution:

Retain the shared callable-truncation policy and land this focused repair once the remaining required-check failure has an admissible disposition.

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

Current-main source retains uncapped recursive normalization, consistent with the submitted failing baseline CLI runs; this read-only review executed no target code.

Is this the best way to solve the issue?

The shared producer-side budget is appropriate: it protects preparation and downstream validators, preserves tools and shallow constraints, and carries reduced-validation provenance through provider rewrites.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 7943ae59280f.

Provenance checked

  • SDK cleaners and deep-schema acceptance changes intended behavior with a stated reason (1d7fd50: The earlier repair preserved complete deep schemas while replacing recursive cleaner walks with heap-stack traversal.)
  • Compact root references keeps the original intent (ea1de33: Eligible root references preserve useful nested argument types without expanding compact plugin declarations.)
  • Schema projection and normalization reuse keeps the original intent (ea1c52f: Prepared normalization reuses matching serialized inputs while preserving fresh projections, detached payloads, and bounded caches.)
  • Shared provider normalization ownership keeps the original intent (9490c11: Provider-specific profiles consolidate traversal without creating competing normalization owners.)
  • Cold subprocess regression keeps the original intent (2a911a7: Compiled subprocess preparation stays outside guarded test deadlines; the replacement retains that infrastructure and exercises the colder validator boundary.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 9490c11 adds packages/ai/src/providers/tool-schema-normalization.ts:2 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 9490c112abba; files: packages/ai/src/providers/tool-schema-normalization.ts)
  • Josh Lehman: Raw commit ea1de33 adds packages/ai/src/providers/tool-schema-refs.ts:261 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ea1de33a1d91; files: packages/ai/src/providers/tool-schema-refs.ts)
  • Ayaan Zaidi: Raw commit 1d7fd50 adds packages/ai/src/providers/clean-for-gemini.ts:303 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1d7fd50b912f; files: packages/ai/src/providers/clean-for-gemini.ts)

PR surface

Source +301, Tests +390, Docs +6, Other 0. Total +697 across 28 files. Added test files: 3.

View PR surface stats
Area Files Added Removed Net
Source 17 421 120 +301
Tests 8 454 64 +390
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 2 4 4 0
Total 28 885 188 +697

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +421/-120; tests, support, and fixture registration +458/-68. Growth supports the shared budget, serialization and cache provenance, provider boundaries, and a cold validator regression that detects failures missed by larger worker stacks.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: Unusually deep configured tool schemas can fail agent preparation, but the evidence does not establish a widespread runtime outage.
  • merge-risk: 🚨 compatibility: Existing SDK cleaners now truncate deep constraints and OpenAI requests can lose strict validation; the area owner explicitly accepted this documented tradeoff to preserve callable tools.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.
  • 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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (6 earlier review cycles)
  • reviewed 2026-10-04T08:42:43.905Z sha c93bb4b :: needs real behavior proof before merge. :: [P1] Contain depth rejection before aborting the entire tool list
  • reviewed 2026-10-05T04:23:42.203Z sha 6854132 :: blocked before merge. :: [P1] Contain depth rejection before aborting the MCP tool list | [P2] Count schema maps transparently in strict normalization | [P2] Contain depth errors while building strict diagnostics | [P2] Reconcile tool choices against tools surviving depth rejection
  • reviewed 2026-10-05T04:52:28.784Z sha 3e665b5 :: blocked before merge. :: [P1] Contain depth rejection in App-only MCP projections | [P2] Reconcile tool choices against the post-rejection projection | [P1] Avoid returning uncleaned llama.cpp schemas after rejection
  • reviewed 2026-10-05T05:28:13.409Z sha 3e665b5 :: blocked before merge. :: [P1] Contain depth rejection in App-only MCP projections | [P2] Reconcile tool choices against the post-rejection projection | [P1] Avoid returning uncleaned llama.cpp schemas after rejection
  • reviewed 2026-10-05T05:57:16.548Z sha dbd3867 :: blocked before merge. :: [P2] Reconcile tool choices against the post-rejection projection
  • reviewed 2026-10-11T06:42:21.910Z sha 0311e44 :: needs changes before merge. :: none

Reviewed October 11, 2026, 4:14 AM ET / 08:14 UTC (Revision 7).

@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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 Oct 5, 2026
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Oct 5, 2026
@RXQ6

RXQ6 commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@RXQ6

RXQ6 commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

steipete and others added 2 commits October 10, 2026 21:39
Merge origin/main into the contributor branch and replace depth rejection
with one shared 512-level truncation budget. Keep tools available, report
reduced validation once per named schema, and downgrade strict requests
when schema truncation requires best-effort validation.

Preserve provider projection freshness and getter semantics. Cover deep
normalizers, reference expansion, provider hooks, and real argument
validation. Remove superseded rejection and subprocess proof paths.

Co-authored-by: XuRuuuy <[email protected]>
Complete the shared schema truncation policy, preserve warning and strict-mode provenance through cache copies, and retain deep tools through provider preparation and argument validation.

Co-authored-by: XuRuuuy <[email protected]>
Use one 128-level budget after live proof showed that 512 overflows both TypeBox generated validators and the managed llama.cpp grammar resolver. Preserve the real required-message and optional-metadata regression, including a cold main-thread validator fixture.
@steipete steipete changed the title fix: deeply nested external tool schemas crash schema normalization with RangeError fix(tools): keep deeply nested tool schemas callable Oct 11, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Oct 11, 2026
@steipete
steipete merged commit aecb969 into openclaw:main Oct 11, 2026
173 of 179 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 12, 2026
* fix(tools): bound tool-schema traversal so deep external schemas fail fast instead of overflowing the call stack

* fix(tools): share schema depth accounting and contain depth rejection per tool

* fix(tools): contain MCP and list-schema depth rejections and share strict nesting accounting

* fix(tools): quarantine over-budget provider tools and contain App-only MCP projections

* fix(tools): preserve truncation through provider projections

Complete the shared schema truncation policy, preserve warning and strict-mode provenance through cache copies, and retain deep tools through provider preparation and argument validation.

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

* fix(tools): retain truncation from serialized schema results

* fix(tools): key prepared schemas by truncation state

* fix(tools): preserve bounded schema state across provider rewrites

* fix(tools): preserve dependency names at the schema cutoff

* fix(tools): bound schemas for cold validators and native grammars

Use one 128-level budget after live proof showed that 512 overflows both TypeBox generated validators and the managed llama.cpp grammar resolver. Preserve the real required-message and optional-metadata regression, including a cold main-thread validator fixture.

---------

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

Labels

agents Agent runtime and tooling merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Deeply nested external tool schema crashes normalization with RangeError (no depth budget)

3 participants