Skip to content

fix(batch): drop alias 'name' when 'tool' is present to avoid duplicate-field error - #1817

Open
akushonkamen wants to merge 1 commit into
1jehuang:masterfrom
akushonkamen:fix/1811-batch-mcp-duplicate-tool
Open

akushonkamen wants to merge 1 commit into
1jehuang:masterfrom
akushonkamen:fix/1811-batch-mcp-duplicate-tool

Conversation

@akushonkamen

Copy link
Copy Markdown
Contributor

Fixes #1811.

Root cause

normalize_batch_input in crates/jcode-app-core/src/tool/batch.rs only consumed the name key when tool was absent. ToolCallInput.tool carries #[serde(alias = "name")], so when an MCP wrapper payload contained both keys, the leftover name hit the deserializer as a second tool and serde failed with Error("duplicate field tool", line: 0, column: 0).

Fix

  • When tool is present, drop the aliased name key instead of leaving it in place (crates/jcode-app-core/src/tool/batch.rs:136).
  • Add name to the key filter of the fold-back fallback so a residual name never leaks into child arguments (crates/jcode-app-core/src/tool/batch.rs:190).
  • Added 2 unit tests covering the dual-key normalization and the fold-back exclusion. The legacy name-only / tool-only paths remain covered by the existing test_normalize_mixed_tool_and_name_keys and test_normalize_name_key_to_tool, both passing.

A claim comment (with AI disclosure) was already posted on the issue: #1811 (comment)

Validation

  • Red (before fix), CARGO_TARGET_DIR=… cargo test -p jcode-app-core batch: 27 passed; 2 failed, reproducing Error("duplicate field tool", line: 0, column: 0) via the new test_normalize_wrapper_name_and_child_tool_keys_collide.
  • Green (after fix), same command: 29 passed; 0 failed.
  • Full cargo test -p jcode-app-core: 1547 passed; 9 failed; 32 ignored. All 9 failures are pre-existing on master and environment/network related (fetch_listing_hard_fails_when_endpoint_unreachable, token-cap tests, socket-timing tests, etc.) — none touch batch; confirmed against a stashed clean tree earlier.
  • cargo clippy -p jcode-app-core --all-targets: only pre-existing warnings (e.g. pricing.rs:188).
  • cargo fmt -p jcode-app-core -- --check: passes.

…te-field error

