Skip to content

FE-1604: Allow Voice interruption by speaking - #9550

Draft
kostandinang wants to merge 3 commits into
kostandin/fe-1580-harden-voice-safety-and-ux-on-the-unified-flue-routefrom
kostandin/fe-1604-allow-voice-interruption-by-speaking
Draft

FE-1604: Allow Voice interruption by speaking#9550
kostandinang wants to merge 3 commits into
kostandin/fe-1580-harden-voice-safety-and-ux-on-the-unified-flue-routefrom
kostandin/fe-1604-allow-voice-interruption-by-speaking

Conversation

@kostandinang

@kostandinang kostandinang commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

🌟 What is the purpose of this PR?

This PR lets a person interrupt Voice assistant playback by speaking without losing the interrupting utterance. It keeps the existing Your turn handoff as an optional half-duplex fallback and locally rejects likely false interruption transcripts before they become answers.

The change is stacked directly on #9531, which owns the shared Brunch Voice session, completed-transcript authority, canonical playback, and acknowledged manual handoff.

🔗 Related links

🚫 Blocked by

🔍 What does this change?

  • Keeps microphone capture active during canonical playback when Interruption by speaking is enabled.
  • Preserves immediate speech_started → response.cancel → output_audio_buffer.clear. Interruption never clears the input buffer, and transcript validation does not gate cancellation.
  • Preserves the same input item through completed transcription and submits the answer exactly once through the existing Brunch admission path.
  • Retains an accepted interrupted answer while the previous Brunch turn settles and submits it when Voice input reopens.
  • Adds a browser-saved, default-on Interruption by speaking checkbox to the existing playback menu.
  • Hides Your turn while automatic interruption is enabled and preserves its existing behavior when the preference is disabled.
  • Preserves mute, pause, Stop, end, reconnect, and exact replay behavior.
  • Updates the website README and Petrinaut Voice guide; the PR retains its dedicated patch changeset.

Completed-transcript hardening

A false VAD event can cause gpt-4o-transcribe to repeat its vocabulary prompt or transcribe assistant playback. The Realtime bridge now runs a deterministic classifier only for completed interruption-originated transcripts, before retaining or submitting them:

  • Prompt regurgitation: reject strong ordered overlap with the configured transcription vocabulary, including the reported “SDCPN, stochastic Petri net, place, transition, arc, token, marking, guard, rate, distribution, parameter, subnet, scenario, and metric.” leak.
  • Self-echo: reject strong overlap with exact canonical text whose playback was active when interruption started. The snapshot excludes queued speech and conversation history and is cleaned up with the input/session lifecycle.
  • Comparison uses Unicode NFKC, lowercase, punctuation removal, and whitespace collapse. The conservative threshold is at least 80% ordered bigram overlap, with minimum lengths of eight tokens for prompt regurgitation and six for self-echo.
  • Short novel answers such as “stop”, “no”, and “wait” remain valid. Ordinary capture remains unchanged even when interruption is enabled. Comparison normalization does not change admitted wording, casing, or punctuation.
  • Rejected completions create no user turn, error, or pending answer. Provisional text is silently cleared; diagnostics contain only operational metadata and a rejection reason, never transcript, prompt, or assistant text.

The transcription model and prompt remain unchanged. The prompt is shared between provider configuration and local validation to avoid drift. No extra model call, acoustic processing, debounce, or cancellation delay is introduced.

Pre-Merge Checklist 🚀

🚢 Has this modified a publishable library?

  • Modifies an npm-publishable library; kostandinang has added a patch changeset.

📜 Does this require a change to the docs?

  • Yes — libs/@hashintel/petrinaut/docs/ai-assistant.md and apps/petrinaut-website/README.md document interruption, retained answers, local rejection, and the manual fallback.

🕸️ Does this require a change to the Turbo Graph?

  • No Turbo execution-graph change is required.

⚠️ Known issues

  • False VAD can still stop playback even when the completed transcript is discarded. Preventing that interruption is explicitly out of scope.
  • The local classifier is conservative and heuristic; the real speaker/microphone witness is still required. Browser echo cancellation continues to use the existing media constraints.
  • Protocol tests establish immediate event ordering, input preservation, and local transcript rejection. Real-microphone interruption latency was not benchmarked.
  • The website unit suite has six pre-existing maximum-update-depth failures in voice-interview-control.test.tsx. These were reproduced before editing at the prior PR head, and the same six tests fail after hardening. This change does not fix or suppress them.

🛡 What tests cover this?

The prompt-leak and canonical-echo regression tests were written first and observed failing before implementation. Coverage includes immediate cancellation, short novel answers, unchanged ordinary capture, duplicate completions, delayed/pending admission, active-playback-only snapshots, and lifecycle cleanup.

Current hardening verification:

  • Focused Voice suites: 213 passed:
    yarn workspace @apps/petrinaut-website test:unit src/main/app/voice-interview src/server/voice src/voice-diagnostics.test.ts --exclude '**/voice-interview-control.test.tsx'
    The known-failing control suite is excluded only from this focused command; it is included in the full run below.
  • yarn workspace @apps/petrinaut-website test:unit: 350 passed, 6 failed, compared with 317 passed, 6 failed before editing. The failing test names and maximum-update-depth error are unchanged.
  • yarn workspace @apps/petrinaut-website build: passed.
  • yarn workspace @apps/petrinaut-website lint:tsc: passed.
  • yarn workspace @apps/petrinaut-website lint:eslint: passed with zero errors and one existing set-state-in-effect warning in the unchanged control component.
  • yarn workspace @local/petrinaut-arch-docs lint:arch-docs: passed.
  • yarn lint:format and git diff --check: passed.

Earlier PR verification recorded 618/618 Petrinaut library unit tests and passing library TypeScript checks. Those library checks were not rerun for this website-only runtime hardening; the library change in this increment is documentation only.

❓ How to test this?

  1. Start Voice and open Voice playback options. Confirm Interruption by speaking is checked by default.
  2. While Brunch is speaking, begin answering, including short answers such as “stop”, “no”, or “wait”. Confirm playback stops immediately and the same utterance appears once without repetition.
  3. Interrupt while the previous Brunch turn is still settling. Confirm an accepted answer shows Answer captured. Waiting for Brunch. and submits once input reopens. The automated regression tests inject false vocabulary and canonical-echo completions and verify that neither becomes a turn or occupies the pending-answer slot.
  4. Uncheck Interruption by speaking. Confirm Your turn returns and the microphone stays closed during playback until the acknowledged handoff completes. Reload and confirm the preference is remembered.
  5. Exercise mute, pause, Stop, end, reconnect, Repeat question, and Read full response in both modes. Check speaker feedback separately: a rejected false transcript may still have stopped playback.

@vercel

vercel Bot commented Sep 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hash Ready Ready Preview Sep 6, 2026 3:06pm UTC
petrinaut Ready Ready Preview Sep 6, 2026 3:06pm UTC
petrinaut-docs Ready Ready Preview Sep 6, 2026 3:06pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
hashdotdesign-tokens Ignored Ignored Preview Sep 6, 2026 3:06pm UTC

Request Review

kostandinang and others added 2 commits September 6, 2026 14:52
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/apps area/infra Relates to version control, CI, CD or IaC (area) area/libs Relates to first-party libraries/crates/packages (area) type/eng > frontend Owned by the @frontend team

Development

Successfully merging this pull request may close these issues.

1 participant