Repository navigation
Description
Environment
Where are you using Unsloth?
- Unsloth desktop application
- Unsloth web UI (
unsloth studio) - Unsloth CLI
- Python package or notebook
- Colab or Kaggle
Operating system and version:
Windows 11
GPU model(s) and accelerator backend:
AMD ROCm
Versions:
Unsloth Desktop: v0.1.919-beta
llama.cpp: b12347-mix-241a0f3
What happened?
Steps to reproduce:
- Fresh chat, local GGUF vision model loaded, computer use enabled.
- Ask the model to interact with the desktop (click / open apps / type) so it chains ~10
computercalls. - Watch prompt processing time per tool result: fast for the first ~7-8 calls, then jumps to 10-30 s on every new tool result and keeps growing with conversation length.
Expected behavior:
The KV cache stays warm (append-only) across computer use calls, so each tool result is processed quickly.
Actual behavior:
After ~6-7 calls to the computer tool (each returning a screenshot), the KV cache is repeatedly invalidated: prompt processing jumps from ~2 s to 10-30 s on every new tool result, and keeps growing with conversation length. A manually pasted image does not trigger this behavior — only screenshots returned by the computer tool cause the invalidation.
Model and operation involved:
Qwen3.8-27B-GGUF, inference (computer use / tool calling).
Diagnostics and logs
No crash or error log applies — this is a performance issue (prompt-eval time), not a failure. The relevant evidence is in Additional context below.
Additional context
Root cause (my analysis)
After investigating the source code, this is not a classic bug but an arbitrary limitation:
File: studio/backend/core/inference/mcp_images.py
Constant: MAX_TOTAL_MODEL_IMAGES = 8
Link: https://github.com/unslothai/unsloth/blob/main/studio/backend/core/inference/mcp_images.py#L25
This constant sets a budget of 8 images in the prompt. In my analysis, as long as the conversation holds ≤ 8 screenshots, the prompt is append-only and the prefix cache works. Beyond that, older screenshots are removed to make room, which breaks the prefix and forces an invalidation on every new call.
Local confirmation
By changing:
MAX_TOTAL_MODEL_IMAGES = 8
to:
MAX_TOTAL_MODEL_IMAGES = 30
then restarting the app, the invalidation disappears: my agent was able to complete all its multi-step tasks without any invalidation. The cliff moves from ~8 to ~30 calls.
Proposal
Increase the default value (30, 50, or more).
I am aware that a larger value can fill the KV cache faster. But a KV cache filling up gradually is much more readable and easier to understand than a mandatory re-prefill every turn. This solution is not ideal nor definitive, but it makes computer use usable for multi-step tasks.
I do not know if changing this value has other implications.
Related issue (not investigated)
Another invalidation case exists during computer use: when the LLM finishes its task, or when the user sends a message or cuts off the LLM's response, this invalidates the KV cache. I have not dug into the origin of this behavior and am leaving it out of scope here.
Activity
A-P-Shukla commentedon Nov 18, 2026
Traced the full flow across frontend and backend , this explains both why bumping only
mcp_images.pymoved your single-task cliff and why you hit the second invalidation when a task ends or you send a new message:Two separate caps at two stages:
generate_chat_completion_with_tools→execute_computer_tool): The backend executes thecomputerchain server-side and trims screenshots usingMAX_TOTAL_MODEL_IMAGES = 8inmcp_images.py. Raising only that Python constant moves the cliff within one uninterrupted chain.boundMcpImageResultsonrawMessageswith its ownMAX_TOTAL_MCP_IMAGES = 8, pruning older screenshots back to 8 and breaking the KV prefix again as soon as you send another message or retry.Why a flat bump (
8 -> 30) isn't a real fix: A 1-in-1-out sliding window still invalidates the prefix on every step once you cross the cap, and 30–50 screenshots will OOM smaller GPUs or hit the 12 MB payload limit. Hysteresis / batch trimming (e.g., when hitting the cap, drop the oldest 4 at once so the next 4 turns remain strictly append-only) plus keeping the frontend and backend limits synced fixes the per-turn thrashing without raising peak VRAM.@danielhanchen Happy to put up a PR with tests if you want hysteresis trimming or a configurable synced cap here.
danielhanchen commentedon Nov 18, 2026
Fixed! Past 8 screenshots Studio dropped the oldest one on every computer call, and since that screenshot sits near the start of the chat, llama-server had to re-read almost the whole conversation each time. Fixed in #18256: with auto-compact on (the default) screenshots are no longer dropped, so each call only appends and the prompt cache stays warm until the context window fills, at which point the normal compaction takes over. With auto-compact off, old screenshots are now dropped 4 at a time, so 3 of every 4 calls stay cached. Thanks for the detailed analysis!
To update: Unsloth Desktop will have an update banner. For Studio, use
unsloth studio update. For Docker, usedocker exec <container> unsloth-studio-update. Reopen if it still happens.Studio: keep tool screenshots in compacting GGUF chats so the prompt …
Merge main into feat/computer-use-image-budget