Commit graph

4 commits

Author SHA1 Message Date
pre-commit-ci[bot]
5e87eb714d [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2026-07-07 09:25:02 +00:00
danielhanchen
dbf503e9a5 Studio: scope the confirm_code_execution stream requirement to code-execution tools
The streaming requirement for confirm_code_execution now fires only when a
local code-execution tool (python/terminal) could actually run, so a
non-streaming request that enables only non-code tools (web_search,
render_html, ...) is no longer rejected. This matches the documented behavior
that confirm_code_execution leaves non-code tools unaffected.

- Per-handler (GGUF and safetensors): gate on the resolved tool list
  intersecting python/terminal.
- Pre-switch: gate on a payload-level predicate that mirrors
  _select_request_tools (built-ins off unless the tool loop is enabled; an
  explicit enabled_tools filter must list python/terminal).
- External-provider and Anthropic server-tool rejections stay broad: the local
  confirm gate cannot apply there at all.

Tests: predicate coverage for both the resolved and payload-level checks.
2026-07-07 09:24:28 +00:00
danielhanchen
5f5eaef386 Studio: mirror confirm_tool_calls validation for confirm_code_execution
Review follow-up: validate confirm_code_execution at the same request-lifecycle
points as confirm_tool_calls so it can never be silently accepted where the
confirm gate cannot apply.

- External providers: reject confirm_code_execution (code_execution runs
  provider-side, so the local confirm gate cannot intercept it) instead of
  giving the caller a false approval guarantee.
- Pre-switch: reject a non-stream confirm_code_execution local tool request
  before automatic model loading, so an invalid shape does not evict the
  resident model only to 400 after the swap.
- Drop the code-execution tool scoping on the per-request stream requirement so
  it mirrors confirm_tool_calls exactly (removes _enables_code_execution_tool).

Tests: provider rejection for confirm_code_execution; existing streaming
requirement + gate tests still pass.
2026-07-07 09:01:45 +00:00
danielhanchen
3f883a3e5f Studio: add confirm_code_execution to gate only python/terminal tool calls
Adds an opt-in request field, confirm_code_execution, that routes local
code-execution tool calls (python, terminal) through the existing
confirmation gate while other tools (web_search, render_html, MCP, ...)
continue to run without a prompt.

This lets a caller require approval for code execution specifically,
without the friction of confirm_tool_calls prompting on every tool. It is
independent of confirm_tool_calls, defaults off (no change to existing
behavior), requires stream=true when a code-execution tool is enabled
(same as confirm_tool_calls), and bypass_permissions still takes
precedence.

The tool-call parser and tool detection are unchanged, so no tool-calling
behavior is affected when the flag is off.

- models: new confirm_code_execution field on ChatCompletionRequest
- tools: CODE_EXECUTION_TOOL_NAMES = {python, terminal}
- safetensors and gguf loops: needs_confirm also fires for code-execution
  tools when confirm_code_execution is set (bypass still wins)
- routes: thread the flag to both local loops; require streaming when a
  code-execution tool is enabled
- tests: loop-level gate behavior, the scoping predicate, and the route
  streaming requirement for both backends
2026-07-07 08:19:14 +00:00