rohitsar567 commited on
Commit
a6115b2
·
1 Parent(s): 47e7eeb

fix(voice): KI-131 — voice OFF by default + surface AudioWorklet failure

Browse files

Two bugs reported on live HF Space after KI-130 deploy:

Issue A — voice mode shows green 'Voice on — just speak' pill at page load
even for users who never opted in. Root cause: the useEffect in page.tsx
rehydrated insurance_live_pref from localStorage and flipped userPrefersLive
to true if a prior session had set it 'on'. Combined with ADR-028's
'Default ON' decision, anyone who'd ever visited had a sticky-green pill.

Fix: remove the rehydration entirely + wipe the stale key on every load.
Voice is now strictly opt-in per visit until the user clicks the pill.
The persist-on-toggle effect at L210 still writes the user's *current*
choice, but no one starts green. NOTE: this amends ADR-028; an ADR-033
should be written to record the new default — flagging as a follow-up.

Issue B — voice was on but the mic captured nothing. Root cause (most
likely per voice-diagnosis agent): AudioWorklet.addModule() can fail
silently on some browsers/devices; the previous catch block at
useLiveConversation.ts:539 only console.error'd, leaving live.live=true
and micPermissionDenied=false. Result: green pill, no PCM frames, no
waveform, no transcription. The user sees 'Voice on' but nothing happens.

Fix: when the worklet setup throws, flip BOTH setLive(false) AND
setMicPermissionDenied(true) so the pill correctly switches to
'🔇 Mic blocked' — at least the user gets a visible failure signal
rather than silent breakage. If the worklet succeeds, behavior is
unchanged.

This is a blind fix for suspect #1 in the agent's ranked list. If the
user still can't get mic working after KI-131 deploys, the next step is
DevTools Console + Network inspection on the live Space (agent has a
checklist; gated on this commit landing first).

frontend/src/app/page.tsx CHANGED
@@ -197,12 +197,13 @@ export default function Page() {
197
  // actual mic state, PTT temporarily flips it to false during a recording
198
  // even while userPrefersLive stays true (so Live resumes after PTT).
199
  const [userPrefersLive, setUserPrefersLive] = useState(false);
200
- // Load persisted preference on mount. Only "on" persists; default and
201
- // explicit "off" both render grey.
 
 
202
  useEffect(() => {
203
  if (typeof window === "undefined") return;
204
- const pref = localStorage.getItem("insurance_live_pref");
205
- if (pref === "on") setUserPrefersLive(true);
206
  }, []);
207
  // Persist + sync to the live hook whenever the user toggles preference.
208
  useEffect(() => {
 
197
  // actual mic state, PTT temporarily flips it to false during a recording
198
  // even while userPrefersLive stays true (so Live resumes after PTT).
199
  const [userPrefersLive, setUserPrefersLive] = useState(false);
200
+ // KI-131 (2026-05-15) — voice is OFF by default. Previously persisted
201
+ // "on" preferences are wiped on next load so users with a stale green
202
+ // pill from before this change also see grey and have to re-opt in.
203
+ // This amends ADR-028 "Default ON" — see ADR-033 for rationale.
204
  useEffect(() => {
205
  if (typeof window === "undefined") return;
206
+ localStorage.removeItem("insurance_live_pref");
 
207
  }, []);
208
  // Persist + sync to the live hook whenever the user toggles preference.
209
  useEffect(() => {
frontend/src/lib/useLiveConversation.ts CHANGED
@@ -536,8 +536,17 @@ export function useLiveConversation(opts: LiveConversationOptions): LiveConversa
536
  node.connect(silentSink);
537
  silentSink.connect(ctx.destination);
538
  } catch (e) {
 
 
 
 
 
 
539
  // eslint-disable-next-line no-console
540
- console.error("[live-mode] AudioWorklet setup failed; fallback to silence", e);
 
 
 
541
  }
542
 
543
  setMicPermissionDenied(false);
 
536
  node.connect(silentSink);
537
  silentSink.connect(ctx.destination);
538
  } catch (e) {
539
+ // KI-131 (2026-05-15) — previously, a worklet-setup failure left
540
+ // setMicPermissionDenied=false and live.live=true so the UI pill
541
+ // stayed green ("Voice on — just speak") while no PCM frames were
542
+ // ever delivered — silent functional break. Now flip both states
543
+ // so the pill correctly switches to "🔇 Mic blocked" and the user
544
+ // gets a visible signal that voice is broken on their device.
545
  // eslint-disable-next-line no-console
546
+ console.error("[live-mode] AudioWorklet setup failed", e);
547
+ setMicPermissionDenied(true);
548
+ setLive(false);
549
+ return;
550
  }
551
 
552
  setMicPermissionDenied(false);