Skip to content

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.

Studio: confirm a web_search call that fetches a url in auto mode (#8313)

Daniel Han70b5d6fb40c5
diff --git a/studio/backend/core/inference/tools.py b/studio/backend/core/inference/tools.py
index c63806054f8..f0d19211d4d 100644
--- a/studio/backend/core/inference/tools.py
+++ b/studio/backend/core/inference/tools.py
@@ -4474,6 +4474,16 @@ def has_text_only_provisional_card(name: str) -> bool:
return name in _TEXT_PREVIEW_TOOLS
+def _web_search_fetches_url(name: str, arguments: dict) -> bool:
+ """web_search carrying a ``url`` fetches that exact page instead of searching.
+
+ That fetch is egress to a host the *call* names, the one such case in the built-in
+ set, so it asks even though plain search stays always-safe. Name-only
+ ``is_always_safe_tool`` is deliberately unchanged: it runs before arguments exist
+ (provisional card, stream requirement), where a query-only search must not prompt."""
+ return name == "web_search" and bool(str(arguments.get("url", "") or "").strip())
+
+
def is_potentially_unsafe_tool_call(name: str, arguments: dict) -> bool:
"""Whether a tool call must still pause for approval in auto mode.
@@ -4481,6 +4491,8 @@ def is_potentially_unsafe_tool_call(name: str, arguments: dict) -> bool:
auto-run, anything that can mutate state, execute arbitrary code, or is
simply unrecognized asks first. Unknown tools fail closed.
"""
+ if _web_search_fetches_url(name, arguments):
+ return True
if name in _ALWAYS_SAFE_TOOLS:
return False
# render_html auto-runs a static canvas but asks once its HTML/JS reaches the
@@ -6464,6 +6476,8 @@ def is_high_risk_tool_call(name: str, arguments: dict) -> bool:
set, rlimits and secret-env stripping remain in force underneath. Unknown tools
fail closed (prompt).
"""
+ if _web_search_fetches_url(name, arguments):
+ return True
if name in _ALWAYS_SAFE_TOOLS:
return False
if name == "render_html":
diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.py
index 094ccf8b26c..7d26e5a3d42 100644
--- a/studio/backend/routes/inference.py
+++ b/studio/backend/routes/inference.py
@@ -2597,7 +2597,10 @@ def _confirm_gate_needs_stream(payload) -> bool:
return False
from core.inference.tools import is_always_safe_tool
- return not all(is_always_safe_tool(t) for t in enabled)
+ # web_search prompts once the model supplies a ``url`` (it fetches that page), and the
+ # gate can only prompt while streaming. Without this a non-streaming auto request is
+ # admitted, then blocks in wait_tool_decision on an approval the client never reads.
+ return not all(is_always_safe_tool(t) and t != "web_search" for t in enabled)
# Cancel registry. Proxies (e.g. Colab) can swallow client fetch aborts so
diff --git a/studio/backend/tests/test_permission_mode.py b/studio/backend/tests/test_permission_mode.py
index 00e7ccf4a4a..ab3f6cf4322 100644
--- a/studio/backend/tests/test_permission_mode.py
+++ b/studio/backend/tests/test_permission_mode.py
@@ -2277,6 +2277,25 @@ def test_builtin_readonly_tools_are_safe():
assert is_potentially_unsafe_tool_call("render_html", {}) is False
+def test_web_search_gated_only_when_it_fetches_a_url():
+ # Searching stays always-safe; a ``url`` fetches that named host, so it asks in auto too.
+ for gate in (is_potentially_unsafe_tool_call, is_high_risk_tool_call):
+ assert gate("web_search", {"query": "hi"}) is False
+ assert gate("web_search", {}) is False
+ assert gate("web_search", {"url": ""}) is False
+ assert gate("web_search", {"url": None}) is False
+ assert gate("web_search", {"url": " "}) is False
+ assert gate("web_search", {"url": "https://example.com/page"}) is True
+ assert gate("web_search", {"query": "hi", "url": "https://example.com"}) is True
+
+
+def test_web_search_name_only_gate_is_unchanged():
+ # Runs before arguments exist (provisional card, stream requirement), so a query-only
+ # search must not start prompting.
+ from core.inference.tools import is_always_safe_tool
+ assert is_always_safe_tool("web_search") is True
+
+
def test_render_html_gated_only_when_networked():
# A static canvas auto-runs; one whose HTML/JS reaches the network asks.
def rh(code):
@@ -2934,11 +2953,24 @@ def test_confirm_gate_needs_stream():
safe = ["web_search", "search_knowledge_base"]
# auto + a safe-only selection never prompts -> no stream needed.
- assert _confirm_gate_needs_stream(req(permission_mode = "auto", enabled_tools = safe)) is False
assert (
- _confirm_gate_needs_stream(req(permission_mode = "auto", enabled_tools = ["web_search"]))
+ _confirm_gate_needs_stream(
+ req(permission_mode = "auto", enabled_tools = ["search_knowledge_base"])
+ )
is False
)
+ # web_search prompts once the model supplies a ``url``, so it needs a stream to deliver
+ # that prompt, else the request is admitted then blocks out the decision timeout.
+ assert (
+ _confirm_gate_needs_stream(req(permission_mode = "auto", enabled_tools = ["web_search"]))
+ is True
+ )
+ assert (
+ _confirm_gate_needs_stream(
+ req(permission_mode = "auto", enabled_tools = ["web_search", "search_knowledge_base"])
+ )
+ is True
+ )
# render_html can prompt when its canvas reaches the network, so a selection
# that includes it needs a stream to deliver that prompt.
assert (