Skip to content

fix(mcp)!: bound validation work before tool dispatch - #7905

Merged
gensokyo-dev merged 7 commits into
mainfrom
fix/7882-mcp-validation-resources
Oct 29, 2026
Merged

gensokyo-dev merged 7 commits into
mainfrom
fix/7882-mcp-validation-resources

Conversation

@gensokyo-dev

@gensokyo-dev gensokyo-dev commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #7882. On tested main, a 16,542-byte malformed argument object produced 8,192 diagnostics and a 556,706-byte MCP error. Reuse SDK 2.3.1's existing admission counter before validation expands those diagnostics.

  • The shared eager/deferred HTTP and stdio constructor defaults to 1,024 combined array elements and object members, including nested containers. No custom walker, Zod internals, provider changes or new dependency.
  • REA_MCP_MAX_INPUT_ELEMENTS selects another positive decimal safe-integer allowance at startup; invalid values fail explicitly. Setup forwards an explicitly selected value through its existing approval/backup workflow.
  • Refused calls return a bounded, nonretryable resource_constraint / transport with reported_limits.max_input_elements. Validation, lazy runtime loading and tool execution do not start for them; no complete input count is claimed.
  • Canonical CLI/application parsers, advertised schemas and admitted input values remain unchanged. Ordinary diagnostics retain their existing behavior. Separate semantic workload limits ([Bug] batch_decompile accepts unbounded address arrays #5930) and structured ordinary SDK diagnostics ([Bug] MCP input-error normalization replaces rejected field paths with one root issue #7661) remain outside this repair.

Breaking change: larger previously valid inline MCP calls require a higher finite allowance and restart, or retained/file selectors where supported. Input is never silently truncated. This is a per-call transport policy, not an exact heap guarantee or complete denial-of-service protection.

Scope: repair existing admission; no new target execution, mutation, exposure or configuration-writing authority.

Expected effects:

  • Read existing files/captured data through existing workflows.
  • Launch existing MCP/native verification processes.

Validation performed

Final local head: c762ffaee, based on main 37827af59. Production behavior is unchanged from 655d83965; subsequent commits migrate verification fixtures to explicit finite allowances while preserving their original assertions. Default-policy HTTP/native proofs keep the production allowance.

  • 123 related source tests; five public/native cases covering actual HTTP/stdio, default structured-input admission, a guarded near-4-MiB request, real Linux TShark capture → Evidence export → explicit pair comparison, and continued service.
  • Existing downstream coverage: analysis-view 29, native matching 6, process comparison 25, and SQLite bind-capacity cases passed. Full-inline conformance fixtures select a shared finite 65,536 allowance; capacity fixtures retain their original stronger limits and failure assertions.
  • Expanded verification of 24 independent stdio files: 115 cases passed / 3 skipped across runs. The initial run lacked generated catalog metadata; the focused preparation and all 30 deferred-runtime cases then passed. A Pi assertion comparing Node path spellings also failed on unchanged main; its full 8-case file passed with the same pinned Node's real directory first on PATH. No unrelated production/test assertion was changed. Earlier affected workflow files and shared lifecycle regressions also passed.
  • Supplementary MCP boundary cohort: 136 files passed / 3 files skipped across bounded runs. Its initial 20-minute run was stopped by the time guard; one trace fixture needed the shared explicit allowance to retain its original 200-event diagnostic assertion. The final 10-file / 189-case run passed: 155.628 s / 180.077 s CPU / 2802.9 MiB RSS. CPU for the interrupted run is unavailable; it is not reported as a completed green run.
  • npm run verify:package passed: actual archive/install, CLI analysis/Evidence, setup/backup/readback/uninstall, idempotence, failure recovery, extracted plugin MCP, 231 tools / 6 prompts, and verified cleanup. 301.002 s elapsed / 330.403 s CPU / 1335.7 MiB sampled family RSS.
  • npm run check:ci:fast passed: types, lint, format and module boundaries — 53.927 s / 84.873 s CPU / 5365.5 MiB RSS. npm run docs:check passed, including 9 tests — 4.047 s / 4.732 s CPU / 522.9 MiB.
  • CI on runtime-identical head 5db72c85f: 21,421 source tests passed / 15 skipped, all four SQLite Node combinations and four native package platforms passed. Real macOS CLI/MCP validated 6 bundles across directory/ZIP/DMG, detached the DMG and preserved Mach-O bytes. Its previous inventory-admission failure was repaired in the shared artifact verifier. Current-head checks qualify the final fixture follow-up.

Resource evidence and limits

Missing fields amplify too: direct canonical validation of 1,024 empty Evidence objects produced 16,384 issues / about 26 MiB heapUsed delta before formatting. This drove the conservative default. Actual bulk validation is exercised through build_call_path; find_changed_behavior already authenticates items individually, so its advertised schema alone does not establish public-path amplification.

Completed verification Observed outcome
build_call_path, default boundary 1,019 empty objects + five members are admitted; ordinary error remains 1,456,474 bytes. One more object returns 824 bytes. Isolated flow: 3.926 s / 4.863 s CPU / 601.8 MiB RSS, including formatting and subsequent valid calls.
Guarded default HTTP request 2,090,000 numbers / 4,180,158 argument-JSON bytes return 824 bytes, then ping/settings succeed. Small calibration proves admission active before constructing this fixture. No crashing baseline was attempted.
Real portable artifact verifier An owned 128-entry ZIP supplies 146,420 bytes of inline Evidence. The original helper refuses at default admission; its explicit verification allowance delivers 2 of 129 nodes, keeps serving and preserves the ZIP digest. Repaired flow: 14.578 s / 16.895 s CPU / 932.9 MiB RSS.
Real TShark → bundle → explicit pair Baseline 6.808 s / 8.360 s CPU / 869.0 MiB; fixed 6.884 s / 8.328 s CPU / 864.8 MiB.

Local runners use two CPUs and a 3-GiB Node heap allowance. HTTP/stdio/TShark capacity-proof servers explicitly use that heap allowance; other fixture/verifier children retain their existing limits. The input-capacity and portable-artifact proof runs additionally use a 2-GiB/120-s family guard; other recorded local gates use a 12-GiB/1200-s family guard. One mixed-file run triggered that guard and was stopped; separated proof runs passed. RSS is sampled every 50 ms and can count shared pages twice.

No overall speedup claim; model-token costs are unmeasured. Processes are fresh, but filesystem/code-cache warmth is uncontrolled. Catalog size remains 3,804,043 bytes; client schema-compilation cost is unchanged. Ordinary admitted errors can still be large. Native local proof is Linux; CI establishes the stated platform coverage, rather than full licensed Hopper GUI behavior.

Full measurements, commands and executed limitations: validation record.

Author readiness

Human owner: @gensokyo-dev

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • Issue, policy owner and breaking compatibility change are recorded.
  • Actual transports, real tools, default admission and downstream semantics were exercised.
  • Docs and explicit setup forwarding are current; generated outputs, binaries and credentials are excluded.

Use the pinned SDK's element admission for eager and deferred MCP servers.
Share a finite configurable default across HTTP, stdio and saved setup env.
Normalize the SDK refusal with the configured limit and preserve canonical
schemas, ordinary diagnostics and admitted input values.

Fixes #7882

BREAKING CHANGE: MCP arguments now default to at most 65,536 combined array
elements and object members. Select REA_MCP_MAX_INPUT_ELEMENTS at launch for
workloads requiring a different finite allowance.

Assisted-by: Reimu (gensokyo-skills:reimu-incident-triage)
Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)
Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T00:40:31.625288Z c762ffa Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: apex

