Commit 77026f6e6 for llama.cpp

commit 77026f6e6184730c060727c52dd0fe306cd77f2e
Author: Aleksander Grygier <aleksander.grygier@gmail.com>
Date:   Wed Nov 25 13:47:52 2026 +0100

    ui: open the warm microphone only once the pointer rests on its button (#33033)

    The record button opened the microphone as soon as the pointer entered it,
    so a mouse only passing over turned the browser's recording indicator on.
    It now waits until the pointer (or the focus) has rested on the button for
    VOICE_WARMUP_REST_MS; moving on the button restarts the wait.

    Assisted-by: Claude (Opus 5.5 Medium)

diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatForm.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatForm.svelte
index f17cb3f90..775b4c295 100644
--- a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatForm.svelte
+++ b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatForm.svelte
@@ -903,7 +903,7 @@
 						voice={{
 							action: voice.label,
 							hint: voice.hint,
-							prepare: () => void voice.prepare(),
+							prepare: voice.prepare,
 							show: voice.showButton,
 							unavailableReason: voice.unavailableReason,
 							unprepare: voice.unprepare
diff --git a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormActions/ChatFormActionRecord.svelte b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormActions/ChatFormActionRecord.svelte
index 33d52171d..a583e9a17 100644
--- a/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormActions/ChatFormActionRecord.svelte
+++ b/ui/apps/chat/src/lib/components/app/chat/ChatForm/ChatFormActions/ChatFormActionRecord.svelte
@@ -27,7 +27,10 @@
 		/** With `secondary`: filled like the stop button it stands beside, not bare. */
 		filled?: boolean;
 		onMicClick?: () => void;
-		/** A mouse or the focus came to the button: a press may follow, the microphone can open. */
+		/**
+		 * A mouse or the focus is on the button: a press may follow, the microphone can open
+		 * once it rests there. Called again as the pointer moves on it.
+		 */
 		onPrepare?: () => void;
 		/** It left again without a press. */
 		onPrepareEnd?: () => void;
@@ -70,6 +73,11 @@
 		if (event.pointerType !== PointerType.TOUCH && !isRecording) onPrepare?.();
 	}

+	// the pointer still moving over the button is passing, so the wait for it to rest restarts
+	function handlePointerMove(event: PointerEvent) {
+		if (event.pointerType !== PointerType.TOUCH && !isRecording) onPrepare?.();
+	}
+
 	function handlePointerLeave(event: PointerEvent) {
 		if (event.pointerType !== PointerType.TOUCH) onPrepareEnd?.();
 	}
@@ -110,6 +118,7 @@
 				onpointerdown={handlePointerDown}
 				onpointerenter={handlePointerEnter}
 				onpointerleave={handlePointerLeave}
+				onpointermove={handlePointerMove}
 				type="button"
 				variant={isRecording || showWarning
 					? 'ghost'
diff --git a/ui/apps/chat/src/lib/constants/voice.constants.ts b/ui/apps/chat/src/lib/constants/voice.constants.ts
index d897a1c73..7fb1a80d0 100644
--- a/ui/apps/chat/src/lib/constants/voice.constants.ts
+++ b/ui/apps/chat/src/lib/constants/voice.constants.ts
@@ -47,6 +47,13 @@ export const VOICE_ELAPSED_TICK_MS = 200;
  */
 export const VOICE_PRESS_CLICK_MS = 1000;

+/**
+ * How long the pointer or the focus rests on the microphone button before the microphone
+ * opens ahead of a press, so a pointer only passing over it opens nothing (and the browser
+ * shows no recording indicator for it).
+ */
+export const VOICE_WARMUP_REST_MS = 300;
+
 /** How long a transcript that came back keeps looking for the message it belongs to. */
 export const VOICE_TRANSCRIPT_APPLY_RETRY_DELAYS_MS = [500, 1500, 4000] as const;

diff --git a/ui/apps/chat/src/lib/hooks/use-chat-form-voice.svelte.ts b/ui/apps/chat/src/lib/hooks/use-chat-form-voice.svelte.ts
index da024261b..259c9f1a8 100644
--- a/ui/apps/chat/src/lib/hooks/use-chat-form-voice.svelte.ts
+++ b/ui/apps/chat/src/lib/hooks/use-chat-form-voice.svelte.ts
@@ -27,7 +27,8 @@ import {
 	VOICE_CLIP_NAME_PREFIX,
 	VOICE_ELAPSED_TICK_MS,
 	VOICE_MODE_MESSAGE,
-	VOICE_SEPARATE_MODEL_HINT_LOCALSTORAGE_KEY
+	VOICE_SEPARATE_MODEL_HINT_LOCALSTORAGE_KEY,
+	VOICE_WARMUP_REST_MS
 } from '#lib/constants/index.ts';
 import { BooleanString, ChatFormVoiceState, MimeTypeAudio, VoiceMode } from '#lib/enums/index.ts';
 import { VoiceService } from '#lib/services/voice.service.ts';
@@ -115,6 +116,8 @@ export function useChatFormVoice(options: UseChatFormVoiceOptions) {
 	let generation = 0;
 	// the pointer or the focus is on the microphone button, see prepare
 	let preparing = false;
+	// waits for the pointer or the focus to rest on the button, see prepare
+	let restTimer: ReturnType<typeof setTimeout> | undefined;

 	const warmup = new MicrophoneWarmup();
 	const dictation = createDictation({
@@ -174,15 +177,27 @@ export function useChatFormVoice(options: UseChatFormVoiceOptions) {
 	}

 	/**
-	 * Opens the microphone while the pointer or the focus is on its button, if the page may
+	 * Opens the microphone once the pointer or the focus rests on its button, if the page may
 	 * already use it: by the click it has settled, so the first words are not quiet, and the
-	 * recording starts at once. Let go shortly after the pointer leaves (unprepare).
+	 * recording starts at once. Each call (the pointer moving on the button) waits again, so
+	 * a pointer only passing over opens nothing. Let go shortly after it leaves (unprepare).
 	 */
-	async function prepare() {
+	function prepare() {
 		if (!recorder || state !== ChatFormVoiceState.IDLE || resolution.mode === VoiceMode.UNAVAILABLE)
 			return;

 		preparing = true;
+		clearTimeout(restTimer);
+		restTimer = setTimeout(() => void openWarm(), VOICE_WARMUP_REST_MS);
+	}
+
+	async function openWarm() {
+		if (
+			!preparing ||
+			state !== ChatFormVoiceState.IDLE ||
+			resolution.mode === VoiceMode.UNAVAILABLE
+		)
+			return;

 		const wiring = await wiringFor(resolution.mode, resolution.transcriptionModel);

@@ -192,6 +207,7 @@ export function useChatFormVoice(options: UseChatFormVoiceOptions) {

 	function unprepare() {
 		preparing = false;
+		clearTimeout(restTimer);
 		warmup.release();
 	}

@@ -214,6 +230,8 @@ export function useChatFormVoice(options: UseChatFormVoiceOptions) {

 		const run = ++generation;

+		clearTimeout(restTimer);
+
 		try {
 			const wiring = await wiringFor(mode, model);
 			// the microphone the hover opened, when it is open for the same options
@@ -336,6 +354,7 @@ export function useChatFormVoice(options: UseChatFormVoiceOptions) {

 	onDestroy(() => {
 		preparing = false;
+		clearTimeout(restTimer);
 		warmup.drop();

 		if (state !== ChatFormVoiceState.IDLE) cancel();
diff --git a/ui/apps/chat/tests/client/chat-form-voice.svelte.test.ts b/ui/apps/chat/tests/client/chat-form-voice.svelte.test.ts
index a03f8248c..3c846682b 100644
--- a/ui/apps/chat/tests/client/chat-form-voice.svelte.test.ts
+++ b/ui/apps/chat/tests/client/chat-form-voice.svelte.test.ts
@@ -8,7 +8,7 @@ import ChatFormVoiceTestWrapper from './components/ChatFormVoiceTestWrapper.svel
 import { EditorView } from '@codemirror/view';
 import { VoiceTranscriptStatus } from '@ggml-org/llama-ui/voice';
 import { VoiceRecorderStatus } from '@ggml-org/llama-voice';
-import { SETTINGS_KEYS, VOICE_MODE_MESSAGE } from '#lib/constants/index.ts';
+import { SETTINGS_KEYS, VOICE_MODE_MESSAGE, VOICE_WARMUP_REST_MS } from '#lib/constants/index.ts';
 import { ServerRole, VoiceInputMode } from '#lib/enums/index.ts';
 import { voiceTranscriptsStore } from '#lib/stores/index.ts';
 import { parseFilesToMessageExtras } from '#lib/utils/browser-only.ts';
@@ -571,3 +571,59 @@ describe('a voice message', () => {
 		voiceTranscriptsStore.forget(file.name);
 	});
 });
+
+// the microphone opens ahead of a press only once the pointer rests on the button
+describe('the microphone warm-up', () => {
+	function grantMicrophone() {
+		const getUserMedia = vi.fn(async () => new MediaStream());
+		const spies = [
+			vi
+				.spyOn(navigator.permissions, 'query')
+				.mockResolvedValue({ state: 'granted' } as PermissionStatus),
+			vi.spyOn(navigator.mediaDevices, 'getUserMedia').mockImplementation(getUserMedia)
+		];
+
+		return { getUserMedia, restore: () => spies.forEach((spy) => spy.mockRestore()) };
+	}
+
+	const pointer = (type: string) =>
+		new PointerEvent(type, { bubbles: type !== 'pointerenter', pointerType: 'mouse' });
+
+	it('opens nothing for a pointer only passing over the button', async () => {
+		seed(true);
+
+		const mic = grantMicrophone();
+		const { screen } = await renderForm();
+		const button = screen
+			.getByRole('button', { name: VOICE_MODE_MESSAGE.voiceMessage })
+			.last()
+			.element();
+
+		button.dispatchEvent(pointer('pointerenter'));
+		button.dispatchEvent(pointer('pointermove'));
+		await new Promise((resolve) => setTimeout(resolve, VOICE_WARMUP_REST_MS / 2));
+		button.dispatchEvent(pointer('pointerleave'));
+		await new Promise((resolve) => setTimeout(resolve, VOICE_WARMUP_REST_MS * 2));
+
+		expect(mic.getUserMedia).not.toHaveBeenCalled();
+		mic.restore();
+	});
+
+	it('opens the microphone once the pointer rests on the button', async () => {
+		seed(true);
+
+		const mic = grantMicrophone();
+		const { screen } = await renderForm();
+		const button = screen
+			.getByRole('button', { name: VOICE_MODE_MESSAGE.voiceMessage })
+			.last()
+			.element();
+
+		button.dispatchEvent(pointer('pointerenter'));
+
+		await expect.poll(() => mic.getUserMedia.mock.calls.length).toBe(1);
+
+		button.dispatchEvent(pointer('pointerleave'));
+		mic.restore();
+	});
+});