Repository navigation
perf(tests): give MCP test clients the shared lazy schema validation - #10960
Conversation
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Medium impact] The PR appears safe to merge; no blocking issues were found. SummaryThis PR moves MCP test clients onto lazy schema validation and shares compiled validators through a bounded worker cache.
morluto accepted conservative counting of parenthesized, conditional, spread, and nested options. morluto also noted that regex literals remain unsupported by the older No new actionable issues or security problems were found. The changes are not already present in the supplied base. Reviews (12) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile |
da1558a to
53c949b
Compare
53c949b to
82e0975
Compare
3d24b37 to
1dd25fb
Compare
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
The MCP SDK client compiles every listed tool's output schema on its first tool call. With the SDK's default Ajv options, REA's catalog costs gigabytes of allocation per client (inspect_analysis_view alone: 1.7 s and ~500 MiB retained), so native MCP files peaked at 1-2 GiB per worker. tests/fixtures/mcpSchemaValidation already owns lazy, reference-preserving validation. Route the native MCP, process-boundary and shared harness clients through it, share compiled validators across clients in a worker (bounded LRU keyed by schema text), and add a counted architecture guard so default-validation test clients cannot spread; the remaining copies are the baseline.
1dd25fb to
632d2ee
Compare
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
@greptileai please review the latest commit: the branch was rebased onto main after #10693, and the findings from the earlier review are addressed in the current head. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Verification of the remaining-cleanup note ("regex literals are not tokenized; none occur at the counted sites"), run against this branch's tree at f66e2a1. I parsed every
So the claim holds: no counted site has a regex literal that changes the count. The failure mode is real, though, as that uncounted site shows. A future keyed |
# Conflicts: # tests/boundary/mcp/binaryDiagnosticsMcp.test.ts
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
…11316 split the guard baselines
The default-validation counter searched each new Client(...) call's text for jsonSchemaValidator, so an inline comment, a string literal or a client name naming the option hid a default client. Parse the source with @babel/parser and count NewExpressions of Client whose object-literal arguments have no jsonSchemaValidator property; a source that does not parse counts every textual call. The guard reads raw test sources, and the generated-child-script allowlist entry, which no longer counts as a call, is removed.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
…schema-validation
5e22c5a to
5e38086
Compare
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
…schema-validation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
@greptileai review — please review the latest commit (merge of current main). |
Conflicting MCP test files take main's version (gdbMcpServer and the shared binding table) and pass createMcpSchemaValidation() to each client. Two clients main added since (analysisSettingsMcp, debuggerExternalMutationLifecycleMcp) take it too. The guard's call reader now tokenizes with scripts/verify/source-tokens.mjs instead of @babel/parser: CI runs the architecture guards before npm ci, so the parser import failed Static checks with ERR_MODULE_NOT_FOUND. providerSelectionMcp: the snapshot-mismatch test exceeded max-lines-per-function after the client gained its option; its raw-binary entry-point scenario is now its own helper, and the file's three local SHA-256 copies use sha256Hex from src/kernel.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
…teral argument
The default-validation counter skipped files without the text
'new Client(', so a comment between the tokens hid a client, and it took
any depth-two key as an option, so 'enabled ? { jsonSchemaValidator } : {}'
passed while its false branch uses the SDK default. The skip now only
requires the name Client, and the validator counts only when it is a key
of an object literal that is a whole argument; anything else counts as the
default.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
…schema-validation # Conflicts: # tests/boundary/mcp/largeToolResult.test.ts # tests/boundary/mcp/sessionEvidenceReuseMcp.test.ts
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Follow main's shared MCP test-client validation (morluto#10960): the architecture guard rejects a default-validating SDK client in tests. Pass createMcpSchemaValidation through the client, matching the other MCP boundary suites. Signed-off-by: Hemang Varshney <[email protected]>
Summary
Most of the memory in MCP boundary tests goes to compiling output-schema validators. With the SDK's default Ajv options, the MCP SDK client compiles every listed tool's output schema on its first
callTool.tests/fixtures/mcpSchemaValidation.tsalready compiles lazily and keeps$refs as shared functions, but about 165 test files still builtnew Client(...)with the SDK default. This PR moves the native MCP files, the process-boundary MCP files, and four shared harnesses onto the fixture. It also shares compiled validators across clients in a worker and adds a counted guard so that default-validation test clients cannot spread.Problem and expected behavior
Measured on macOS, warm (artifacts built), with peak process-family RSS sampled every 200 ms:
nativeValueTraceCompleteness.test.tsshows 13.2 GiB allocated, 11.2 GiB of it under the client'soutputValidator→ AjvcompileSchema.inspect_analysis_view(724 KB, 1,106$defs) takes 1.7–2.6 s to compile and retains about 500 MiB. Through the fixture it takes 0.65 s and retains 16 MiB.tests/boundary/mcp/*native*files together peaked at 3.7 GiB. This matches the reported 3.5 GiB "native set" peak.Expected: test clients pay only for the tools they call, and they pay once per worker.
Change and scope
new Client(...)sites to passcreateMcpSchemaValidation(): 15 native MCP files, 7 process-boundary files, and the sharedenhancedToolsHarness.ts,sessionMcpHarness.ts,tests/fixtures/buildComputerMcp.tsandtests/fixtures/promptOccurrenceCompletion.ts(about 37 dependent test files).androidMappingMcp.test.tsnow usescreateTestMcp.mcpSchemaValidation.tsadds a worker-wide cache of compiled SDK validators. The cache is keyed by full schema text and holds at most 32 entries, evicting the least recently used. Sharing is safe because a validator call is synchronous and keeps no state between calls. The bound limits how much the shared module graph retains across files inisolate: falseworkers.scripts/verify/architecture-guards.mjscounts thenew Client(...)calls intests/**/*.tswhose own arguments do not namejsonSchemaValidator, using a counted baseline that can only shrink (test-mcp-client-default-validation).scripts/verify/mcp-client-validation.mjsreads each call from the dependency-freescripts/verify/source-tokens.mjstokens (CI runs the guards beforenpm ci) and looks forjsonSchemaValidatoras a key of an object-literal argument, so neighbouring clients, comments and strings cannot hide a default one. The baseline holds the remaining copies.generatedToolCatalog.test.ts, which was added on main after this branch, now uses the shared validation.Not included:
outputValidatorReuse,outputSchemaProfile,toolSchemaValidity,advertisedDialect) should stay on the default.inspect_analysis_viewoutput schema is a production contract question that affects real SDK clients too, so it is reported separately rather than changed here..mjsscripts are not changed.Contract and boundary impact
tests/fixtures/mcpSchemaValidation.ts, which owns test-client output validation; migrated call sites consume it.inlineRefs.Evidence and regression coverage
Before → after, macOS, warm (vitest and build caches populated; cold runs not measured). Peak is process-family RSS; CPU is user time.
tests/boundary/mcp/*native*filesnativeValueTraceCompletenessalonenativeUiFactsMcpalonenativeInputContractsaloneandroidMappingMcpalone (single worker)The set's peak is still about 3 GiB. With
pool: "threads"andisolate: false, two mcp-boundary worker isolates share one process, and each keeps its high-water heap. That remaining cost needs its own investigation.nativeUiFactsMcp.test.tsfrom main makesarchitecture-guards.mjsfail with "new copies are not allowed … nativeUiFactsMcp.test.ts: 1 (baseline 0)".Validation performed
node scripts/run-exact-tests.mjs run <56 affected test files>— 56 files / 448 tests passed (303 s wall, 2.5 GiB peak).node scripts/run-exact-tests.mjs run <29 tests/boundary/mcp/*native* files>after the final change — 29 files / 146 tests passed.node scripts/run-exact-tests.mjs run <40 other files using createMcpSchemaValidation>— 38 passed.mcpDoctoranddeferredRuntimefailed only because.cache/mcp-tool-catalog.jsonwas missing.npm run test:focused -- tests/boundary/mcp/mcpDoctor.test.ts tests/boundary/mcp/deferredRuntime.test.tsthen passed: 2 files / 72 tests.node scripts/verify/architecture-guards.mjs— passed.npm run check:fast— passed.After the rebase onto main and the review fixes (53c949b):
npm run test:focused -- tests/boundary/mcp/mcpSchemaValidation.test.ts tests/boundary/filesystem/mcpClientValidationGuard.test.ts tests/boundary/filesystem/keyedFirstMatchGuard.test.ts tests/boundary/mcp/generatedToolCatalog.test.ts: 4 files, 36 tests passed (18 s wall, 1.3 GiB peak). With per-fixture compilation in place of the shared cache, the new cache test fails as expected.node scripts/verify/architecture-guards.mjs,npm run check:fastandnpx oxfmt --checkon the changed files all passed.After rebasing onto main at 5c53bca (#10693), head 1dd25fb: the guard now reuses main's test-file list (
testFilesfiltered totests/, comments stripped) instead of a secondlistTestFiles;androidMappingMcp.test.tskeeps main'scanonicalOutputSchemaimport.npm run test:focused -- tests/boundary/filesystem/mcpClientValidationGuard.test.ts tests/boundary/process/androidMappingMcp.test.ts tests/boundary/mcp/mcpSchemaValidation.test.ts: 3 files, 22 tests passed.node scripts/verify/architecture-guards.mjs --shrink-baselines(no change) andnpm run check:fastpassed;npx oxfmt --checkon the changed files passed.Review fix (866ddd6):
closingParenskips string and template literals, so a)in a client name does not end the call.npm run test:focused -- tests/boundary/filesystem/mcpClientValidationGuard.test.ts tests/boundary/filesystem/keyedFirstMatchGuard.test.ts: 31 tests passed.node scripts/verify/architecture-guards.mjs --shrink-baselines: passed, no baseline change.Merged main (42bb643). I resolved one conflict in
tests/boundary/mcp/binaryDiagnosticsMcp.test.ts: main'sregisterServiceToolsregistration combined with this PR'screateMcpSchemaValidation()client.npm run check:fast— passed, including the architecture guards.npm run test:focused -- tests/boundary/mcp/binaryDiagnosticsMcp.test.ts tests/boundary/filesystem/mcpClientValidationGuard.test.ts tests/boundary/mcp/mcpSchemaValidation.test.ts— 3 files, 28 tests passed.oxfmt --check .,npm run check:fastandnpm run verify:advertised-schemasall passed.Merged main after #11316 (fc0c31e). The guard registration conflicted with the per-guard baseline loop; this PR's guard is kept ahead of main's loop. Review fix (07249a6): the counter parses the source with
@babel/parserand reads thejsonSchemaValidatorproperty from the call's object-literal arguments. Comments, string literals and client names no longer hide a default client. The generated-child-script allowlist entry no longer matches a call, so it was removed.npm run test:focused -- tests/boundary/filesystem/mcpClientValidationGuard.test.ts: 20 tests passed. The 6 new cases fail against the previous counter.node scripts/verify/architecture-guards.mjs --shrink-baselinespassed (no baseline change), and so didnpm run check:fast.main(merge 84f5ab4; import-only conflicts in five more test files after refactor(contracts): own CLI command names, catalog identity and schema presentation in contracts #11425), commit written without the pre-commit lint-staged pass so it carries no unrelated autofixes; pre-push hook ran. Resolved by keeping main's changes (shared binding table registration,phaseGatelifecycle harness,src/portsimports) and re-applyingcreateMcpSchemaValidation()to each client;hostRestrictedAvailabilityMcp.test.tsmoved totests/boundary/mcp/on main and gets the shared validation there, andwebRuntimeMcp.test.ts(new on main) migrates its one remaining default client so the guard stays at zero. After the merge:npm run check:fast(guards included) pass;npm run test:focused --withcutterCancellationMcp,evidenceImportLifecycle,guidanceMcp,progressMcp,hostRestrictedAvailabilityMcp,webRuntimeMcpandmcpClientValidationGuard46 passed;briefs/local-gate.sh 10960 perf/test-mcp-shared-schema-validationpass.Merged main at 465796a (head 3e05330). Conflicting MCP tests take main's version (
gdbMcpServer, shared binding table) and passcreateMcpSchemaValidation()to each client; two clients main added since (analysisSettingsMcp,debuggerExternalMutationLifecycleMcp) take it too. CI Static checks had failed withERR_MODULE_NOT_FOUND: @babel/parserbecause the guard step runs before dependency installation; the counter now uses main's tokenizer instead.providerSelectionMcp's snapshot-mismatch test exceededmax-lines-per-functionafter the merge: its raw-binary entry-point scenario is now a helper, and its three local SHA-256 copies usesha256Hexfromsrc/kernel.npm run test:focused -- tests/boundary/filesystem/mcpClientValidationGuard.test.ts— 20 passed.npm run test:focused -- <5 files: providerSelectionMcp, analyzeFunctionDetail, gdbCloseDisposition, analysisSettingsMcp, batchSourcePublicationRecovery>— 39 passed (13.7 s, 1.2 GB peak).npm run test:focused -- <9 files: cutter/frida/gdb/rizin cancellation and output MCP tests, RizinDebugSessionInferiorStdin, debuggerExternalMutationLifecycleMcp>— 120 passed, 9 skipped (20.8 s, 1.2 GB peak).node scripts/verify/architecture-guards.mjsand pre-pushnpm run check:fast— passed.cliOptionAliases.test.tsalso fails on main; fixed separately in fix(cli): describe a contract option whose description sits inside .optional() #11661.Compatibility, safety, and release
Author readiness
Human owner:
Before merge
type(scope): outcome.