Skip to content

Upgrade llama-cpp-sys-2 when Gemma 4 12B peg-gemma4 parser fixes land upstream #1348

Description

@malibio

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

  • `llama-cpp-sys-2` releases a version bundling llama.cpp with peg-gemma4 loop fix
  • Bump version in `packages/nlp-engine/Cargo.toml`
  • Re-run `aichat-matrix.ts 12b-gguf` — `create_schema` executes with full field definitions without truncation
  • E4B GGUF behavior unchanged

Technical Specifications

Reference Files

Watch For

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions