Skip to content

[Bug]: cron tool schema incompatible with llama.cpp grammar-constrained tool calling (2026.7.1 regression) #108580

Closed

Description

@arbilli82

Bug type

Regression (worked before, now fails)

Beta release blocker

No

Summary

The cron tool's schema in OpenClaw 2026.7.1 contains fields that fail to compile into a valid GBNF grammar under llama.cpp's grammar-constrained tool calling, causing every chat request to fail — not just cron-related ones — whenever the cron tool is present in the active tool list. Three distinct schema issues were found, each masking the next until the previous one was patched:

job.declarationKey has pattern: "\S" — unanchored. llama.cpp requires all pattern values to be fully anchored (^...$); unanchored patterns are rejected with 400: Pattern must start with '^' and end with '$'.
After anchoring to ^\S+$, llama.cpp's regex-to-GBNF converter fails with unknown escape — it doesn't support PCRE shorthand character classes like \S, only a small set of literal escapes (\n, \t, \r, etc.).
After replacing \S with an explicit character class, job.trigger.script.maxLength: 65536 fails GBNF compilation with number of repetitions exceeds sane defaults, please reduce the number of repetitions — llama.cpp enforces a hard repetition ceiling (~2000) for length-bounded string fields under grammar constraints.

Because tool schemas are compiled into a single grammar covering the entire active tool list, one malformed field anywhere in that set blocks all messages on all channels, not just requests that would invoke the affected tool.

Steps to reproduce

Run OpenClaw 2026.7.1 against a llama.cpp llama-server backend with strict JSON-schema grammar tool calling enabled (default for OpenAI-compatible tool calling on llama.cpp).
Ensure the cron tool is enabled/present in the active tool list.
Send any message on any channel.

Expected behavior

The message is processed normally; the model responds, using or ignoring the cron tool as appropriate.

Actual behavior

Every request fails with a 400 from the llama.cpp endpoint. OpenClaw surfaces this generically as LLM request failed: provider rejected the request schema or tool payload. with rawError varying depending on which of the three schema issues is hit first (see Summary). No indication is given of which tool or field caused the failure — diagnosing this required a custom logging proxy to capture the raw outbound request and cross-referencing llama.cpp's own server-side grammar-parse error log.

OpenClaw version

2026.7.1 (2d2ddc4)

Operating system

Ubuntu 24.04, Linux

Install method

npm global install

Model

Qwen3.6-27B

Provider / routing chain

openclaw → llamacpp (OpenAI-compatible /v1/chat/completions) → self-hosted llama-server (latest build, --flash-attn on, grammar-constrained tool calling)

Additional provider/model setup details

No response

Logs

Screenshots, recordings, and evidence

No response

Impact and severity

No response

Additional information

No response

