Repository navigation
fix(mcp): re-emit advertised patterns in a portable regex grammar - #10582
Conversation
Codex Review Summary: ✅ CompletedThis 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 810a8e25f2
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
[Medium impact] The changes affect regex patterns shown across MCP tool catalogs, but not server-side validation. Fix repeated alternatives that overlap after widening before merging.
|
… into HEAD # Conflicts: # scripts/lib/verify-package-core.mjs # src/contracts/advertisedDialectBaseline.ts # tests/boundary/mcp/advertisedDialect.test.ts
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dfb8ca0751
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
# Conflicts: # tests/boundary/mcp/advertisedDialect.test.ts
# Conflicts: # docs/development/testing.md # scripts/lib/verify-package-core.mjs # src/contracts/advertisedDialectBaseline.ts # tests/boundary/mcp/advertisedDialect.test.ts # tests/boundary/mcp/advertisedPatternsVMode.test.ts
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 01d0b22a59
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4d499450af
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 897cd485ca
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b44abc9c13
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8d6721cdab
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…draft-07 reference siblings
| #group(): string { | ||
| return this.#disjunction() | ||
| .map((terms) => terms.join("")) | ||
| .join("|"); |
There was a problem hiding this comment.
Repeated alternatives freeze clients
Widening separate characters can make repeated alternatives overlap. ^(?:é|è)+$ becomes ^(?:[^\x00-\x7f]|[^\x00-\x7f])+$, which both presenters advertise. On Node 24.22.3, rejecting "é".repeat(28) + "A" took about 1.9 seconds with the projected pattern, versus 0.03 ms with the source. Longer mismatches can freeze a client that checks requests or responses.
Combine overlapping alternatives before repeating them, or omit patterns whose widened form is unsafe. Add a rejected-string regression.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/contracts/portablePattern.ts
Line: 187-190
Comment:
**Repeated alternatives freeze clients**
Widening separate characters can make repeated alternatives overlap. `^(?:é|è)+$` becomes `^(?:[^\x00-\x7f]|[^\x00-\x7f])+$`, which both presenters advertise. On Node 24.22.3, rejecting `"é".repeat(28) + "A"` took about 1.9 seconds with the projected pattern, versus 0.03 ms with the source. Longer mismatches can freeze a client that checks requests or responses.
Combine overlapping alternatives before repeating them, or omit patterns whose widened form is unsafe. Add a rejected-string regression.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Summary
The presentation owner now re-emits every advertised
pattern, in input and output schemas, into the portable regex grammar from #10567. When a pattern has no exact portable form it is widened, or omitted when it has no form at all. Server-side validation is unchanged: the Zod contracts still validate the real rule. The pattern entries leave the dialect baseline, so every advertised pattern is now enforced at zero in every profile, on the Windows lane and in the packaged catalog check.Stacked on #10567 (base branch
test/advertised-dialect-checker).Refs #10389 #10436 #7151
Problem and expected behavior
#10567 measured the patterns advertised today that fall outside the grammar that compiles in V8 (
""/u/v), Pythonre, Goregexp(RE2), Rustregexandfancy-regex:\s, unanchored^\/prefixes).\d,., an unescaped^in a class, and\x80-\xff.\d,., unanchored base64 probes).Each past fix escaped one construct at one source site (
\x2d,\x2f,\x00, look-around rewritten asnot). Nothing stopped the next site from reintroducing a construct.Expected: whatever a contract author writes, the advertised pattern is portable. The advertisement may widen a constraint, but it never narrows one.
Change and scope
src/contracts/portablePattern.tsparses an ECMAScript (u) pattern and re-emits it. It returns:exact, for the same strings;wider, for a superset;unexpressible, for backreferences, inline flags and empty classes.How it re-emits:
\-,\/,\^and\xHHescapes. A class's non-ASCII members become an exact or widening[^\x00-\x7f]alternative, or are removed from a negated class.\dbecomes[0-9]and\wbecomes[A-Za-z0-9_], both exact.\sand\Sbecome ASCII-whitespace forms (wider)..becomes[^\n\r](wider).\bare removed (wider).[^\x00]*(?:\x00[^\x00]*)*. This is a single-class loop, so V8 does not keep one backtracking frame per character.inputSchemaPresentation.tsapplies the projection inside the existing normalization:notorif/then/else, turnsoneOfintoanyOf, and handles$refdependents. The advertisement therefore only widens. Dropping a pattern undernotwould instead narrow the schema.presentOutputJsonSchemais applied intoolOutputSchemaWithMetadata. Output schemas whose patterns are all exact take a structural copy instead of the dependency analysis, because output schemas reach several megabytes.advertisedDialectBaseline.tsloses every pattern key and the output baseline, which is now empty. ThefullinputoneOfcount drops from 223 to 219, because four unions whose branches widened becomeanyOf. The test and the packaged verifier now enforce output patterns at zero.Tests that matched advertised pattern spellings (canonical base64, JavaScript route paths) now compare against the projected form. Each still checks exact Ajv semantics on line terminators and padding.
Docs (
testing.md): source regexes no longer need client-oriented escaping.Intentionally not included:
\x2d/\x2ffor clients. They are harmless and the projection now covers them. Changing canonical server regexes is churn without client benefit, so I propose it as an optional follow-up.rejectUnpairedSurrogates, which stays as it is: a\uD800class would project to "any character", the same as advertising nothing.fullprofile.Contract and boundary impact
Semantic owner and earliest changed stage: the presentation (
inputSchemaPresentation.ts, usingportablePattern.ts) owns how a pattern is advertised. The canonical Zod contracts and server-side validation are unchanged.Contribution scope fit and linked maintainer decision: not applicable (advertisement-only fix within existing boundaries).
CLI and MCP/tool-catalog contract: the
patternvalues intools/listchange in every profile. All changes are exact or widening; widened sites drop enclosingnot/ifor relaxoneOftoanyOf. Catalog digests change accordingly and are regenerated at build. Examples from the default catalog:^\/becomes^\/[^\x00]*(?:\x00[^\x00]*)*$(exact).^[^\x00\s"']+$becomes^[^\x00\x09-\x0d "']+$(wider: it now admits non-ASCII spaces).^-?\d+$becomes^-?[0-9]+$(exact).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: the recorded catalogs change with the advertised patterns.
Documentation or usability only; no target interaction.
Evidence and regression coverage
src/contracts/portablePattern.test.tscovers 34 source patterns, including every non-portable pattern advertised today and the refused constructs from [Bug] Full input-schema profile advertises look-ahead and v-mode-incompatible patterns #10389 and 6.9.0 advertised tool schemas contain \uD800 surrogate-class patterns that the DeepSeek official API rejects with 400 (worked in 6.8.0) #10436. For each one, the test checks that:""/u/v;exactresult matches the source exactly and awiderresult admits a superset.It also covers the expected spellings, the unexpressible cases, and the presentation polarity: a widened pattern under
notremoves thenot, an exact one keeps it, and a widenedoneOfbranch becomesanyOf, for input and output.advertisedDialect.test.ts: pattern keys are removed from the baseline, so the 12-combination catalog test fails if any advertised pattern leaves the grammar.regexp;regexandfancy-regex, using the audit harness;re.Validation performed
npm run check:fast: passed.npm run docs:check: passed.npm run test:local -- src/contracts/portablePattern.test.ts: 46 tests passed.npm run test:focused --with the 25 schema-related files: 354 tests passed. The files are:src/contracts:portablePattern,compactOutputSchema,inputObservationPresentation,toolInputReferences,toolOutputReferences,canonicalBase64Metadata;src/server:registerGuidedWorkflowTool,JavaScriptRouteAdvertisedSchema;tests/boundary/mcp:advertisedDialect,advertisedPatternsVMode,contractPresentation,deferredRuntime,mcpDoctor,serverIdentity,stdioFrameDiagnostics,processCaptureCleanupSchema,compactInputSchemaMcp,toolSchemaValidity,packageCatalogVerification,browserScenarioMcp,officialTools,absoluteLocalPathSchema,applicationEvidenceMcp;tests/conformance/contracts/mcpOutputSchemaProfile;tests/conformance/verifiers/clientSchemaPatterns.Local cross-engine compile of the 183 advertised patterns (Go, Rust, fancy-regex, Python): all compiled.
Performance: output presentation over all 255 output schemas (4.26 MB) took about 100 to 175 ms of CPU in one process. This is an estimate on a machine shared with other jobs. It runs once per contract per process, because the projection is memoized.
tools/listat default profiles: about 0.8 to 1.0 s wall time, against about 0.6 to 1.0 s before. Runs were noisy and the difference is within run-to-run variance.Review follow-up (4d49945, 95eda9b):
npx vitest run src/contracts/portablePattern.test.ts tests/boundary/mcp/advertisedDialect.test.ts tests/boundary/mcp/advertisedPatternsVMode.test.ts src/contracts/toolInputReferences.test.ts src/contracts/inputObservationPresentation.test.ts: 165 passed. The new regressions (references into removednot/if/then/else,$dynamicRef, astral literal in V8 plain mode) each failed before their fix.Second follow-up (95d1fcb): astral literals are now omitted (
unexpressible) instead of projected, which removes the backtracking form 95eda9b introduced. Unresolved$refsites, such as an embedded resource reached by$id, are relaxed when anything widens. Same vitest set plustoolSchemaMetadata.test.ts: 168 passed. The embedded-resource regression failed before the fix.Third follow-up (d7aa9c8, b71c9c1): union collapse and pointer protection both decide from canonical branches (
collapsesToBoolean); the four new relaxed-reference union regressions failed on 897cd48. Non-uastral matching in single wildcard/shorthand/negated-class positions is documented as an accepted limitation, and the test pins equal BMP acceptance in V8 plain,uandvmodes.npm run test:local -- src/contracts/portablePattern.test.ts: 78 passed.npm run test:focused -- tests/boundary/mcp/advertisedPatternsVMode.test.ts: passed.npm run check:fast: passed. Offline, projected patterns over 1922 BMP samples: Goregexpmatched V8uexactly; Pythonrediffered only on strings ending in\n(its$matches before a final newline, wider only). Rust was not run. Also restored the cancellation paragraph intesting.mdthat an earlier commit dropped by mistake.Fourth follow-up (b44abc9, 8d6721c):
canonicalBase64Metadata.test.tsnow expects the advertisement to admitAB==(the unbounded pad-bit probe is omitted on the wire; the server still refuses it); references intounevaluatedProperties/unevaluatedItemsremoved by lost evaluation are protected. New regressions failed before the fix.npm run test:focusedover 22 schema-related files: 378 passed (before 8d6721c); after it,portablePattern,canonicalBase64Metadata,advertisedDialect,advertisedPatternsVMode,toolInputReferences,toolOutputReferences,toolSchemaValidity: all passed. Merged currentmain.Compatibility, safety, and release
Author readiness
Human owner:
Before merge
type(scope): outcome.