Overview
Gemma 4 12B tool calls work correctly via the Ollama backend but fail on the GGUF/llama.cpp path. The root cause is that `llama-cpp-sys-2 0.1.146` (released 2026-04-30) predates Gemma 4 12B (released 2026-06-03) and the bundled llama.cpp has known bugs in the `peg-gemma4` parser for 12B-scale tool call payloads.
Root Cause
The `peg-gemma4` streaming parser (llama.cpp PR #21326) enters an infinite repetition loop when the model generates large tool call JSON (issue #21375 upstream). For `create_schema` with full field definitions, 12B generates ~500+ tokens of JSON; the parser re-parses on every token and never exits the tool call block. EOS (`<turn|>`) fires mid-JSON, delivering truncated `{}` args to the tool executor.
Verified in the #1329 A/B trial on M4 Pro / 48GB:
- E4B GGUF: ✅ works (generates minimal 15-token args, closes cleanly)
- 12B GGUF (Unsloth): ❌ peg-gemma4 loop, EOS at token 544 with `brace_depth=3`
- 12B via Ollama: ✅ works (Ollama has its own template handling, uses non-streaming API)
Fix
When a new `llama-cpp-sys-2` release bundles llama.cpp with the upstream peg-gemma4 fixes (PRs #21375, #21697), bump the version constraint in `packages/nlp-engine/Cargo.toml` and re-run the `aichat-matrix.ts` scenario matrix against `gemma-4-12b-unsloth-q4km` to verify.
This is a passive wait — no code change needed on our side until the crate is updated.
Acceptance Criteria
Technical Specifications
Reference Files
Watch For
Related Issues
Overview
Gemma 4 12B tool calls work correctly via the Ollama backend but fail on the GGUF/llama.cpp path. The root cause is that `llama-cpp-sys-2 0.1.146` (released 2026-04-30) predates Gemma 4 12B (released 2026-06-03) and the bundled llama.cpp has known bugs in the `peg-gemma4` parser for 12B-scale tool call payloads.
Root Cause
The `peg-gemma4` streaming parser (llama.cpp PR #21326) enters an infinite repetition loop when the model generates large tool call JSON (issue #21375 upstream). For `create_schema` with full field definitions, 12B generates ~500+ tokens of JSON; the parser re-parses on every token and never exits the tool call block. EOS (`<turn|>`) fires mid-JSON, delivering truncated `{}` args to the tool executor.
Verified in the #1329 A/B trial on M4 Pro / 48GB:
Fix
When a new `llama-cpp-sys-2` release bundles llama.cpp with the upstream peg-gemma4 fixes (PRs #21375, #21697), bump the version constraint in `packages/nlp-engine/Cargo.toml` and re-run the `aichat-matrix.ts` scenario matrix against `gemma-4-12b-unsloth-q4km` to verify.
This is a passive wait — no code change needed on our side until the crate is updated.
Acceptance Criteria
Technical Specifications
Reference Files
Watch For
Related Issues