Repository navigation
server: a grammar over 512 KiB is refused before it is compiled - #3038
Merged
Merged
Conversation
Owner
Author
|
Review: almost ready; three small fixes first.
The check itself is right: one length compare per request, a clean 400 before any token, and nothing on the token path.
|
Owner
Author
|
Review fixes pushed (de792da):
Results:
Lean: 345 before and after.
|
ashhart
marked this pull request as ready for review
November 12, 2026 23:22
ashhart
force-pushed
the
security/grammar-size-cap
branch
from
November 14, 2026 07:28
3c0a0f6 to
d3eea8d
Compare
This was referenced Nov 14, 2026
ashhart
added a commit
that referenced
this pull request
Nov 17, 2026
ashhart
added a commit
that referenced
this pull request
Nov 17, 2026
This was referenced Nov 17, 2026
Closed
xgrammar's compile grows with the square of the grammar's text and the server holds one lock across it. A grammar over 512 KiB now gets HTTP 400 before the compiler sees it.
…al of their own A sent grammar is checked where it is read, before compiling. A tool grammar is measured as the grammar for one call, which holds each tool's name and schema once, so the repeat a parallel-call grammar adds no longer refuses tools under the limit (300 KiB of required tools is served); names and many small tools still count. Its 400 names tools. The docs say a JSON schema or a choice list is measured as the server re-serializes it.
ashhart
force-pushed
the
security/grammar-size-cap
branch
from
November 17, 2026 09:51
d3eea8d to
3984195
Compare
This was referenced Nov 19, 2026
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.
What this changes
Before: a grammar of any size up to the 32 MiB body limit went to xgrammar, whose compile grows with the square of the text while the server holds one lock: a 2 MB enum schema took 61 seconds on eight cores. After: a grammar over 512 KiB gets HTTP 400 before the compiler sees it.
SECURITY.mdasks for private reports, so there is no public issue.atc overlap --json: not run.Checks on this head
3c0a0f6a52caca491336c83b49d77cf5f3fcb707. Three commits: the change (1e8cd3f8e90f), the review fixes (de792da9f348, described in the comments below), and a merge of main at223da7659b2f. The merge keeps both sides oftool_required_test.zig, this PR's test and main's helper from grammar budget: exploring a grammar stops at a work limit and a time limit #3037, and folds the size check into the statement after it soserver.zigstays at 600 lines. The check's order and message are unchanged.python3 tools/zig/lean_check.py, on the base and on this head: 341 on main, 341 on this head, 0 new.zig fmt --checkandgit diff --check: passzig build test-grammar-size-host test-tool-required-host: 6/6 steps succeeded; 51/51 tests passedzig build test-server-security test-pull-security: 72/72 steps succeeded; 47/47 tests passedzig build test-server-cpu: 5/5 steps succeeded; 1339/1346 tests passed (7 skipped)zig build check-native-cuda-host compile-flashnext-mtp-parity-host compile-glm-native-open: 11/11 steps succeededzig build -Dxgrammar=<xgrammar v0.2.8> test-grammar-budget test-grammar-tools: 8/8 steps succeeded; 52/52 tests passedzig build test-golden: 5/5 steps succeeded2cd0ec7fa50d. The head merges223da7659b2f, two commits later, which touch no file of this PR, and on the headtest-grammar-size-host test-tool-required-host test-server-securitypass againsecurity: a grammar over the size limit is refused before the compiler sees it, and one at the limit compilessecurity: tools count once against the grammar size limit: 300 KiB of required tools is served, 600 KiB refused, from the review fixeszig build testand every step that runs on a GPU were not run: this Mac's GPU was serving a model, and no CUDA, ROCm or Intel hardware was available.Receipt
n/a. This change cannot reach inference: it refuses a request before any grammar is compiled. A request that passes takes the same path as on main.
Checklist
zig build test-server-cpu: exit 1. It does not compile: the new test readsgrammar.max_text, which the fix adds, so this base shows no failure on behavior. On the earlier baseb38a4dd02the tests failed with the fix taken out.Notes for the reviewer
Suggested changelog line
Server: a grammar over 512 KiB is refused with HTTP 400 before it is compiled.