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.

fix(studio): sanitize the healer catalog when no render target is available (#7812)

Daniel Han66ff96d9ae60
diff --git a/studio/backend/core/inference/chat_template_helpers.py b/studio/backend/core/inference/chat_template_helpers.py
index b782f798060..4a61b6c48dd 100644
--- a/studio/backend/core/inference/chat_template_helpers.py
+++ b/studio/backend/core/inference/chat_template_helpers.py
@@ -1716,10 +1716,17 @@ def renderable_tool_catalog_for_targets(
Chained rather than intersected by name, so the surviving descriptions carry every
candidate's sweep too. Sanitizing an already-sanitized catalog is stable, since a
broken marker no longer matches, so a clean catalog stays byte-identical."""
+ live = [target for target in targets if target is not None]
+ if not live:
+ # Nothing to profile: the default orchestrator's parent-side mirror carries
+ # capability flags, never the tokenizer or processor (orchestrator.py:1278-1292).
+ # Skipping the targets returned the caller's list unsanitized while the worker
+ # sanitized during the render, so a tool dropped from the prompt stayed authorized
+ # for healing. One None target profiles as unprofilable and takes the curated
+ # sweep, the safe direction (#7066).
+ return renderable_tool_catalog(tools, None, model_info, cache, active_model_name, template)
catalog = tools
- for target in targets:
- if target is None:
- continue
+ for target in live:
catalog = renderable_tool_catalog(
catalog, target, model_info, cache, active_model_name, template
)
diff --git a/studio/backend/tests/test_control_markup_neutralize_7066.py b/studio/backend/tests/test_control_markup_neutralize_7066.py
index dc96e3d1a3c..f117b43ce40 100644
--- a/studio/backend/tests/test_control_markup_neutralize_7066.py
+++ b/studio/backend/tests/test_control_markup_neutralize_7066.py
@@ -5944,3 +5944,35 @@ def test_the_native_authorization_profile_sees_the_special_tokens():
"native_chat_template": "{{ bos_token }}{% for t in tools %}<|im_start|>{{ t }}{% endfor %}"
}
assert catalog_tool_names(renderable_tool_catalog(tools, _Tok(), native)) == {"ok"}
+
+
+def test_a_catalog_with_no_render_target_is_still_sanitized():
+ """The default orchestrator's parent-side model mirror carries capability flags and
+ chat_template_info, never the tokenizer or processor (orchestrator.py), so BOTH render
+ candidates are None on that path. Skipping them handed the caller's list back
+ unsanitized, which is fail-open: the worker sanitizes while rendering, so a tool dropped
+ from the prompt stayed in the healer's catalog and text-form output naming it could be
+ promoted into a real call (#7066)."""
+ tools = [{"type": "function", "function": {"name": "ok", "description": "drops </think> here"}}]
+ for targets in ((None,), (), (None, None)):
+ catalog = renderable_tool_catalog_for_targets(tools, targets, {})
+ assert catalog is not tools, targets
+ assert catalog[0]["function"]["description"] == "drops < /think> here", targets
+ # A tool whose NAME carries markup is dropped outright, as on the single-target path.
+ named = [
+ {"type": "function", "function": {"name": "pay</think>", "description": "d"}},
+ {"type": "function", "function": {"name": "ok", "description": "d"}},
+ ]
+ assert catalog_tool_names(renderable_tool_catalog_for_targets(named, (None,), {})) == {"ok"}
+
+ # A real target still profiles normally rather than falling back. Its template has to
+ # render the schema, or the catalog is emptied for that reason instead.
+ class _Tok:
+ chat_template = (
+ "{% for t in tools %}{{ t }}{% endfor %}"
+ "{% for m in messages %}<|im_start|>{{ m }}{% endfor %}"
+ )
+ added_tokens_decoder = {0: type("_T", (), {"content": "<|im_start|>"})()}
+
+ kept = renderable_tool_catalog_for_targets(tools, (None, _Tok()), {})
+ assert catalog_tool_names(kept) == {"ok"}