Activity

  1. brantzh commented on Jul 16, 2026

    @brantzh

    operator(): got exception: {"error":{"code":400,"message":"Unable to generate parser for this template. Automatic parser generation failed: JSON schema conversion failed:\nPattern must start with '^' and end with '$'","type":"invalid_request_error"}}

  2. thegoldenflow commented on Jul 16, 2026

    @thegoldenflow
    Contributor

    Opened #108671 to fix this.

    It removes the three grammar-hostile constructs from the model-facing tool schemas (src/agents/tools/*), which is what actually reaches llama.cpp — packages/gateway-protocol/src/schema/cron.ts is the RPC validation contract and is never compiled into the model's grammar, so it's deliberately left untouched:

    • cron job.declarationKey: drops pattern: "\S" (both unanchored and PCRE shorthand).
    • cron trigger.script: drops maxLength: 65536 (past the ~2000 GBNF repetition ceiling), on both the job and patch branches.
    • Same-class offenders that also reach the grammar from other tools are swept too: spawn_task prompt/cwd (maxLength 32768/4096) and sessions_search query (maxLength 4096).

    No validation is weakened — the non-blank and length guarantees still hold server-side (cron gateway handler + RPC CronDeclarationKeySchema/CronTriggerSchema, the task-suggestions RPC schema, and the sessions_search runtime guard); the byte caps move into each field's description.

    There's a new generic regression test that walks the real tool schemas (raw and provider-normalized) and asserts every pattern is fully anchored with no PCRE shorthand and every maxLength stays under the repetition ceiling, so future model-facing tools in this family are covered as well. It fails on the pre-fix schemas with exactly the reported violations.

    (Note vs the other open PRs: #107939 and #108469 anchor the pattern but keep the \S shorthand, so they still hit the unknown-escape rejection; #108360 removes the declarationKey pattern only. None address the maxLength ceiling.)

  3. DecentralizedJM commented on Jul 16, 2026

    @DecentralizedJM
    Contributor

    Update on candidate fix: #108469 (head 8bad86f1dd4) now covers all three #108580 GBNF constraints on model-facing tool schemas, with live before/after llama-server proof in the PR body:

    • Broken unanchored \\S → HTTP 400 Pattern must start with '^' and end with '$'
    • Broken maxLength: 65536 → HTTP 400 grammar parse failure
    • Fixed PR schema → HTTP 200, inference proceeds

    Also sweeps spawn_task and sessions_search maxLength offenders. RPC validation in packages/gateway-protocol/ unchanged.

  4. 18 remaining items

  5. aidiffuser commented on Jul 22, 2026

    @aidiffuser
    Contributor

    Confirming this also affects LM Studio (not only raw llama.cpp) on 2026.7.1 stable. After cherry-picking #108360 we found a second grammar-hostile construct in the same schema, still present on main at the time of writing.

    1. pattern: "\S" (fixed by #108360) — fails schema-to-grammar conversion:

    Unable to generate parser for this template. Automatic parser generation failed:
    JSON schema conversion failed: Pattern must start with '^' and end with '$'
    

    2. trigger.script maxLength: 65536 (cron-tool.ts, exit-trigger feature — not yet fixed) — survives conversion but fails sampler initialization:

    Failed to initialize samplers: failed to parse grammar
    

    Isolation method, in case it is useful for triage: we binary-searched our live 73-tool request against LM Studio's /v1/chat/completions (max_tokens: 1 probes), which converged on the cron tool; a keep-one bisect inside that schema converged on job.trigger, whose children all pass individually; A/B probes on the field show maxLength: 65536 fails, 4096 fails, small values (200) pass, and removing maxLength passes. Large string-length bounds appear to expand into repetition rules that the grammar compiler rejects.

    Gateway-side symptom (difficult to connect to this root cause from the logs users see): agent/cron turns fail with a generic LLM request failed., [empty-error-retry] stopReason=error non-visible-output exhausts 3 attempts within milliseconds, and model-fetch logs show status=200 because the error only exists inside the SSE stream. The provider's own server log contains the real message.

    Suggested fix, following the same reasoning as #108360: remove maxLength from the model-facing schema; the CLI/server-side validator already enforces the size limit. We have been running that one-line change in production and all grammar-constrained cron runs are healthy.

    Since stable-channel users with grammar-constrained local engines currently experience silently failing agent turns, a 7.1.x backport of both fixes would be appreciated.

  6. added a commit that references this issue on Jul 22, 2026
    4d77eff
  7. zhidanliu-lab commented on Jul 23, 2026

    @zhidanliu-lab

    OpenClaw: 2026.7.2-beta2
    Working version: 2026.6.11

    Backend:
    llama.cpp master 61328e6a9

    Model:
    Qwen3.6-35B-A3B-UD-Q5_K_XL.gguf

    Repro:

    • Text chat works.
    • Enabling any tool fails.
    • llama.cpp returns:
      400 Failed to initialize samplers: failed to parse grammar
    • Downgrading only OpenClaw to 2026.6.11 fixes the problem immediately.
  8. self-assigned this
    on Jul 29, 2026
  9. steipete commented on Jul 29, 2026

    @steipete
    Contributor

    Fixed by #115598, merged in 98a066c.

    The pattern-related half landed earlier in #108360. #115598 completes the remaining llama.cpp GBNF compatibility fix by projecting tool schemas only for the affected provider family: llama-cpp, LM Studio, and Ollama now strip unsupported patterns and repetition-expanding maxLength constraints, while unrelated providers retain their full schemas.

    Proof: 204 focused tests passed, autoreview was clean, and the required exact-head CI gate succeeded before merge. This issue is complete.

  10. locked as resolved and limited conversation to collaborators on Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1High-priority user-facing bug, regression, or broken workflow.bugSomething isn't workingclawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.issue-rating: 🦪 silver shellfishThin issue quality; more reproduction proof or environment detail is needed.

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions