Developer Tools

llama.cpp b9870 fixes long reasoning loops in StepFun parser

Trimming whitespace before rendering prevents infinite loops in reasoning models.

Deep Dive

llama.cpp, the popular C++ library for running large language models locally, just dropped version b9870. This release patches a critical bug in the StepFun parser that caused long reasoning loops during chat inference. The issue arose when typed content parts (e.g., text and reasoning tokens) were rendered into a single string before whitespace trimming occurred. Since trimming only ran on the concatenated result, per-part whitespace could no longer be stripped, leading to runaway token generation.

The fix, contributed by tarruda and Piotr Wilkin, moves the trim operation ahead of rendering and applies it to both the string content and the `reasoning_content` fields. This ensures that whitespace around reasoning steps is properly cleaned, preventing infinite loops in models that rely on StepFun-style templates. The release also includes a regression test to prevent future breaks. Available across Linux, Windows, macOS, iOS, and Android (CPU, Vulkan, CUDA, ROCm, OpenVINO, SYCL), this update is essential for developers running reasoning-enhanced LLMs locally.

Key Points
  • Fixes long reasoning loops in the StepFun parser by trimming whitespace before rendering
  • Moves trimming to apply to individual content parts, not just the concatenated string
  • Includes a regression test and contributions from multiple developers (tarruda, Piotr Wilkin, assisted by Claude Fable 5)

Why It Matters

This update stabilizes local LLM inference for reasoning models, preventing crashes and loops during chain-of-thought generation.

📬 Get the top 10 AI stories daily