Repository navigation
fix(code-mode): correct MCP array union declarations - #131528
Conversation
Render MCP array item types with Array<...> so API.read and MCP.$api preserve enum and union grouping. Keep advertised schemas and runtime validation unchanged. Fixes #131476. Release context: Code Mode MCP declarations now correctly describe mixed enum and union arrays, including nested arrays.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 28, 2026, 12:40 AM ET / 04:40 UTC. ClawSweeper reviewWhat this changesThe PR renders Code Mode MCP array declarations as Merge readiness✅ Ready for maintainer review No blocking correctness or security finding. Current main still has the array-union precedence bug, and this member-owned PR repairs the shared declaration owner with focused coverage; keep it open for normal merge gating. Priority: P2 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherCode Mode converts MCP tool JSON Schemas into virtual TypeScript-style declarations that guide agent tool calls. The generated declarations are delivered to the QuickJS worker and must agree with the original MCP schema. flowchart LR
A[MCP tool schema] --> B[Namespace model]
B --> C[Declaration renderer]
C --> D[Virtual API files]
D --> E[QuickJS Code Mode]
E --> F[MCP tool dispatch]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource 0, Tests +68. Total +68 across 3 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Merge the single owner-level grouping correction once exact-head required checks complete; retain the two declaration-surface tests as the regression boundary. Do we have a high-confidence way to reproduce the issue? Yes: current main's exact array-rendering expression visibly produces an ungrouped union followed by Is this the best way to solve the issue? Yes: grouping the existing recursive item rendering at the shared array case fixes every affected declaration surface without changing validation, configuration, or transport behavior. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against ec3a8343c5de. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Land-ready proof for The existing MCP schema renderer now uses Exact-head CI run 33142017262 completed successfully. The repository CI watcher exited 0 with Validation commands and results: node scripts/run-vitest.mjs src/agents/code-mode-namespaces.test.ts src/agents/code-mode.mcp.test.ts
# Before the production edit: 8 failed, 19 passed.
node scripts/run-vitest.mjs src/agents/code-mode-namespaces.test.ts src/agents/code-mode.mcp.test.ts src/agents/tool-schema-hints.test.ts
# After the repair: 40 passed.
node scripts/check-changed.mjs -- src/agents/code-mode-mcp-api.ts src/agents/code-mode-namespaces.test.ts src/agents/code-mode.mcp.test.ts
# Passed.
pnpm build
# Passed.
node --import tsx .artifacts/qa-e2e/code-mode-repair-b4970f/mcp-arrays/semantic-contract.mts
# Unchanged independent TypeScript/MCP schema probe: 22/60 mismatches before, 0/60 after.
node --import tsx .artifacts/qa-e2e/code-mode-repair-b4970f/mcp-arrays/mcp-wire-built-proof.mts
# Real local SDK stdio server + OpenClaw transport/namespace + compiled QuickJS:
# 8 exec/resume legs, 6 calls, 4 valid arrays accepted, 2 invalid inputs rejected.
# Owned fixture process exit verified.
node scripts/watch-pr-ci.mjs 131528 0b0249f081a914326dd8e40795996164cb2a0a30
# GREEN, exit 0.The original standalone source-worker transport attempt timed out and its failed log remains retained. The compiled-worker proof passed with the same budgets and assertions. No authenticated external-provider or full Gateway/model-loop run was performed; this is a declaration-only repair with real local MCP transport proof, not UI work or native Codex runtime work. Native Codex's separate freeform/V8 contract was checked directly in upstream Live rules require the GitHub Actions Native preparation: The native hosted-gate verifier accepted exact-head CI #33142017262 and Workflow Sanity #33141991323; no separate Testbox lease was applicable. |
|
Merged via squash.
|
Render MCP array item types with Array<...> so API.read and MCP.$api preserve enum and union grouping. Keep advertised schemas and runtime validation unchanged. Fixes openclaw#131476. Release context: Code Mode MCP declarations now correctly describe mixed enum and union arrays, including nested arrays.
Closes #131476 — Code Mode MCP array-union declarations have incorrect precedence.
What Problem This Solves
Fixes an issue where agents using Code Mode's MCP declarations could be guided toward invalid arguments when an array's item schema contained a union. For example, an array of
"red"or"blue"was advertised as"red" | "blue"[]: that accepts scalar"red"but rejects an array containing"red". BothAPI.read("mcp/<server>.d.ts")andMCP.<server>.$api()were affected.Why This Change Was Made
Use
Array<...>in the existing recursive MCP schema renderer, matching the compact schema-hint renderer's established grouping. Both declaration surfaces already share this owner, so one expression repairs enum,anyOf,oneOf, multi-type, and nested-array item grouping without a new helper, downstream workaround, or alternate path. Actual MCP schemas and validation are unchanged.The incorrect expression was introduced in the typed MCP API work, #88678 (authored and merged by @steipete on May 31, 2026), and carried into the renderer extraction in #115459. It is also present in stable tag
v2026.7.1-2; that is tagged-source evidence, not a run of the historical binary.User Impact
Code Mode now advertises array arguments that agree with the MCP server's schema, including arrays mixing valid enum or union members. The existing namespace, call shape, permissions, and output behavior remain unchanged. No dependency, configuration, SQLite, protocol, or budget changes are included. The existing Code Mode documentation already describes these inferred declarations; this restores that documented contract.
Evidence
Production LOC: +1/-1 (net 0). Tests: +68/-0. Three files; no new production abstraction or test-only production seam.
labels?: "red" | "blue"[].anyOf,oneOf, multi-type, nested, simple, and object arrays on both declaration surfaces.z.array(z.enum(["red", "blue"])); OpenClaw's stdio transport, namespace dispatcher, and built QuickJS worker completed eight exec/resume legs and six calls. Four valid arrays were accepted; scalar"red"and["green"]were rejected by server validation. Both declaration surfaces returned the same corrected header and unchanged schema. The owned fixture process was closed and its exit verified.pnpm buildpassed. No assertions, timeouts, baselines, or limits were weakened.Focused regression command:
Scoped gate:
Build:
Proof limits: the first standalone source-worker transport attempt exceeded its configured timeout. Its failed log was retained; the built-worker driver then passed with the same timeout and assertions. The source-startup cost was not diagnosed by this declaration repair. The transport proof is a real local MCP process, not an authenticated external provider or full Gateway/model-loop run. There is no Control UI change. Native Codex's freeform-source/V8 path is separate from this OpenClaw JSON-exec/QuickJS declaration owner.
AI-assisted implementation and verification with Codex; maintainer reviewed and accepted the scoped repair.