mirror of
https://github.com/open-webui/computer.git
synced 2026-11-05 01:17:24 +00:00
[GH-ISSUE #238] bug: Every new request invalidates the full context cache, causing llama.cpp to reprocess the entire context #151
Labels
No labels
enhancement
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
open-webui/computer#151
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @JKGeovision on GitHub (Aug 26, 2026).
Original GitHub issue: https://github.com/open-webui/computer/issues/238
Hello,
I noticed that every follow-up request in an ongoing chat appears to invalidate the complete context cache, forcing llama.cpp to reprocess the entire prompt from scratch even though the chat history is not modified.
Steps to reproduce:
Qwen3.8 27B (xhigh)proxied on port 45723).Instead of reusing the cached KV context and only processing the new tokens, the logs show the full prompt being reprocessed from the start on the follow-up request (the prompt is roughly 100k+ tokens based on the progress fractions, so the re-prefill penalty is substantial):
Expected behavior:
For consecutive requests within the same chat where the history is unchanged, the cached context should be preserved and only the newly added tokens should be processed.
Thanks in advance!
Joshua Krimmer
@owui-terminator[bot] commented on GitHub (Aug 26, 2026):
🔍 Related Issues Found
I found some existing issues that might be related. Please check if any of these are duplicates or contain helpful solutions:
🟢 #164 bug: problematic cache reuse
This issue reports that cache reuse is ineffective during multi-turn conversations and that the backend reprocesses most or all of the prompt at each turn, which matches the new report of full context cache invalidation on every follow-up request.
by cclecle
🟢 #142 bug: cptr stops incrementing context usage while llama.cpp reports differently
Although it focuses on a mismatch in reported context usage, it is about llama.cpp context growth during workloads and may point to related cache/context accounting behavior in the same integration path.
by JKGeovision
💡 If your issue is a duplicate, please close it and add any additional details to the existing issue instead.
This comment was generated automatically. React with 👍 if helpful, 👎 if not.
@JKGeovision commented on GitHub (Aug 27, 2026):
Problem
load_system_prompt()(cptr/utils/prompt_templates.py) re-renders the system prompt on every chat request, including a fresh two-level filesystem walk for{{FILE_TREE}}(_get_file_tree(), line ~46, used at line ~246). The rendered prompt is prepended as the firstsystemmessage on every API call (cptr/utils/ai.py:568–579).Any workspace change between turns therefore changes the very first tokens of the request. Providers with prefix/KV caching (llama.cpp server slot reuse, vLLM
--enable-prefix-caching,cache_prompt) key their cache on the token prefix, so a single changed line in the file tree invalidates all cached KV behind it — i.e. the entire conversation history is re-parsed every turn the agent touches a file.Measured (llama.cpp server, 27B model, ~11.5k token prompt):
f_sim_bestf_keepThe LCP break point is exactly at the file-tree section. The conversation history itself is already cache-stable (append-only); only the system prompt varies.
Other per-turn dynamic variables in the system prompt (secondary cache-breakers):
{{MEMORY}}: query-dependent recall (build_memory_prompt(),cptr/utils/memory.py:1298, fed bycurrent_message/recent_messages) → changes with every user message when memory is enabled.$skillmentions of the last user message are appended to the system prompt (cptr/utils/chat_task.py:1900–1926) → varies per turn.{{INSTRUCTIONS}}:AGENTS.md/MEMORY.md/… re-read per turn (changes when the agent edits them).{{DATE}}: available to custom templates; a template using it breaks the cache daily.Note: plan mode already documents this concern explicitly ("inject prompt as user message (not system, to preserve cache)",
chat_task.py:1930).Proposed fix
prompt_key(chat id) toload_system_prompt()and cache the dynamic blocks (FILE_TREE,INSTRUCTIONS,SKILLS) per(chat, workspace). Invalidate on new chat, compaction, or explicit refresh. The agent already haslist_directory/search_filesand sees file changes in tool results, so a slightly stale tree is acceptable — this matches how other agent harnesses handle it.chat.system_prompt.file_tree: session | request | none(defaultsession); custom templates keep{{FILE_TREE}}.system, following the existing plan-mode pattern.{{FILE_TREE}}fromDEFAULT_SYSTEM_PROMPT(keep the variable for custom templates).Verification
With llama.cpp server logging, a workspace change between turns should no longer drop
f_sim_bestbelow ~1.0 (expected: ~1.0 with < 50 freshly evaluated prompt tokens per turn); currently it drops to ~0.43, re-parsing the whole history (~15 s on a 27B model).@Classic298 commented on GitHub (Aug 27, 2026):
Cannot reproduce