Repository navigation
fix(tools): keep deeply nested tool schemas callable - #164836
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs changes before merge. What this changesThis 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.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete 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 Before merge
FindingsNone. Agent review detailsHow this fits togetherMCP 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]
Technical reviewBest 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
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +301, Tests +390, Docs +6, Other 0. Total +697 across 28 files. Added test files: 3. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (6 earlier review cycles)
Reviewed October 11, 2026, 4:14 AM ET / 08:14 UTC (Revision 7). |
… fast instead of overflowing the call stack
…rict nesting accounting
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…y MCP projections
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
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.
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
* 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]>
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/
toJSONbehavior. 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 shallowmessageand optionalmetadatacontaining 5,000 nested object schemas.qwen3:8b(/api/chat)Baseline main was pinned at
c6d71fae0ed1c0f7968c8d05c410345246af235b; both depth-2 controls executed successfully. Candidate persisted tool results contain the exact expectedDEEP_SCHEMA_TOOL_CALLED:...markers anddetails.depth: 5000, with exactly one warning namingdeep_schema_echoper 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 usenode scripts/run-vitest.mjs <file> --maxWorkers=1:packages/ai/src/providers/tool-schema-depth.test.tssrc/plugin-sdk/provider-tools.test.tssrc/agents/agent-tools.schema.test.tspackages/ai/src/providers/clean-for-gemini.test.tsThe 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 buildpassed 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-gateis 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 merge5c58293c1955cf062904dfb5318c2118e9a98a37with newer main1fbfd4a567276df895a1547ac923da9f3fba9985.The SQLite worker-fixture failure is proven inherited. Main commit
8267c24051ffadds Solid to shared Vitest plugins. Generated projects useextends:false, copy the plugins, and omit the Node environment, so Solid defaults to jsdom. The exact CI main base reproduces the samecp.execFile.mock.calls[0][1]error after successful SQLite snapshot creation (42.36s); adding onlyenvironment:'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, and26d63bea6c827(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 aggregateopenclaw/ci-gate; exact-head CI remains failed. No CI rerun, source push, or branch rewrite was made solely to obtain green.