Skip to content

server : reject invalid grammar trigger types - #30936

Open
JonSnow1807 wants to merge 1 commit into
ggml-org:masterfrom
JonSnow1807:server-validate-grammar-trigger-type
Open

JonSnow1807 wants to merge 1 commit into
ggml-org:masterfrom
JonSnow1807:server-validate-grammar-trigger-type

Conversation

@JonSnow1807

@JonSnow1807 JonSnow1807 commented Oct 21, 2026 •

Copy link
Copy Markdown

Overview

Fixes #30835

An HTTP request containing an unsupported grammar_triggers[].type value can reach the sampling code and trigger GGML_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), model ggml-org/test-model-stories260K.

Before the fix (master 9febe63):

POST /completion {"prompt":"hi","n_predict":1}                                                -> 200
POST /completion {"prompt":"hi","n_predict":1,"grammar_triggers":[{"type":99,"value":"x"}]}  -> connection dropped
log: common/sampling.cpp:258: GGML_ASSERT(false && "unknown trigger type") failed, process exited

After the fix the same request returns 400 with Field 'grammar_triggers': invalid grammar trigger type: 99 and a following valid /completion returns 200.

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.
cd tools/server/tests
PYTEST_WORKERS=1 ./tests.sh unit/test_completion.py -k grammar_trigger
4 passed, 43 deselected in 5.73s

With tools/server/server-common.h reverted the invalid-type test fails with http.client.RemoteDisconnected (server aborted). The full unit/test_completion.py file: 45 passed, 1 skipped, 1 failed (test_completion_stream_with_openai_library_stops, a @slow test that needs a Phi-3.5 download and fails identically on unmodified master).

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES - Claude Code assisted with investigating the root cause, preparing the implementation, and developing regression tests. I reviewed the changes and am responsible for their correctness.

@JonSnow1807
JonSnow1807 requested a review from a team as a code owner October 21, 2026 17:37
@JonSnow1807
JonSnow1807 force-pushed the server-validate-grammar-trigger-type branch from 0a521d4 to 99d668d Compare October 21, 2026 17:37
@ggml-gh-bot

ggml-gh-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown

Hi @JonSnow1807, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • PR Template not respected: Please respect the template when creating a new pull request. Make sure to fill out all required sections.

Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

@ggml-gh-bot ggml-gh-bot Bot added the draft PR will be changed to draft by github-actions bot label Oct 21, 2026
@github-actions
github-actions Bot marked this pull request as draft October 21, 2026 17:44
@github-actions github-actions Bot removed the draft PR will be changed to draft by github-actions bot label Oct 21, 2026
@JonSnow1807
JonSnow1807 marked this pull request as ready for review October 21, 2026 17:55

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misc. bug: Missing range check on grammar_triggers[].type allows remote SIGABRT in llama-server

1 participant