Skip to content

fix(mcp): valid results fail with nested union schema references - #145533

Merged
roboclaw-bot merged 1 commit into
mainfrom
openclaw/qa-loop-mcp-schema-resources
Sep 12, 2026
Merged

roboclaw-bot merged 1 commit into
mainfrom
openclaw/qa-loop-mcp-schema-resources

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Collaborator
Additional instructions

MUST: Keep Allow edits from maintainers enabled for this PR.

What Problem This Solves

Fixes an issue where valid structured results from MCP tools were rejected when a draft-2020-12 output schema referenced a definition inside a nullable union. A valid result could fail with an error saying the referenced schema was false.

Why This Change Was Made

Use the existing resource-preserving JSON Schema normalizer instead of a competing MCP traversal that relocated definitions while expanding union types. MCP retains its annotation-only format handling; other callers keep their defaults, and older schema drafts retain the existing SDK/AJV path.

This removes 54 net production lines. Original-schema diagnostics, invalid-result rejection, non-mutating validation, and dispatch-time validator capture remain intact. The protocol-specific Codex adapter is unchanged; it has distinct generated-schema/default/diagnostic contracts.

User Impact

MCP tools using valid nested schema references can return their results successfully. Malformed results still fail validation, and unrelated catalog tools remain usable. No constraints are stripped to make a result pass, and no public SDK API or authority behavior changes.

Evidence

  • The actual session MCP runtime and an owned stdio fixture reproduce the valid nested-resource result failure. With TypeBox 1.3.26, the parent independently ran the same regression against current main production and the candidate: baseline rejects the valid leaf with a false-schema error while still rejecting the invalid leaf; the candidate accepts the valid leaf and rejects the invalid one.
  • The two current stdio cases are included in the broader 15-case runtime selection. All 15 runtime cases and 97 normalization/schema/metadata sibling cases pass. These are not additive with the parent rerun.
  • Default and draft-specific format semantics, original malformed-schema diagnostics, no coercion/default insertion, and schema/input immutability remain covered.
  • Fresh independent P0–P2 review included the changed TypeBox 1.3.26 resolver and resource-frame code. It found no actionable issues. The assertion baseline is only reduced for removed casts and preserves unrelated upstream tightening.
  • Normal frozen install, complete changed gate against a9ff794, and normal build (6m32.1s) pass. All four production/test source hashes remain unchanged across the baseline refresh.
  • The earlier hosted CI failure remains unattributed and is not relabeled green. Fresh exact-head CI is required before landing this updated base.

@clawsweeper

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

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Sep 12, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Sep 12, 2026
@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 12, 2026, 1:06 AM ET / 05:06 UTC (Revision 3).

ClawSweeper review

What this changes

The PR reuses shared JSON Schema normalization so MCP tool results can reference definitions inside nullable unions while preserving draft-specific validation behavior.

Merge readiness

✅ Ready for maintainer review

The fix remains necessary: current main and v2026.9.4 retain the faulty schema traversal. No actionable correctness or security defect was found in the introduced patch.

Priority: P2
Reviewed head: 8435f72fb66365306ffbebbd53d961cac64bd00a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful regression coverage and no identified merge-blocking defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied maintainer/bot context exempts this PR from the external-contributor proof gate. Its body records before/after execution through the actual session MCP runtime and stdio client: the candidate accepts the valid leaf and still rejects the invalid leaf; this review inspected the matching source but did not rerun it.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied maintainer/bot context exempts this PR from the external-contributor proof gate. Its body records before/after execution through the actual session MCP runtime and stdio client: the candidate accepts the valid leaf and still rejects the invalid leaf; this review inspected the matching source but did not rerun it.
Evidence reviewed 8 items Current-main defect remains: Current main still expands union types in the MCP format-stripping traversal, moving nested definitions before the shared normalizer receives them.
Latest release retains the old implementation: Inspection of v2026.9.4 found the same competing traversal. The intervening comparison against the earlier review SHA failed because that object was unavailable; no unchanged-head claim relies on that comparison.
Single normalization owner: The shared normalizer preserves schema resource keywords outside union branches. The MCP adapter now requests annotation-only formats through that owner, after checking the original schema; older drafts still use the SDK validator.
Findings None None.
Security None None.

How this fits together

OpenClaw’s MCP client discovers external tools and validates their structured results against advertised output schemas. Schema normalization prepares those schemas for validation before results reach the agent.

flowchart TD
 A[MCP tool catalog] --> B[Output schema]
 B --> C{Schema draft}
 C -->|2020-12| D[Shared schema normalization]
 C -->|Older draft| E[SDK validator]
 D --> F[TypeBox validator]
 E --> G[Accept or reject tool result]
 F --> G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -54, Tests +174, Other 0. Total +120 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 45 99 -54
Tests 2 175 1 +174
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 5 221 101 +120

Review metrics

None.

Technical review

Best possible solution:

Keep schema-resource placement and format handling in the shared normalizer while retaining original-schema diagnostics and strict rejection of invalid tool results.

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

Yes: current source moves the referenced definition away from its JSON pointer, and TypeBox resolves the missing target to false. The stdio regression supplies a concrete reproduction path; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes: removing the competing traversal repairs the producer of the invalid schema while preserving the existing validator contracts and default behavior for other callers.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 39708c63ddd0.

Labels

Label justifications:

  • P2: Repairs valid MCP results rejected by a specific nested-schema shape without changing configuration or authorization.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied maintainer/bot context exempts this PR from the external-contributor proof gate. Its body records before/after execution through the actual session MCP runtime and stdio client: the candidate accepts the valid leaf and still rejects the invalid leaf; this review inspected the matching source but did not rerun it.

Evidence

What I checked:

  • Current-main defect remains: Current main still expands union types in the MCP format-stripping traversal, moving nested definitions before the shared normalizer receives them. (src/agents/mcp-json-schema-validator.ts:66, 39708c63ddd0)
  • Latest release retains the old implementation: Inspection of v2026.9.4 found the same competing traversal. The intervening comparison against the earlier review SHA failed because that object was unavailable; no unchanged-head claim relies on that comparison. (src/agents/mcp-json-schema-validator.ts:66, 3a9d69db306c)
  • Single normalization owner: The shared normalizer preserves schema resource keywords outside union branches. The MCP adapter now requests annotation-only formats through that owner, after checking the original schema; older drafts still use the SDK validator. (packages/normalization-core/src/json-schema.ts:172, 8435f72fb663)
  • Production boundary and regression coverage: The added stdio cases invoke the real session runtime, accept the string leaf, reject the numeric leaf, and retain a healthy sibling tool. Other added cases protect original diagnostic paths, format semantics, schema immutability, and absence of coercion or default insertion. Runtime dispatch still captures its result validator before awaiting the tool call. (src/agents/agent-bundle-mcp-runtime.test.ts:1155, 8435f72fb663)
  • Dependency contract inspected: The changed adapter directly imports TypeBox Compile, establishing the dependency signal. Published TypeBox 1.3.26 source resolves JSON pointers against schema resources and substitutes false for unresolved references, matching the reported failure mechanism. npm metadata verifies repository ownership; the package commit SHA was not supplied.
  • Older-draft behavior preserved: Published SDK 1.30.0 source enables format validation and returns the original input on success without enabling coercion or default insertion. npm metadata verifies this dependency’s repository ownership.

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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-12T02:38:48.310Z sha c42e27f :: needs maintainer review before merge. :: none
  • reviewed 2026-09-12T02:44:36.701Z sha c42e27f :: needs maintainer review before merge. :: none

@roboclaw-bot
roboclaw-bot marked this pull request as ready for review September 12, 2026 02:40
Keep schema resources at their original paths by using the canonical normalizer instead of a competing MCP prepass. Preserve annotation-only formats, older-draft validation, original diagnostics and invalid-result rejection. Removes 54 net production lines. Verified real stdio regression, parent runtime proof, owner siblings, complete changed gates, normal build and exact-source P2 review.

Co-authored-by: steipete <[email protected]>
@roboclaw-bot
roboclaw-bot force-pushed the openclaw/qa-loop-mcp-schema-resources branch from c42e27f to 8435f72 Compare September 12, 2026 04:34
@roboclaw-bot
roboclaw-bot merged commit ccb230e into main Sep 12, 2026
184 of 186 checks passed
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Merged via squash.

@roboclaw-bot
roboclaw-bot deleted the openclaw/qa-loop-mcp-schema-resources branch September 12, 2026 07:03
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 13, 2026
…nclaw#145533)

Use the shared JSON Schema normalization owner for MCP structured-result validation instead of a competing traversal that moves nested resource definitions. Preserve original-schema diagnostics, draft-specific validation and annotation-only format behavior. Production +45/-99, net 54 lines removed.

With TypeBox 1.3.26, the parent independently exercised the real stdio/session runtime before and after the change: baseline rejected a valid leaf with a false-schema error while rejecting the invalid leaf; the candidate accepts the valid leaf and still rejects invalid output. Both production files were restored and source hashes verified.

The 15-case runtime selection, 97 sibling cases, complete changed checks, normal build and fresh P0–P2 review passed. The two parent stdio cases overlap the runtime selection. Exact-head CI passed and the current-head Claw review reported no blocking findings; the earlier head’s hosted failure remains unattributed. No HTTP/provider requests, dependency edits or guard overrides were used for proof.

Co-authored-by: steipete <[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 maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

1 participant