Skip to content

Fix batch MCP routing collisions and preserve native inputs - #1822

Open
anateus wants to merge 10 commits into
1jehuang:masterfrom
anateus:fix/batch-mcp-routing-collision
Open

anateus wants to merge 10 commits into
1jehuang:masterfrom
anateus:fix/batch-mcp-routing-collision

Conversation

@anateus

@anateus anateus commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1811 (batch MCP selector collisions).

Keep the batch selector separate from the complete child input under parameters, and advertise that form in the schema and examples. Legacy flat calls use the effective child schema to preserve native name, arguments, args, and input fields. Unambiguous name: "mcp_call" wrappers retain the raw MCP tool, server, and arguments. Conflicting known routes are rejected before any child executes, while equivalent aliases still select one tool.

This overlaps with #1817, but covers the intended behavior beyond removing a duplicate alias. I ran the same real child-dispatch checks against its e69e269 head and this branch. Its flat skill call loses name, and its legacy MCP call dispatches the raw tool instead of mcp_call. Here, the real SkillTool loads the requested skill and the local MCP transport receives the exact raw tool and arguments. The canonical nested control still works. Regression tests and explicit CI selection are included.

The follow-up fixes address the three findings from this PR's first Greptile review: ordinary conflicting selectors such as read/edit, native names under unresolved external or cyclic schemas, and native argument envelopes declared through patternProperties. Route comparisons use the same session-aware identity as dispatch. Unknown schema traversal preserves child fields rather than guessing a different route. Each defect has a behavioral regression that failed before the fix and passes afterward, plus coverage for equivalent functions.read/read selectors.

The remaining dependentSchemas review finding is fixed in fb857368d. Conditional declarations now preserve native child fields, including local references, without removing the existing traversal limits. The SDK regression failed before the fix with the reported ambiguity error and passes afterward, including its independent sibling callback.

Validation on October 20, 2026, after merging master at c607a88a9: all 44 batch tests and both registry schema-consumer tests passed through the CI timeout runner. Formatting, module resolution, locked metadata, and patch whitespace checks passed. The new batch CI commands also use --locked, matching the surrounding checks. The final base refresh preserves the upstream 200-character description limit with a 194-character nested MCP example.

Earlier validation, before the October 20 base refresh

Previous validation on the earlier repaired sources: 39 batch tests and both schema consumer tests passed through the committed CI timeout runner. The registry cohort passed 59 tests with one existing ignore and three explicit unrelated exclusions (post-tool feedback hook and two token-cap tests). All 9 provider-matrix tests and 60 end-to-end tests passed, with the 7 existing end-to-end ignores retained. Changed-crate warnings-denied Clippy, cargo check --all-targets --all-features, locked metadata, changed-file formatting, module resolution, test-size, dependency-boundary, and wildcard-re-export checks also passed.

I also rebuilt the actual CLI and drove a real isolated daemon through its public debug commands. Flat batch loaded the tracked optimization skill, matching the direct control. Direct mcp_call, the original legacy flat shape, and canonical nested batch all read the same real Cargo manifest through the official filesystem MCP server. The live tool catalog exposes parameters, and ordinary read/edit ambiguity returns the documented error instead of dispatching. This used public repository files, not a mock MCP backend, customer systems, user credentials, or a model prompt.

Current merge gate, October 20, 2026

The pushed head is aade491b7, and GitHub reports it as conflict-free. Both the current-head CI run and linked-issue run are action_required, with no jobs executed. The contributor account has read-only access to the upstream repository, so a maintainer must approve those workflow runs.

The base refresh includes the upstream fixes for the original Windows listener error, missing Tokio test feature, and six jcode-base lint errors. It does not make the PR ready to merge: master CI at 5e7e0457c still fails two Muse provider-matrix tests, Clippy, the warning budget, and the code-size, test-size, panic, and swallowed-error ratchets. The four structural checks also fail locally with the inherited diagnostics. No baselines or gates were relaxed. Merge still depends on those failures being repaired and the required checks passing on this PR head.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium impact] Batch tool routing and schema handling for MCP calls.

Do not merge until the dependentSchemas regression is fixed: valid SDK input can stop an entire flat batch, including independent sibling calls.

Findings

  1. P1 Valid native names stop batches ▶
Fix with agent prompt
### Issue 1
crates/jcode-app-core/src/tool/batch.rs:178
`schema_property_declaration` skips `dependentSchemas`, so it mistakes a native `name` for a second tool selector. An SDK tool can declare `name` under `dependentSchemas.kind.properties` and receive `{"tool":"custom_tool","kind":"lookup","name":"mcp_call"}`. SDK registration accepts this schema, but the walker returns `Some(false)` for `name`. When both routes are registered, the entire flat batch is rejected before the requested tool or any independent sibling executes.

The same request executes successfully on the PR base, and direct and nested calls still succeed on this head. Follow the schemas inside `dependentSchemas`, or treat this form as unknown rather than assuming the field is absent.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

T-Rex evidence

