Skip to content

Eval bug: tool-call grammar build fails (HTTP 400 "failed to parse grammar") above ~58 tools — cumulative schema-size ceiling, distinct from #25746/#24658 #25895

Description

@headbouyJB

Name and Version

version: b454 (571d0d540), HIP/ROCm build (gfx1151 / Strix Halo), llama-server with --jinja. Behaviour also confirmed present on 2f18fe1 (Jun 26). (The failure is in json-schema→GBNF grammar construction, which is backend-independent — reproducible on any build.)

Operating systems

Linux

Which llama.cpp modules do you know to be affected?

llama-server (--jinja tool-call grammar / json-schema-to-grammar)

Problem description & steps to reproduce

When the request carries a large-but-realistic tool set, llama-server rejects it at grammar-build time:

HTTP 400 {"error":{"code":400,"message":"Failed to initialize samplers: failed to parse grammar"}}

The rejection arrives in ~0.13 s with no prefill and no GPU activity — it dies while compiling the combined tool-call grammar, before any inference. Single small tool sets work normally.

The trigger is cumulative schema size, not tool count and not any individual tool. Demonstrated by holding tool count constant and varying only total schema volume:

tools tools-array JSON size result
58 (set A) 97,102 B HTTP 200
58 (set B — same count, larger-schema tools) 100,026 B HTTP 400

Same count, different composition → the larger-volume set fails. So it is not tool count, and not a single culprit schema (the 50-tool base is identical in both sets; a fixed bad schema would fail both).

Boundary scan (base of 50 real tools + N additional real MCP tools), current build:

total tools tools-array size result
58 97,102 B 200
59 97,935 B 400
60 98,951 B 400
65 103,348 B 400
89 121,115 B 400

The 200→400 crossover sits at ~97–98 KB of tools-array JSON (proxy for compiled-grammar size) for this tool mix. All failures return the identical error in ~0.1 s.

Real-world impact: the agent framework driving this (OpenClaw) treats the 400 as a provider failure and silently falls back to a cloud model — local inference stops with no user-visible error. The failure appeared when an installed MCP server's tools pushed the materialized set past the threshold.

Not explained by existing issues

Suspected mechanism

Total compiled GBNF size / rule-count exceeding an internal parser limit as tool schemas accumulate — a volume ceiling in json-schema-to-grammar + the GBNF parser, distinct from the shape triggers already tracked. Secondary observation: in default single-slot config this error is fatal and exits the server; with --parallel 2 the server survives and returns the 400.

Reproduction / offer

Reproducible on gfx1151 (ROCm) with Qwen3.5-122B-A10B and a real 96-tool MCP payload; the grammar-build path is backend-independent so it should reproduce anywhere with a comparably-sized tool set. I have a probe harness (adds real tool schemas to a base set; failures cost ~0.1 s / no prefill) and can share the payloads, and I'm happy to test candidate fixes on this hardware.

(Investigation and write-up done with AI assistance; all HTTP results from live runs on the machine described, reproducible on request.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions