Spaces:
Sleeping
fix: KI-026 — voice mode mutual exclusion (Live blocks legacy mic paths)
Browse filesUser report 2026-05-14: Live ✓ mode produced duplicate user messages,
duplicate bot replies, and two TTS audios played simultaneously for one
spoken utterance. Root cause: three voice paths share no exclusion guard.
Path 1 — Live mode (useLiveConversation): persistent mic stream + VAD +
its OWN MediaRecorder → onUtterance → transcribe → postChat.
Path 2 — Push-to-talk (🎤 button → startRecording): independent mic
stream + ITS OWN MediaRecorder → on stop, transcribe → send → postChat.
Path 3 — Hands-free useEffect: auto-calls startRecording (path 2).
When Live ✓ was on and the user also clicked the 🎤 button (or had
Hands-free ticked), both Path 1 and Path 2 captured the same speech in
slightly different audio buffers, produced slightly different transcripts
("Yeah, no, no parent plans..." vs "No, no parent plans..."), and both
posted to /api/chat. The orchestrator advanced fact-find state on each,
producing different replies to what the user perceived as one utterance.
Fix: three independent guards.
1. startRecording() — early-return + console.warn when live.live is on.
Defends against any UI control that fires the legacy path.
2. Hands-free useEffect — no-op when live.live is on. Also flips the
dependency so the effect re-evaluates when Live toggles.
3. 🎤 mic button — disabled={... || live.live}; title shows "Live mode
is active — voice is handled automatically".
4. Hands-free checkbox — disabled + dimmed when Live is on; tooltip
"Turn off Live to use Hands-free".
After: only ONE voice path can dispatch chat at a time. The other two
controls visually communicate why they're disabled.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- frontend/src/app/page.tsx +27 -5
|
@@ -175,13 +175,17 @@ export default function Page() {
|
|
| 175 |
// care of re-opening the mic after each assistant TTS finishes.
|
| 176 |
useEffect(() => {
|
| 177 |
handsFreeRef.current = handsFree;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
if (handsFree && !recording && !busy) {
|
| 179 |
startRecording();
|
| 180 |
} else if (!handsFree && recording) {
|
| 181 |
stopRecording();
|
| 182 |
}
|
| 183 |
// eslint-disable-next-line react-hooks/exhaustive-deps
|
| 184 |
-
}, [handsFree]);
|
| 185 |
|
| 186 |
function pushUser(text: string) {
|
| 187 |
setMessages((m) => [...m, { id: `u_${Date.now()}`, role: "user", content: text }]);
|
|
@@ -405,6 +409,15 @@ export default function Page() {
|
|
| 405 |
}, [messages, sessionId, ttsLang, openPolicy, showMarketplace, showProfile, showPremium]);
|
| 406 |
|
| 407 |
async function startRecording() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 408 |
try {
|
| 409 |
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
| 410 |
const mime = MediaRecorder.isTypeSupported("audio/webm") ? "audio/webm" : "";
|
|
@@ -717,11 +730,11 @@ export default function Page() {
|
|
| 717 |
<button
|
| 718 |
type="button"
|
| 719 |
onClick={recording ? stopRecording : startRecording}
|
| 720 |
-
disabled={busy && !recording}
|
| 721 |
className={`shrink-0 w-11 h-11 rounded-xl flex items-center justify-center transition-all ${
|
| 722 |
recording ? "bg-[var(--error)] text-white animate-record-pulse" : "bg-[var(--muted)] hover:bg-[var(--border)]"
|
| 723 |
} disabled:opacity-40`}
|
| 724 |
-
title={recording ? "Stop recording" : "Voice input"}
|
| 725 |
>
|
| 726 |
{recording ? <StopIcon /> : <MicIcon />}
|
| 727 |
</button>
|
|
@@ -739,8 +752,17 @@ export default function Page() {
|
|
| 739 |
<label className="flex items-center gap-1.5 cursor-pointer">
|
| 740 |
<input type="checkbox" checked={returnAudio} onChange={(e) => setReturnAudio(e.target.checked)} className="w-3.5 h-3.5 accent-[var(--primary)]" /> Voice reply
|
| 741 |
</label>
|
| 742 |
-
<label
|
| 743 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 744 |
</label>
|
| 745 |
{/* Live conversation — full-duplex with VAD barge-in. Speak any
|
| 746 |
time, even while the bot is still talking, and it stops mid-
|
|
|
|
| 175 |
// care of re-opening the mic after each assistant TTS finishes.
|
| 176 |
useEffect(() => {
|
| 177 |
handsFreeRef.current = handsFree;
|
| 178 |
+
// KI-026 — when Live mode is active it owns the mic; Hands-free must NOT
|
| 179 |
+
// also try to open it. If user enables Hands-free while Live is on, just
|
| 180 |
+
// ignore the request.
|
| 181 |
+
if (live.live) return;
|
| 182 |
if (handsFree && !recording && !busy) {
|
| 183 |
startRecording();
|
| 184 |
} else if (!handsFree && recording) {
|
| 185 |
stopRecording();
|
| 186 |
}
|
| 187 |
// eslint-disable-next-line react-hooks/exhaustive-deps
|
| 188 |
+
}, [handsFree, live.live]);
|
| 189 |
|
| 190 |
function pushUser(text: string) {
|
| 191 |
setMessages((m) => [...m, { id: `u_${Date.now()}`, role: "user", content: text }]);
|
|
|
|
| 409 |
}, [messages, sessionId, ttsLang, openPolicy, showMarketplace, showProfile, showPremium]);
|
| 410 |
|
| 411 |
async function startRecording() {
|
| 412 |
+
// KI-026 (2026-05-14) — voice mode mutual exclusion. If Live mode is
|
| 413 |
+
// active it owns the mic + the chat dispatch; the legacy push-to-talk
|
| 414 |
+
// and Hands-free paths must NOT run in parallel or we get duplicate
|
| 415 |
+
// user transcripts + duplicate /api/chat dispatches + duplicate TTS
|
| 416 |
+
// playback (the bug visible in the 2026-05-14 user screenshot).
|
| 417 |
+
if (live.live) {
|
| 418 |
+
console.warn("[voice] startRecording blocked — Live mode is active");
|
| 419 |
+
return;
|
| 420 |
+
}
|
| 421 |
try {
|
| 422 |
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
| 423 |
const mime = MediaRecorder.isTypeSupported("audio/webm") ? "audio/webm" : "";
|
|
|
|
| 730 |
<button
|
| 731 |
type="button"
|
| 732 |
onClick={recording ? stopRecording : startRecording}
|
| 733 |
+
disabled={(busy && !recording) || live.live}
|
| 734 |
className={`shrink-0 w-11 h-11 rounded-xl flex items-center justify-center transition-all ${
|
| 735 |
recording ? "bg-[var(--error)] text-white animate-record-pulse" : "bg-[var(--muted)] hover:bg-[var(--border)]"
|
| 736 |
} disabled:opacity-40`}
|
| 737 |
+
title={live.live ? "Live mode is active — voice is handled automatically" : recording ? "Stop recording" : "Voice input"}
|
| 738 |
>
|
| 739 |
{recording ? <StopIcon /> : <MicIcon />}
|
| 740 |
</button>
|
|
|
|
| 752 |
<label className="flex items-center gap-1.5 cursor-pointer">
|
| 753 |
<input type="checkbox" checked={returnAudio} onChange={(e) => setReturnAudio(e.target.checked)} className="w-3.5 h-3.5 accent-[var(--primary)]" /> Voice reply
|
| 754 |
</label>
|
| 755 |
+
<label
|
| 756 |
+
className={`flex items-center gap-1.5 ${live.live ? "opacity-40 cursor-not-allowed" : "cursor-pointer"}`}
|
| 757 |
+
title={live.live ? "Disabled — Live mode is on. Turn off Live to use Hands-free." : "Hands-free voice — auto-submits when you stop speaking"}
|
| 758 |
+
>
|
| 759 |
+
<input
|
| 760 |
+
type="checkbox"
|
| 761 |
+
checked={handsFree && !live.live}
|
| 762 |
+
disabled={live.live}
|
| 763 |
+
onChange={(e) => setHandsFree(e.target.checked)}
|
| 764 |
+
className="w-3.5 h-3.5 accent-[var(--primary)]"
|
| 765 |
+
/> Hands-free
|
| 766 |
</label>
|
| 767 |
{/* Live conversation — full-duplex with VAD barge-in. Speak any
|
| 768 |
time, even while the bot is still talking, and it stops mid-
|