Repository navigation
perf(mcp): canonicalize the tool catalog once per digest profile - #11298
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. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
[Low impact] The PR appears safe to merge; no actionable issues remain from this review. SummaryThe PR reuses canonical tool and prompt text when building the combined catalog digest.
Reviews (6) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile |
91eb1ce to
cd8b6c9
Compare
|
@greptileai please review the latest commit (cd8b6c9). It rebases onto main after #11316 and #11268; resolving the conflict with #11268's presentation step, |
dc517b6 to
c323042
Compare
Summary
tests/boundary/mcp/mcpDoctor.test.tsis CPU-bound (54 s user CPU for a 64 s run). A CPU profile of the test worker attributes 4.6 s of its 11 s busy time tocreateCatalogDigests, andcanonicalizealone takes 2.25 s.digestCatalogsinsrc/contracts/catalog/catalogIdentity.tscanonicalized the full tool catalog twice per profile: once fortools_sha256, and again inside the{cli, tools, prompts}document forcombined_sha256. The combined document is now built from the canonical tool and prompt texts.Problem and expected behavior
Every scoped or custom-budget catalog identity (doctor runs, family-scoped servers, tests) computes digests on first use; only the default identity has recorded digests. Expected: the same digests, with the catalog canonicalized once.
Change and scope
RFC 8785 (and the
canonicalizepackage's implementation,node_modules/canonicalize/lib/canonicalize.js) serializes an object as{+ members sorted by key, each"key":<canonical value>, joined by,+}. The combined document's keyscli<prompts<toolsare fixed and its values are never undefined, so{"cli":C(cli),"prompts":C(prompts),"tools":C(tools)}is byte-identical toC({cli, tools, prompts}).digestCatalogscanonicalizestoolsandpromptsonce and hashes the composed text.Not included: the other measured worker hotspot, the MCP client's per-call ajv output-validator compilation (2.9 s), which #10960 addresses. The doctor's child MCP servers are killed before writing CPU profiles, so their share was not attributed.
Scope: not applicable.
Contract and boundary impact
src/contracts/catalog/catalogIdentity.tsdigestCatalogs.Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.
Evidence and regression coverage
tests/boundary/mcp/serverIdentity.test.tsadds "composes the combined digest exactly as whole-document canonicalization", which checksdigestPresentedCatalogs(the exported digest step after presentation;digestCatalogspresents the catalog and delegates to it) againstsha256(canonicalize(...))for escaped and non-ASCII strings, unsorted keys, and empty catalogs under both profiles.canonicalizevariant give identicalcombined_sha256for both profiles (off0613528d…85d1,compactd8c9204b…5eb1). WarmcreateCatalogDigestsfor both profiles: ~240 ms → ~168 ms. The old-formula stand-in also re-parsed the texts, so that figure slightly overstates the saving.npm run test:focused -- tests/boundary/mcp/mcpDoctor.test.tsmaximum resident set size)The file-level difference is larger than the digest saving alone explains, so part of it is load variance; the per-call A/B above is the controlled measurement.
Validation performed
npm run test:focused -- tests/boundary/mcp/mcpDoctor.test.ts tests/boundary/mcp/serverIdentity.test.ts— 44 passed; after adding the composition test,serverIdentity.test.ts— 12 passed.npm run test:focused -- tests/boundary/mcp/mcpDoctor.test.ts— before 33 passed in 64.2 s; after 33 passed in 49.4 s.dist/catalogIdentity.js— identical digests (above).check:fast, architecture guards) — passed.npm run check:fast— passed;npm run test:focused -- tests/boundary/mcp/serverIdentity.test.ts— 12 passed;briefs/local-gate.sh(merge with main, oxfmt, check:fast, guards, affected tests, advertised schemas) — passed.main(merge 219e031; refactor(contracts): own CLI command names, catalog identity and schema presentation in contracts #11425 movedsrc/catalogIdentity.tstosrc/contracts/catalog/catalogIdentity.ts, and this change moved with it), commit written without the pre-commit lint-staged pass so it carries no unrelated autofixes; pre-push hook ran; the only conflicts wereserverIdentity.test.tsimports (kept main's paths and this PR'screateHash,canonicalizeanddigestPresentedCatalogsimports). After the merge:npm run check:fastpass;npm run test:focused -- tests/boundary/mcp/serverIdentity.test.ts12 passed;briefs/local-gate.sh 11298 perf/mcp-doctor-testpass.Compatibility, safety, and release
Author readiness
Human owner:
Before merge
type(scope): outcome.