Repository navigation
fix(batch): drop alias 'name' when 'tool' is present to avoid duplicate-field error - #1817
akushonkamen wants to merge 1 commit into
Conversation
…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]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
| } else { | ||
| obj.remove("name"); |
There was a problem hiding this comment.
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.
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.| } else { | ||
| obj.remove("name"); |
There was a problem hiding this comment.
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.
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.|
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. |
|
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 |
Fixes #1811.
Root cause
normalize_batch_inputincrates/jcode-app-core/src/tool/batch.rsonly consumed thenamekey whentoolwas absent.ToolCallInput.toolcarries#[serde(alias = "name")], so when an MCP wrapper payload contained both keys, the leftovernamehit the deserializer as a secondtooland serde failed withError("duplicate fieldtool", line: 0, column: 0).Fix
toolis present, drop the aliasednamekey instead of leaving it in place (crates/jcode-app-core/src/tool/batch.rs:136).nameto the key filter of the fold-back fallback so a residualnamenever leaks into child arguments (crates/jcode-app-core/src/tool/batch.rs:190).test_normalize_mixed_tool_and_name_keysandtest_normalize_name_key_to_tool, both passing.A claim comment (with AI disclosure) was already posted on the issue: #1811 (comment)
Validation
CARGO_TARGET_DIR=… cargo test -p jcode-app-core batch: 27 passed; 2 failed, reproducingError("duplicate fieldtool", line: 0, column: 0)via the newtest_normalize_wrapper_name_and_child_tool_keys_collide.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.