Skip to content

Commit 0dd7958

Browse files
authored
fix(sendbox): cancel pending warmup when user submits (#2719)
When a user focuses the input, a 1s timer schedules a `/api/conversations/{id}/warmup` request as a "pre-warm worker bootstrap" hint. If the user submits inside that 1s window the timer still fires later, racing the real `/messages` request on the same conversation. The backend already single-flights `get_or_build_task`, so the race is no longer corrupting state, but the extra request is pure waste. In `sendMessageHandler`, clear any pending warmup timer and mark the active conversation as already warmed. Covers all submit paths — normal, side-question, and early-return cases — since the guard runs before the branch switch.
1 parent 69fc626 commit 0dd7958

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

src/renderer/components/chat/sendbox.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,18 @@ const SendBox: React.FC<{
11411141

11421142
const sendMessageHandler = () => {
11431143
if (isUploading) return;
1144+
// Cancel any pending warmup: once the user actually submits, the
1145+
// forthcoming /messages request will build the agent on its own.
1146+
// Without this, a focus-triggered warmup timer still fires ~1s later
1147+
// and races the real send over the same conversation.
1148+
if (warmupTimerRef.current) {
1149+
clearTimeout(warmupTimerRef.current);
1150+
warmupTimerRef.current = null;
1151+
}
1152+
const activeCid = conversationContext?.conversation_id;
1153+
if (activeCid) {
1154+
warmedConversationRef.current = activeCid;
1155+
}
11441156
if (enableBtw && btwQuestion !== null) {
11451157
const normalizedQuestion = btwQuestion.trim();
11461158
if (!normalizedQuestion) {

0 commit comments

Comments
 (0)