From db5a9880b007c06f0a8cd6462f7ee8a373139f30 Mon Sep 17 00:00:00 2001 From: Roland Tannous <115670425+rolandtannous@users.noreply.github.com> Date: Fri, 29 May 2026 12:46:16 +0400 Subject: [PATCH] Studio: keep web search/code pills off on model load if user disabled them (#5851) * Studio: keep web search/code pills off on model load if user disabled them * Studio: avoid redundant localStorage reads when resolving tool pills on load --- .../src/features/chat/api/chat-adapter.ts | 10 ++++------ .../chat/hooks/use-chat-model-runtime.ts | 15 +++++++-------- .../features/chat/stores/chat-runtime-store.ts | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/studio/frontend/src/features/chat/api/chat-adapter.ts b/studio/frontend/src/features/chat/api/chat-adapter.ts index a74a4a2dea..666a304c3e 100644 --- a/studio/frontend/src/features/chat/api/chat-adapter.ts +++ b/studio/frontend/src/features/chat/api/chat-adapter.ts @@ -34,6 +34,7 @@ import { } from "../provider-capabilities"; import { type PendingImageEditReference, + resolveToolsEnabledOnLoad, useChatRuntimeStore, } from "../stores/chat-runtime-store"; import { useExternalProvidersStore } from "../stores/external-providers-store"; @@ -1034,8 +1035,7 @@ async function autoLoadSmallestModel(): Promise<{ supportsPreserveThinking: loadResp.supports_preserve_thinking ?? false, supportsTools: loadResp.supports_tools ?? false, - toolsEnabled: loadResp.supports_tools ?? false, - codeToolsEnabled: loadResp.supports_tools ?? false, + ...resolveToolsEnabledOnLoad(loadResp.supports_tools ?? false), kvCacheDtype: loadResp.cache_type_kv ?? null, loadedKvCacheDtype: loadResp.cache_type_kv ?? null, defaultChatTemplate: loadResp.chat_template ?? null, @@ -1098,8 +1098,7 @@ async function autoLoadSmallestModel(): Promise<{ sfLoadResp.supports_preserve_thinking ?? false, supportsTools: sfLoadResp.supports_tools ?? false, // Parity with the GGUF branch above. - toolsEnabled: sfLoadResp.supports_tools ?? false, - codeToolsEnabled: sfLoadResp.supports_tools ?? false, + ...resolveToolsEnabledOnLoad(sfLoadResp.supports_tools ?? false), defaultChatTemplate: sfLoadResp.chat_template ?? null, chatTemplateOverride: null, loadedChatTemplateOverride: null, @@ -1197,8 +1196,7 @@ async function autoLoadSmallestModel(): Promise<{ reasoningStyle: loadResp.reasoning_style ?? "enable_thinking", supportsPreserveThinking: loadResp.supports_preserve_thinking ?? false, supportsTools: loadResp.supports_tools ?? false, - toolsEnabled: loadResp.supports_tools ?? false, - codeToolsEnabled: loadResp.supports_tools ?? false, + ...resolveToolsEnabledOnLoad(loadResp.supports_tools ?? false), kvCacheDtype: loadResp.cache_type_kv ?? null, loadedKvCacheDtype: loadResp.cache_type_kv ?? null, defaultChatTemplate: loadResp.chat_template ?? null, diff --git a/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts b/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts index 810a769a46..47216cf93d 100644 --- a/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts +++ b/studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts @@ -27,6 +27,7 @@ import { CHAT_REASONING_ENABLED_KEY, loadOptionalBool, type ReasoningEffort, + resolveToolsEnabledOnLoad, useChatRuntimeStore, } from "../stores/chat-runtime-store"; import { @@ -698,14 +699,12 @@ export function useChatModelRuntime() { reasoningEffort: clampedReasoningEffort, supportsPreserveThinking: loadResponse.supports_preserve_thinking ?? false, supportsTools, - toolsEnabled: - reloadingSameModel && supportsTools - ? stateBeforeUnload.toolsEnabled - : supportsTools, - codeToolsEnabled: - reloadingSameModel && supportsTools - ? stateBeforeUnload.codeToolsEnabled - : supportsTools, + ...(reloadingSameModel && supportsTools + ? { + toolsEnabled: stateBeforeUnload.toolsEnabled, + codeToolsEnabled: stateBeforeUnload.codeToolsEnabled, + } + : resolveToolsEnabledOnLoad(supportsTools)), kvCacheDtype: loadedKv, loadedKvCacheDtype: loadedKv, speculativeType: loadedSpec, diff --git a/studio/frontend/src/features/chat/stores/chat-runtime-store.ts b/studio/frontend/src/features/chat/stores/chat-runtime-store.ts index 09c06f92d8..8f0767b7b8 100644 --- a/studio/frontend/src/features/chat/stores/chat-runtime-store.ts +++ b/studio/frontend/src/features/chat/stores/chat-runtime-store.ts @@ -184,6 +184,23 @@ export function loadOptionalBool(key: string): boolean | null { } } +/** + * Resolve the web-search / code-execution pill state to apply when a model + * loads. Honors the user's persisted preference so loading a tool-capable + * model never silently re-enables a pill the user turned off; falls back to + * the model's capability only when no preference has been expressed. + */ +export function resolveToolsEnabledOnLoad(supportsTools: boolean): { + toolsEnabled: boolean; + codeToolsEnabled: boolean; +} { + if (!supportsTools) return { toolsEnabled: false, codeToolsEnabled: false }; + return { + toolsEnabled: loadOptionalBool(CHAT_TOOLS_ENABLED_KEY) ?? true, + codeToolsEnabled: loadOptionalBool(CHAT_CODE_TOOLS_ENABLED_KEY) ?? true, + }; +} + function saveBool(key: string, value: boolean): void { if (!canUseStorage()) return; try {