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(settings): Abbruchknopf fuer ComfyUI-Install und Repair, mit Ergebniszeile

purple6be9b8cabaef
diff --git a/src/components/settings/SettingsPage.tsx b/src/components/settings/SettingsPage.tsx
index 07c49414..32abd899 100644
--- a/src/components/settings/SettingsPage.tsx
+++ b/src/components/settings/SettingsPage.tsx
@@ -479,7 +479,16 @@ function ImportLocalModels() {
// ── ComfyUI Settings ────────────────────────────────────────────
-function ComfyUISettings() {
+// What the user is told once a cancelled run has really stopped. A cancel that
+// leaves the panel blank reads as "nothing happened", and after a repair that
+// is a lie: the venv is half rebuilt at that point.
+export const COMFY_CANCEL_NOTICE = {
+ install: 'Install cancelled. ComfyUI is not set up yet, you can start the install again at any time.',
+ update: 'Update cancelled. ComfyUI may be updated only in part, so run Update ComfyUI again to finish it.',
+ repair: 'Repair cancelled. The environment is only half rebuilt, so run Repair environment again before you start ComfyUI.',
+} as const
+
+export function ComfyUISettings() {
const [status, setStatus] = useState<{ running: boolean; found: boolean; complete?: boolean; path?: string; port?: number; host?: string; isLocal?: boolean; starting?: boolean; stalled?: boolean } | null>(null)
// Why the last start attempt did not stick. The button used to swallow this
// whole (E16): on a box with no ComfyUI python environment, Start answered
@@ -502,6 +511,11 @@ function ComfyUISettings() {
const [installErr, setInstallErr] = useState('')
// #162: size, rate and remaining time in the bracket next to the spinner.
const [installDl, setInstallDl] = useState({ progress: 0, total: 0, speed: 0 })
+ // A13 (Windows counter-check 2026-09-02): Onboarding could stop a running
+ // install, Settings could not. A repair takes 20 minutes and pulls two
+ // gigabytes of PyTorch, and the only way out of it was killing the app.
+ const [cancelling, setCancelling] = useState(false)
+ const [installNotice, setInstallNotice] = useState('')
useEffect(() => {
let cancelled = false
@@ -557,6 +571,8 @@ function ComfyUISettings() {
setInstallPhase('repair')
setInstallLogs(['Repairing the ComfyUI environment…'])
setInstallDl({ progress: 0, total: 0, speed: 0 })
+ setCancelling(false)
+ setInstallNotice('')
try {
const { backendCall } = await import('../../api/backend')
await backendCall('repair_comfyui_env')
@@ -567,9 +583,18 @@ function ComfyUISettings() {
setInstallDl({ progress: data.download_progress || 0, total: data.download_total || 0, speed: data.download_speed || 0 })
if (data.status === 'complete') {
clearInterval(poll)
+ setCancelling(false)
setInstallPhase('idle')
- } else if (data.status === 'error' || data.status === 'cancelled') {
+ } else if (data.status === 'cancelled') {
+ // A cancel the user asked for is not a failure, and it must leave a
+ // sentence behind: the venv is half rebuilt at this point.
clearInterval(poll)
+ setCancelling(false)
+ setInstallPhase('idle')
+ setInstallNotice(COMFY_CANCEL_NOTICE.repair)
+ } else if (data.status === 'error') {
+ clearInterval(poll)
+ setCancelling(false)
const lastLog = (data.logs?.length ? data.logs[data.logs.length - 1] : '') as string
setInstallErr(withInstallerOutput('Repairing the environment did not finish.', lastLog))
setInstallPhase('error')
@@ -582,6 +607,24 @@ function ComfyUISettings() {
}
}
+ // One button for every long run this panel starts. Rust checks the same flag
+ // in every step of the installer and of the repair, so the run stops at the
+ // next step boundary; until it does, the panel says it is cancelling instead
+ // of pretending the click did nothing.
+ const handleCancelInstall = async () => {
+ if (cancelling) return
+ setCancelling(true)
+ try {
+ const { backendCall } = await import('../../api/backend')
+ await backendCall('cancel_comfyui_install')
+ } catch (err) {
+ // The flag is the only thing that can stop the run. If setting it failed,
+ // a button stuck on "Cancelling…" would be the second lie in a row.
+ setCancelling(false)
+ setInstallErr(err instanceof Error ? err.message : 'Could not cancel the run')
+ }
+ }
+
const handleStop = async () => {
try {
const { backendCall } = await import('../../api/backend')
@@ -769,6 +812,8 @@ function ComfyUISettings() {
const { backendCall } = await import('../../api/backend')
setInstallErr('')
setInstallLogs([])
+ setCancelling(false)
+ setInstallNotice('')
// P14 pre-flight: ensure Python is on the box before
// pip-installing ComfyUI. The carcass case (status.complete
@@ -826,9 +871,16 @@ function ComfyUISettings() {
setInstallDl({ progress: data.download_progress || 0, total: data.download_total || 0, speed: data.download_speed || 0 })
if (data.status === 'complete') {
clearInterval(poll)
+ setCancelling(false)
setInstallPhase('idle')
+ } else if (data.status === 'cancelled') {
+ clearInterval(poll)
+ setCancelling(false)
+ setInstallPhase('idle')
+ setInstallNotice(COMFY_CANCEL_NOTICE.install)
} else if (data.status === 'error') {
clearInterval(poll)
+ setCancelling(false)
const lastLog = (data.logs?.length ? data.logs[data.logs.length - 1] : '') as string
setInstallErr(withInstallerOutput('Installing ComfyUI did not finish.', lastLog))
setInstallPhase('error')
@@ -855,6 +907,8 @@ function ComfyUISettings() {
setInstallPhase('comfyui')
setInstallErr('')
setInstallLogs(['Updating ComfyUI…'])
+ setCancelling(false)
+ setInstallNotice('')
try {
await backendCall('update_comfyui')
const poll = setInterval(async () => {
@@ -864,9 +918,16 @@ function ComfyUISettings() {
setInstallDl({ progress: data.download_progress || 0, total: data.download_total || 0, speed: data.download_speed || 0 })
if (data.status === 'complete') {
clearInterval(poll)
+ setCancelling(false)
+ setInstallPhase('idle')
+ } else if (data.status === 'cancelled') {
+ clearInterval(poll)
+ setCancelling(false)
setInstallPhase('idle')
+ setInstallNotice(COMFY_CANCEL_NOTICE.update)
} else if (data.status === 'error') {
clearInterval(poll)
+ setCancelling(false)
const lastLog = (data.logs?.length ? data.logs[data.logs.length - 1] : '') as string
setInstallErr(withInstallerOutput('Updating ComfyUI did not finish.', lastLog))
setInstallPhase('error')
@@ -888,16 +949,33 @@ function ComfyUISettings() {
Installs to your home folder by default. Set Path above (e.g. D:\ComfyUI) to install on another drive.
</p>
)}
+ {installNotice && installPhase === 'idle' && (
+ <p className="w-full text-[0.55rem] text-amber-500 dark:text-amber-400 leading-relaxed">{installNotice}</p>
+ )}
{installPhase !== 'idle' && (
<div className="w-full mt-2 space-y-1">
<div className="flex items-center gap-1.5 text-[0.6rem] text-gray-400">
{installPhase !== 'error' && <Loader2 size={10} className="animate-spin" />}
<span>
- {installPhase === 'python' && 'Installing Python 3.12 (~30 MB)…'}
- {installPhase === 'comfyui' && `Installing ComfyUI…${downloadSuffix(installDl)}`}
- {installPhase === 'repair' && `Rebuilding the ComfyUI environment…${downloadSuffix(installDl)}`}
- {installPhase === 'error' && 'Install failed'}
+ {cancelling && installPhase !== 'error'
+ ? 'Cancelling…'
+ : <>
+ {installPhase === 'python' && 'Installing Python 3.12 (~30 MB)…'}
+ {installPhase === 'comfyui' && `Installing ComfyUI…${downloadSuffix(installDl)}`}
+ {installPhase === 'repair' && `Rebuilding the ComfyUI environment…${downloadSuffix(installDl)}`}
+ {installPhase === 'error' && 'Install failed'}
+ </>}
</span>
+ {(installPhase === 'comfyui' || installPhase === 'repair') && (
+ <button
+ onClick={handleCancelInstall}
+ disabled={cancelling}
+ title={installPhase === 'repair' ? 'Stop the repair' : 'Stop the ComfyUI install'}
+ className="ml-auto px-1.5 py-[1px] rounded border border-red-500/40 text-[0.55rem] text-red-500 dark:text-red-300 hover:bg-red-500/10 transition-colors disabled:opacity-50 disabled:cursor-default"
+ >
+ {cancelling ? 'Cancelling…' : 'Cancel'}
+ </button>
+ )}
</div>
{installLogs.length > 0 && (
<div className="bg-black/50 rounded p-1.5 max-h-24 overflow-y-auto font-mono text-[0.5rem] text-gray-500 space-y-0.5">
diff --git a/src/components/settings/__tests__/comfy-install-cancel.test.ts b/src/components/settings/__tests__/comfy-install-cancel.test.ts
new file mode 100644
index 00000000..73a68ad9
--- /dev/null
+++ b/src/components/settings/__tests__/comfy-install-cancel.test.ts
@@ -0,0 +1,109 @@
+/**
+ * @vitest-environment jsdom
+ *
+ * A13, Windows counter-check 2026-09-02: "waehrend des Repairs gibt es keinen
+ * Abbruchknopf". Rust has had one the whole time (`cancel_comfyui_install`
+ * sets the flag, and every step of the installer and of `repair_comfyui_env`
+ * reads it), Onboarding offered it, and Settings did not. A repair pulls two
+ * gigabytes of PyTorch and runs for twenty minutes, so the only way out was
+ * killing the app.
+ *
+ * This mounts the real panel, presses Repair environment, presses Cancel and
+ * reads back what the backend was told and what the panel says afterwards.
+ *
+ * Run: npx vitest run src/components/settings/__tests__/comfy-install-cancel.test.ts
+ */
+import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
+import { createElement } from 'react'
+import { render, screen, fireEvent, cleanup, act } from '@testing-library/react'
+
+const backendCall = vi.fn()
+vi.mock('../../../api/backend', () => ({
+ backendCall: (...args: unknown[]) => backendCall(...args),
+ isTauri: () => true,
+ isMacOS: () => false,
+ openExternal: vi.fn(),
+ secretGet: vi.fn().mockRejectedValue(new Error('no keychain here')),
+ secretSet: vi.fn(),
+ secretDelete: vi.fn(),
+ setComfyPort: vi.fn(),
+ setComfyHost: vi.fn(),
+}))
+
+const { ComfyUISettings, COMFY_CANCEL_NOTICE } = await import('../SettingsPage')
+
+/** What `install_comfyui_status` answers next. */
+let installStatus: { status: string; logs: string[] } = { status: 'installing', logs: ['pip install torch'] }
+
+beforeEach(() => {
+ installStatus = { status: 'installing', logs: ['pip install torch'] }
+ backendCall.mockReset()
+ backendCall.mockImplementation(async (cmd: string) => {
+ if (cmd === 'comfyui_status') return { running: false, found: true, complete: true, path: 'C:\\ComfyUI', isLocal: true }
+ if (cmd === 'install_comfyui_status') return installStatus
+ if (cmd === 'repair_comfyui_env') return { status: 'installing' }
+ if (cmd === 'cancel_comfyui_install') return { status: 'cancelling' }
+ return {}
+ })
+})
+afterEach(() => { cleanup(); vi.useRealTimers() })
+
+/** Mount the panel and get past the "Checking..." first status read. */
+async function mountPanel() {
+ render(createElement(ComfyUISettings))
+ await act(async () => { await Promise.resolve(); await Promise.resolve() })
+}
+
+/** Let the 2 s status poll fire `times` times. */
+async function poll(times = 1) {
+ for (let i = 0; i < times; i++) {
+ await act(async () => { await vi.advanceTimersByTimeAsync(2000) })
+ }
+}
+
+describe('cancelling a repair from Settings', () => {
+ it('offers Cancel while the repair runs, and not before', async () => {
+ vi.useFakeTimers({ shouldAdvanceTime: true })
+ await mountPanel()
+ expect(screen.queryByText('Cancel')).toBeNull()
+ await act(async () => { fireEvent.click(screen.getByText('Repair environment')) })
+ expect(screen.getByText(/Rebuilding the ComfyUI environment/)).toBeTruthy()
+ expect(screen.getByText('Cancel')).toBeTruthy()
+ })
+
+ it('tells Rust to cancel, locks the button and says it is cancelling', async () => {
+ vi.useFakeTimers({ shouldAdvanceTime: true })
+ await mountPanel()
+ await act(async () => { fireEvent.click(screen.getByText('Repair environment')) })
+ await act(async () => { fireEvent.click(screen.getByText('Cancel')) })
+
+ expect(backendCall.mock.calls.some(([cmd]) => cmd === 'cancel_comfyui_install')).toBe(true)
+ const button = screen.getByRole('button', { name: 'Cancelling…' }) as HTMLButtonElement
+ expect(button.disabled).toBe(true)
+ // The line above the button says the same thing, so the state is readable
+ // without hunting for a greyed-out button.
+ expect(screen.getAllByText('Cancelling…').length).toBe(2)
+
+ // A second click must not fire a second cancel.
+ const before = backendCall.mock.calls.filter(([cmd]) => cmd === 'cancel_comfyui_install').length
+ await act(async () => { fireEvent.click(button) })
+ expect(backendCall.mock.calls.filter(([cmd]) => cmd === 'cancel_comfyui_install').length).toBe(before)
+ })
+
+ it('leaves a sentence behind once the run really stopped, not an error', async () => {
+ vi.useFakeTimers({ shouldAdvanceTime: true })
+ await mountPanel()
+ await act(async () => { fireEvent.click(screen.getByText('Repair environment')) })
+ await act(async () => { fireEvent.click(screen.getByText('Cancel')) })
+
+ installStatus = { status: 'cancelled', logs: ['Repair cancelled during the PyTorch download.'] }
+ await poll(1)
+
+ expect(screen.getByText(COMFY_CANCEL_NOTICE.repair)).toBeTruthy()
+ // Cancelled is not a failure: the panel goes back to idle and offers the
+ // repair again instead of showing "did not finish".
+ expect(screen.queryByText(/did not finish/)).toBeNull()
+ expect(screen.getByText('Repair environment')).toBeTruthy()
+ expect(screen.queryAllByText('Cancelling…').length).toBe(0)
+ })
+})