Repository navigation
server : reject invalid grammar trigger types - #30936
Open
JonSnow1807 wants to merge 1 commit into
Open
JonSnow1807 wants to merge 1 commit into
JonSnow1807 wants to merge 1 commit into
Conversation
JonSnow1807
force-pushed
the
server-validate-grammar-trigger-type
branch
from
October 21, 2026 17:37
0a521d4 to
99d668d
Compare
|
Hi @JonSnow1807, 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. |
JonSnow1807
marked this pull request as ready for review
October 21, 2026 17:55
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.
Overview
Fixes #30835
An HTTP request containing an unsupported
grammar_triggers[].typevalue can reach the sampling code and triggerGGML_ASSERT, terminating the entire llama-server process rather than rejecting the malformed request.This PR validates grammar trigger types at the request-parsing boundary, before invalid enum values can reach sampler initialization. Unsupported types are rejected with a client error while existing behavior for valid trigger types is preserved.
Additional information
Build:
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DGGML_METAL=OFF -DLLAMA_BUILD_SERVER=ON -DLLAMA_CURL=ON && ninja -C build llama-server(macOS arm64), modelggml-org/test-model-stories260K.Before the fix (master 9febe63):
After the fix the same request returns
400withField 'grammar_triggers': invalid grammar trigger type: 99and a following valid/completionreturns200.New tests in
tools/server/tests/unit/test_completion.py:test_completion_invalid_grammar_trigger_type[-1|4|99]: negative and out-of-range values get a 400 and the server still answers a subsequent valid request.test_completion_valid_grammar_trigger_types: all four valid types (0..3) in one lazy-grammar request are accepted.With
tools/server/server-common.hreverted the invalid-type test fails withhttp.client.RemoteDisconnected(server aborted). The fullunit/test_completion.pyfile: 45 passed, 1 skipped, 1 failed (test_completion_stream_with_openai_library_stops, a@slowtest that needs a Phi-3.5 download and fails identically on unmodified master).Requirements