Commit 3fccd98e9 for llama.cpp
commit 3fccd98e9dba9f19b2f5bf3818e06c3262adcf3e
Author: Aleksander Grygier <aleksander.grygier@gmail.com>
Date: Tue Nov 24 09:25:04 2026 +0100
ui: let the chat form's model selection decide the submit state (#32920)
When the last assistant message came from a model that is no longer
available, the submit button stayed red and disabled even after an
available model was picked in the form, since availability checked the
conversation's model first. The form's selection now decides it; the
conversation's model only counts when nothing is selected.
Assisted-by: Claude (Opus 5.5 Medium)
diff --git a/ui/apps/chat/src/lib/hooks/use-chat-form-model.svelte.ts b/ui/apps/chat/src/lib/hooks/use-chat-form-model.svelte.ts
index d9f81b6ad..a2b559ac7 100644
--- a/ui/apps/chat/src/lib/hooks/use-chat-form-model.svelte.ts
+++ b/ui/apps/chat/src/lib/hooks/use-chat-form-model.svelte.ts
@@ -11,6 +11,7 @@
import { conversationsStore, modelsStore, serverStore } from '#lib/stores/index.ts';
import type { DatabaseMessage } from '#lib/types/database.js';
import { getConversationModel } from '#lib/utils/index.ts';
+import { getChatFormModelState } from '#lib/utils/model-selection.ts';
export function useChatFormModel() {
const isRouter = $derived(serverStore.isRouterMode);
@@ -82,22 +83,17 @@ export function useChatFormModel() {
return activeModelId ? modelsStore.props.modelSupportsVision(activeModelId) : false;
});
- const hasModelSelected = $derived(
- !isRouter || !!conversationModel || !!modelsStore.selectedModelId
+ // the form's selection decides the state; the conversation's model only counts when nothing is selected
+ const modelState = $derived(
+ getChatFormModelState({
+ conversationModel,
+ isRouter,
+ models: modelsStore.models,
+ selectedModelId: modelsStore.selectedModelId
+ })
);
- const isSelectedModelInCache = $derived.by(() => {
- if (!isRouter) return true;
-
- if (conversationModel) {
- return modelsStore.models.some((option) => option.model === conversationModel);
- }
-
- const currentModelId = modelsStore.selectedModelId;
-
- if (!currentModelId) return false;
-
- return modelsStore.models.some((option) => option.id === currentModelId);
- });
+ const hasModelSelected = $derived(modelState.hasModelSelected);
+ const isSelectedModelInCache = $derived(modelState.isSelectedModelAvailable);
return {
get conversationModel() {
diff --git a/ui/apps/chat/src/lib/utils/model-selection.ts b/ui/apps/chat/src/lib/utils/model-selection.ts
new file mode 100644
index 000000000..948c7efef
--- /dev/null
+++ b/ui/apps/chat/src/lib/utils/model-selection.ts
@@ -0,0 +1,43 @@
+import type { ModelOption } from '#lib/types/models.js';
+
+export interface ChatFormModelStateInput {
+ conversationModel: string | null;
+ isRouter: boolean;
+ models: readonly Pick<ModelOption, 'id' | 'model'>[];
+ selectedModelId: string | null;
+}
+
+export interface ChatFormModelState {
+ hasModelSelected: boolean;
+ isSelectedModelAvailable: boolean;
+}
+
+/**
+ * Whether the chat form has a model to send with and whether that model is available.
+ * The form's own selection always wins; the conversation's last model only counts
+ * when nothing is selected in the form.
+ */
+export function getChatFormModelState({
+ conversationModel,
+ isRouter,
+ models,
+ selectedModelId
+}: ChatFormModelStateInput): ChatFormModelState {
+ if (!isRouter) return { hasModelSelected: true, isSelectedModelAvailable: true };
+
+ if (selectedModelId) {
+ return {
+ hasModelSelected: true,
+ isSelectedModelAvailable: models.some((option) => option.id === selectedModelId)
+ };
+ }
+
+ if (conversationModel) {
+ return {
+ hasModelSelected: true,
+ isSelectedModelAvailable: models.some((option) => option.model === conversationModel)
+ };
+ }
+
+ return { hasModelSelected: false, isSelectedModelAvailable: false };
+}
diff --git a/ui/apps/chat/tests/client/chat-form-model-availability.svelte.test.ts b/ui/apps/chat/tests/client/chat-form-model-availability.svelte.test.ts
new file mode 100644
index 000000000..2ea96c704
--- /dev/null
+++ b/ui/apps/chat/tests/client/chat-form-model-availability.svelte.test.ts
@@ -0,0 +1,84 @@
+// Regression: when the conversation's last assistant message names a model that is no
+// longer available, picking an available model in the chat form must clear the submit
+// button's error state. The form's selection always decides it.
+
+import ChatFormTestWrapper from './components/ChatFormTestWrapper.svelte';
+import { MessageRole, ServerRole } from '#lib/enums/index.ts';
+import { conversationsStore } from '#lib/stores/conversations/index.svelte.ts';
+import { serverStore } from '#lib/stores/llama-server.svelte.ts';
+import { modelsStore } from '#lib/stores/models/index.svelte.ts';
+import type { DatabaseMessage, ModelOption } from '#lib/types/index.ts';
+import { tick } from 'svelte';
+import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+import { render } from 'vitest-browser-svelte';
+
+const AVAILABLE: ModelOption = {
+ capabilities: [],
+ id: 'org/available:Q4_K_M',
+ model: 'org/available:Q4_K_M',
+ name: 'org/available:Q4_K_M'
+};
+const GONE = 'org/gone:Q4_K_M';
+
+function assistantMessage(model: string): DatabaseMessage {
+ return {
+ children: [],
+ content: 'Hello',
+ convId: 'c1',
+ id: 'm1',
+ model,
+ parent: null,
+ role: MessageRole.ASSISTANT,
+ timestamp: 0,
+ type: 'text'
+ } as DatabaseMessage;
+}
+
+function sendButton(container: HTMLElement) {
+ const button = container.querySelector<HTMLButtonElement>('button[type="submit"]');
+
+ if (!button) throw new Error('send button not rendered');
+
+ return button;
+}
+
+const isErrorState = (button: HTMLButtonElement) => button.classList.contains('bg-surface-danger');
+
+beforeEach(() => {
+ serverStore.role = ServerRole.ROUTER;
+ modelsStore.models = [AVAILABLE];
+ modelsStore.clearSelection();
+ conversationsStore.activeMessages = [assistantMessage(GONE)];
+});
+
+afterEach(() => {
+ conversationsStore.activeMessages = [];
+ modelsStore.clearSelection();
+ modelsStore.models = [];
+});
+
+describe('ChatForm model availability', () => {
+ it('shows the error state while the only model is the conversation one that is gone', async () => {
+ const { container } = render(ChatFormTestWrapper, { initialValue: 'Hi' });
+
+ await tick();
+
+ const button = sendButton(container);
+
+ expect(isErrorState(button)).toBe(true);
+ expect(button.disabled).toBe(true);
+ });
+
+ it('clears the error state once an available model is selected in the form', async () => {
+ const { container } = render(ChatFormTestWrapper, { initialValue: 'Hi' });
+
+ await tick();
+ await modelsStore.selectModelById(AVAILABLE.id);
+ await tick();
+
+ const button = sendButton(container);
+
+ expect(isErrorState(button)).toBe(false);
+ expect(button.disabled).toBe(false);
+ });
+});
diff --git a/ui/apps/chat/tests/unit/chat-form-model-state.test.ts b/ui/apps/chat/tests/unit/chat-form-model-state.test.ts
new file mode 100644
index 000000000..ab8281206
--- /dev/null
+++ b/ui/apps/chat/tests/unit/chat-form-model-state.test.ts
@@ -0,0 +1,70 @@
+// Guards which model decides the chat form's submit state: the form's own selection
+// always wins over the model of the conversation's last assistant message.
+
+import { getChatFormModelState } from '#lib/utils/model-selection.ts';
+import { describe, expect, it } from 'vitest';
+
+const AVAILABLE = { id: 'org/available:Q4_K_M', model: 'org/available:Q4_K_M' };
+const GONE = 'org/gone:Q4_K_M';
+
+describe('getChatFormModelState', () => {
+ it('reports an available model when the form selects one, even if the conversation used a gone model', () => {
+ expect(
+ getChatFormModelState({
+ conversationModel: GONE,
+ isRouter: true,
+ models: [AVAILABLE],
+ selectedModelId: AVAILABLE.id
+ })
+ ).toEqual({ hasModelSelected: true, isSelectedModelAvailable: true });
+ });
+
+ it('reports an unavailable model when the form selects one that left the list', () => {
+ expect(
+ getChatFormModelState({
+ conversationModel: AVAILABLE.model,
+ isRouter: true,
+ models: [AVAILABLE],
+ selectedModelId: GONE
+ })
+ ).toEqual({ hasModelSelected: true, isSelectedModelAvailable: false });
+ });
+
+ it('falls back to the conversation model when nothing is selected in the form', () => {
+ const state = (conversationModel: string) =>
+ getChatFormModelState({
+ conversationModel,
+ isRouter: true,
+ models: [AVAILABLE],
+ selectedModelId: null
+ });
+
+ expect(state(GONE)).toEqual({ hasModelSelected: true, isSelectedModelAvailable: false });
+ expect(state(AVAILABLE.model)).toEqual({
+ hasModelSelected: true,
+ isSelectedModelAvailable: true
+ });
+ });
+
+ it('has no model selected on a router with neither a selection nor a conversation model', () => {
+ expect(
+ getChatFormModelState({
+ conversationModel: null,
+ isRouter: true,
+ models: [AVAILABLE],
+ selectedModelId: null
+ })
+ ).toEqual({ hasModelSelected: false, isSelectedModelAvailable: false });
+ });
+
+ it('always has an available model outside router mode', () => {
+ expect(
+ getChatFormModelState({
+ conversationModel: GONE,
+ isRouter: false,
+ models: [],
+ selectedModelId: null
+ })
+ ).toEqual({ hasModelSelected: true, isSelectedModelAvailable: true });
+ });
+});