Skip to content

fix: emit v-mode-compatible patterns for tool schemas - #1220

Merged
morluto merged 2 commits into
morluto:mainfrom
felipeatp:fix/v-mode-schema-patterns
Oct 9, 2026
Merged

morluto merged 2 commits into
morluto:mainfrom
felipeatp:fix/v-mode-schema-patterns

Conversation

@felipeatp

@felipeatp felipeatp commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

tools/list emits pattern strings that are invalid under ECMA-262 v mode, and one of them
(^[^\s[\]]+$, used by observe_native_calls) is also rejected by Ruby, per #1212. A provider that
validates tool parameters with format: "regex" rejects the whole request before the model
runs, so the affected tools are unreachable rather than degraded.

Two changes: the reserved characters in the emitted pattern literals are escaped, and the one
pattern that came from Zod's offset datetime class is replaced by a schema whose pattern is valid
under v. A boundary regression now compiles every advertised input and output pattern.

Refs #1212.

Problem and expected behavior

Smallest trigger, no target artifact needed:

new RegExp("^[^\\s[\\]]+$", "v");   // SyntaxError: invalid character in class
new RegExp("^[^\\s[\\]]+$", "u");   // fine — this is why REA never sees it

The emitted catalog must contain patterns that are valid in every engine a client may use.
Measured against the 6.1.0 tools/list with the ECMA-262 engine in Node 22.23.1, two scopes,
both reproducible — read the counts below as the 6.1.0 catalog: revisions after it emit fewer fields for the
same set of patterns (on main: 988 pattern fields across input and output, the same 12 unique rejected
before this change):

  • input schemas, 138 tools: 351 pattern fields, 71 rejected under v — the same census
    reported in [Bug] MCP tool schemas emit regex patterns rejected under strict-mode validation (observe_native_calls blocks the whole request) #1212;
  • input and output schemas: 1,976 pattern fields, 117 rejected under v, reducing to
    12 unique patterns across 11 tools
    (observe_native_calls, capture_browser_scenario, evaluate_reconstruction_coverage,
    compare_process_captures, open_binary, build_call_path, inspect_binary_layout,
    inspect_recorded_crash, compare_source_to_bundle,
    build_reconstruction_obligation_ledger, verify_reconstruction) — the two tools beyond the
    input-only census carry the same patterns in their output schemas. All of them compile with no
    flag and with u, so Zod's own validation cannot observe the defect. Because schema compilation
    happens before arguments are supplied, a single offending field is enough to fail the entire
    tools request.

Change and scope

