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
This commit is contained in:
Classic298 2026-09-01 20:10:22 +02:00
parent 6ea321370e
commit 3774512dee

View file

@ -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;