Skip to content

Fix Finder / Troubleshooting

llama.cpp context length exceeded: check input and output budgets

If llama.cpp returns exceed_context_size_error, compare the rendered prompt with the context allocated to that request. Then reserve space for the output. Count the chat template, conversation history and tool definitions as part of the input.

Kingy retained a 518-token prompt that failed in a 512-token allocation. Increasing only the allocation to 2,048 preserved the full source and restored the three required facts. Use the example below to inspect the rejection and the budget arithmetic.

Check a context error locally

Free browser-local debugger

Why did my AI response fail?

Check an empty answer, context overflow, or a schema sent to the wrong endpoint. Inspect a proposed change, then verify it against your original task.

Pasted data stays in this tab. This debugger makes no API calls, executes no tools, and saves no inputs. Diagnosis does not prove a correction works on your setup.

Try a retained example or paste your own JSON below.

Up to 40,000 characters per box. Use the final assembled Chat Completions JSON body, not a streaming fragment, cURL command, or HTTP headers. Native /completion requests are supported for schema-envelope checks. Leave keys and account details out.

Context counts and local file import

Use measured runtime counts, including template, history and tools. This tool does not estimate tokens from character count or predict memory fit.

Loading local debugger…

Evidence and supported scope

Rules reuse the ten completed pilot repairs listed below. Model tests used pinned llama.cpp 0.6.0 b11429 and Qwen3-4B Q4_K_M on one Mac. The first four have separate-agent reruns on that Mac; the remaining six have same-agent repeats. No second-machine, human reproduction, or universal compatibility is claimed. Example previews replay retained data; they run no new model inference.

Malformed JSON, conflicting schemas and unsupported response shapes remain unresolved. A parseable response can still contain wrong facts. Schema-envelope proposals preserve the supplied schema; they do not establish general schema support.

Read the error counts before editing the prompt

The retained baseline returned HTTP 400:

{"error":{"code":400,"message":"request (518 tokens) exceeds the available context size (512 tokens), try increasing it","type":"exceed_context_size_error","n_prompt_tokens":518,"n_ctx":512}}

The error identified an input rejection before a useful answer was generated. The model's advertised context limit does not establish the allocation used by your running server or its slots. Record the actual launch settings and reported counts.

Include an output allowance

The retained repair 002 budget
Budget itemTokens
Complete rendered input518
Requested output allowance128
Combined input and output allowance646
Corrected context allocation2,048

The 2,048-token allocation was tested; a minimum allocation was not measured. The corrected answers used 36 completion tokens, but the requested 128-token allowance was retained. Arithmetic headroom does not establish memory fit or answer quality.

In the debugger, paste the response body and request JSON. If the response omits counts, enter measured rendered-prompt tokens and allocated context under the optional context controls. Conflicting reported and entered counts remain unresolved. The debugger does not estimate tokens from character count.

What changed in the tested repair

The server command changed from --ctx-size 512 to --ctx-size 2048. The entire 1,861-character source, rendered prompt and token sequence stayed the same. The corrected answers recovered ALPHA-17, BRAVO-42 and CHARLIE-93 from the beginning, middle and end.

All three corrected attempts passed for the author and for a separate agent rerunning the frozen package on the same Mac. Reverting the allocation restored the rejection. These repeats are not a reliability estimate for arbitrary documents.

Read the full context-overflow repair and original evidence.

Check memory and preserve the task

A larger allocation needs sufficient memory for the selected runtime, model and cache settings. This repair did not measure a general memory requirement. The separate Gemma KV-cache allocation case concerns different hardware and artifacts; it is not proof that your Qwen setup will fit.

If you shorten or summarize the source, record that as a changed task and check which facts were removed. For a direct reproduction of repair 002, keep the original input unchanged. After correction, require normal completion and validate the original expected values.

A successful request with finish_reason: length is a different condition: generation started and reached its output limit. Use the empty-response guide to inspect that path.

What this evidence covers

These model tests were qualified October 15–16, 2026, using llama.cpp 0.6.0 build 11429 and Qwen3-4B Q4_K_M on one M4 Pro Mac with 24 GiB unified memory. Repairs 001–004 have separate-agent reruns on that Mac. Repairs 005–010 have same-agent repeats in fresh server processes. No second-machine or human reproduction is claimed.

This guide reuses those retained results. Loading an example runs no model. The debugger performs local static checks and cannot verify a proposed correction on your setup. Each linked repair retains its exact artifacts, failed attempts and applicability limits.

Open the full Fix Finder debugger · Browse all tested repairs

Guide published October 16, 2026. Repair measurements remain dated October 15–16, 2026.