From 3774512dee7cec5c4f6e05e905c31cc9a143acc4 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Tue, 1 Sep 2026 20:10:22 +0200 Subject: [PATCH] fix: apply new model's defaults before reading them on send Switching the composer's model mid-chat and sending right away could ship the previous model's feature flags: applying the new model's default tools/skills/features (including web_search) is asynchronous, and nothing made a send wait for it, so features.web_search could go out false even though the toggle showed on. Track the in-flight defaults application in a promise and have the send path await it before reading tools/skills/features, with a small guard so a second rapid send can't slip past that wait and read stale state too. The wait is scoped to just that point rather than the whole send handler, so it doesn't delay clearing the input or block a follow-up message from queuing while the assistant is still generating. Fixes #29326 --- src/lib/components/chat/Chat.svelte | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 875aee0e07..301fa9c2b5 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -982,10 +982,8 @@ } let settingDefaults = false; - const setDefaults = async () => { - if (settingDefaults) return; - settingDefaults = true; - + let defaultsPromise = Promise.resolve(); + const applyDefaults = async () => { try { if (!$tools) { tools.set(await getTools(localStorage.token)); @@ -1096,6 +1094,13 @@ } }; + const setDefaults = () => { + if (settingDefaults) return defaultsPromise; + settingDefaults = true; + defaultsPromise = applyDefaults().catch((error) => console.error(error)); + return defaultsPromise; + }; + const showMessage = async (message, scroll = true, save = true) => { const _chatId = JSON.parse(JSON.stringify($chatId)); let _messageId = JSON.parse(JSON.stringify(message.id)); @@ -2867,6 +2872,8 @@ ////////////////////////// const submitPrompt = async (inputContent, inputFiles) => { + await defaultsPromise; + const _files = structuredClone(inputFiles); chatFiles.push( @@ -3054,6 +3061,7 @@ prompt = ''; }; + let awaitingDefaults = false; const submitHandler = async (userPrompt, { _raw = false } = {}) => { console.log('submitHandler', userPrompt, $chatId); @@ -3088,6 +3096,15 @@ return; } + // Drop a second send that races this wait, since prompt isn't cleared until after it + if (awaitingDefaults) return; + awaitingDefaults = true; + try { + await defaultsPromise; + } finally { + awaitingDefaults = false; + } + if (pendingOAuthTools.length > 0) { toast.warning($i18n.t('Please connect all required integrations before sending a message')); return;