Validate call_tools up front and report every batch in one envelope (0.1.1-dev.1) #105

Merged
john merged 1 commit from feat/batch-envelope into main 2026-11-25 03:14:53 +00:00
Owner

Why

A corn_call_tools request today came back as a raw pydantic error because the caller had copied response fields (succeeded, total_ms) into its request. While reproducing it I found a worse, silent bug: BatchCallItem drops unknown keys, so {"tool": "coder_workspace_bash", "args": {...}} runs the tool with empty arguments.

What changes

  • Unknown keys are rejected, never dropped (extra="forbid" on the item and the whole request; this also shows in the published input schema as additionalProperties: false).
  • The whole batch is validated before any call runs (_BatchArgumentErrors, innermost middleware so auth and timing still wrap it). A rejected batch has the same shape as an accepted one:
{
  "status": "rejected", "executed": 0, "succeeded": 0, "failed": 0, "invalid": 1, "not_run": 1,
  "results": [
    {"index": 0, "id": "edit",  "tool": "record", "ok": false, "status": "not_run"},
    {"index": 1, "id": "tests", "tool": "record", "ok": false, "status": "invalid",
     "errors": {"args": "unknown key; did you mean 'arguments'?"}}
  ],
  "total_ms": 0.1,
  "error": {"code": "invalid_arguments", "message": "Nothing ran. Fix the listed fields and resend the same calls.",
            "expected": "{calls: [{tool, arguments?, id?}] (1-20 items), max_concurrency?: 1-10}"}
}

Problems with the batch itself go in error.errors, for example "succeeded": "response field copied from a previous corn_call_tools result; remove it". Rejections are flagged isError and carry the envelope as both structured and text content. Submitted values are never echoed (include_input=False), and more than 20 calls are never listed back.

  • Accepted batches gain status: completed|partial, executed, invalid, not_run, and a per-call status: ok|error|invalid. They are never flagged isError, because some clients drop the structured content of error-flagged results.

Behaviour change for reviewers

Unknown-tool and recursive calls never ran, so they now count as invalid, not failed. failed now means a call ran and returned an error. All existing fields (results, ok, succeeded, failed, total_ms) are kept.

Version

0.1.1-dev.1, the next dev version after stable 0.1.0 (release.py next dev). Notes: deploy/releases/0.1.1-dev.1.md.

Verification (sprite, head 5152380)

  • pytest: 530 passed (test_batch.py now has 17 tests: response-field echo for both entry names, the args/name typos, per-call type errors, more than 20 calls, a missing calls, max_concurrency 11, timing logs a rejection as tool_error, and the published schema forbids extra keys)
  • deploy/host unittest 12 OK; browser_web.py, browser_picker.py passed; wheel built; scripts/verify_yawn.sh OK; release.py check OK
  • code-review 0.1.0-dev.1 diff a099d62..5152380: Python-only change in src/corn/batch.py plus tests, no diagnostics. The changed path is register → _BatchArgumentErrors.on_call_tool → BatchRequest.model_validate / rejected_batch → _field_message, _summary; and corn_batch → _summary. No other module's call graph changed.
## Why A `corn_call_tools` request today came back as a raw pydantic error because the caller had copied response fields (`succeeded`, `total_ms`) into its request. While reproducing it I found a worse, silent bug: `BatchCallItem` **drops** unknown keys, so `{"tool": "coder_workspace_bash", "args": {...}}` runs the tool with **empty arguments**. ## What changes - **Unknown keys are rejected, never dropped** (`extra="forbid"` on the item and the whole request; this also shows in the published input schema as `additionalProperties: false`). - **The whole batch is validated before any call runs** (`_BatchArgumentErrors`, innermost middleware so auth and timing still wrap it). A rejected batch has the same shape as an accepted one: ```json { "status": "rejected", "executed": 0, "succeeded": 0, "failed": 0, "invalid": 1, "not_run": 1, "results": [ {"index": 0, "id": "edit", "tool": "record", "ok": false, "status": "not_run"}, {"index": 1, "id": "tests", "tool": "record", "ok": false, "status": "invalid", "errors": {"args": "unknown key; did you mean 'arguments'?"}} ], "total_ms": 0.1, "error": {"code": "invalid_arguments", "message": "Nothing ran. Fix the listed fields and resend the same calls.", "expected": "{calls: [{tool, arguments?, id?}] (1-20 items), max_concurrency?: 1-10}"} } ``` Problems with the batch itself go in `error.errors`, for example `"succeeded": "response field copied from a previous corn_call_tools result; remove it"`. Rejections are flagged `isError` and carry the envelope as both structured and text content. Submitted values are never echoed (`include_input=False`), and more than 20 calls are never listed back. - **Accepted batches** gain `status: completed|partial`, `executed`, `invalid`, `not_run`, and a per-call `status: ok|error|invalid`. They are never flagged `isError`, because some clients drop the structured content of error-flagged results. ## Behaviour change for reviewers Unknown-tool and recursive calls never ran, so they now count as **`invalid`, not `failed`**. `failed` now means a call ran and returned an error. All existing fields (`results`, `ok`, `succeeded`, `failed`, `total_ms`) are kept. ## Version `0.1.1-dev.1`, the next dev version after stable `0.1.0` (`release.py next dev`). Notes: `deploy/releases/0.1.1-dev.1.md`. ## Verification (sprite, head 5152380) - `pytest`: **530 passed** (test_batch.py now has 17 tests: response-field echo for both entry names, the `args`/`name` typos, per-call type errors, more than 20 calls, a missing `calls`, `max_concurrency` 11, timing logs a rejection as `tool_error`, and the published schema forbids extra keys) - `deploy/host` unittest 12 OK; `browser_web.py`, `browser_picker.py` passed; wheel built; `scripts/verify_yawn.sh` OK; `release.py check` OK - `code-review 0.1.0-dev.1 diff a099d62..5152380`: Python-only change in `src/corn/batch.py` plus tests, no diagnostics. The changed path is `register` → `_BatchArgumentErrors.on_call_tool` → `BatchRequest.model_validate` / `rejected_batch` → `_field_message`, `_summary`; and `corn_batch` → `_summary`. No other module's call graph changed.
feat(mcp): validate call_tools up front and report batches in one envelope (0.1.1-dev.1)
All checks were successful
Corn CI / host (pull_request) Successful in 11s
Corn CI / release-check-1 (pull_request) Successful in 2s
Corn CI / release-check (pull_request) Successful in 0s
Security / scan (pull_request) Successful in 23s
Security / security (pull_request) Successful in 0s
Corn CI / test (pull_request) Successful in 3m58s
Corn CI / release (pull_request) Has been skipped
Review / change impact (pull_request_target) Successful in 4m59s
5152380235
Reject unknown keys instead of dropping them: a call item with 'args' used to
run the tool with empty arguments. Validate the whole batch before any sub-call
runs and return rejected batches in the same shape as accepted ones (status,
executed, per-call status and field errors), flagged isError and without
echoing submitted values. Accepted batches gain status completed|partial and
separate executed/failed/invalid/not_run counts; they are never isError.
john merged commit 56e6821994 into main 2026-11-25 03:14:53 +00:00
john deleted branch feat/batch-envelope 2026-11-25 03:14:54 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
john/corn!105
No description provided.