Skip to content

fix(mcp): bundle surfaces received keys on missing-arg errors (#357)#362

Merged
justrach merged 2 commits into
mainfrom
fix/issue-357-bundle-diagnostic
May 3, 2026
Merged

fix(mcp): bundle surfaces received keys on missing-arg errors (#357)#362
justrach merged 2 commits into
mainfrom
fix/issue-357-bundle-diagnostic

Conversation

@justrach

@justrach justrach commented May 3, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #357.

The issue reports repeated error: missing 'path' argument from bundled codedb_outline calls and suspects codedb_bundle is dropping nested arguments. It isn't — verified two ways:

  1. Direct MCP probe — bundles with nested arguments: {path: "..."} and inline {tool, path: "..."} both work. The error fires only when the op genuinely lacks path (wrong key like file_path, or no args at all).
  2. Sonnet 4.6 sub-agent reproducer independently confirmed the same.

From the user's side it's indistinguishable from "codedb dropped path", which is why this issue was filed. The issue's "Expected behavior" actually allows a second resolution: machine-readable diagnostics on malformed ops. That's what this PR ships.

Change

When a bundled op fails with error: missing ..., the bundle wrapper now appends a received keys: [...] line listing the keys actually present in that op. Callers can immediately tell whether codedb dropped the field or the client sent it under the wrong name.

Before

--- [0] codedb_outline ---
error: missing 'path' argument

After

--- [0] codedb_outline ---
error: missing 'path' argument
received keys: [tool, arguments]

When the agent sent file_path by mistake:

--- [0] codedb_outline ---
error: missing 'path' argument
received keys: [file_path]

Implementation

  • New helper appendBundleArgKeysDiagnostic in src/mcp.zig.
  • handleBundle calls it when sub_out.items starts with error: missing.
  • Iterates the op's resolved sub_args map (which is whichever side of the nested/inline format the bundle resolved) and writes the keys.

Test coverage

  • src/tests.zig:
  • scripts/test_issue_357_bundle_diagnostic.py — E2E driver against real JSON-RPC stdio. 11/11 pass against the freshly-built binary. Covers all four shapes (nested ok, inline ok, wrong-key fail+diagnostic, no-args fail+diagnostic).

Test plan

  • zig build test — 423/423 pass
  • python3 scripts/test_issue_357_bundle_diagnostic.py — 11/11 pass
  • Failing test committed before the fix (per repo policy)
  • Reviewer: spot-check that the diagnostic doesn't leak sensitive values (it lists keys, not values, and only on the explicit error: missing path)

🤖 Generated with Claude Code

justrach and others added 2 commits May 4, 2026 01:05
Adds two tests under issue-357:

1. Pin the existing nested-args bundle path — verifies a bundle with
   {tool, arguments: {path}} preserves path correctly. Passes today;
   serves as a regression guard against future bundle arg-marshalling
   regressions.

2. Failing test for the diagnostic improvement: when a bundle op fails
   with 'missing path argument', the bundle wrapper should append the
   keys actually received in that op so callers can tell whether
   codedb dropped the arg or the client sent it under the wrong name
   (e.g. file_path instead of path).

The second test fails on main — 'received keys' diagnostic is not
implemented yet. This is the actionable fix #357 actually asks for in
its 'Expected behavior' section.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Issue #357 reported repeated 'missing path argument' errors from
bundled codedb_outline calls, suspecting that codedb_bundle was
dropping nested arguments. Direct MCP probes and a Sonnet 4.6
agent reproducer both confirm bundled args are preserved correctly
through both supported formats:

  {"tool": "codedb_outline", "arguments": {"path": "..."}}   # nested
  {"tool": "codedb_outline", "path": "..."}                   # inline

The error fires only when the bundle op genuinely lacks a 'path'
key — e.g. agent sends 'file_path' instead of 'path', or omits args
entirely. From the user-visible side it's indistinguishable from
"codedb dropped path", which is why the issue was filed.

This matches the issue's "Expected behavior" #2 (machine-readable
diagnostics for malformed ops): when a bundled op fails with
'error: missing ...', the bundle wrapper now appends a
'received keys: [...]' line listing the keys actually present in
that op. Callers can immediately tell whether the field was
dropped by codedb or sent under the wrong name.

Example output for a malformed op:

    --- [0] codedb_outline ---
    error: missing 'path' argument
    received keys: [tool, arguments]

Fix: src/mcp.zig
  - new helper appendBundleArgKeysDiagnostic
  - handleBundle calls it when sub_out starts with "error: missing"

Tests: src/tests.zig
  - issue-357: bundle preserves nested 'arguments' for codedb_outline
    (regression pin — passes today, guards against future regressions)
  - issue-357: bundle surfaces received keys when an op is missing
    required path (failing on main, passes with this fix)

E2E coverage: scripts/test_issue_357_bundle_diagnostic.py
  Drives the real MCP over JSON-RPC stdio with all four shapes
  (nested ok, inline ok, wrong-key fail+diagnostic, no-args
  fail+diagnostic). 11/11 pass against the built binary.

Closes #357

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@justrach justrach merged commit 2ea44c5 into main May 3, 2026
1 check passed
@github-actions

github-actions Bot commented May 3, 2026

Copy link
Copy Markdown

Benchmark Regression Report

Thresholds: 10.00% and 50,000 ns absolute delta

NOISE means the percentage threshold was exceeded, but the absolute delta was too small to fail CI.

Tool Base (ns) Head (ns) Delta Abs Delta (ns) Status
codedb_bundle 525119 522997 -0.40% -2122 OK
codedb_changes 56708 54661 -3.61% -2047 OK
codedb_deps 9070 10346 +14.07% +1276 NOISE
codedb_edit 7339 5352 -27.07% -1987 OK
codedb_find 61380 61655 +0.45% +275 OK
codedb_hot 99082 97773 -1.32% -1309 OK
codedb_outline 291087 285676 -1.86% -5411 OK
codedb_read 93432 93117 -0.34% -315 OK
codedb_search 175909 172656 -1.85% -3253 OK
codedb_snapshot 281581 268238 -4.74% -13343 OK
codedb_status 201251 199529 -0.86% -1722 OK
codedb_symbol 59235 58650 -0.99% -585 OK
codedb_tree 45410 44106 -2.87% -1304 OK
codedb_word 68422 68940 +0.76% +518 OK

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.

MCP bundle should preserve nested tool arguments for codedb_outline

1 participant