Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(chat): Regenerate and Edit refuse what sendMessage refuses before deleting the turn

purplefff35e722d95
diff --git a/src/hooks/__tests__/regenerate-asks-before-it-deletes.test.ts b/src/hooks/__tests__/regenerate-asks-before-it-deletes.test.ts
new file mode 100644
index 00000000..248bf4ac
--- /dev/null
+++ b/src/hooks/__tests__/regenerate-asks-before-it-deletes.test.ts
@@ -0,0 +1,27 @@
+/**
+ * Bug hunt 01.10.2026 (H9). Regenerate and Edit delete the turn and then call
+ * sendMessage. resend checked for a model, but sendMessage also refuses a
+ * model from the other mode (Local/Cloud switch) and a second send while this
+ * conversation's run is in flight. Either way the question was gone and
+ * nothing went out. resend now asks all three before it deletes.
+ */
+import { it, expect } from 'vitest'
+import { readFileSync } from 'node:fs'
+import { resolve } from 'node:path'
+
+const chat = readFileSync(resolve(__dirname, '..', 'useChat.ts'), 'utf8')
+
+it('resend refuses what sendMessage refuses, before deleteMessagesAfter', () => {
+ const at = chat.indexOf('const resend = useCallback(')
+ const body = chat.slice(at, chat.indexOf('}, [sendMessage])', at))
+ const del = body.indexOf('deleteMessagesAfter')
+ const mode = body.indexOf('modelOutOfMode(activeModel, useSettingsStore.getState().settings.appMode)) return')
+ const run = body.indexOf('if (activeChatRuns.has(conversationId)) return')
+ expect(mode).toBeGreaterThan(0)
+ expect(run).toBeGreaterThan(0)
+ expect(mode).toBeLessThan(del)
+ expect(run).toBeLessThan(del)
+ // The same two refusals sendMessage applies.
+ expect(chat).toContain('if (modelOutOfMode(activeModel, settings.appMode)) {')
+ expect(chat).toContain('if (activeChatRuns.has(convId)) {')
+})
diff --git a/src/hooks/useChat.ts b/src/hooks/useChat.ts
index bd57b1d1..282a5968 100644
--- a/src/hooks/useChat.ts
+++ b/src/hooks/useChat.ts
@@ -1600,8 +1600,12 @@ export function useChat() {
* per click and the model was asked it twice.
*/
const resend = useCallback((conversationId: string, targetId: string, override?: string) => {
- // sendMessage bails without a model; deleting first would eat the question.
- if (!useModelStore.getState().activeModel) return
+ // sendMessage bails without a model, with a model from the other mode, and
+ // while this conversation's run is in flight; deleting first would eat
+ // the question. The last two were missing (bug hunt 01.10.2026, H9).
+ const { activeModel } = useModelStore.getState()
+ if (!activeModel || modelOutOfMode(activeModel, useSettingsStore.getState().settings.appMode)) return
+ if (activeChatRuns.has(conversationId)) return
const conv = useChatStore.getState().conversations.find(c => c.id === conversationId)
if (!conv) return
const plan = planResend(conv.messages, targetId, override)