Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: keep checkpoint compaction under --disable-tools (#12119)
Daniel Han9290d18ad3da
diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.pyindex 02e4f9a800e..815cf0bb1e9 100644--- a/studio/backend/core/inference/llama_cpp.py+++ b/studio/backend/core/inference/llama_cpp.py@@ -203,13 +203,11 @@ def _can_reset_epoch(# carried-forward header tells the model to search. Same refusal, one scope down.return Falsetry:- from state.tool_policy import get_tool_policy+ from state.tool_policy import conversation_recall_allowed- # `supports_tools` is the TEMPLATE's capability, not "will this request be given- # the tool". `--disable-tools` refuses every tool for the life of the process, so- # resetting would strand the epoch behind a tool that never arrives. Rolling keeps- # the newest turns in view and re-injects the inline recall, needing no tool.- if get_tool_policy() is False:+ # `supports_tools` is the TEMPLATE's capability; where recall is refused a reset would+ # strand the epoch behind a tool that never arrives, and rolling needs no tool.+ if not conversation_recall_allowed():return Falseexcept Exception: # noqa: BLE001 -- an unreadable policy is "no", never an errorreturn Falsediff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.pyindex a9de136bca0..0514be2f75e 100644--- a/studio/backend/routes/inference.py+++ b/studio/backend/routes/inference.py@@ -5916,8 +5916,11 @@ async def _select_request_tools(if getattr(payload, "deep_research_armed", None):# Appended past every filter above, including the tools_on gate: arming research in the# composer is what offers this tool, and it is the only way the model can start a run.+ # Not under `--disable-tools`, where the loop can open only for search_conversation.from core.inference.tools import DEEP_RESEARCH_TOOL- tools = tools + [DEEP_RESEARCH_TOOL]+ from state.tool_policy import get_tool_policy+ if get_tool_policy() is not False:+ tools = tools + [DEEP_RESEARCH_TOOL]return tools@@ -5984,10 +5987,10 @@ def _checkpoint_needs_search(payload = None) -> bool:def _checkpoint_recall_may_enable_tools(payload) -> bool:- """Whether checkpoint recovery can force the internal recall tool loop."""- from state.tool_policy import get_tool_policy+ """Whether checkpoint recovery can force the internal recall tool loop (also under --disable-tools)."""+ from state.tool_policy import conversation_recall_allowedreturn bool(- get_tool_policy() is not False+ conversation_recall_allowed()and _rolling_context_policy(payload) is not Noneand _checkpoint_needs_search(payload)and _thread_has_conversation_archive(getattr(payload, "thread_id", None))diff --git a/studio/backend/routes/preview.py b/studio/backend/routes/preview.pyindex 719756e696e..7153ba2e438 100644--- a/studio/backend/routes/preview.py+++ b/studio/backend/routes/preview.py@@ -128,6 +128,8 @@ def _sanitize_preview_payload("bypass_permissions": False,"confirm_tool_calls": False,"session_id": None,+ # A streamed body outlives tools_force_disabled(), so no thread archive may be reachable.+ "thread_id": None,"rag_scope": None,"openai_code_exec_container_id": None,"anthropic_code_exec_container_id": None,diff --git a/studio/backend/state/tool_policy.py b/studio/backend/state/tool_policy.pyindex 0938a11f71e..18f475b9949 100644--- a/studio/backend/state/tool_policy.py+++ b/studio/backend/state/tool_policy.py@@ -100,6 +100,11 @@ def get_tool_policy_default() -> Optional[bool]:return _tool_policy_default+def conversation_recall_allowed() -> bool:+ """Recall reads only this thread's archive: `--disable-tools` keeps it, `tools_force_disabled` does not."""+ return not _force_disabled.get()++@contextmanagerdef tools_force_disabled() -> Iterator[None]:"""Hard-disable server-side tools for the current async context."""diff --git a/studio/backend/tests/data/refactor_guard/patch_targets.json b/studio/backend/tests/data/refactor_guard/patch_targets.jsonindex 954bec4d13e..93a3eb5d847 100644--- a/studio/backend/tests/data/refactor_guard/patch_targets.json+++ b/studio/backend/tests/data/refactor_guard/patch_targets.json@@ -938,8 +938,6 @@"tests/test_media_auto_switch.py"],"state.tool_policy.get_tool_policy": [- "tests/test_checkpoint_compaction.py",- "tests/test_checkpoint_compaction.py","tests/test_checkpoint_compaction.py"],"storage.studio_db.add_scan_folder_with_status": [diff --git a/studio/backend/tests/test_checkpoint_compaction.py b/studio/backend/tests/test_checkpoint_compaction.pyindex d70bf141773..04528b70d28 100644--- a/studio/backend/tests/test_checkpoint_compaction.py+++ b/studio/backend/tests/test_checkpoint_compaction.py@@ -537,23 +537,70 @@ def test_a_restated_instruction_does_not_crowd_out_every_other_rule():assert any(item.startswith("Second standing rule") for item in items)-def test_a_process_with_tools_disabled_never_resets(monkeypatch):- """`supports_tools` is the TEMPLATE's capability, not "this request gets the tool".-- `--disable-tools` sets the process policy to False, so every tool is refused and the- checkpoint override is blocked. Resetting anyway would leave the epoch behind a tool- that never arrives while the header tells the model to search for what was dropped.- """+def test_a_process_with_tools_disabled_still_resets(monkeypatch):+ """`--disable-tools` keeps checkpoint resets; a per-context hard-off still refuses them."""from core.inference import llama_cpp+ from state.tool_policy import tools_force_disabledmonkeypatch.setattr("core.rag.conversation_archive.enabled", lambda: True)monkeypatch.setattr("core.rag.conversation_archive.can_archive", lambda thread_id: True)- monkeypatch.setattr("state.tool_policy.get_tool_policy", lambda: None)+ monkeypatch.setattr("state.tool_policy._tool_policy", None)assert llama_cpp._can_reset_epoch("thread-1", True) is True- monkeypatch.setattr("state.tool_policy.get_tool_policy", lambda: False)- assert llama_cpp._can_reset_epoch("thread-1", True) is False+ monkeypatch.setattr("state.tool_policy._tool_policy", False)+ assert llama_cpp._can_reset_epoch("thread-1", True) is True++ with tools_force_disabled():+ assert llama_cpp._can_reset_epoch("thread-1", True) is False+++def test_disable_tools_reopens_the_loop_for_recall_only(monkeypatch):+ """The recall loop under `--disable-tools` offers search_conversation alone."""+ import asyncio+ import types++ import routes.inference as routes_mod+ from state.tool_policy import tools_force_disabled++ monkeypatch.setattr("state.tool_policy._tool_policy", False)+ monkeypatch.setattr(routes_mod, "_thread_has_conversation_archive", lambda _tid: True)+ monkeypatch.setattr(routes_mod, "_thread_has_checkpoint", lambda *_a: True)+ monkeypatch.setattr(routes_mod, "_enabled_agent_skills", lambda: [{"name": "hf-cli"}])+ monkeypatch.setattr("core.inference.checkpoint.enabled", lambda: True)+ monkeypatch.delenv("UNSLOTH_CONTEXT_OVERFLOW", raising = False)++ payload = types.SimpleNamespace(+ enabled_tools = ["web_search", "read_skill"],+ rag_scope = None,+ thread_id = "t1",+ messages = [],+ bypass_permissions = False,+ context_overflow = "truncate_oldest",+ context_policy = None,+ deep_research_armed = True,+ )+ assert routes_mod._checkpoint_recall_may_enable_tools(payload) is True+ with tools_force_disabled():+ assert routes_mod._checkpoint_recall_may_enable_tools(payload) is False++ tools = asyncio.run(+ routes_mod._select_request_tools(+ payload, tools_on = False, mcp_allowed = False, checkpoint_fitted = True+ )+ )+ assert [tool["function"]["name"] for tool in tools] == ["search_conversation"]++ monkeypatch.setattr("state.tool_policy._tool_policy", None)+ tools = asyncio.run(+ routes_mod._select_request_tools(+ payload, tools_on = False, mcp_allowed = False, checkpoint_fitted = True+ )+ )+ assert [tool["function"]["name"] for tool in tools] == [+ "search_conversation",+ "deep_research",+ ]def _memory_tool_branch():diff --git a/studio/backend/tests/test_preview_routes.py b/studio/backend/tests/test_preview_routes.pyindex 77774ab91a0..44c9114ff8c 100644--- a/studio/backend/tests/test_preview_routes.py+++ b/studio/backend/tests/test_preview_routes.py@@ -290,6 +290,7 @@ def test_chat_payload_sanitized(client, captured):"use_adapter": False,"confirm_tool_calls": True,"session_id": "abc",+ "thread_id": "someone-elses-thread","rag_scope": {"project_id": "x"},"enable_thinking": True,"reasoning_effort": "high",@@ -308,6 +309,7 @@ def test_chat_payload_sanitized(client, captured):# Tool-loop levers neutralized regardless of the tool gate.assert p.confirm_tool_calls is Falseassert p.session_id is None+ assert p.thread_id is Noneassert p.rag_scope is None# Provider routing stripped so /p can't proxy an arbitrary endpoint.assert p.provider_id is None