Repository navigation
Key a budget-declined pattern to its own schema - #2969
Merged
Merged
Conversation
Ajv registers each pattern in the engine-wide scope under rx.toString() and hands back the first entry for a key, so a LinearPattern declined because one schema's compile budget ran out was reused by every later schema on the engine. Give such a decline a unique key; every other outcome depends only on the pattern and keeps the shared key. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
2 tasks done
There was a problem hiding this comment.
🟢 Approval recommended
There are no outstanding review issues requiring changes.
No open issues 🎉
What changed in this PR
Fixes #2934 in the shared schema validator so a pattern declined because one schema exhausted its compile budget does not affect later schemas on the same validator.
Changes:
- Assigns unique cache keys to budget-declined patterns while preserving shared keys for pattern-only outcomes.
- Corrects the cache documentation to describe Ajv’s engine-wide scope.
- Adds regression coverage for later-schema validation and continued reporting of the original schema’s decline.
| File | Description |
|---|---|
core/mcp/linearPatternValidator.ts |
Isolates budget-declined pattern cache entries and clarifies scope-key behavior. |
clients/web/src/test/core/mcp/linearPatternValidator.test.ts |
Tests that an over-budget schema does not poison a later schema’s pattern validation. |
Review effort: Balanced
Member
Author
|
Copilot review closed: round 1 was clean (no inline comments, no suppressed findings), so the loop stopped on the first clean round. |
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2934
Problem
Ajv's
usePatternregisters each regex in the engine-wideValueScopeunderrx.toString(), andValueScope.value()returns the first entry registered for a key.LinearPattern.toString()returned/${source}/${flags}, so aLinearPatterndeclined withCOMPILE_BUDGET_EXHAUSTEDwhile compiling one over-budget schema became the entry every later schema on that engine tested against — the later schema's own compile ran against its fresh budget, and its result was discarded. A heavyoutputSchemaon one tool made other tools' structured output (and app elicitation results) read as "could not be verified" for the rest of the session.Fix
core/mcp/linearPatternValidator.ts:LinearPatterncomputes its scope key once, in its constructor./${source}/${flags}key, so it is still compiled once per engine.#<n>suffix from a module-level counter, so it stays with the schema whose budget it reflects.The doc comment on the new
keyfield replaces the old "per-schema pattern cache" comment, which was inaccurate (the cache is engine-wide).tracked(), the budgets andgetValidatorare unchanged.Tests
New case in the "bounded pattern compilation" block of
clients/web/src/test/core/mcp/linearPatternValidator.test.ts: an over-budget schema declines^[a-z]+$; a later{ type: "string", pattern: "^[a-z]+$" }on the same provider then validates"abc"and rejects"ABC"with the ordinarymust match patternerror; the heavy schema still reports its own decline. Fails onv2/main, passes with the change.npm run local:gateis green.Approach follows the prototype prompt shared on the issue.
🤖 Generated with Claude Code