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(review-2.5.5): Stop interrupts ComfyUI on both buttons, VRAM card back-to-back, tighter CUDA regex

purpleea7768bbbaa8
diff --git a/src/api/vram-handoff.ts b/src/api/vram-handoff.ts
index 648c8fbe..a63950ff 100644
--- a/src/api/vram-handoff.ts
+++ b/src/api/vram-handoff.ts
@@ -876,7 +876,7 @@ async function runHandoff(kind: 'image' | 'video', args: VramHandoffArgs): Promi
// ComfyUI restart (the next generation lazily restarts it via ensureComfyRunning).
const msg = String(e instanceof Error ? e.message : e)
log.warn('vram_handoff.reload_failed', { textModel: evictedModel, err: msg })
- if (/cuda|shared object|terminated|0xc0000409|llama[ -](?:runner|server)/i.test(msg)) {
+ if (/cuda|shared object|0xc0000409/i.test(msg)) {
try {
log.warn('vram_handoff.reload_cuda_wedge_recover', { textModel: evictedModel })
await backendCall('stop_comfyui')
@@ -975,7 +975,9 @@ async function generateImage(prompt: string, model: string, args: VramHandoffArg
// Remember the produced filename so a follow-up "animate it" video call can
// fall back to it when the model passes a wrong/hallucinated inputImage.
const fn = result.match(/generated:\s*([^\s(]+\.(?:png|jpe?g|webp))/i)
- if (fn) _lastImageFilename = fn[1]
+ // Don't let an abandoned (cancelled) gen that finishes in the background
+ // overwrite the filename a later "animate it" might pick up.
+ if (fn && !_genCancelRequested) _lastImageFilename = fn[1]
return result
} catch (err) {
// Surface ComfyUI's message verbatim — an OOM must NOT be masked.
diff --git a/src/hooks/useAgentChat.ts b/src/hooks/useAgentChat.ts
index 9f2dc584..223ca23a 100644
--- a/src/hooks/useAgentChat.ts
+++ b/src/hooks/useAgentChat.ts
@@ -3,6 +3,7 @@ import { v4 as uuid } from 'uuid'
import { chatNonStreaming } from '../api/agents'
import { setActiveChatId, clearActiveChatId, chatWorkspaceSlug, setActiveWorkspace, setActiveAgentModel, renderWorkspaceSection, setChatArtifactMode, takeChatArtifacts } from '../api/agent-context'
import { isOllamaLocal } from '../api/backend'
+import { requestGenerationCancel } from '../api/vram-handoff'
import { resolveWorkspace } from '../api/agents/workspace-resolve'
import { useAgentModeStore } from '../stores/agentModeStore'
import { streamOllamaChatWithTools } from '../lib/ollama-stream-tools'
@@ -1383,6 +1384,10 @@ export function useAgentChat() {
runningRef.current = false
abortRef.current?.abort()
abortRef.current = null
+ // Interrupt any in-flight ComfyUI gen too — the main Stop button only aborted
+ // the agent loop before, so a running image/video kept burning unless the user
+ // happened to click the small in-chat tool Stop. Now both Stops agree.
+ requestGenerationCancel()
for (const entry of approvalQueueRef.current) entry.resolve(false)
approvalQueueRef.current = []
setPendingApproval(null)
diff --git a/src/hooks/useChat.ts b/src/hooks/useChat.ts
index 7fed663f..dbaedd09 100644
--- a/src/hooks/useChat.ts
+++ b/src/hooks/useChat.ts
@@ -8,6 +8,7 @@ import { useMemoryStore } from "../stores/memoryStore"
import { retrieveContext } from "../api/rag"
import { getModelMaxTokens } from "../lib/context-compaction"
import { getModelContextCached } from "../api/ollama"
+import { requestGenerationCancel } from "../api/vram-handoff"
import { effectiveContextWindow } from "../lib/context-window"
import { useAgentChat } from "./useAgentChat"
import { useMemory } from "./useMemory"
@@ -448,6 +449,10 @@ export function useChat() {
const stopGeneration = useCallback(() => {
abortRef.current?.abort()
+ // Also interrupt an in-flight ComfyUI image/video gen, not just the JS loop —
+ // otherwise the main Stop button leaves ComfyUI burning (only the in-chat
+ // tool Stop did this before; now both affordances agree).
+ requestGenerationCancel()
}, [])
const regenerateMessage = useCallback((conversationId: string, assistantMessageId: string) => {
diff --git a/src/hooks/useVramHandoff.ts b/src/hooks/useVramHandoff.ts
index 8dbc0387..ec824bec 100644
--- a/src/hooks/useVramHandoff.ts
+++ b/src/hooks/useVramHandoff.ts
@@ -16,7 +16,7 @@
* `done`/`error` are terminal and reset the state.
*/
-import { useEffect, useState } from 'react'
+import { useEffect, useRef, useState } from 'react'
import { onHandoff, type HandoffPhase } from '../api/vram-handoff'
export interface VramHandoffState {
@@ -38,12 +38,23 @@ const INITIAL: VramHandoffState = { active: false, evicted: false, phase: null,
export function useVramHandoff(): VramHandoffState {
const [state, setState] = useState<VramHandoffState>(INITIAL)
+ // Pending terminal-reset timer. Stored so a NEW generation that starts within
+ // the 1200ms window cancels the previous gen's reset — otherwise the orphaned
+ // timer fires mid-gen-#2 and blanks the live card (back-to-back image→video).
+ const resetTimer = useRef<ReturnType<typeof setTimeout> | null>(null)
useEffect(() => {
const unsub = onHandoff((d) => {
+ // Any new event means a gen is in flight — cancel a pending reset from a
+ // prior gen so it can't clobber this one.
+ if (resetTimer.current) { clearTimeout(resetTimer.current); resetTimer.current = null }
setState((prev) => {
let active = prev.active
let evicted = prev.evicted
+ // `deciding` is the orchestrator's first emit for every generation, so
+ // re-arm the per-cycle flags here. Without this, gen #2 inherits gen #1's
+ // `evicted` and shows a false "VRAM swap" / "restoring chat model" copy.
+ if (d.phase === 'deciding') { active = false; evicted = false }
// A real swap is marked by `freeing_vram`; the card becomes visible as
// soon as the gen starts loading its model, so a no-eviction image gen
// still gets an honest "loading / generating" banner.
@@ -61,10 +72,10 @@ export function useVramHandoff(): VramHandoffState {
// After a terminal event, fully reset shortly so a fresh generation starts
// from a clean slate (and the card unmounts cleanly).
if (d.terminal) {
- setTimeout(() => setState(INITIAL), 1200)
+ resetTimer.current = setTimeout(() => { resetTimer.current = null; setState(INITIAL) }, 1200)
}
})
- return unsub
+ return () => { if (resetTimer.current) clearTimeout(resetTimer.current); unsub() }
}, [])
return state