Executed SDK and batch regression test

  • The authored Rust harness exercises SDK configuration, direct and nested controls, and flat batches at both revisions, asserting callback payloads and counts.

Before and after validation runner

  • The executed Python runner includes the same test at the selected base and head, captures exact commands and results, and restores tracked source files.

Selected PR diff and current source locations

  • Executed Git and numbered-source commands capture the selected scope and the schema traversal and rejection locations, tying the observed behavior to the changed code.

Base responses with successful flat batch

  • The base run captures accepted configuration and successful direct, nested, and flat requests, showing that the custom tool and independent sibling both execute.

Head responses with rejected flat batch

  • The head run captures successful direct and nested controls followed by the flat batch ambiguity error and zero callbacks, confirming the regression.

Complete validation command and output

  • The captured runner execution records the reproduction command, exit code 0, and both test runs, showing that all before and after behavioral assertions completed.

Tracked file restoration and worktree cleanup

  • Executed Git checks show no tracked diff and only the original head worktree remains, confirming that temporary source changes were restored.

Evidence from the check

  • The authored Rust harness exercises SDK configuration, direct and nested controls, and flat batches at both revisions, asserting callback payloads and counts.

Evidence from the check

  • The executed Python runner includes the same test at the selected base and head, captures exact commands and results, and restores tracked source files.

Command output from the check

  • Executed Git and numbered-source commands capture the selected scope and the schema traversal and rejection locations, tying the observed behavior to the changed code.

Command output from the check

  • The base run captures accepted configuration and successful direct, nested, and flat requests, showing that the custom tool and independent sibling both execute.

Command output from the check

  • The head run captures successful direct and nested controls followed by the flat batch ambiguity error and zero callbacks, confirming the regression.

Command output from the check

  • The captured runner execution records the reproduction command, exit code 0, and both test runs, showing that all before and after behavioral assertions completed.

Command output from the check

  • Executed Git checks show no tracked diff and only the original head worktree remains, confirming that temporary source changes were restored.

View artifacts

Summary

The PR separates batch routing from child input through parameters, while keeping legacy flat calls.

  • Batch calls keep child inputs separate from routing selectors.

Reviews (3) · Last reviewed commit: "fix(batch): preserve fields in explicitl..." · Reviewed by Greptile

Comment thread crates/jcode-app-core/src/tool/batch.rs Resolved
Comment thread crates/jcode-app-core/src/tool/batch.rs Resolved
Comment thread crates/jcode-app-core/src/tool/batch.rs Resolved
anateus added a commit to anateus/jcode that referenced this pull request Oct 13, 2026
Reject conflicting known selectors before dispatch using their effective
session-aware route identity. Preserve native fields when external references,
cycles or pattern properties prevent proving that the child schema omits them.

Add execution and SDK callback regressions for all three review findings,
including equivalent qualified selectors and independent sibling dispatch.

Refs 1jehuang#1811, 1jehuang#1822

@1jehuang 1jehuang left a comment •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the thorough implementation and validation. I refreshed this PR against master, independently reviewed it, and added a focused follow-up in e4b3e91 that preserves native fields allowed by explicit additionalProperties. The new SDK callback regression failed before the fix and passes afterward; your original commits are preserved.

Final local verification passed 44 batch tests, both schema-consumer tests, and 69 provider-matrix/e2e tests (7 existing ignores). A rebuilt isolated CLI also loaded the tracked optimization skill through direct, flat-batch, and nested-batch calls with matching contents, and rejected conflicting selectors. Remote verification was attempted but fell back locally because the remote machine could not create the isolated checkout path.

I approved and monitored current-head CI (38543181237). Its Windows cross-target job failed on unchanged jcode-companion/src/server.rs:209 (E0596), and Quality Guardrails failed on six unchanged jcode-base warning/Clippy findings. Other platform jobs are still running, but these completed failed jobs already prevent a green CI result. I am leaving the PR open rather than bypassing that merge gate. Code/test-size, panic, and swallowed-error gate outputs were identical on clean master and the integrated patch. No baselines or CI gates were relaxed.


Jcode agent (automated triage), on behalf of @1jehuang

Comment thread crates/jcode-app-core/src/tool/batch.rs Resolved
anateus and others added 8 commits October 21, 2026 18:29
Expose nested parameters in the batch schema and examples so wrapper selectors don't compete with native child fields. Preserve flat calls, recover unambiguous name-routed wrappers using effective tool schemas, and reject ambiguous routes before execution.

Keep native arguments, args, input, and name fields intact. Bound schema inspection without resolving external references. Add regressions for duplicate MCP selectors, routing-field loss, nested dispatch, and compatibility cases.
Preserve a schema-declared native name even when its value names another registered tool. Add regressions for direct properties, schema combiners, and local references, plus execution-level checks for ambiguous selectors and session-local SDK schemas.

Keep the new parameter description within the prompt budget and remove the production selector unwrap. Run the batch cohort and both registry schema checks explicitly in the Linux and macOS CI matrix. The existing no-run step compiled these tests without executing them.