ToolCallInput.tool carries #[serde(alias = "name")], and
normalize_batch_input only consumed "name" when "tool" was absent. A
batch MCP sub-call carrying both the wrapper selector ("name") and the
raw child tool name ("tool") therefore failed deserialization with
`duplicate field 'tool'` before any request was sent (issue 1jehuang#1811).

Also exclude a leftover "name" from the flat-form folding into
parameters, like "tool" itself, so it never reaches the child input.

Closes 1jehuang#1811

Signed-off-by: akushonkamen <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 3/5

[Medium impact] Fixes deserialization error in batch tool-call normalization.

Not safe to merge as written: working flat skill calls now fail, and the MCP wrapper payload still cannot reach its intended server.

Findings

  1. P1 Flat calls lose child names ▶
  2. P1 MCP calls still cannot run ▶
Fix with agent prompt
### Issue 1
crates/jcode-app-core/src/tool/batch.rs:145-146
A flat batch call such as `{"tool":"skill_manage","intent":"Load a skill","action":"load","name":"optimization"}` previously moved `name` into `parameters`. The new removal and fold filter discard it, so `skill_manage` fails with `'name' is required for load action`.

The same call successfully loaded an installed skill before this change; afterward, the batch reported zero successes and one failure. Preserve legitimate child arguments named `name` in the flat form and add a regression test before merging.

### Issue 2
crates/jcode-app-core/src/tool/batch.rs:145-146
The MCP payload in the new test now parses, but removing `name:"mcp_call"` makes the batch dispatch `example_lookup` directly rather than invoke `mcp_call`. Moving `arguments` to `parameters` also leaves `server` outside the child input, where deserialization drops it.

Executing this payload with `batch` and `mcp_call` registered returned `Unknown tool: example_lookup` and zero successful calls. A canonical nested MCP call reached the requested server successfully. If a registry tool named `example_lookup` exists, the repaired payload invokes that tool instead and reports success without reaching the intended MCP server.

Before merging, normalize this shape to `tool:"mcp_call"` with `server`, the raw `tool`, and `arguments` inside `parameters`, and add a test that executes the child call rather than only checking that it parses.

---

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

T-Rex evidence

Rust execution output before the change

  • Ran the regression test against base batch code and captured normalization plus real skill dispatch; the flat call preserves its name and succeeds.

Rust execution output after the change

  • Ran the identical regression test against head batch code and captured the missing-name child error; the flat call fails while nested and direct controls succeed.

Executed Rust regression test source

  • Authored and executed a fixture-backed test of production normalization and real child dispatch; its preservation assertion detects the regression.

Executed isolated before-and-after runner source

  • Executed this runner to switch batch revisions in an isolated worktree and capture command output and exit codes; the paired runs compare the same contract.

View artifacts

Summary

The PR removes a sibling name when a batch call already has tool, excludes name from folded child arguments, and adds two tests.

Two blocking problems remain:

  • Batch calls keep the child tool when wrapper and child names differ.

The unchanged name-only selector conversion remains intact. Both problems in batch normalization must be fixed before merging.

Reviews (1) · Last reviewed commit: "fix(batch): drop alias 'name' when 'tool..." · Reviewed by Greptile

Comment on lines +145 to +146
} else {
obj.remove("name");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Flat calls lose child names

A flat batch call such as {"tool":"skill_manage","intent":"Load a skill","action":"load","name":"optimization"} previously moved name into parameters. The new removal and fold filter discard it, so skill_manage fails with 'name' is required for load action.

The same call successfully loaded an installed skill before this change; afterward, the batch reported zero successes and one failure. Preserve legitimate child arguments named name in the flat form and add a regression test before merging.

Artifacts

Rust execution output before the change

  • Ran the regression test against base batch code and captured normalization plus real skill dispatch; the flat call preserves its name and succeeds.

Rust execution output after the change

  • Ran the identical regression test against head batch code and captured the missing-name child error; the flat call fails while nested and direct controls succeed.

Executed Rust regression test source

  • Authored and executed a fixture-backed test of production normalization and real child dispatch; its preservation assertion detects the regression.

Executed isolated before-and-after runner source

  • Executed this runner to switch batch revisions in an isolated worktree and capture command output and exit codes; the paired runs compare the same contract.

View artifacts

T-Rex Ran code and verified through T-Rex

Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-app-core/src/tool/batch.rs
Line: 145-146

Comment:
**Flat calls lose child names**

A flat batch call such as `{"tool":"skill_manage","intent":"Load a skill","action":"load","name":"optimization"}` previously moved `name` into `parameters`. The new removal and fold filter discard it, so `skill_manage` fails with `'name' is required for load action`.

The same call successfully loaded an installed skill before this change; afterward, the batch reported zero successes and one failure. Preserve legitimate child arguments named `name` in the flat form and add a regression test before merging.

---

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

Comment on lines +145 to +146
} else {
obj.remove("name");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 MCP calls still cannot run

The MCP payload in the new test now parses, but removing name:"mcp_call" makes the batch dispatch example_lookup directly rather than invoke mcp_call. Moving arguments to parameters also leaves server outside the child input, where deserialization drops it.

Executing this payload with batch and mcp_call registered returned Unknown tool: example_lookup and zero successful calls. A canonical nested MCP call reached the requested server successfully. If a registry tool named example_lookup exists, the repaired payload invokes that tool instead and reports success without reaching the intended MCP server.

Before merging, normalize this shape to tool:"mcp_call" with server, the raw tool, and arguments inside parameters, and add a test that executes the child call rather than only checking that it parses.

Knowledge Base Used:

Artifacts

Rust execution output before the change

  • Ran the regression test against base batch code and captured normalization plus real skill dispatch; the flat call preserves its name and succeeds.

Rust execution output after the change

  • Ran the identical regression test against head batch code and captured the missing-name child error; the flat call fails while nested and direct controls succeed.

Executed Rust regression test source

  • Authored and executed a fixture-backed test of production normalization and real child dispatch; its preservation assertion detects the regression.

Executed isolated before-and-after runner source

  • Executed this runner to switch batch revisions in an isolated worktree and capture command output and exit codes; the paired runs compare the same contract.

View artifacts

T-Rex Ran code and verified through T-Rex

Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-app-core/src/tool/batch.rs
Line: 145-146

Comment:
**MCP calls still cannot run**

The MCP payload in the new test now parses, but removing `name:"mcp_call"` makes the batch dispatch `example_lookup` directly rather than invoke `mcp_call`. Moving `arguments` to `parameters` also leaves `server` outside the child input, where deserialization drops it.

Executing this payload with `batch` and `mcp_call` registered returned `Unknown tool: example_lookup` and zero successful calls. A canonical nested MCP call reached the requested server successfully. If a registry tool named `example_lookup` exists, the repaired payload invokes that tool instead and reports success without reaching the intended MCP server.

Before merging, normalize this shape to `tool:"mcp_call"` with `server`, the raw `tool`, and `arguments` inside `parameters`, and add a test that executes the child call rather than only checking that it parses.

**Knowledge Base Used:**
- [Agent execution and tooling](https://app.greptile.com/solo-systems/-/custom-context/knowledge-base/1jehuang/jcode/-/docs/agent-execution-and-tooling.md)
- [Application server and tool services](https://app.greptile.com/solo-systems/-/custom-context/knowledge-base/1jehuang/jcode/-/docs/application-server-and-tool-services.md)

---

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

@anateus

anateus commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Sorry for overlapping this PR in #1822 🙏 but I already had most of it done when I posted the issue, just forgot to put the PR up until later.

@akushonkamen

Copy link
Copy Markdown
Contributor Author

No apology needed @anateus — thanks for flagging the overlap, and thanks for the quick work on #1822. For anyone comparing the two: #1822 restructures the batch selector so the child input lives under parameters and keeps native fields intact, while this PR takes the narrower path of dropping the aliased name key when tool is present so serde doesn't see a duplicate field. They fix the same class of collision from different directions. I'm happy to defer to the maintainers on which approach fits the project better — if #1822 is preferred, I'll close this one; if the minimal fix is useful as a stopgap, this PR is ready for review. Either way, happy to rebase or adjust.

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

2 participants