Repository navigation
Conversation
The clamp in parse_sequence only rewrites repetitions strictly above
MAX_REPETITION_THRESHOLD, but the guard in handle_repetitions rejected
the threshold value itself (>=), so a repetition of exactly {0,2000}
passed parsing and then aborted with an uncaught std::runtime_error.
In practice any JSON schema with "maxLength": 2000 crashed the process.
Align the guard with the parse-side clamp (>) and add regression tests:
{0,2000} and {2000} must parse, nested products above the threshold are
still rejected.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Hi @fjc9, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
This was referenced Sep 2, 2026
This branch has not been deployed
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.
Problem
A grammar repetition of exactly
MAX_REPETITION_THRESHOLD(2000) crashes with an uncaughtstd::runtime_error, while both 1999 and 2001 work:"a"{0,1999}→ parses and expands normally"a"{0,2001}→ the parse-side clamp inparse_sequencekicks in (max_times > MAX_REPETITION_THRESHOLD→ unbounded), so it parses"a"{0,2000}→ passes the parse-side check (2000 is not>2000), thenhandle_repetitionsthrows because its guard uses>=:The practical impact: any JSON schema with
"maxLength": 2000(a very natural round number to pick) makesjson_schema_to_grammaremit.{0,2000}and aborts the process, e.g. viallama-completion -j '<schema>':This is the boundary case of #25746, and appears to be an off-by-one left over from the clamp introduced for #27087: the two checks disagree about whether the threshold value itself is allowed.
Fix
Make
handle_repetitionsagree with the parse-side clamp by using a strict comparison, so the threshold value itself expands normally. Values above the threshold keep their existing behavior (clamped to unbounded at parse time for a single repetition, rejected for nested products).Tests
Added to
tests/test-grammar-parser.cpp:"a"{0,2000}and"a"{2000}must parse (previously failed)("a"{0,50}){0,50}(nested product 2500 > threshold) must still be rejectedVerified locally on macOS (arm64): the new tests pass, the previously crashing JSON schema (
"maxLength": 2000) now generates valid constrained output, and the nested-product rejection still triggers.🤖 Generated with Claude Code