Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(desktop): drop the queued mini voice start

Max99bddabc7199
diff --git a/docs/plans/2026-10-12-desktop-mini-delivery.md b/docs/plans/2026-10-12-desktop-mini-delivery.md
index 9d9182ef6..a389acc9d 100644
--- a/docs/plans/2026-10-12-desktop-mini-delivery.md
+++ b/docs/plans/2026-10-12-desktop-mini-delivery.md
@@ -58,12 +58,12 @@ can be verified on a real desktop test prerelease. Pet voice now appears
whenever Web Locks, `getUserMedia` and ASR are all available; missing Web Locks
still denies it, and hotkey/hold still falls back to text in that case. ASR
status is read as soon as voice may be used (the pet window starts unfocused,
-so this read does not wait for focus). Every press-and-hold entry (hotkey and
-avatar) goes through one queued decision that waits for that first read while
-held and falls back to text if released first. Each window reactivation re-reads it, so a settings change takes
-effect without restarting the pet; a failed re-read keeps the last known status.
-Availability gates only starting a capture; an active capture keeps its stop
-control.
+so this read does not wait for focus). A press-and-hold that arrives before
+the first read settles opens text immediately; it does not queue a later
+microphone start. Each window reactivation re-reads it, so a settings change
+takes effect without restarting the pet; a failed re-read keeps the last known
+status. Availability gates only starting a capture; an active capture keeps
+its stop control.
A microphone or transcription failure reopens the text input with the pre-voice
draft and a short note; the mini does not keep the failed recording for retry
(the main Composer does).
@@ -140,10 +140,13 @@ keeps its page-coloured plate solely to cover the surrounding web-page text.
## Validation
-- Focused pet, voice ownership, dictation-wrapper and bridge suites: 156 tests.
- The parity sweep also ran all 15 existing session-action hook tests,
- including “Show in pet”, and 13 session-action component tests:
- 184 passing UI tests in total.
+- Focused pet, voice ownership, dictation-wrapper and bridge suites: 156 tests
+ at the original desktop-mini delivery. This PR adds PetPage cases for
+ ungated production voice (failure notes, ASR refresh, stop-while-listening,
+ and text fallback while the first ASR read is pending); `npx vitest run
+ src/pet` is 136 passing. The original parity sweep also ran all 15 existing
+ session-action hook tests, including “Show in pet”, and 13 session-action
+ component tests: 184 passing UI tests in that baseline.
The five retained-card regressions were also run against isolated copies of
the pre-fix `be8701709` surface: all five fail because the revoked title
remains visible. They pass with the epoch repair. The temporary copies were
@@ -183,7 +186,7 @@ background work. A failed-first-session-read case verifies that the status event
performs a second read, restores the validated chat capability and permits a
send; it no longer uses the removed v1 session-title header as a proxy.
-The suite has 92 cases after additions. In particular, the quick-reply tests
+The suite had 92 cases after the original v2 additions; this PR adds the ungated-voice cases on top of that baseline. In particular, the quick-reply tests
exercise both orders of `message.updated` and the POST response, preserve the
single-message lock while pending, and verify an older update cannot reclaim a
newer result's options. A separate uncertain quick-reply case blocks both typed
diff --git a/ui/src/pet/PetPage.test.tsx b/ui/src/pet/PetPage.test.tsx
index c9be2accf..484146cc5 100644
--- a/ui/src/pet/PetPage.test.tsx
+++ b/ui/src/pet/PetPage.test.tsx
@@ -1723,26 +1723,26 @@ describe('desktop mini v2 interaction contract', () => {
});
});
- it('holds a voice summon until the first ASR status read settles', async () => {
+ it('opens text while the first ASR status read is still pending, and does not start voice when it later succeeds', async () => {
const status = deferred<{ ok: boolean; json: () => Promise<unknown> }>();
- class Dictation { done = new Promise<string>(() => {}); start = async () => {}; finish = () => {}; abort = () => {}; }
+ const start = vi.fn(async () => {});
+ class Dictation { done = new Promise<string>(() => {}); start = start; finish = () => {}; abort = () => {}; }
await withVoiceEnv(() => true, Dictation, async () => {
vi.stubGlobal('fetch', vi.fn(() => status.promise));
devBind('S'); render(<PetPage />); summon('listen');
- await act(async () => new Promise((resolve) => setTimeout(resolve, 15)));
- expect(screen.queryByRole('textbox')).toBeNull();
+ expect(await screen.findByRole('textbox')).toBeTruthy();
expect(pose()).not.toBe('listening');
await act(async () => status.resolve({ ok: true, json: async () => ({ available: true }) }));
- await waitFor(() => expect(pose()).toBe('listening'));
+ await waitFor(() => expect(screen.getByLabelText('pet.voice.open')).toBeTruthy());
+ expect(pose()).not.toBe('listening');
+ expect(start).not.toHaveBeenCalled();
});
});
- it.each([
- ['still held', true],
- ['released', false],
- ])('decides an avatar hold that outlives a pending ASR read once it settles (%s)', async (_label, held) => {
+ it('opens text from an avatar hold while ASR status is pending, and does not start voice when it later succeeds', async () => {
const status = deferred<{ ok: boolean; json: () => Promise<unknown> }>();
- class Dictation { done = new Promise<string>(() => {}); start = async () => {}; finish = () => {}; abort = () => {}; }
+ const start = vi.fn(async () => {});
+ class Dictation { done = new Promise<string>(() => {}); start = start; finish = () => {}; abort = () => {}; }
await withVoiceEnv(() => true, Dictation, async () => {
vi.stubGlobal('fetch', vi.fn(() => status.promise));
devBind('S'); render(<PetPage />); await screen.findByText('Session S');
@@ -1751,18 +1751,15 @@ describe('desktop mini v2 interaction contract', () => {
try {
fireEvent.pointerDown(avatar, { button: 0, pointerId: 1 });
await act(async () => vi.advanceTimersByTime(400));
- expect(screen.queryByRole('textbox')).toBeNull();
- expect(pose()).not.toBe('listening');
- if (!held) fireEvent.pointerUp(avatar, { pointerId: 1 });
- await act(async () => status.resolve({ ok: true, json: async () => ({ available: true }) }));
} finally {
vi.useRealTimers();
}
- if (held) await waitFor(() => expect(pose()).toBe('listening'));
- else {
- expect(await screen.findByRole('textbox')).toBeTruthy();
- expect(pose()).not.toBe('listening');
- }
+ expect(await screen.findByRole('textbox')).toBeTruthy();
+ expect(pose()).not.toBe('listening');
+ await act(async () => status.resolve({ ok: true, json: async () => ({ available: true }) }));
+ await waitFor(() => expect(screen.getByLabelText('pet.voice.open')).toBeTruthy());
+ expect(pose()).not.toBe('listening');
+ expect(start).not.toHaveBeenCalled();
});
});
diff --git a/ui/src/pet/PetPage.tsx b/ui/src/pet/PetPage.tsx
index 29eb72cd0..39d0a199d 100644
--- a/ui/src/pet/PetPage.tsx
+++ b/ui/src/pet/PetPage.tsx
@@ -421,9 +421,9 @@ const PetSurface: React.FC = () => {
if (!listenPending || !binding || !canChat || !expanded) return;
petComposer.takeListen();
if (uncertain) { setDetailOpen(true); return; }
- if (hotkeyHeld.current) voice.begin();
+ if (hotkeyHeld.current && voice.available) voice.start();
else openComposer(draft);
- }, [listenPending, binding, canChat, expanded, voice.begin, openComposer, draft, uncertain]);
+ }, [listenPending, binding, canChat, expanded, voice.available, voice.start, openComposer, draft, uncertain]);
useEffect(() => {
const onBlur = () => { if (!voice.listening && !draft.trim()) void setPanel(false); };
window.addEventListener('blur', onBlur);
@@ -484,7 +484,8 @@ const PetSurface: React.FC = () => {
target.setPointerCapture?.(pointerId);
if (!canChat || !binding) { void setPanel(true); return; }
if (uncertain) { void setPanel(true); setDetailOpen(true); return; }
- voice.begin();
+ if (voice.available) voice.start();
+ else openComposer(draft);
}, HOLD_MS) };
}}
onPointerMove={(event) => {
@@ -715,8 +716,7 @@ function useHitRegions(rootRef: React.RefObject<HTMLDivElement | null>, epoch?:
}
function usePetVoice({ enabled, epoch, draft, onOpenComposer }: { enabled: boolean; epoch: PetSurfaceEpoch; draft: string; onOpenComposer: (text?: string) => void }) {
- // `settled` turns true once the first status read has finished either way.
- const [asr, setAsr] = useState<{ available: boolean; checked: boolean; settled: boolean; maxFileBytes?: number }>({ available: false, checked: false, settled: false });
+ const [asr, setAsr] = useState<{ available: boolean; checked: boolean; maxFileBytes?: number }>({ available: false, checked: false });
const [preview, setPreview] = useState('');
const [listening, setListening] = useState(false);
// A failed capture or transcription falls back to text with this note.
@@ -734,26 +734,15 @@ function usePetVoice({ enabled, epoch, draft, onOpenComposer }: { enabled: boole
if (!enabled) return;
let alive = true;
// A failed re-read keeps the last known status instead of flapping to off.
- const unknown = () => setAsr((current) => (current.checked ? current : { available: false, checked: false, settled: true }));
+ const unknown = () => setAsr((current) => (current.checked ? current : { available: false, checked: false }));
void fetch('/api/asr/status', { credentials: 'same-origin' }).then((response) => response.ok ? response.json() : null).then((value) => {
if (!alive || !epoch.isCurrent()) return;
if (value === null) unknown();
- else setAsr({ available: Boolean(value.available), checked: true, settled: true, maxFileBytes: value.max_file_bytes });
+ else setAsr({ available: Boolean(value.available), checked: true, maxFileBytes: value.max_file_bytes });
}).catch(() => { if (alive && epoch.isCurrent()) unknown(); });
return () => { alive = false; };
}, [enabled, epoch, asrReads]);
- // A press-and-hold is queued here and decided by an effect with the current
- // render's state, so callers holding a stale closure still decide correctly.
- // Before the first status read settles a held press waits; releasing it
- // falls back to text right away.
- const queuedRef = useRef<'held' | 'released' | null>(null);
- const [queueTick, setQueueTick] = useState(0);
const stop = useCallback((commit: boolean) => {
- if (queuedRef.current) {
- queuedRef.current = commit ? 'released' : null;
- setQueueTick((tick) => tick + 1);
- return;
- }
const capture = captureRef.current;
if (!capture) return;
capture.ending = true;
@@ -806,24 +795,7 @@ function usePetVoice({ enabled, epoch, draft, onOpenComposer }: { enabled: boole
const clearError = useCallback(() => setError(null), []);
useEffect(() => cancel, [epoch, enabled, cancel]);
useEffect(() => () => setError(null), [epoch, enabled]);
- // Press-and-hold entry for every surface (hotkey and avatar): voice when it
- // is available, text otherwise.
- const pending = enabled && supported && !asr.settled;
- const begin = useCallback(() => {
- queuedRef.current = 'held';
- setQueueTick((tick) => tick + 1);
- }, []);
- useEffect(() => {
- const queued = queuedRef.current;
- if (!queued || (queued === 'held' && pending)) return;
- queuedRef.current = null;
- // A deferred press handler: it acts on a user press once state allows.
- // eslint-disable-next-line react-hooks/set-state-in-effect
- if (queued === 'held' && available) start();
- else onOpenComposer(draft);
- }, [queueTick, pending, available, start, onOpenComposer, draft]);
- useEffect(() => () => { queuedRef.current = null; }, [epoch, enabled]);
- return { available, begin, cloudRequired: asr.checked && !asr.available, listening, preview, error, clearError, start, stop, cancel };
+ return { available, cloudRequired: asr.checked && !asr.available, listening, preview, error, clearError, start, stop, cancel };
}
type VoiceFailure = 'startFailed' | 'empty' | 'failed';