Skip to content

voice: send request_narration only after session context is sent - #325928

Merged
Megan Rogge (meganrogge) merged 1 commit into
microsoft:megrogge/voice-backend-narrate-apifrom
accnops:arthurcnops/voice-narration-ordering
Jul 15, 2026
Merged

Megan Rogge (meganrogge) merged 1 commit into
microsoft:megrogge/voice-backend-narrate-apifrom
accnops:arthurcnops/voice-narration-ordering

Conversation

@accnops

Copy link
Copy Markdown
Contributor

Stacked on #325682 (base = megrogge/voice-backend-narrate-api), follow-up to the auto-narrate opt-out from #325799.

Problem

requestNarration only checks that the socket is OPEN. A focus- or state-driven narration can therefore be sent in the window between the WebSocket opening and start_session / resume_session being sent. The backend drops a request_narration that arrives before the session exists, but the client still gets a narration id back and treats the audio as inbound: it tears down listening via _prepareForPlayback, records a solicited narration id, and arms a safety timer for audio that never arrives. The narration is not queued for replay, so it is lost until the next focus/state event.

Solution

Track whether start_session / resume_session (which carries session_context) has been sent on the current connection (_sessionContextSent, reset per connection in onopen, set after each send) and gate requestNarration on it. The WebSocket preserves send order, so this guarantees the backend has processed the session before it sees a narration request. Pre-session, requestNarration now returns undefined, so _narrate queues the item in _pendingNarrationRetries and onSessionInit replays it once the session exists — reusing the existing retry path.

Tests

None. This file has no existing unit tests and the change is a small ordering guard on the WS send path; adding a WebSocket-mocking harness for it is out of scope for this follow-up. Verified by tracing the client/backend ordering and the _narrate / onSessionInit replay interaction.

Risks

Low. Behavior only changes in the pre-session-init window: narration is deferred to session_init replay instead of being sent-then-dropped. Steady-state narration is unaffected (_sessionContextSent is true once the session is established).

Non-goals

No backend changes; no change to the narration payload or the auto_narrate opt-out.

requestNarration only checked that the socket was OPEN, so a focus- or
state-driven narration could be sent in the window between the WebSocket
opening and start_session/resume_session being sent. The backend drops a
request_narration that arrives before the session exists, but the client
still gets a narration id back and treats the audio as inbound: it tears
down listening via _prepareForPlayback, records a solicited narration id,
and arms a safety timer for audio that never comes. The narration is not
queued for replay, so it is lost until the next focus/state event.

Track whether start_session/resume_session (which carries session_context)
has been sent on the current connection and gate requestNarration on it.
The WebSocket preserves send order, so this guarantees the backend has the
session before it sees a narration request. Pre-session, requestNarration
now returns undefined, so _narrate queues the item in
_pendingNarrationRetries and onSessionInit replays it once the session
exists.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 803dc35b-1aee-4354-85c7-df6076293a49
@meganrogge
Megan Rogge (meganrogge) marked this pull request as ready for review July 15, 2026 12:58
@meganrogge
Megan Rogge (meganrogge) merged commit 7b02243 into microsoft:megrogge/voice-backend-narrate-api Jul 15, 2026
7 of 9 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.130.0 milestone Jul 15, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Aug 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

2 participants