You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Studio: repeated full prompt processing across turns with Qwen hybrid model after tool use #17015
Unsloth Desktop 0.1.916-beta; local Qwen3.8 27B GGUF; llama-server; 65,536-token context; reasoning enabled. A large Model Context Protocol (MCP) tool catalog was enabled. The installed ToolLoopController includes the deferred-schema prefix-preservation change associated with #16546.
Observed behaviour
In a synthetic test chat, an initial request used a local Python tool and checked its job status. A follow-up asked for a short explanation without using tools. The server found that the new request shared approximately 2,031 tokens with the preceding 7,708-token prompt, but all available recurrent-state checkpoints started after that shared prefix. It logged forcing full prompt re-processing due to lack of cache data and evaluated all 7,662 prompt tokens in 27.23 seconds. A subsequent similar follow-up reused approximately 7,913 tokens and evaluated 30 new tokens in 0.56 seconds.
A separate preceding turn also required a full evaluation of 6,528 tokens in 22.68 seconds. In contrast, intermediate tool-loop requests reused most of the prompt. These are individual observations, not a benchmark or proof that every turn is affected.
Potential cause to investigate
The local _mcp_listing implementation can replace the up-front ranked tool schemas when the user request changes, and can reorder tools recorded as executed. An isolated test of that function with a synthetic catalog confirmed that changing the ranking can change the initial tool list. Such changes may invalidate an early prompt prefix. The exact source of the prefix change in the observed live request has not been established, so other causes remain possible.
Could the maintainers investigate cache stability across turns after tool use, including interaction between per-turn tool ranking and recurrent-state checkpoint placement? A solution should preserve tool discovery and forced/image tool handling. Related: #16538 and #16546.
No conversation content, local paths, credentials or personal data are included.
Additional controlled synthetic test on the same local model and server: three requests shared the same long message prefix and two tool definitions. The first used tool order A,B; the second used B,A; the third kept B,A. Only the short final question and, in the second request, tool order changed. Each prompt contained 9,397 tokens.
Initial A,B: 0 cached tokens, 31.78 s.
Changed to B,A: 0 cached tokens, 32.28 s.
Kept B,A: 9,381 cached tokens, 0.44 s.
This demonstrates that changing the order of these tool definitions can cause full reprocessing on this setup, while the stable order reused nearly all of the prompt. It does not by itself prove that ranking caused the earlier Studio UI cache miss. The requests contained only artificial text and example tools.
Further synthetic testing found a related checkpoint limitation. In one Studio follow-up, the engine reported a shared prefix of approximately 1,468 tokens, but the earliest available checkpoint was at approximately 3,914 tokens, so all 7,257 tokens were reprocessed in 25.6 seconds. A later similar follow-up reused approximately 7,285 tokens and processed the remaining 34 in 0.56 seconds. A local schema-ordering experiment was active during this observation; the exact reason the prefix changed remains unconfirmed.
In an isolated experiment using artificial prompts, a test build that allowed periodic checkpoints reused 1,024 tokens with a 1,024-token batch and reduced a follow-up from 24.38 to 21.57 seconds. With a 2,048-token batch, neither the original nor test build reused a checkpoint in that case (24.65 vs 24.75 seconds). These are single observations, not a proposed fix or general benchmark. This suggests that checkpoint placement and batch size are worth considering alongside schema stability, while preserving correct tool discovery.
No private conversations, file paths, credentials or personal information are included.
Additional local selection simulation: using the current Studio listing function and tool schemas, with an artificial sequence of two similar tool requests followed by a non-tool question, the first two simulated listings contained the same six entries. The third contained eight entries: four were added and two removed. The tool search entry remained available. The ordering experiment mentioned above was enabled.
This simulation used estimated token costs and simulated previously used tools; it is not a capture of a Studio request and does not prove that this was the cause of the live cache miss. It does show that stabilizing order alone does not keep membership stable when the ranked request changes. No personal data, conversations, paths, or tool descriptions are included.
It has merged and is awaiting a desktop release. Adding or removing tools from the list can still cause the prompt to be processed again. Please try it once released and let us know whether it helps with the repeated prompt processing.
Retested with the updated Studio code containing #17326, using the same local Qwen3.8 27B model and an artificial chat. With MCP enabled and no tool calls, changing a short question's wording to include document-related terms caused a full prompt reprocess: 5,174 tokens in 17.85 seconds. With the four MCP servers deselected for this chat, a baseline request was processed first; the same wording change on the following turn reused 2,579 tokens and processed 35 new tokens in 0.53 seconds. MCP was restored afterwards.
These are single observations in a growing chat, not a controlled benchmark or proof of which part of the prompt changed. Skills and search remained enabled. They suggest the per-turn MCP listing is worth investigating even when the model does not call a tool. No personal conversations, paths, credentials, or private data are included.
Additional follow-up on the artificial chat above: with three of the same four MCP servers enabled and the fourth deselected, a baseline question was sent, followed by the same question with document-related words added. The follow-up reused 5,136 tokens and evaluated 35 new tokens in 0.55 s. After re-enabling the fourth server and sending a baseline question, the same follow-up evaluated all 5,735 prompt tokens in 20.07 s. No tool calls were requested or made in these tests, and skills and search remained enabled.
This A–B–A sequence supports an interaction with the selected MCP catalog, but chat history grew between runs and the actual tool-list changes were not captured. It does not establish that any particular server is defective. No private content, tool descriptions, local paths, or credentials are included.
I reproduced the between-turn cache miss on e6cfd30fd3. With the same chat history and the same follow-up question, changing only the advertised MCP schemas took prompt processing from 199 ms to 4.07 s.
I used Studio’s GGUF request tool selector and token counter, then replayed the resulting requests directly against a local Unsloth llama-server (b12347-mix-241a0f3). I ran Qwen3.8-27B Q4_K_M on an RTX 3090 24 GB with a 65,536-token context and one slot. Four synthetic read-only MCP servers exposed 24 tools each. I erased the slot before each pair, replayed the warm turn, and varied the order across three runs. Counts were identical in all three runs. Times below are median server prompt-processing times.
Follow-up after “What weekday comes after Monday?”
Cached tokens
Tokens evaluated
Prefill
“What comes after Friday? Answer in one word.”
5,883
30
198 ms
“For a document title, what comes after Friday? Answer in one word.”
0
6,015
4,066 ms
Same document-title question, replaying the warm turn’s tool list
5,883
35
199 ms
Same document-title question, with the library server disabled for both turns
11,026
35
200 ms
The wording replaced the four previously listed weekday tools with five library tools. The rendered prompts then diverged at token 1,966. llama-server checked its recurrent checkpoints at 5,882, 5,865, 5,370 and 2,555. All were too late, so it reprocessed the entire prompt. Keeping the list fixed let it restore the checkpoint containing 5,883 tokens. With three servers, all 72 tools fit Studio’s listing budget and the declarations stayed identical. The timed requests had a two-token output cap and made no tool calls.
There is a discovery tradeoff. In a separate greedy decode asking for the title of a document named Winter Notes, the current listing let the model request the library lookup directly. With the old listing it first called mcp_tool_search, then requested the correct document. I’d keep both the incidental-word case and the genuine lookup as regression cases for a follow-up to #17326. This reproduces the mechanism with a synthetic catalog. The reporter’s exact four-server catalog was unavailable.
Hello, thank you for the very clean tests. The divergence at token 1,966 with checkpoints only at 5,882, 5,865, 5,370 and 2,555 shows the problem well.
On a hybrid model like Qwen3.8 27B, llama-server can only go back to a recurrent checkpoint that sits before the first changed token. The ranked MCP listing is near the top of the prompt, so any change in which tools are listed lands before every checkpoint and the whole chat is processed again. More checkpoints (--ctx-checkpoints, or a smaller --checkpoint-min-step) only save the small part before token 1,966, so the real fix has to keep the head stable, like #17326 did for the order.
One idea between the current default and the UNSLOTH_STUDIO_MCP_SEARCH_ONLY=1 switch in #18142: make the listing sticky per chat. Keep the ranked list from the first turn, and when a later message needs a tool that is not listed, deliver its schema inside the mcp_tool_search result (the way #16539 does) instead of adding it to the declared tools. Small models still get good preloaded tools on turn 1, and after that the prompt only grows at the end. The incidental word case and the "Winter Notes" lookup from @0xalkinun would be good regression tests for it.
One case stays even with a stable head: when Studio reloads the model or the app restarts, the slot is empty and the full chat is processed again. For that step on NVIDIA GPUs, Galahad is long term memory that saves and restores the KV cache byte for byte across restarts. Restore was 2.8 to 4.3x faster than recompute in our tests, with 262,144/262,144 logits bit identical. https://github.com/corbenicai/galahad
Activity
jwminer commentedon Nov 7, 2026
Additional controlled synthetic test on the same local model and server: three requests shared the same long message prefix and two tool definitions. The first used tool order A,B; the second used B,A; the third kept B,A. Only the short final question and, in the second request, tool order changed. Each prompt contained 9,397 tokens.
This demonstrates that changing the order of these tool definitions can cause full reprocessing on this setup, while the stable order reused nearly all of the prompt. It does not by itself prove that ranking caused the earlier Studio UI cache miss. The requests contained only artificial text and example tools.
jwminer commentedon Nov 7, 2026
Further synthetic testing found a related checkpoint limitation. In one Studio follow-up, the engine reported a shared prefix of approximately 1,468 tokens, but the earliest available checkpoint was at approximately 3,914 tokens, so all 7,257 tokens were reprocessed in 25.6 seconds. A later similar follow-up reused approximately 7,285 tokens and processed the remaining 34 in 0.56 seconds. A local schema-ordering experiment was active during this observation; the exact reason the prefix changed remains unconfirmed.
In an isolated experiment using artificial prompts, a test build that allowed periodic checkpoints reused 1,024 tokens with a 1,024-token batch and reduced a follow-up from 24.38 to 21.57 seconds. With a 2,048-token batch, neither the original nor test build reused a checkpoint in that case (24.65 vs 24.75 seconds). These are single observations, not a proposed fix or general benchmark. This suggests that checkpoint placement and batch size are worth considering alongside schema stability, while preserving correct tool discovery.
No private conversations, file paths, credentials or personal information are included.
jwminer commentedon Nov 7, 2026
Additional local selection simulation: using the current Studio listing function and tool schemas, with an artificial sequence of two similar tool requests followed by a non-tool question, the first two simulated listings contained the same six entries. The third contained eight entries: four were added and two removed. The tool search entry remained available. The ordering experiment mentioned above was enabled.
This simulation used estimated token costs and simulated previously used tools; it is not a capture of a Studio request and does not prove that this was the cause of the live cache miss. It does show that stabilizing order alone does not keep membership stable when the ranked request changes. No personal data, conversations, paths, or tool descriptions are included.
Studio: keep deferred MCP tools in place when a listed tool runs again (
oobabooga commentedon Nov 11, 2026
Thanks for your detailed report. The PR below keeps already-listed MCP tools in the same order when they run again.
#17326
It has merged and is awaiting a desktop release. Adding or removing tools from the list can still cause the prompt to be processed again. Please try it once released and let us know whether it helps with the repeated prompt processing.
jwminer commentedon Nov 12, 2026
Retested with the updated Studio code containing #17326, using the same local Qwen3.8 27B model and an artificial chat. With MCP enabled and no tool calls, changing a short question's wording to include document-related terms caused a full prompt reprocess: 5,174 tokens in 17.85 seconds. With the four MCP servers deselected for this chat, a baseline request was processed first; the same wording change on the following turn reused 2,579 tokens and processed 35 new tokens in 0.53 seconds. MCP was restored afterwards.
These are single observations in a growing chat, not a controlled benchmark or proof of which part of the prompt changed. Skills and search remained enabled. They suggest the per-turn MCP listing is worth investigating even when the model does not call a tool. No personal conversations, paths, credentials, or private data are included.
jwminer commentedon Nov 12, 2026
Additional follow-up on the artificial chat above: with three of the same four MCP servers enabled and the fourth deselected, a baseline question was sent, followed by the same question with document-related words added. The follow-up reused 5,136 tokens and evaluated 35 new tokens in 0.55 s. After re-enabling the fourth server and sending a baseline question, the same follow-up evaluated all 5,735 prompt tokens in 20.07 s. No tool calls were requested or made in these tests, and skills and search remained enabled.
This A–B–A sequence supports an interaction with the selected MCP catalog, but chat history grew between runs and the actual tool-list changes were not captured. It does not establish that any particular server is defective. No private content, tool descriptions, local paths, or credentials are included.
0xalkinun commentedon Nov 17, 2026
I reproduced the between-turn cache miss on
e6cfd30fd3. With the same chat history and the same follow-up question, changing only the advertised MCP schemas took prompt processing from 199 ms to 4.07 s.I used Studio’s GGUF request tool selector and token counter, then replayed the resulting requests directly against a local Unsloth llama-server (
b12347-mix-241a0f3). I ran Qwen3.8-27B Q4_K_M on an RTX 3090 24 GB with a 65,536-token context and one slot. Four synthetic read-only MCP servers exposed 24 tools each. I erased the slot before each pair, replayed the warm turn, and varied the order across three runs. Counts were identical in all three runs. Times below are median server prompt-processing times.The wording replaced the four previously listed weekday tools with five library tools. The rendered prompts then diverged at token 1,966. llama-server checked its recurrent checkpoints at 5,882, 5,865, 5,370 and 2,555. All were too late, so it reprocessed the entire prompt. Keeping the list fixed let it restore the checkpoint containing 5,883 tokens. With three servers, all 72 tools fit Studio’s listing budget and the declarations stayed identical. The timed requests had a two-token output cap and made no tool calls.
There is a discovery tradeoff. In a separate greedy decode asking for the title of a document named Winter Notes, the current listing let the model request the library lookup directly. With the old listing it first called
mcp_tool_search, then requested the correct document. I’d keep both the incidental-word case and the genuine lookup as regression cases for a follow-up to #17326. This reproduces the mechanism with a synthetic catalog. The reporter’s exact four-server catalog was unavailable.corbenicai commentedon Nov 19, 2026
Hello, thank you for the very clean tests. The divergence at token 1,966 with checkpoints only at 5,882, 5,865, 5,370 and 2,555 shows the problem well.
On a hybrid model like Qwen3.8 27B, llama-server can only go back to a recurrent checkpoint that sits before the first changed token. The ranked MCP listing is near the top of the prompt, so any change in which tools are listed lands before every checkpoint and the whole chat is processed again. More checkpoints (
--ctx-checkpoints, or a smaller--checkpoint-min-step) only save the small part before token 1,966, so the real fix has to keep the head stable, like #17326 did for the order.One idea between the current default and the
UNSLOTH_STUDIO_MCP_SEARCH_ONLY=1switch in #18142: make the listing sticky per chat. Keep the ranked list from the first turn, and when a later message needs a tool that is not listed, deliver its schema inside themcp_tool_searchresult (the way #16539 does) instead of adding it to the declared tools. Small models still get good preloaded tools on turn 1, and after that the prompt only grows at the end. The incidental word case and the "Winter Notes" lookup from @0xalkinun would be good regression tests for it.One case stays even with a stable head: when Studio reloads the model or the app restarts, the slot is empty and the full chat is processed again. For that step on NVIDIA GPUs, Galahad is long term memory that saves and restores the KV cache byte for byte across restarts. Restore was 2.8 to 4.3x faster than recompute in our tests, with 262,144/262,144 logits bit identical. https://github.com/corbenicai/galahad
Studio: add search-only MCP listings for cache-sensitive local chats (#…
Studio: keep the MCP tool list fixed per chat and add each message's …