Refs 1jehuang#1811.
Add isolated local MCP endpoint tests for the original selector collision, canonical nested input, and native server/arguments preservation. Assert the raw tool and exact arguments received by the backend, with a cleared environment, bounded work, and disconnect after every outcome.

The same tests fail on the unchanged master parser for both bug cases while the nested control passes. All three pass on the fix, and the existing batch CI selector runs them.

Refs 1jehuang#1811.
Verify that flat skill_manage calls retain the child name and load the requested temporary project skill. Exercise the real SkillTool through batch dispatch, with an empty global registry and isolated project fixture.

Refs 1jehuang#1811.
Reject conflicting known selectors before dispatch using their effective
session-aware route identity. Preserve native fields when external references,
cycles or pattern properties prevent proving that the child schema omits them.

Add execution and SDK callback regressions for all three review findings,
including equivalent qualified selectors and independent sibling dispatch.

Refs 1jehuang#1811, 1jehuang#1822
Follow dependentSchemas when identifying native child fields so a conditional
name declaration does not reject a valid flat batch or block its siblings.
Keep local-reference resolution and the existing depth and work limits.

Add an SDK callback regression, declaration and traversal-limit checks, and
coverage for conditional arguments. Require locked dependencies in the batch
CI commands, matching the surrounding test steps.

Validation: 44 batch tests and both registry schema-consumer tests passed.
Refs 1jehuang#1811.
@anateus
anateus force-pushed the fix/batch-mcp-routing-collision branch from aade491 to 1959013 Compare October 22, 2026 01:46
@timorunge

Copy link
Copy Markdown

One more shape that fails today and isn't in the new tests: the unified mcp tool with action: "call", where arguments is the MCP tool's own field.

Observed on jcode v0.99.1 (7206efd), macOS arm64:

// works
{"tool_calls":[{"tool":"mcp","action":"search","server":"example_server","query":"lookup","intent":"x"}]}

// fails: "missing field `action`" (the sibling fields are dropped once `arguments` is present)
{"tool_calls":[{"tool":"mcp","action":"search","server":"example_server","query":"lookup","arguments":{"x":1},"intent":"x"}]}

// fails the same way: the real-world case
{"tool_calls":[{"tool":"mcp","action":"call","server":"example_server","tool":"example_lookup","arguments":{"id":"abc123"},"intent":"x"}]}

// without `arguments` the error moves to the next field: "missing field `tool`"
{"tool_calls":[{"tool":"mcp","action":"call","server":"example_server","intent":"x"}]}

The same mcp call works outside batch. The workaround that works today is to nest everything under arguments:

{"tool_calls":[{"tool":"mcp","intent":"x","arguments":{"action":"call","server":"example_server","tool":"example_lookup","arguments":{"id":"abc123"}}}]}

So two things collide here: arguments is read as the sub-call envelope, and the child's own tool param collides with batch's tool selector. It's worth adding the mcp + action: "call" case next to normalization_preserves_flat_arguments_and_routing_siblings, so the fix covers the unified tool as well as mcp_call and mcp__server__tool.

xenking added a commit to xenking/jcode that referenced this pull request Nov 22, 2026
Port the intent of 1jehuang#1822.

Co-authored-by: Michael Katsevman <[email protected]>
xenking added a commit to xenking/jcode that referenced this pull request Nov 22, 2026
Upstream-PR: 1jehuang#1357
Upstream-PR-Commit: 1jehuang#1357 0da5e81
Upstream-PR: 1jehuang#1362
Upstream-PR-Commit: 1jehuang#1362 5962058
Upstream-PR: 1jehuang#1486
Upstream-PR-Commit: 1jehuang#1486 fadc624
Upstream-PR: 1jehuang#1733
Upstream-PR-Commit: 1jehuang#1733 01f3415
Upstream-PR: 1jehuang#1750
Upstream-PR-Commit: 1jehuang#1750 1ac0c82
Upstream-PR: 1jehuang#1822
Upstream-PR-Commit: 1jehuang#1822 73f85fc
Upstream-PR: 1jehuang#1912
Upstream-PR-Commit: 1jehuang#1912 36d7682
Upstream-PR: 1jehuang#1978
Upstream-PR-Commit: 1jehuang#1978 0f55643
Upstream-PR: 1jehuang#2007
Upstream-PR-Commit: 1jehuang#2007 638f87c
Upstream-PR: 1jehuang#2213
Upstream-PR-Commit: 1jehuang#2213 c5e1487
Upstream-PR: 1jehuang#2234
Upstream-PR-Commit: 1jehuang#2234 0d4d5d4
Upstream-PR: 1jehuang#2266
Upstream-PR-Commit: 1jehuang#2266 217ddc2
Upstream-PR: 1jehuang#2267
Upstream-PR-Commit: 1jehuang#2267 e98c40b

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Batch MCP calls fail with duplicate field tool when wrapper and child selectors collide

3 participants