Skip to content

refactor(mcp): leave input literal portability to the advertised dialect projection - #11207

Merged
morluto merged 9 commits into
mainfrom
refactor/portable-dialect-rules
Nov 15, 2026
Merged

morluto merged 9 commits into
mainfrom
refactor/portable-dialect-rules

Conversation

@morluto

@morluto morluto commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Advertised input schemas rewrote boolean and empty-string literals twice: once in inputSchemaPresentation.ts (widenGatewayLiterals, a Gemini-named branch), and again in the advertised dialect projection (literalKeywords, the dialect's enum rule). Every listed input schema passes through the projection, so the first rewrite changed nothing a client receives. This PR removes it, along with the Boolean-collapse code that only it could trigger, and replaces the remaining client-named comments in inputSchemaPresentation.ts and compactInputSchema.ts with the dialect rule each one implements. Part of W3 (portable advertised schema dialect).

Problem and expected behavior

  • presentInputJsonSchema widened const: false, const: "" and boolean or empty-string enums, citing Gemini. projectToAdvertisedDialect (src/contracts/advertisedDialectProjection.ts) already keeps only non-empty string enums and gives other literals their type. It runs on every listed input schema (presentAdvertisedInput, the only input presentation since feat(mcp)!: retire the full schema profiles and declare schema facts as typed annotations #10693). The same rule therefore had two owners.
  • The literal rewrite also marked sites as changed, which drove a Boolean-collapse path (oneOf or anyOf of Boolean literals became type: "boolean"). Without the rewrite, that path cannot trigger.
  • Expected: the dialect projection is the only owner of literal portability, and comments name dialect rules rather than clients. Client evidence stays with the rule declarations in advertisedDialect.ts.

Change and scope

  • src/contracts/inputSchemaPresentation.ts: removed widenGatewayLiterals, hasNormalizedLiteral, the NormalizationOptions input/output switch, isBooleanLiteralSchema, isBooleanSchema, collapsesToBoolean, preserveSharedDefault, and the anyOf collapse case in throughRemovableLocation. Normalization now rewrites only patterns, which it already did for both input and output. The root-union flattening comment now cites the dialect's root-shape rule instead of Anthropic.
  • src/contracts/compactInputSchema.ts: the header cites the dialect (no $ref/$defs) instead of Kimi and Moonshot. The input-bytes rule in advertisedDialect.ts keeps the evidence that the cap is measured after clients expand references.
  • Tests that asserted literal widening on the intermediate presentation now assert the advertised schema (presentAdvertisedInputSchema after presentInputJsonSchema). Tests that used a literal only to trigger dependency analysis now use a pattern with no portable form (^😀$). One test only checked that literal payloads were not rewritten; it was removed, because no literal rewrite remains. The shared advertisedSchemaErrors fixture and compactInputSchemaMcp.test.ts no longer apply the Gemini literal denylist (unsupportedInputLiteralSchemaError). For registered (pre-dialect) schemas the check no longer holds. For listed schemas, advertisedDialect.test.ts already checks every listed input against all dialect rules with an empty baseline, and const and non-string or empty enums are violations there.

Not included:

  • The Gemini/Kimi-named item and type repairs in compactJsonSchema.ts. That module also serves compact output schemas, which the dialect projection does not cover. They are left for the W3 step that gives one function ownership of everything advertised.
  • tests/fixtures/mcpClientSchemaConstraints.ts and scripts/lib/gemini-schema-literals.mts are kept. They still check served environment catalogs (environmentServeWritesMcp.test.ts), which the dialect projection does not present, and the Gemini verifier uses the second against the real client. arrayItemSchemaError still checks registered output schemas.

Contribution scope: not applicable (internal refactor within an existing boundary).

Collapsed from #11238

This PR now also carries #11238. The dialect projection re-emits input patterns through projectPortablePattern and owns dependency prose. presentInputJsonSchema only describes fields and presents the root as one object. The dependency-tracking pattern normalization moved to the new src/contracts/outputSchemaPresentation.ts, because output schemas are now its only consumer. inputSchemaPresentation.ts went from 1,105 lines on main to 470. Listed input schemas, tool descriptions and output schemas are byte-identical for all 255 contracts. verify:advertised-schemas -- --update-summary gives identical output on this branch and on its base. Later fix: compactInputSchema.test.ts now forces the reduced form by depth, because the unanchored pattern it relied on is now re-emitted. Across the 27 test files that import these modules, 445 tests passed; the one failure, applicationEvidenceMcp.test.ts, also fails on main.

Contract and boundary impact

  • Semantic owner and earliest changed stage: projectToAdvertisedDialect owns literal portability. presentInputJsonSchema (the intermediate registered presentation) now keeps canonical literals.

  • Contribution scope fit and linked maintainer decision: not applicable.

  • CLI and MCP/tool-catalog contract: listed input and output schemas are byte-identical before and after (see Evidence). The intermediate advertisedInputJsonSchema changes for 6 tools: it now keeps their Boolean/empty-string literals. That projection feeds the catalog identity digest, so the catalog digest changes, as it does on any schema change.

  • Provider, bridge, target-format, or platform compatibility: none.

  • Evidence, artifact, provenance, or reconstruction contract: none.

  • Target selection, authority, upstream behavior, and cleanup details: not applicable.

  • Generated metadata, package, or installation impact: none.

  • Read existing files or captured data.

  • Launch or attach to a process.

  • Inject instrumentation or run scripts/code.

  • Change process memory, registers, files, or configuration.

  • Contact network services.

  • Recover protected code or work around protections.

  • Documentation or usability only; no target interaction.

  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Executed: a script serialized presentAdvertisedInput(advertisedInputJsonSchema(c), COMPACT_INPUT_SCHEMA_PRESENTATION) (schema and guidance) for all 255 contracts, and advertisedOutputJsonSchema(c) for each. Results were compared before and after with cmp/deep-equality. Listed input: identical. Output: 0 of 255 differ. Intermediate input: 6 of 255 differ (literals kept).
  • Tests updated: src/contracts/toolInputReferences.test.ts (literal cases assert the advertised schema), src/contracts/inputObservationPresentation.test.ts (dependency triggers use an unexpressible pattern), tests/boundary/mcp/toolSchemaValidity.test.ts (Boolean-literal relaxation is checked on the advertised schema), tests/boundary/mcp/compactInputSchemaMcp.test.ts and tests/fixtures/mcpAdvertisedSchemaValidity.ts (the literal denylist is dropped there, because the dialect check covers listed inputs).
  • The literal-relaxation tests now fail if the dialect projection stops widening literals, instead of passing on the redundant intermediate rewrite.
  • Remaining proof gaps: no real-client run. The listed bytes are unchanged, so client behavior should be unchanged.

Validation performed

  • npm run test:focused -- <18 files that use presentInputJsonSchema, presentOutputJsonSchema, canonicalTools or toolRegistrationOptions>: 18 files, 334 tests passed.
  • npm run test:focused -- tests/boundary/mcp/toolSchemaValidity.test.ts tests/boundary/mcp/compactInputSchemaMcp.test.ts tests/boundary/mcp/environmentServeWritesMcp.test.ts tests/conformance/verifiers/geminiSchemaLiterals.test.ts tests/boundary/mcp/serverWorkflowMcp.test.ts tests/boundary/mcp/javascriptFactsViewMcp.test.ts tests/boundary/mcp/evidenceInputContractsMcp.test.ts tests/boundary/mcp/browserScenarioMcp.test.ts tests/boundary/mcp/serverIdentity.test.ts tests/boundary/mcp/advertisedDialect.test.ts src/contracts/enhancedInputs.test.ts src/contracts/advertisedDialectProjection.test.ts src/contracts/portablePattern.test.ts: passed after the compact-only literal check (13 files).
  • After dropping the denylist from compactInputSchemaMcp.test.ts: npm run test:focused -- tests/boundary/mcp/compactInputSchemaMcp.test.ts tests/boundary/mcp/advertisedDialect.test.ts: 2 files, 55 tests passed.
  • npm run check:fast: passed (typecheck, lint, architecture guards).
  • npm run docs:check: passed.
  • npx oxfmt --check on the changed files: passed.
  • tests/boundary/mcp/applicationEvidenceMcp.test.ts fails with a ZodError on exclusions[0].entry_kind. It fails the same way with this PR's inputSchemaPresentation.ts reverted to main, so it is unrelated.
  • npm run verify:advertised-schemas (macOS, engines: V8 plain/u/v, Go RE2, Python re, C++ RE2; Rust regex, fancy-regex and jsonschema not verified because jsonschema_rs is not installed): 31/31 patterns accepted by every installed engine. The summary comparison reports summary.json stale, and it reports the same on this PR's base (104b1a3), whose committed summary records another host's absolute-path patterns. --update-summary output from this branch is byte-identical to the output from the base, so every listed schema in every profile is unchanged.

After #11268 merged (38dbadd): merged main. Three tests added on this branch still called the removed presentAdvertisedInputSchema, which is why the merger's gate refused this PR on check:fast. They now take the advertised input from advertiseToolInput / advertiseTool in src/contracts/advertisedTool.ts.

  • npm run check:fast — passed.
  • npm run test:focused -- src/contracts/toolInputReferences.test.ts src/contracts/portablePattern.test.ts tests/boundary/mcp/toolSchemaValidity.test.ts tests/boundary/mcp/compactInputSchemaMcp.test.ts src/contracts/compactInputSchema.test.ts — 5 files, 198 tests passed.
  • Gate equivalent run on this head merged into main fdf856a: oxfmt --check ., npm run check:fast and npm run verify:advertised-schemas all passed.

After the merger's gate refused this PR on affected tests (5bdab9f): src/contracts/canonicalBase64Metadata.test.ts still expected the registered input schema to admit AB==. Since this PR, the registered schema keeps canonical patterns, so it rejects AB== exactly, and advertiseToolInput widens the negated pad-bit probe away for clients. The advertised projection was not broken; the test was checking the wrong layer. The test now checks the registered input (exact), the advertised input from advertiseToolInput, and the output presentation (both admit AB==), and checks that the server refuses AB== in both directions. I also corrected the advertisedInputJsonSchema doc comment.

  • npm run test:local -- src/contracts/canonicalBase64Metadata.test.ts: 2 tests passed.
  • npm run test:focused -- on the registered-input consumers that were outside the gate's affected set (applicationEvidenceMcp, serverWorkflowMcp, javascriptFactsViewMcp, evidenceInputContractsMcp, browserScenarioMcp, generatedToolCatalog, toolInputAdmission, plus src/contracts/toolSchemaMetadata.test.ts): 8 files, 19 tests passed.
  • Pre-push hook (check:fast plus architecture guards): passed.
  • briefs/local-gate.sh 11207: oxfmt, check:fast, the guards and verify:advertised-schemas passed, and canonicalBase64Metadata passed. Two acceptance tests (analysisSettingsMcp, adbNumericDeclarations) timed out at 120 s while the machine was under load (load average about 9). Run alone on this head with npm run test:focused, both passed: 11 tests, with the slowest case at 5.8 s.
  • Second gate run: 9/60 files failed again. Seven were 120 s timeouts and SDK request timeouts. The other two were CLI assertions in applicationManifestRoots and applicationVersionMatchingCli. The host load average was 8 to 9 from concurrent agents. npm run test:focused -- on the two assertion failures and the two PR-relevant schema tests (compactInputSchemaMcp, toolSchemaValidity): 4 files, 36 tests passed in 14.8 s wall time, 1.35 GB peak RSS.
  • Third gate run, after main-fix test(environment): read an omitted advertised required list as empty #11391 merged: passed, 60 files, 548 tests.

Compatibility, safety, and release

  • Breaking changes or migration steps: none. Listed schemas are unchanged.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable.
  • Package or release metadata impact: the catalog identity digest changes (intermediate input projection).
  • Security, privacy, process, or containment review: none.

Author readiness

Human owner:

  • 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

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-15T14:18:51.496739Z
We couldn’t complete this review. Comment @codex review to try again.
3234ae8 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

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@greptile-apps

greptile-apps Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Low impact] The PR appears safe to merge; no new blocking issue was identified.

Summary

Makes projectToAdvertisedDialect the owner of input literal, pattern, and dependency portability. Moves output-only pattern rewriting into outputSchemaPresentation.ts.

  • Input presentation leaves portability to the advertised dialect projection.
  • Output schemas use a separate presenter for portable patterns.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  C["Canonical Zod contract"] --> V["Runtime input checks"]
  C --> I["presentInputJsonSchema"]
  I --> A["advertiseToolInput"]
  A --> P["projectToAdvertisedDialect"]
  P --> L["Listed input schema and tool guidance"]
  C --> O["presentOutputJsonSchema"]
  O --> R["Registered output schema"]
Loading

Reviews (8) · Last reviewed commit: "Merge branch 'main' into refactor/portab..." · Reviewed by Greptile

…ndency prose (#11238)

* refactor(mcp): let the dialect projection own input patterns and dependency prose

* refactor(mcp): drop the unused import from the output schema presentation
@morluto
morluto merged commit b0e0d52 into main Nov 15, 2026
13 of 15 checks passed
@morluto
morluto deleted the refactor/portable-dialect-rules branch November 15, 2026 19:55
@morluto morluto added the area: mcp MCP server, transport, and tool registration label 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant