Skip to content

Voice: narrate confirmations/responses stranded on the user_speaking latch - #326378

Merged
Megan Rogge (meganrogge) merged 3 commits into
mainfrom
copilot/fix-voice-narration-user-speaking-latch
Jul 17, 2026
Merged

Megan Rogge (meganrogge) merged 3 commits into
mainfrom
copilot/fix-voice-narration-user-speaking-latch

Conversation

@meganrogge

Copy link
Copy Markdown
Collaborator

Problem

In hands-free voice mode, a confirmation (or completed response) is sometimes never read aloud. Trace shows:

[voice] narrate kind=confirmation id=…
[voice] request_narration kind=confirmation narration_id=…
[voice] narration_ack busy id=… reason=user_speaking; deferring

…and no narration_unblocked ever follows, so the narration is stranded.

Root cause

On connect (and for barge-in), the controller opens a passive auto-listen mic turn — ptt_start is sent and the turn is left open with no ptt_end. The backend latches user_is_speaking on ptt_start, so a client-driven request_narration issued while that latch is set is NACK'd busy: user_speaking and deferred, waiting for a narration_unblocked nudge.

For a silent passive turn that nudge never arrives: _prepareForPlayback() ran after the request and used _finishPtt('auto') → abortPtt(), which stops the mic locally without emitting ptt_end. The backend never learns the turn ended, never clears the latch, and never unblocks — so the confirmation/response is never spoken.

Fix

In _narrate, when the user is not actively dictating, end the open listen turn with a genuine ptt_end before requesting the narration (the WebSocket preserves send order, so the backend clears the latch and accepts the request immediately). When the user is mid-utterance, leave the turn open and keep the existing busy/defer + narration_unblocked path so their speech isn't cut off.

  • _prepareForPlayback(endOpenTurn) — finishes via _finishPtt('local') (real ptt_end) when true, else the prior 'auto' abort.
  • _isActivelyDictating() — true only when the transcript tail is a non-empty partial user turn.
  • IVoiceClientService.canRequestNarration — gates the force-end so a closed-socket path still queues a retry without tearing down a freshly-entered listen on connect.

Behavior

  • Silent auto-listen open → confirmation/response narrates right away.
  • User genuinely mid-utterance → still defers politely and narrates once they finish.

Validation

  • ./node_modules/.bin/tsc --noEmit -p src/tsconfig.json (clean)
  • precommit hygiene hooks

Note: unit tests were not executed (no build output in the isolated worktree).

…he user_speaking latch

In hands-free mode the controller opens a passive auto-listen mic turn on
connect (and for barge-in), leaving the turn open (ptt_start sent, no
ptt_end). The backend latches user_is_speaking on ptt_start, so a
client-driven request_narration issued while that latch is set is NACK'd
`busy: user_speaking` and deferred until a narration_unblocked nudge.

For a SILENT passive turn that nudge never arrives: _prepareForPlayback ran
AFTER the request and used _finishPtt('auto') -> abortPtt(), which stops the
mic locally without emitting ptt_end, so the backend never learns the turn
ended and never clears the latch. The confirmation/response is stranded and
never spoken.

Fix: in _narrate, when the user is NOT actively dictating, end the open
listen turn with a genuine ptt_end BEFORE requesting the narration (WS
preserves order, so the backend clears the latch and accepts the request
immediately). When the user IS mid-utterance, leave the turn open and keep
the existing busy/defer + narration_unblocked path so their speech isn't cut
off.

- _prepareForPlayback(endOpenTurn) finishes via _finishPtt('local') (real
  ptt_end) when true, else the prior 'auto' abort.
- _isActivelyDictating() detects a non-empty partial user transcript.
- IVoiceClientService.canRequestNarration gates the force-end so a
  closed-socket path still queues a retry without tearing down a
  freshly-entered listen on connect.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: d527ed3c-29a9-435f-8772-c8117077d394
Copilot AI review requested due to automatic review settings July 17, 2026 16:48
@meganrogge Megan Rogge (meganrogge) added this to the 1.130.0 milestone Jul 17, 2026
@meganrogge
Megan Rogge (meganrogge) enabled auto-merge (squash) July 17, 2026 16:50

Copilot AI 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.

Pull request overview

Fixes stranded voice narration by ending passive listening turns before requesting playback.

Changes:

  • Detects active user dictation.
  • Adds narration readiness state.
  • Selects local PTT completion for silent passive turns.
Show a summary per file
File Description
voiceClientService.ts (common) Adds narration readiness to the service contract.
voiceSessionController.ts Coordinates passive turns and narration playback.
voiceClientService.ts (browser) Implements narration readiness detection.

Review details

  • Files reviewed: 3/3 changed files
  • Comments generated: 5
  • Review effort level: Medium

Megan Rogge (meganrogge) and others added 2 commits July 17, 2026 13:16
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
…m comments

- The force-end path used `_finishPtt('local')` → `pttUp()`, which drains ~500ms
  before `onPttEnd`/`ptt_end` fires, so the synchronous `requestNarration` still
  raced ahead of `ptt_end` and was NACK'd `busy: user_speaking`. Add a
  `_finishPtt('immediate')` reason that aborts the mic with no drain and sends
  `ptt_end` synchronously, so the backend clears its latch before the narration
  request frame.
- `_isActivelyDictating()` relied on recognized text, so it reported false in the
  window between `speech_started` and the first transcription — force-ending a
  user who had already begun speaking. Track a `_userSpeechActive` VAD flag
  (set on `speech_started`, cleared on final transcription / turn end).
- Trim the oversized inline comments in `_narrate` and `_prepareForPlayback` to a
  single non-obvious line each.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: d527ed3c-29a9-435f-8772-c8117077d394
@meganrogge

Copy link
Copy Markdown
Collaborator Author

