A local coding agent decides when to compact from its own idea of the context window. The server decides when to stop from the context it actually loaded. When the two numbers differ, the agent fills the server, replies get cut off ("Response truncated due to token limits"), and compaction never starts. Enter both numbers to see which one breaks first.
compaction point = the agent's rule applied to the window it assumes Qwen Code: min(0.85 x window, window - 20,000 - 13,000) (0.85 x window when that is <= 0) Pi: window - 16,384 other: 0.85 x window compacts in time = compaction point < server context reply room = server context - compaction point conversation room = compaction point (or server context) - fixed prompt
:27b from the model name, then maps any qwen3.x name to a 1,000,000-token window and a 64,000-token reply (packages/core/src/core/tokenLimits.ts). The compaction ladder is computeThresholds() in packages/core/src/services/chatCompressionService.ts; the 0.85 is context.autoCompactThreshold. QwenLM/qwen-code main 16151b03cb, read 2026-11-15.contextTokens > contextWindow - reserveTokens, with reserveTokens 16,384 (packages/coding-agent/docs/compaction.md); contextWindow is 128,000 when models.json leaves it out. At 128,000 that is 111,616 tokens. earendil-works/pi main 22fc026b87, read 2026-11-15.finish_reason: "length"; a prompt that is already too long gets "request (N tokens) exceeds the available context size" (tools/server/server-context.cpp, llama.cpp master 9fba51d2c9, read 2026-11-15). Ollama either rejects a too-long prompt or drops tokens from the middle and logs "truncating input prompt" (llm/llama_server.go, ollama main 15af2b261c).| Qwen Code setting | Server | Compacts at | Reply room then | Result |
|---|---|---|---|---|
| No contextWindowSize | 32K | 850,000 | none | Server fills first |
| contextWindowSize 32,768 | 32K | 27,852 | 4,916 | Replies get cut |
| contextWindowSize 65,536 | 64K | 32,536 | 33,000 | Works |
prompt eval time = … / N tokens. N is the system prompt, the tool definitions and your message.prompt_eval_count in the response.Qwen Code prints it when the server ends a reply with finish_reason "length" (packages/core/src/core/openaiContentGenerator/converter.ts maps "length" to MAX_TOKENS). The reply hit a cap: the max_tokens limit, or the server's context filled up while the model was still writing. llama-server stops a reply when prompt plus reply reaches its context size and reports "length". A thinking model spends its reasoning tokens from the same room, so a long think on a nearly full context ends this way.
Because Qwen Code does not read the server's context. For an Ollama tag such as qwen3.6:27b it looks the name up in its own table and plans for 1,000,000 tokens, so it compacts at 850,000 tokens. A 32K server fills long before that. Set contextWindowSize in the model's generationConfig to the server's real context, so compaction starts in time.
At least 64K. Ollama's own docs say coding tools "should be set to at least 64000 tokens". With Qwen Code and contextWindowSize set to 65,536, compaction starts at 32,536 tokens and leaves 33,000 tokens for a reply, enough for the 32,768 the Qwen3.6 card recommends. At 32K the same setup leaves 4,916 tokens.
It depends on VRAM: under 24 GiB it is 4K, 24 to 48 GiB gives 32K, and 48 GiB or more gives 256K (docs/context-length.mdx). The FAQ page still says 4096, but the server code (envconfig/config.go) follows the VRAM rule. Check the CONTEXT column of ollama ps to see what you got.
Restart the server, start the agent, and send one short message. On llama-server, read the "prompt eval time = ... / N tokens" log line; N is the fixed prompt plus your message. On Ollama's native API the same number is prompt_eval_count. Take the first request only: later requests reuse the cached prefix and show fewer tokens.