Commit 212c547fe for llama.cpp
commit 212c547fe908b288f6659d48741e6ffac1ff409c
Author: Wenyu Chen <wenyuc21@gmail.com>
Date: Mon Nov 23 03:27:44 2026 -0500
ui: add cancel button to cancel model loading (#32225)
diff --git a/ui/apps/chat/src/lib/components/app/models/ModelLoadControl.svelte b/ui/apps/chat/src/lib/components/app/models/ModelLoadControl.svelte
index 0607ddced..454b9f2c4 100644
--- a/ui/apps/chat/src/lib/components/app/models/ModelLoadControl.svelte
+++ b/ui/apps/chat/src/lib/components/app/models/ModelLoadControl.svelte
@@ -31,7 +31,29 @@
<div class={['flex w-5 shrink-0 items-center justify-center', className]}>
{#if isLoading}
- <MODEL_LOAD_ICONS.loading class="{ICON_CLASS_DEFAULT} animate-spin text-muted-foreground" />
+ <MODEL_LOAD_ICONS.loading
+ class="{ICON_CLASS_DEFAULT} animate-spin text-muted-foreground {showAction && revealOnHover
+ ? 'group-hover:hidden [@media(pointer:coarse)]:hidden'
+ : ''}"
+ />
+
+ <div
+ class={!showAction
+ ? 'hidden'
+ : revealOnHover
+ ? 'hidden group-hover:flex [@media(pointer:coarse)]:flex'
+ : 'flex'}
+ >
+ <ActionIcon
+ class="h-5 w-5 hover:text-foreground"
+ icon={MODEL_LOAD_ICONS.cancel}
+ iconSize="h-4 w-4"
+ onclick={() => modelsStore.status.cancelLoad(option.model)}
+ stopPropagationOnClick
+ tooltip="Cancel loading model"
+ tooltipAsTitle
+ />
+ </div>
{:else}
<!-- the state dot is what the row shows at rest; the action takes its place on hover -->
{#if showAction && revealOnHover}
diff --git a/ui/apps/chat/src/lib/constants/icons.constants.ts b/ui/apps/chat/src/lib/constants/icons.constants.ts
index c096e9a69..c61000967 100644
--- a/ui/apps/chat/src/lib/constants/icons.constants.ts
+++ b/ui/apps/chat/src/lib/constants/icons.constants.ts
@@ -22,6 +22,7 @@ import LoadIcon from '@lucide/svelte/icons/power';
import RetryIcon from '@lucide/svelte/icons/rotate-cw';
import PromptCommandIcon from '@lucide/svelte/icons/sparkles';
import VideoIcon from '@lucide/svelte/icons/video';
+import CancelLoadIcon from '@lucide/svelte/icons/x';
import { ChatFormCommandAction, FileTypeCategory, ModelCapability } from '#lib/enums/index.ts';
import type { ModelCapabilities } from '#lib/types/models.js';
import type { Component } from 'svelte';
@@ -80,6 +81,7 @@ export const MODEL_DOWNLOAD_ICONS = {
/** Icons the model load control shows for its states and actions. */
export const MODEL_LOAD_ICONS = {
+ cancel: CancelLoadIcon,
failed: LoadFailedIcon,
load: LoadIcon,
loading: LoadingIcon,
diff --git a/ui/apps/chat/src/lib/stores/models/status.svelte.ts b/ui/apps/chat/src/lib/stores/models/status.svelte.ts
index ade2b701a..01d36e96c 100644
--- a/ui/apps/chat/src/lib/stores/models/status.svelte.ts
+++ b/ui/apps/chat/src/lib/stores/models/status.svelte.ts
@@ -152,6 +152,8 @@ export class ModelStatusManager {
private listedSidecarsByRepo = $derived.by(() =>
ModelsService.draftSidecarsByRepo(this.host.routerModels)
);
+ /** Models whose load the user cancelled; the failure the force-kill triggers is intentional, not a load failure. */
+ private loadCancelRequests = new SvelteSet<string>();
private loadingStates = new SvelteMap<string, boolean>();
private loadProgress = new SvelteMap<string, ModelLoadProgress>();
/** Paused downloads with their last reported progress, or null when none arrived before the pause. */
@@ -198,8 +200,8 @@ export class ModelStatusManager {
});
// /models/sse feed state, the single source of truth for status and load progress
private statusAbort: AbortController | null = null;
- private statusReaderActive = false;
+ private statusReaderActive = false;
private statusWaiters = new SvelteMap<
string,
{ target: ServerModelStatus; resolve: () => void; reject: (e: Error) => void }[]
@@ -269,10 +271,15 @@ export class ModelStatusManager {
this.subscribe();
+ // mark before the kill: the feed can report the child's death before
+ // this request returns, and load() must not toast it as a failure
+ this.loadCancelRequests.add(modelId);
+
try {
await ModelsService.unload(modelId);
toast.info(`Load cancelled: ${this.host.toDisplayName(modelId)}`);
} catch (error) {
+ this.loadCancelRequests.delete(modelId);
toast.error(`Failed to cancel load: ${this.host.toDisplayName(modelId)}`);
throw error;
@@ -516,11 +523,17 @@ export class ModelStatusManager {
toast.success(`Model loaded: ${this.host.toDisplayName(modelId)}`);
} catch (error) {
this.rejectStatus(modelId, error instanceof Error ? error : new Error('load failed'));
- this.host.error = error instanceof Error ? error.message : 'Failed to load model';
- toast.error(`Failed to load model: ${this.host.toDisplayName(modelId)}`);
+
+ // a user cancel force-kills the child, which settles this waiter as a
+ // failure; cancelLoad already reported the cancel, so stay silent
+ if (!this.loadCancelRequests.delete(modelId)) {
+ this.host.error = error instanceof Error ? error.message : 'Failed to load model';
+ toast.error(`Failed to load model: ${this.host.toDisplayName(modelId)}`);
+ }
throw error;
} finally {
+ this.loadCancelRequests.delete(modelId);
this.loadingStates.set(modelId, false);
}
}