Addressed the review feedback in 0857117:

  • Ordering race (_prepareForPlayback(true) didn't put ptt_end on the socket first): _finishPtt('local') → pttUp() drains ~500ms before onPttEnd/ptt_end, so the synchronous requestNarration still won the race and got NACK'd. Added a _finishPtt('immediate') reason that aborts the mic with no drain and calls sendPttEnd() synchronously, so ptt_end is on the wire before the narration request frame.
  • _isActivelyDictating() false after speech_started but before first transcription: now tracks a _userSpeechActive VAD flag set on speech_started and cleared on final transcription / turn_auto_ended / turn end (and reset on teardown), instead of inferring from recognized text — so a user who has started speaking is never force-ended.
  • Oversized inline comments in _narrate and _prepareForPlayback trimmed to a single non-obvious line each. (The _isActivelyDictating JSDoc comment was already resolved.)

tsc --noEmit -p src/tsconfig.json clean; precommit hygiene passed.

@meganrogge
Megan Rogge (meganrogge) merged commit a935b0a into main Jul 17, 2026
29 checks passed
@meganrogge
Megan Rogge (meganrogge) deleted the copilot/fix-voice-narration-user-speaking-latch branch July 17, 2026 17:43
Arthur Cnops (accnops) pushed a commit to accnops/vscode that referenced this pull request Jul 17, 2026
Extend the passive open-mic flag to the auto-listen path (not just barge-in)
so every hands-free turn opened without a deliberate user press sends
ptt_start with passive:true. The backend then leaves user_is_speaking clear
on those silent turns, so a client-driven narration request is accepted
instead of being NACK'd busy: user_speaking and stranded.

This supersedes the force-ptt_end workaround from microsoft#326378: a passive turn
never latches in the first place, so there is no latch to force-clear. Remove
that mechanism (_userSpeechActive, _isActivelyDictating, the _finishPtt
'immediate' variant, _prepareForPlayback(endOpenTurn), and canRequestNarration)
and restore _narrate to unconditionally prepare for playback on a sent request.

Depends on backend passive handling (yolo#56284): must be live in GA before
this lands, or silent hands-free turns latch again on the old backend.

Adds controller tests: auto-listen opens a passive mic turn; a deliberate
press stays non-passive.
Arthur Cnops (accnops) pushed a commit to accnops/vscode that referenced this pull request Jul 18, 2026
Extend the passive open-mic flag to the auto-listen path (not just barge-in)
so every hands-free turn opened without a deliberate user press sends
ptt_start with passive:true. The backend then leaves user_is_speaking clear
on those silent turns, so a client-driven narration request is accepted
instead of being NACK'd busy: user_speaking and stranded.

This supersedes the force-ptt_end workaround from microsoft#326378: a passive turn
never latches in the first place, so there is no latch to force-clear. Remove
that mechanism (_userSpeechActive, _isActivelyDictating, the _finishPtt
'immediate' variant, _prepareForPlayback(endOpenTurn), and canRequestNarration)
and restore _narrate to unconditionally prepare for playback on a sent request.

Depends on backend passive handling (yolo#56284): must be live in GA before
this lands, or silent hands-free turns latch again on the old backend.

Adds controller tests: auto-listen opens a passive mic turn; a deliberate
press stays non-passive.
Megan Rogge (meganrogge) pushed a commit that referenced this pull request Jul 20, 2026
…326405)

* fix(voice): flag passive barge-in ptt_start so backend does not latch user speaking

Thread a `passive` flag immutably through mic-start into the ptt_start
frame instead of reading controller state at emit time, which could
race with the async getUserMedia acquire in the cold-capture path.

- micCaptureService: pttDown(turnId, passive = false) now captures
  passive per-press and fires it on onPttStart (Emitter<boolean>) at
  both the warm and post-acquire fire sites.
- voiceClientService: sendPttStart(turnId, passive = false) serializes
  `passive: true` only when true, keeping the wire frame byte-identical
  for real presses / old clients.
- voiceSessionController: onPttStart forwards the captured passive to
  sendPttStart; _startBargeInListen is the only caller passing
  passive=true (verified single true caller).

Safe because barge-in promotion (a real press during a passive listen)
does not re-send ptt_start, so the passive flag captured at listen-open
time remains correct for the whole turn.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 803dc35b-1aee-4354-85c7-df6076293a49

* fix(voice): adopt server session id and clear resuming flag on (re)init

`_isResuming` was set on reconnect but never cleared, and a failed
resume refused to adopt the server's fresh session_init id, leaving
the client believing it still owned a dead session and stalling
reconnect. On both `session_init` and `session_resumed`, always adopt
`msg.session_id` and clear `_isResuming`; also reset `_isResuming` in
`_cleanup()` for terminal disconnects.

Adopting a fresh id on a failed resume is strictly more correct than
the previous refusal.

Extended the test createTestWindow harness to bind setInterval and
clearInterval to the real window target (native timer methods are
branded and throw Illegal invocation when called with a Proxy as
this), which was needed to drive ws.onopen in the new tests.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 803dc35b-1aee-4354-85c7-df6076293a49

* fix(voice): replay deferred narrations on reconnect

`_deferredNarrations` (busy/interrupted narrations awaiting a
narration_unblocked nudge) was never replayed on reconnect - only
_pendingNarrationRetries was. The narration_unblocked nudge that would
otherwise trigger a retry is itself lost with the dropped socket, so a
narration deferred right before a disconnect could be silently lost
forever.

On session_init/session_resumed, now also replay _deferredNarrations by
reusing _retryDeferredNarration for each entry - the same revalidation
already used for the live narration_unblocked path: it re-checks
_currentNarratable before firing and reuses the same narration_id when
the text is unchanged, so backend idempotency returns accepted without
re-synth for anything already spoken. Entries no longer warranted or no
longer the shown session are dropped without speaking, same as before.

_retryDeferredNarration now returns whether it actually sent a retry
(mirrors _narrate's return) so the reconnect handler can gate entering
auto-listen the same way it already does for _pendingNarrationRetries -
a narration about to play should not be torn down by a listen that
starts moments later.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 803dc35b-1aee-4354-85c7-df6076293a49

* fix(voice): retry the specific unblocked narration id

`_retryDeferredNarration` ignored the `narration_id` carried by
`narration_unblocked` and always retried whatever was currently
deferred for the session key. `_deferredNarrations` is latest-wins per
session key, so if a second narration for the same session went busy
before the first one's `narration_unblocked` arrived, the stale nudge
would retry the newer (possibly still-busy) entry early instead of
waiting for its own unblock.

`_retryDeferredNarration` now takes an optional `unblockedNarrationId`;
when it does not match the currently deferred entry's id, the retry is
skipped - the correct nudge for that entry will arrive separately once
its own guard clears. The reconnect replay path (no unblock event, no
id to compare against) is unaffected and keeps retrying whatever is
currently deferred.

Low risk: retrying a superseded id was already an idempotent no-op
server-side, so this only removes an unnecessary/early retry attempt.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 803dc35b-1aee-4354-85c7-df6076293a49

* feat(voice): emit telemetry when narration is deferred or dropped client-side

Add voiceNarrationDeferred/voiceNarrationDropped telemetry events
(voiceTelemetry.ts) following the existing publicLog2 pattern used
elsewhere in voiceSessionController.ts (owner meganrogge, SystemMetaData/
FeatureInsight classification). Only `kind` (response|confirmation) and a
`reason` enum are logged - never narration text.

Wired into the four client-side branches where a narration is deferred or
dropped without ever playing:
- _handleNarrationAck: 'invalid' disposition -> dropped (reason: invalid);
  'busy' disposition -> deferred (reason: busy)
- _handleNarrationInterrupted -> deferred (reason: interrupted)
- _retryDeferredNarration: no longer warranted -> dropped (reason: stale);
  session no longer shown -> dropped (reason: session_changed)

No dedicated unit test: voiceSessionController has no unit harness (per
task scope, not building a new one). Verified via typecheck/eslint on the
touched files and the unaffected voiceClientService.test.ts suite (15/15
passing).

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 803dc35b-1aee-4354-85c7-df6076293a49

* voice: make passive ptt_start the canonical narration-latch fix

Extend the passive open-mic flag to the auto-listen path (not just barge-in)
so every hands-free turn opened without a deliberate user press sends
ptt_start with passive:true. The backend then leaves user_is_speaking clear
on those silent turns, so a client-driven narration request is accepted
instead of being NACK'd busy: user_speaking and stranded.

This supersedes the force-ptt_end workaround from #326378: a passive turn
never latches in the first place, so there is no latch to force-clear. Remove
that mechanism (_userSpeechActive, _isActivelyDictating, the _finishPtt
'immediate' variant, _prepareForPlayback(endOpenTurn), and canRequestNarration)
and restore _narrate to unconditionally prepare for playback on a sent request.

Depends on backend passive handling (yolo#56284): must be live in GA before
this lands, or silent hands-free turns latch again on the old backend.

Adds controller tests: auto-listen opens a passive mic turn; a deliberate
press stays non-passive.

* voice: preserve a held deliberate press when preparing for narration playback

A deliberate (non-passive) ptt_start latches the backend's user_is_speaking,
so its narration request is NACK'd busy and deferred. _prepareForPlayback
previously aborted any held turn via _finishPtt('auto'), which sends no
ptt_end and strands that latch (the later physical release no-ops because
_pttHeld is already false). Track the current turn's passiveness and skip the
abort for a held deliberate press, leaving its natural release to send
ptt_end and clear the guard. Passive open-mic turns (auto-listen / barge-in),
which never latch, are still torn down to free the mic for narration audio.

* voice: document the drain-flush ordering that keeps ptt_end correct without a turn_id

* voice: don't play buffered narration over a held deliberate press

When a deliberate (non-passive) press is held, its natural release drives the
narration_unblocked retry, so the playback slot must not be torn down under it
(that sends no ptt_end and strands the backend latch). Three changes keep a
held press intact without dropping or duplicating its buffered reply:

- _flushDeferredResponse peeks the slot via _prepareForPlayback() (now returns
  a boolean) and only deletes/enqueues the buffered chunks once the slot is
  actually free; a held deliberate press leaves the buffer intact and reports
  `retained` plus the buffered reply's transcript. Passive open-mic turns
  (which never latched) are still torn down.
- _activateShownSession skips a fresh narration only for the SAME reply the
  retained buffer will replay on release (matched by normalized transcript);
  otherwise it would double up with that buffer. An unrelated confirmation or a
  newer, different response for the session still narrates, because a stale
  buffered response can outlive its turn (thinking clears _deferredNarrations,
  not _deferredResponses). The pending indicator stays until the buffer plays.
- Clear _pttCurrentTurnPassive when a passive barge-in listen is promoted to a
  deliberate press, so playback prep preserves the promoted press.

---------

Co-authored-by: Arthur Cnops <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Arthur Cnops <[email protected]>
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Aug 31, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants