Skip to content

fix(identity): digest the advertised input schema, examples included - #3015

Closed
hemv-857 wants to merge 1 commit into
morluto:mainfrom
hemv-857:fix-2578-catalog-digest-examples
Closed

hemv-857 wants to merge 1 commit into
morluto:mainfrom
hemv-857:fix-2578-catalog-digest-examples

Conversation

@hemv-857

Copy link
Copy Markdown
Contributor

Fixes #2578

The bug

createToolCatalog hashed z.toJSONSchema(contract.inputSchema) directly, but a client is handed the schema that toolInputSchemaWithMetadata projects — and that projection attaches advertisedInputExamples. The digest therefore covered a schema without examples while the catalog served to the client had them.

Editing a tool's examples changed what the model was shown and left both the tool and combined digests byte-identical, so createServerIdentity reported aligned against the original catalog. docs/mcp-contracts.md states the identity covers fields that change what clients receive; examples are exactly that.

The fix

Hash the advertised projection, the same value toolRegistrationOptions hands the SDK, instead of a parallel re-derivation of it:

input_schema: advertisedInputJsonSchema(contract),

where advertisedInputJsonSchema projects toolInputSchemaWithMetadata(contract) at the same draft-2020-12 target z.toJSONSchema defaulted to.

This removes a second implementation of "what the input schema looks like on the wire" rather than adding a third: the digest and the registration now read from one source, so they cannot drift again.

The output schema is deliberately left as it is. toolOutputSchemaWithMetadata adds an $id that is itself a digest of that schema, so an output change already moves the digest through the schema it is derived from — there is no equivalent blind spot to close.

Testing

src/catalogIdentity.test.ts (new), three cases:

  • The bug: drop a tool's examples and assert both digests change. Fails on the parent commit, passes here.
  • Control: flipping returns_target_content still changes both digests, so the fix above cannot regress what was already covered. Passes on both.
  • Stability: two computations of an unchanged catalog agree.

The tool with examples is discovered at runtime rather than named, so a renamed or removed tool cannot silently turn the first case into a no-op.

Verification run locally:

  • npm run test:run -- src/catalogIdentity.test.ts — 3 passed
  • npm run typecheck — clean
  • npm run verify:module-boundaries, npm run verify:test-discovery — clean
  • npx oxlint on both changed files — clean

Nothing asserts a hardcoded digest; tests/boundary/mcp/serverIdentity.test.ts reads CATALOG_IDENTITY.digests at runtime, so it picks up the new value rather than breaking on it.

One note on the pre-push hook

npm run lint currently reports 2 errors on main — max-lines-per-function on tests/boundary/filesystem/artifactComparison.test.ts:346 (202 lines) and src/dotnet/ManagedCilDecoding.test.ts:248 (162 lines), both against a 150-line maximum. Both were introduced by 9630c8f and neither is touched here. Per CONTRIBUTING.md's guidance to keep cosmetic-only work out of useful fixes, I left them alone and pushed past the local hook, but the gate is currently red for everyone. Happy to open a separate issue if that is useful.

createToolCatalog hashed z.toJSONSchema(contract.inputSchema) directly,
while a client is handed the schema that toolInputSchemaWithMetadata
projects, which attaches advertisedInputExamples. The digest therefore
omitted examples, so editing a tool's examples changed the catalog the
client received without changing the tool or combined digests, and
comparing the two reported aligned.

Project the advertised schema instead, the same value the server
registers, so an examples-only edit moves the digest like any other
client-visible change. The output schema is left as it is: its
advertised $id is derived from the schema that is already digested, so
it cannot change without changing the digest anyway.
Copilot AI balanced review requested due to automatic review settings October 13, 2026 20:58

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 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-13T21:04:41.627157Z be14282 PR opened
ℹ️ 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.

@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: be1428292b

ℹ️ 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/catalogIdentity.ts
Comment on lines +24 to +26
toolInputSchemaWithMetadata(contract)["~standard"].jsonSchema.input({
target: "draft-2020-12",
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Hash the schema after applying the active presentation profile

When REA_MCP_INPUT_SCHEMA_PROFILE=compact is active, this is not the schema the client receives: EvidenceMcpServer.registerTool applies compactAdvertisedInputSchema afterward (src/server/EvidenceMcpServer.ts:104-115), and that transform explicitly drops root examples (src/contracts/compactInputSchema.ts:74-92). Consequently, an examples-only edit now changes tools_sha256 and combined_sha256 even though the compact tools/list is byte-identical, so catalog comparisons can report a false catalog_digest_mismatch; compute the digest from the active post-profile projection (or keep a deliberately profile-neutral projection) instead.

AGENTS.md reference: AGENTS.md:L31-L31

Useful? React with 👍 / 👎.

Comment on lines +43 to +46
it("still changes when returns_target_content changes", () => {
// Control: an unrelated contract field the digest already covered must keep
// affecting it, so the examples fix above cannot regress silently.
const contract = findContract((c) => !c.returnsTargetContent);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Remove the duplicated target-content digest test

This case duplicates tests/boundary/mcp/serverIdentity.test.ts:121-140, which already toggles returnsTargetContent and asserts that both the tool and combined digests change (and that the prompt digest does not). It therefore adds no distinct semantic coverage but leaves the same invariant in two test layers; remove this control case rather than maintaining redundant tests.

AGENTS.md reference: AGENTS.md:L23-L23

Useful? React with 👍 / 👎.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issue was found.

Summary

The PR makes catalog digests include the advertised input schema, including examples.

  • Catalog digests now include the input schema tools advertise.

Reviews (2) · Last reviewed commit: "fix(identity): digest the advertised inp..." · Reviewed by Greptile

@morluto morluto added area: domain Domain logic, errors, and pure functions bug Something isn't working labels Oct 13, 2026
@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: The fix works on Node 22, 24 and 26. When I edited one tool's example, the digest moved and a stale server was caught. Before the fix, it still said aligned.

The digest is a fingerprint of the tool list a client is handed. "Before" means this head with the old src/catalogIdentity.ts from 9630c8f (#2990), plus the PR's new test.

Unit test

src/catalogIdentity.test.ts has three cases.

Tree Node 22.23.1 Node 24.18.0 Node 26.11.1
Head be14282 3 passed 3 passed 3 passed
Before 1 failed, 2 passed 1 failed, 2 passed 1 failed, 2 passed

On before, the failing case is the examples case.

Live server

I started the built rea mcp over stdio on Node 24. The binary_session tool reports the digest in server_identity.catalog.digests. Then I edited the annotate_native_function example and rebuilt. I gave each edited server the unedited digest of its own tree.

Tree Tool list after edit Digest after edit Server check
Head changed moved flagged stale
Before changed did not move aligned

On both trees, the tool list changed. Only head's digest followed it.

Also checked

  • On head, the digested input schema equals the tools/list input schema for all 194 tools (key order aside).
  • No committed file holds the old or new digest values. I searched for each one in full and by its first 12 characters. The folder docs/public/ does not exist in this tree.
  • tests/boundary/mcp/serverIdentity.test.ts: 6 passed on Node 24.

Not run

  • The live-server check and the serverIdentity test on Node 22 and 26.
  • typecheck and lint. The PR's claims about them are unchecked.
  • The issue's own fixture file.
  • Removing an example on a live server. I edited its text. The unit case covers removal.
  • The PR merged onto current main.

Thanks, hemv-857, for this fix.

Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 22.23.1, 24.18.0, 26.11.1
  • Head: be14282
  • Base: 9630c8f (fix(adb): remove false exclusivity from the push-file description #2990), the merge base
  • Other: Vitest 5.0.3. Main was 80592b8, 30 commits ahead of the base. Main left catalogIdentity.ts, toolSchemaMetadata.ts and serverIdentity.ts alone. It added 5 lines to toolContractExamples.ts. Another test run shared the box, so I give no timings.
Commands

Each run used HOME and TMPDIR inside a scratch folder, under a memory cap of 8 GB. All exit codes were 0 except the three before-tree test runs, which exited 1 as expected.

npm ci
npm run build
node scripts/run-development-tests.mjs focused src/catalogIdentity.test.ts
node scripts/run-development-tests.mjs focused tests/boundary/mcp/serverIdentity.test.ts

The live-server probe is a small script. It starts scripts/rea.mjs mcp, sends initialize, tools/list and tools/call binary_session as JSON lines, and reads server_identity. The edit was one sed line on src/contracts/toolContractExamples.ts, changing the annotate_native_function comment.

Exact values

The combined digest is combined_sha256. The tools digest is tools_sha256. The tool list hash is a SHA-256 over the JSON that tools/list returned.

Head, original example
  tools_sha256     18135bb9c782121e5a5f52ebf6bc4607fb5fd879fac5caaef5336a94aa114385
  combined_sha256  e0193f61c370955462cde87db69770621615f1359e24f638c611b59431d8f392
  tools/list hash  46d1a1e305064a1bf53b57b452d63c8347bc98d0ccdba061d560f6c2153acfc9
Head, edited example
  tools_sha256     a5bad4cb6ab27fd98adfa38d1fbd51836abb257b4dcd45394d3528b8a64ef48d
  combined_sha256  6843abad1489094dd8d0fffdd248a58f8d77460342130ba8482be74ab6c7363b
  tools/list hash  743b16df5df9d80f9eb8a6eeab1481a1508d58d680cefbee22a6e5664ff6c9a3
  alignment vs the original combined digest: mcp_server_restart_required, reason catalog_digest_mismatch
Before, original example
  tools_sha256     6c130b60f64b1b3f5bfeb715a9f77b83edc65714ae8ecdf9163167e312c32a94
  combined_sha256  070a4c592360e6df537b2e8466537370260e1bd9485872af4a9e46743227bf99
  tools/list hash  46d1a1e305064a1bf53b57b452d63c8347bc98d0ccdba061d560f6c2153acfc9
Before, edited example
  tools_sha256     6c130b60f64b1b3f5bfeb715a9f77b83edc65714ae8ecdf9163167e312c32a94
  combined_sha256  070a4c592360e6df537b2e8466537370260e1bd9485872af4a9e46743227bf99
  tools/list hash  743b16df5df9d80f9eb8a6eeab1481a1508d58d680cefbee22a6e5664ff6c9a3
  alignment vs the original combined digest: aligned

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

morluto added a commit that referenced this pull request Oct 14, 2026
Use one named input-schema projection for clients and catalog identity, preserve dialect declarations, and bound compact schema depth. Keep canonical SDK output validation when output advertisements are disabled. Release request-owned state on cancellation and carry upstream limitations through composed workflows. Preserve doctor full-output envelopes and validate navigation facts at their owner.

Reviewed fixes: #2088, #2108, #2513, #2684, #2693, #2695, #2836, #2864, #2868, #2877, #2933, #2998, #3002, #3015.

Validation: focused schema, SDK output-validation, context, and workflow tests passed; no schema dialect or canonical output validation was relaxed.
@morluto

morluto commented Oct 14, 2026 •

Copy link
Copy Markdown
Owner

The advertised-schema digest fix and its input-example regression are already on main in 80de314. Thank you @hemv-857 for the contribution. The later ee9bf58 commit separately materializes server identity as plain JSON; it did not introduce example coverage.

Current validation: tests/boundary/mcp/serverIdentity.test.ts passed all 8 tests in the focused phase-four run, including the advertised-input-example change, unchanged prompt digest control, real MCP identity, and target availability. The PR adds no remaining behavior beyond that owning schema and regression. Complete current-main CI remains in progress.

@morluto morluto closed this Oct 14, 2026
@morluto

morluto commented Oct 14, 2026

Copy link
Copy Markdown
Owner

Correction to my earlier supersession note: I missed the unresolved review thread #discussion_r4264002008. Main still hashes advertisedInputJsonSchema(contract) in src/catalogIdentity.ts, while the compact MCP registration applies compactAdvertisedInputSchema, which strips root examples. On a compact-profile server, an examples-only contract change can therefore change the identity digest while the client-visible tools/list schema remains unchanged, causing a false catalog_digest_mismatch and restart advice.

This is a valid, currently unfixed identity inconsistency based on the producer → compact presentation → identity comparison path. I am reopening the PR to investigate and correct that profile-aware digest behavior. The second review thread is a duplicate-test maintenance suggestion, not a behavior blocker. Sorry for my earlier blanket supersession conclusion; thank you for the review finding.

@morluto morluto reopened this Oct 14, 2026
morluto added a commit that referenced this pull request Oct 14, 2026
Capture the current entrypoint once without inventing a path. Preserve unknown registration ownership through setup and doctor, refuse unsafe registration plans, and retain exact pinned-launcher readiness checks. Hash the same full or compact schema projection advertised by each MCP server and use that identity in doctor comparisons.

BREAKING CHANGE: server.command_path may be null when the invocation path is unavailable. Registration and setup statuses, and doctor classifications, may report unknown.

Reviewed-PR: #3230, #3015
Co-authored-by: qorvr <[email protected]>
Co-authored-by: Hemang Varshney <[email protected]>
@morluto

morluto commented Oct 14, 2026

Copy link
Copy Markdown
Owner

Superseded by 187f113f798b5b8a080d22285b51c05596c3e0f2. The catalog now hashes the same advertised schema projection, including examples, that clients receive. Validation: tests/boundary/mcp/serverIdentity.test.ts (“changes catalog identity when advertised input examples change” and compact tools/list identity), plus tests/conformance/contracts/mcpInputSchemaProfile.test.ts; both passed in the phase-five public/final logs. This covers the reported digest mismatch. Thanks to the PR author and reviewers for identifying the projection mismatch. Validation used production MCP test children, not external MCP clients.

@morluto morluto closed this Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(identity): example-only catalog changes retain the same digest

4 participants