Repository navigation
Studio: add search-only MCP listings for cache-sensitive local chats - #18142
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
LeoBorcherding
left a comment
There was a problem hiding this comment.
Tested at 842146f on a MacBook Pro M5 (macOS 26, llama.cpp Metal), gemma-4-12b Q4_K_XL at 16K context, a 96-tool stdio MCP server. Same branch with the flag off vs on.
The cache win reproduces. On a follow-up that names new topics, the default reprocessed 484 tokens (4.9 s) because the preloaded tools changed; search-only reprocessed 44 (1.4 s). One run each.
| Follow-up turn | Flag off (default) | UNSLOTH_STUDIO_MCP_SEARCH_ONLY=1 |
|---|---|---|
| Tokens reused from cache | 3,511 of 3,995 | 3,510 of 3,554 |
| Tokens reprocessed | 484 | 44 |
| Prompt eval time | 4.9 s | 1.4 s |
The tradeoff the docs mention showed up on a mid-size model. Asked for the title of doc-42, the default called get_document_title directly and answered. With the flag on, gemma-4-12b ran mcp_tool_search 8+ times and never called the loaded tool, so I stopped it. Since the flag is opt-in and the default is unchanged, I don't think this blocks the PR, but the MCP.md note could name what it was verified on (Qwen3.8-27B in your run) and that gemma-4-12b looped, so "smaller models" doesn't read as only tiny ones.
Code: the early return keeps the search tool and pinned tools and skips the held-tool bookkeeping, which is right for this mode. 170/170 MCP server tests pass locally, and the new stability test fails on main's tools.py.
CI: the one red shard (m-r) is two NPU tests in test_multi_model_serving.py that also fail on the main commit this branch merged (ad003cd), fixed on main by #18197; nothing in this diff touches them.
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
#18324) ## Multi-LoRA packing: load the num_proc policy without importing unsloth `studio/backend/tests/test_dataset_map_num_proc.py::test_the_batched_packing_pool_asks_the_same_veto` fails in `(Python 3.13, a-f)` on every PR since #17701, for example #18015, #18108, #18142 and #18303: ``` core/training/multi_lora_trainer.py:686: in _pack_num_proc from unsloth_zoo.dataset_num_proc import get_dataset_num_proc E ModuleNotFoundError: No module named 'unsloth_zoo' core/training/multi_lora_trainer.py:688: in _pack_num_proc from unsloth.dataset_num_proc import get_dataset_num_proc unsloth/_gpu_init.py:241: in <module> E ImportError: Unsloth: Please install unsloth_zoo via `pip install unsloth_zoo` then retry! ``` ### Cause `_pack_num_proc`, the multi-LoRA packing pool's worker count from #15733, looks up the shared `dataset_num_proc` policy in two steps: 1. it imports `unsloth_zoo`; 2. if that fails, it falls back to `from unsloth.dataset_num_proc import ...`. That fallback runs the whole `unsloth` package `__init__`, which needs `unsloth_zoo` anyway and patches torch on the way. The rest of the backend already avoids this. `utils.hardware.hardware._shared_policy()` tries `unsloth_zoo` first and otherwise loads the stdlib-only `dataset_num_proc.py` straight off disk, precisely so that no caller runs `import unsloth`. #17701 added the first test that reaches `_pack_num_proc`, and the backend shard runs without `unsloth_zoo`, so the fallback fails there. ### Fix `_pack_num_proc` now gets the policy from `_shared_policy()`, the same loader the single-job tokenize pool uses. - **With a policy**, which is every real install: the call is unchanged, `get_dataset_num_proc(count)` on the same module. - **With no policy at all:** it keeps that function's contract, so a serial count of 1 still means `None`. ### Verification - Faithful repro of the CI state: `core.training.trainer` already imported, then `unsloth_zoo` made unimportable, then `_pack_num_proc` called with a tight host-memory snapshot. - `main`: `ModuleNotFoundError: No module named 'unsloth_zoo'`. - This PR: returns `None`, as the test expects. - With `unsloth_zoo` installed: `tests/test_dataset_map_num_proc.py` and the multi-LoRA tests pass (88 passed). - ruff is clean.
…h_zoo (main regression blocking this PR's CI)
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…env-only and needs exactly 1
|
Pushed two small follow-ups to this branch, neither worth blocking the merge on:
No behavior change. |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
# Conflicts: # tests/studio/test_model_picker_contracts.py
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
# Conflicts: # studio/backend/tests/test_dataset_map_num_proc.py
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |




What changes
Long local chats with an oversized MCP catalog can lose their cached prefix when a follow-up mentions a new topic. Studio can then spend seconds reprocessing the conversation before it answers.
Set
UNSLOTH_STUDIO_MCP_SEARCH_ONLY=1to keep the up-front MCP listing stable across changes in wording and past tool use. The model getsmcp_tool_search, any explicitly forced tool, and the tools mapped to an attached image. The switch applies after Studio decides the full catalog is too large. Ranked preloading remains the default because smaller models may struggle to discover tools on their own.Refs #17015. Earlier controlled reproduction.
Verification
I replayed a fixed synthetic conversation through Studio's GGUF tool selector and a dedicated llama-server slot on an RTX 3090, with Qwen3.8-27B Q4_K_M, a 65,536-token context and 96 MCP tools. Each pair started with an empty slot. The follow-up mentioned a document title without asking for a lookup.
For a separate request that explicitly asked for a lookup, both modes fetched the correct title from a loopback MCP server. The default called a library tool directly. Search-only made two catalog searches before calling the library tool. The timing above covers prompt processing on the incidental follow-up.
The new regression test fails on the base revision. All 170 MCP server tests and 14 related GGUF and safetensors tool-loop tests pass on the change. Coverage includes a catalog that fits the window, an explicit tool choice, a mapped image, and the next turn after a tool executes.