[Medium impact] The reviewed changes appear safe to merge.

Summary

Adds a finite MCP input allowance before schema validation and tool execution. The latest changes share a 65,536-element allowance across verification workflows while leaving the 1,024-element production default unchanged.

  • MCP checks tool arguments against a shared element limit before validation.
  • Operators can choose a finite MCP input limit at startup.
  • Large inline-input fixtures select finite limits to reach their existing checks.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["Tool arguments"] --> B["SDK counts elements and members"]
  B -->|"Over selected allowance"| C["Return bounded transport error"]
  B -->|"Within allowance"| D["Load runtime if deferred"]
  D --> E["Check canonical schema"]
  E -->|"Valid input"| F["Run tool"]
Loading

Reviews (7) · Last reviewed commit: "test(mcp): preserve trace parity coverag..." · Reviewed by Greptile

Missing required fields multiply diagnostics without increasing object
member counts. A bounded canonical probe produced 16,384 issues and about
26 MiB heapUsed delta from 1,024 empty Evidence objects.

Lower the default allowance to 16,384 combined elements, preserve selected
operator allowances, and verify rejection before structured validation.
Check the calibration refusal's error kind before considering larger input.

Assisted-by: Reimu (gensokyo-skills:reimu-incident-triage)
Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)
Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 62d3b90388

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/config/mcpInputBudget.ts Resolved
Set the default allowance to 1,024 elements using measured missing-field
expansion rather than extrapolating a scalar array measurement. Exercise the
actual build_call_path HTTP registration at its exact admitted boundary and
one element beyond, including subsequent successful requests.

Select finite fixture allowances in existing SQLite, portable capture,
native matching and deep trace tests so their stronger downstream capacity,
identity and validation assertions continue to execute.

BREAKING CHANGE: MCP defaults to 1,024 combined array elements and object
members per tool call. Select REA_MCP_MAX_INPUT_ELEMENTS and restart for
larger inline workloads, or use retained/file selectors where available.

Assisted-by: Reimu (gensokyo-skills:reimu-incident-triage)
Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)
Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis)
Complete-Evidence workflow fixtures need an explicit input allowance after
the new transport default. Own that finite selection in the application and
file-scoped MCP harnesses, preserve caller overrides, and share the same
selection with their direct stdio scenarios.

Keep depth and configuration regressions reaching their original producing
boundaries. Preserve their existing assertions and leave dedicated admission
and real TShark default-policy proof servers on the production default.

Assisted-by: Reimu (gensokyo-skills:reimu-incident-triage)
Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)
Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis)
The native Apple verifier also resends complete inventory Evidence through
its independent stdio harness. Move the finite verification environment to
a dependency-free JS/TS module and use it in that harness as well as the
existing workflow fixtures. Remove the superseded TypeScript-only owner.

Keep production admission at 1,024 elements. Verify the real portable ZIP
workflow, unchanged source bytes, paging, and shared fixture cleanup locally;
the existing native Apple scenario continues to own macOS verification.

Assisted-by: Reimu (gensokyo-skills:reimu-incident-triage)
Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)
Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis)
Select the shared finite conformance allowance in the independent stdio
identity fixture. Its complete inline operands must reach the existing
identity and integrity checks, including retained and mixed source forms.
Keep all original assertions and production admission unchanged.

Assisted-by: Reimu (gensokyo-skills:reimu-incident-triage)
Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)
Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis)
Select the shared finite inline-Evidence allowance in the trace comparison
fixture so the original 200-event diagnostic reaches its domain validation.
Keep production admission and all existing parity assertions unchanged.

Assisted-by: Reimu (gensokyo-skills:reimu-incident-triage)
Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)
Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis)
@gensokyo-dev

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: c762ffaeef

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@gensokyo-dev
gensokyo-dev merged commit f60e42a into main Oct 29, 2026
44 of 48 checks passed
@gensokyo-dev
gensokyo-dev deleted the fix/7882-mcp-validation-resources branch October 29, 2026 05:56
Entrpi added a commit to Entrpi/rea that referenced this pull request Oct 29, 2026
morluto#7905 bounds MCP arguments at 1,024 elements by default, which two inline
ESP flash-dump inventories exceed, so the ESP flash comparison test now
compares the Evidence its session retained. morluto#7981 reports an input issue at
its field path with zod's reason, so the Rizin decoder-input refusal is
`invalid_format` at `asm_cpu`.
Entrpi added a commit to Entrpi/rea that referenced this pull request Oct 30, 2026
This branch carried morluto#7498's pre-squash commits, which upstream merged as
squash 64196b0 with maintainer commits. The merge therefore used the
absorbed prototype ea2b386 as its base, so the result differs from main
only in this branch's own changes; git's own base reported every morluto#7498
region as a conflict.

Adaptations to main:

- morluto#8054 describes formats in one registry. The esp-flash-image descriptor
  in artifactFormats.ts now owns the reader construction, admission,
  classification retention, container role, extraction and reader
  limitation that this branch had spread over createArtifactReader,
  classify, ArtifactGraphConstruction, ArtifactExtraction and the
  inventory reader. EspFlashAdmission joins ArtifactFormatAdmission.
- morluto#7498 moved the ESP image fixture to tests/fixtures/espImage.ts; the ESP
  flash tests import it from there.
- morluto#7481's vocabulary guard expected every caller-selected format hint to
  name an executable target; an ESP flash dump is read as an archive.
- morluto#7905 bounds MCP arguments at 1,024 elements by default, which the inline
  flash-dump inventories exceed, so the ESP flash comparison test compares
  the Evidence its session retained.
@morluto morluto added area: mcp MCP server, transport, and tool registration bug Something isn't working labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: mcp MCP server, transport, and tool registration bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(mcp): bound input-validation allocation before amplified diagnostics

2 participants