Conversation
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.
Summary
Preserve full JSON Schema reference identities instead of treating an existing grammar rule with the same last path token as an already resolved reference.
Two distinct references such as
#/$defs/left/$defs/Itemand#/$defs/right/$defs/Itemcurrently reuse the firstItemrule. A definition namedstringorintegercan also reuse an unrelated built-in rule. This can silently drop a valid union alternative or remove a referenced property's constant constraint.The fix caches each full resolved reference, reserves a unique sanitized name before descending into its target, and retains that name for recursive and repeated references. It also covers empty definition names and names that collide after sanitization. No changes to native code, schema fetching, or JSON Pointer token decoding are included.
Minimal reproduction
Before the fix, both alternatives reference
Item, and its only literal is"left";"right"is absent from the generated grammar. After the fix, each alternative reaches its corresponding literal.Validation
llama-cpp-python==0.3.36PyPI source distribution and verified its published SHA-256. Itsllama_grammar.pyis byte-identical to currentmainat1652066e0af45f2313b339670ef9555e8a54e545string/integer/spacecollisions, same-reference reuse, self-recursion, and mutual recursion with colliding leaf nameslibllamagrammar executiongit diff --checkpassesThe full repository suite, native
libllamagrammar execution, inference, model-dependent tests, and GPU tests were not run. No model weights were downloaded. The separate existing root-$reftraversal and JSON Pointer escape issues are outside this patch's scope.AI assistance
This contribution was prepared with AI assistance. The root cause, diff, and tests were independently reviewed, and the validation limits above are intentional and explicit.