Escaped literals. 22 pattern literals in 18 files — no other token changes, no pattern is
rewritten. Reserved characters are escaped as \x2d, \x2f, \x5b and \x5d rather than
\-, \/ and \[, because the repository's own pre-commit hook normalizes the shorter escapes
away (oxlint --fix through lint-staged treats an escaped - inside a character class as a
useless escape and removes it):

$ printf 'const a = /^[a-z0-9\\-]*$/u;\nconst b = /^[a-z0-9\\x2d]*$/u;\n' > probe.ts
$ npx oxlint --fix probe.ts
const a = /^[a-z0-9-]*$/u;      // escape removed — the defect returns silently
const b = /^[a-z0-9\x2d]*$/u;   // preserved

An earlier revision of this change used \- and was reduced from 18 files to 5 by that hook.
\xNN escapes are valid under Annex B, u and v, match the same characters, and are not
useless-escape candidates. Escaping \:/\%/\~/\_ would have been wrong in the opposite
direction: u and v reject those as invalid escapes.

Offset datetime. src/domain/reconstructionCoverage.ts used
z.string().datetime({ offset: true }), and Zod projects that validator's offset class as
[+-], which no escape in this repository's sources can reach. That site now uses the new
offsetDateTimeSchema in src/domain/offsetDateTime.ts: the same accepted set, with the offset
class escaped as [+\x2d]. This was not left as a dependency exception because the affected
tool (evaluate_reconstruction_coverage) was still unreachable for exactly the clients this
change targets.

Regression. tests/boundary/mcp/advertisedPatternsVMode.test.ts performs the real
tools/list projection through createServer and an in-memory transport, traverses every
advertised input and output schema, and compiles each pattern under v. It asserts the
inventory it walked (>100 tools, >500 patterns) so a traversal that silently collapses fails
rather than passing vacuously.

Contract and boundary impact

  • Semantic owner and earliest changed stage: domain/contract schema literals and one domain
    datetime schema; validation text only.
  • CLI and MCP/tool-catalog contract: the same inputs are accepted. Emitted pattern text changes
    from e.g. [a-z0-9-] to [a-z0-9\x2d] and from [+-] to [+\x2d], both equivalent under
    Annex B and u and now also valid under v.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: unchanged; the datetime validator
    still rejects the same non-conforming strings.
  • Process execution, authorization, cleanup, or containment impact: none.
  • Generated metadata, package, or installation impact: none — no generated artifact embeds
    pattern text, and docs:check passes without regenerating anything.

Evidence and regression coverage

  • Tests added or updated: tests/boundary/mcp/advertisedPatternsVMode.test.ts (new boundary
    regression over the advertised projection).

  • Base reproduction: restoring z.string().datetime({ offset: true }) in
    reconstructionCoverage.ts while the regression is present fails it with

    evaluate_reconstruction_coverage
    inputSchema/$defs/__schema0/properties/verifier_results/items/properties/observed_at/pattern
    ...: Invalid character in character class
    

    Replacing that schema makes it pass. Before the change the whole catalog was rejected under
    v with nothing in CI able to notice.

  • User-visible CLI/MCP output (if applicable): a client that validates schemas with
    format: "regex" can dispatch the 11 affected tools instead of failing the whole request.

  • Remaining proof gaps: none known for the advertised catalog; the regression covers future
    additions, and provider-level behavior is untouched.

Validation performed

  • new RegExp(pattern, "v" | "u" | undefined) over all 22 changed pairs — all 22 originals throw
    under v; all 22 patched patterns compile under v, u and with no flags.
  • Semantic equivalence, original (u) vs patched (v and u), over 1,525 strings per pattern
    (21,340 comparisons): empty input, -, /, [, ], \, :, ~, 0x1, 0XAB, s:0x1f,
    %2Fhost:0xff, base64 samples, CSP directive names, module paths and 400k generated random
    strings — 0 divergences.
  • Offset datetime accepted set re-checked with Z, +02:00, -03:00, a date-only string and a
    non-date: identical verdicts to z.string().datetime({ offset: true }).
  • npm run build:unlocked then a real initialize + tools/list handshake against the local
    build — rejected input-and-output patterns went from 117 to 0 (input-only scope: 71 to 0).
  • npx vitest run --project mcp-boundary tests/boundary/mcp/advertisedPatternsVMode.test.ts —
    1 passed, and 1 failed with the datetime schema restored.
  • npx vitest run --project domain --project services --project adapters --project conformance --project evaluation — 3,427 passed, 4 skipped.
  • npx tsc --noEmit — exit 0.
  • npm run docs:check — 2 tasks successful.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable; no provider, bridge or launch
    behavior is touched.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none; the change only affects the text of
    validation patterns, and it removes a state where a strict client silently loses tool access.

Review checklist

  • This PR addresses a concrete problem or an agreed enhancement.
  • 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.

Character classes in emitted patterns carried unescaped '-', '/' and '['. Annex-B and u-mode accept them, so REA's own Zod validation (u) and every u-based validator never saw a defect, but v-mode rejects ClassSetSyntaxCharacters and Ruby rejects [^s[]]. With 6.1.0 tools/list, 117 pattern fields across 11 tools were rejected under v.

The characters are escaped as \x2d, \x2f, \x5b and \x5d rather than \-/\//\[, because oxlint --fix removes an escaped '-' inside a character class as a useless escape, so an escape-only change does not survive the pre-commit hook. \x2d-style escapes are valid under Annex B, u and v, are matched identically, and are not useless-escape candidates.

22 pattern literals in 18 files are touched; no other token changes.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 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-09T07:49:40.787279Z d5b30e1 New commits
ℹ️ 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: 0db50d731d

ℹ️ 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/domain/reconstructionCoverage.ts Resolved
The offset datetime site projected Zod's offset class as [ +- ], which no escape in this repository's sources can reach, so evaluate_reconstruction_coverage stayed unreachable for exactly the clients this change targets. It now uses offsetDateTimeSchema in src/domain/offsetDateTime.ts: the same accepted set with the offset class escaped as [ +\x2d ].

Adds tests/boundary/mcp/advertisedPatternsVMode.test.ts, which performs the real tools/list projection, traverses every advertised input and output schema, compiles each pattern under v, and asserts the inventory it walked so a silent traversal collapse fails instead of passing vacuously.
@morluto
morluto merged commit f0da05f into morluto:main Oct 9, 2026
@felipeatp

Copy link
Copy Markdown
Contributor Author

Second review pass on the pushed commits (an independent model, separate from the Codex review). One finding taken, three noted as out of scope.

Taken — the parity claim had no test. src/domain/offsetDateTime.ts documents that its accepted set matches z.string().datetime({ offset: true }), and nothing in the suite checked it; the only coverage was incidental fixture values. Added src/domain/offsetDateTime.test.ts: table-driven accept and reject cases (leap years including the 1900/2000 century pair, month, day, hour and offset ranges, fractional and omitted seconds, missing offset, basic format) plus a differential assertion that classifies every case exactly as the replaced validator does, so the oracle is the validator itself rather than a hand-written expectation that can rot. It also asserts the emitted pattern compiles under u and v while the replaced pattern is asserted not to compile under v.

Not taken — out of scope for this fix, happy to follow up separately:

  • src/browser/CdpSafeMetadata.ts still carries unescaped - inside classes (lines 125, 126, 146, 152, 155, 335, 343), so the file mixes styles. Those literals are internal and are not part of the advertised projection: a tools/list census of the local build reports 0 patterns rejected under v. If any of them ever reaches a tool schema, the new boundary regression fails — which is the property that matters here.
  • The canonical base64 pattern is duplicated verbatim in binaryLayout.ts and recordedCrash.ts, and the stable-id patterns repeat across ~8 modules. That is real maintenance cost (this diff had to apply the same escape twice), but consolidating them is a separate change with its own contract review.

Validation on the final commit: fast lane 3,463 passed / 4 skipped, tsc --noEmit exit 0, docs:check 2 tasks successful, and the boundary regression tests/boundary/mcp/advertisedPatternsVMode.test.ts fails with the Zod offset schema restored and passes with the replacement.

@morluto

morluto commented Oct 9, 2026

Copy link
Copy Markdown
Owner

Thank you for making the schemas v mode compatible. I went through the escaped reserved characters and the offset datetime schema replacement, plus the new boundary regression that compiles every advertised input and output pattern. Fixing the 12 unique rejected patterns across 11 tools so providers no longer reject the whole request before the model runs is important work. Really grateful for the careful census and tests.

darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
* fix: emit v-mode-compatible patterns for tool schemas

Character classes in emitted patterns carried unescaped '-', '/' and '['. Annex-B and u-mode accept them, so REA's own Zod validation (u) and every u-based validator never saw a defect, but v-mode rejects ClassSetSyntaxCharacters and Ruby rejects [^s[]]. With 6.1.0 tools/list, 117 pattern fields across 11 tools were rejected under v.

The characters are escaped as \x2d, \x2f, \x5b and \x5d rather than \-/\//\[, because oxlint --fix removes an escaped '-' inside a character class as a useless escape, so an escape-only change does not survive the pre-commit hook. \x2d-style escapes are valid under Annex B, u and v, are matched identically, and are not useless-escape candidates.

22 pattern literals in 18 files are touched; no other token changes.

* fix: replace the Zod offset pattern and guard the advertised catalog

The offset datetime site projected Zod's offset class as [ +- ], which no escape in this repository's sources can reach, so evaluate_reconstruction_coverage stayed unreachable for exactly the clients this change targets. It now uses offsetDateTimeSchema in src/domain/offsetDateTime.ts: the same accepted set with the offset class escaped as [ +\x2d ].

Adds tests/boundary/mcp/advertisedPatternsVMode.test.ts, which performs the real tools/list projection, traverses every advertised input and output schema, compiles each pattern under v, and asserts the inventory it walked so a silent traversal collapse fails instead of passing vacuously.
@morluto morluto added the bug Something isn't working label Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants