Skip to content

fix(workspace): dictate on the path we control, and say why voice failed (#2212) - #2239

Merged
vybe merged 1 commit into
devfrom
fix/2212-portal-stt-silent-failures
Aug 17, 2026
Merged

vybe merged 1 commit into
devfrom
fix/2212-portal-stt-silent-failures

Conversation

@dolho

@dolho dolho commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

What this fixes

The Workspace mic "kind of turns on and dies instantly", with nothing shown, and dictation never reaches the composer. Two independent causes.

1. The branch — we preferred the path we do not control

micMode chose the browser Web Speech API whenever the object merely existed, so Chrome never reached the MediaRecorder + /stt path.

Real signal captured (Playwright Chromium, http://127.0.0.1 secure context, microphone permission granted, --use-fake-device-for-media-stream):

capabilities: {"hasSpeechRec":true,"hasMediaDevices":true,"hasMediaRecorder":true,"isSecureContext":true}
WEB SPEECH: { "continuousDefault": false, "threw": null, "endedBy": "timeout-15s", "events": [] }
MEDIARECORDER: { "ok": true, "mimeType": "audio/webm;codecs=opus", "bytesFor2s": 24236 }

start() does not throw and the engine then emits no event at all — no start, no audiostart, no result, no error, no end — so listening sticks on with no recourse. continuous also defaults to false, so even where the service does answer (official Chrome), recognition ends at the first pause. It is a browser-hosted, Google-backed service: not ours to fix, not ours to see into.

2. The silence — every failure path discarded its own signal

onerror dropped the error code; getUserMedia was wrapped in catch { return } (a denied mic is then indistinguishable from success-then-stop); a short blob was dropped with no feedback; the transcription call ended in catch { /* keep text mode */ }.

Changes

  • Prefer the server path. resolveMicMode picks record (MediaRecorder → POST /stt) whenever the platform can transcribe — that path is ours end to end: a real status, a real message, a real transcript. Web Speech stays the no-key fallback instead of the default.
  • A separate honest bit. New roster-card field stt_available = exactly the /stt gate (platform ElevenLabs key resolves). It cannot be folded into voice_available, which additionally needs an effective voice to speak with: on a key-but-no-voice agent, dictation works and narration does not, and one bit has no correct answer for that. With neither path available the mic is not rendered — no dead control.
  • Every failure speaks, in one inline aria-live notice beside a composer that still works: SpeechRecognition error codes (blocked permission vs unreachable service — the distinction the discarded code held), the getUserMedia rejection name, a too-short recording, the /stt detail verbatim, and a narration (TTS) failure.
  • A watchdog for the engine that reports nothing (the measured case), so the button cannot stay lit forever.
  • continuous = true plus final-result accumulation, so a pause is not the end of dictation.
  • Firefox upload mislabel, found while verifying. Firefox reports mediaRec.mimeType === "" and puts audio/ogg; codecs=opus on the chunks, so every clip from the one engine that always records was uploaded as voice.webm labelled audio/webm while containing Ogg. resolveRecordingMimeType reads the chunk when the recorder is silent.

Decisions live in pure helpers (portalUtils.js) because this project has no component-mount harness; the wiring is pinned by source-structure guards in the shape of portalVoiceModePersistence.spec.js.

Acceptance criteria

  • Root cause confirmed with the real signal captured — the probe above; not inferred.

  • Dictation produces a transcript — real end-to-end: ElevenLabs TTS → Chromium fake-mic capture → MediaRecorder (audio/webm;codecs=opus, 97 KB) → ElevenLabs Scribe returned "Book the meeting for Thursday afternoon and send Rachel the agenda.", the sentence spoken in.

  • Failures surfaced with an actionable message — permission denied / no speech / network-service / not configured / too short / provider detail, each its own line (asserted distinct in tests).

  • No dead control — mic hidden when neither path can work; the card bit and the endpoint's own 404 gate are asserted to be the same condition, since drift between them is the dead-control bug.

  • Verified in both engines, feeding each engine's real capabilities into the shipped resolver:

    engine speechApi canRecord with key without key
    Chromium true true record speech
    Firefox false true record (no mic)
  • Header speaker toggle (TTS) reviewed separately — it stays on its own voice_available gate, untouched apart from now reporting a failure instead of silently doing nothing; the bug(voice): agents tell Workspace clients the surface is text-only — portal TTS is never advertised, and the channel/portal voice gates disagree #2157 gate test still passes, and the TTS provider call returned 200 with this instance's key during the end-to-end above.

  • Room composer — components/rooms/RoomComposer.vue has no mic/voice control (the only STT call site in the frontend is PortalConversation.vue), so there is nothing to apply there.

Verification

  • vitest run — 841 passed / 37 files (34 new in portalVoiceDictation.spec.js)
  • pytest tests/unit/test_2212_portal_stt_gate.py — 6 passed
  • every client_portal backend unit test — 444 passed
  • vite build clean; check-design-tokens clean

Fixes #2212

🤖 Generated with Claude Code

…led (#2212)

The Workspace mic "kind of turns on and dies instantly" with nothing shown.
Two causes, both fixed here.

THE BRANCH. `micMode` preferred the browser Web Speech API whenever the object
merely EXISTED, so Chrome never reached the MediaRecorder path. Measured in
Playwright's Chromium (secure context, microphone permission granted, fake audio
device): `webkitSpeechRecognition` exists, `start()` does not throw, and the
engine then emits NO event at all for 15s — no start, no audiostart, no result,
no error, no end. `continuous` also defaults to false, so even where the service
does answer, recognition ends at the first pause. That API is a browser-hosted,
Google-backed service: not ours to fix and not ours to see into.

THE SILENCE. Every failure path discarded its own signal — `onerror` dropped the
error code, `getUserMedia` was wrapped in `catch { return }` (a denied mic looked
exactly like success-then-stop), a short blob was dropped with no feedback, and
the transcription call ended in `catch { /* keep text mode */ }`.

- prefer MediaRecorder + `POST /stt` whenever the platform can transcribe, since
  that path is ours end to end (real status, real message, real transcript); Web
  Speech stays the no-key fallback rather than the default (`resolveMicMode`)
- new roster-card bit `stt_available` = exactly the `/stt` gate (platform
  ElevenLabs key), separate from `voice_available`, which additionally needs an
  effective voice to speak WITH. On a key-but-no-voice agent the old single bit
  had no correct answer; with neither path available the mic is now not rendered
  at all instead of being a dead control
- every failure says what happened, in one inline aria-live notice beside a
  composer that still works: SpeechRecognition error codes (blocked permission
  vs unreachable service — the distinction the discarded code held), the
  getUserMedia rejection name, a too-short recording, the `/stt` `detail`
  verbatim, and a narration (TTS) failure
- a watchdog for the engine that reports nothing — the measured case — so the
  button cannot stay lit forever with no recourse
- `continuous = true` plus final-result accumulation, so a pause is not the end
- Firefox reports `mediaRec.mimeType === ""` and puts `audio/ogg; codecs=opus`
  on the chunks, so every clip from the one engine that ALWAYS records was
  uploaded as `voice.webm` labelled audio/webm while containing Ogg
  (`resolveRecordingMimeType`)

The decisions live in pure helpers (`portalUtils.js`) because this project has
no component-mount harness; the wiring is covered by source-structure guards in
the shape of `portalVoiceModePersistence.spec.js`.

Verified: cross-engine capability probe feeding each engine's REAL capabilities
into the shipped resolver (Chromium → `record` with a key, `speech` without;
Firefox → `record` with a key, no mic without); and a real end-to-end —
ElevenLabs TTS → Chromium fake-mic capture → MediaRecorder (audio/webm;codecs=
opus, 97 KB) → ElevenLabs Scribe returned the spoken sentence. 841 frontend unit
tests pass (34 new), 6 new backend tests, full client_portal backend suite 444
passed, production build and design-token check clean.

Related to #2212

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@dolho dolho added type-bug Bug fix ui PR touches the frontend UI — triggers Playwright e2e tests theme-ui-ux Theme: UI/UX labels Aug 17, 2026

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validated via /validate-pr. Root cause captured from the running browser rather than inferred; the stt_available split is argued from a case the single-bit design cannot express, and the card bit is literally tts_service.is_available() on both sides — pinned by a parametrized test, which is the drift that is the dead-control bug. All 22 checks green.

@vybe
vybe merged commit 4a1e6fb into dev Aug 17, 2026
25 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

theme-ui-ux Theme: UI/UX type-bug Bug fix ui PR touches the frontend UI — triggers Playwright e2e tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants