Skip to content

fix: speech to text unexpectedly undoing user edits in chat input#303919

Open
hamirmahal wants to merge 2 commits intomicrosoft:mainfrom
hamirmahal:fix/speech-to-text-in-chat-sidebar-unexpectedly-undoing-user-edits
Open

fix: speech to text unexpectedly undoing user edits in chat input#303919
hamirmahal wants to merge 2 commits intomicrosoft:mainfrom
hamirmahal:fix/speech-to-text-in-chat-sidebar-unexpectedly-undoing-user-edits

Conversation

@hamirmahal
Copy link
Copy Markdown
Contributor

Fixes #303918

Copilot AI review requested due to automatic review settings March 22, 2026 21:18
@vs-code-engineering vs-code-engineering Bot added this to the 1.113.0 milestone Mar 22, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a chat voice dictation regression where ongoing speech-to-text updates could override/undo user edits in the chat input by introducing explicit “committed vs preview” dictation state handling.

Changes:

  • Track dictation state (committedInput vs previewInput) instead of using a single accumulated inputValue.
  • Apply dictation updates via a helper (applyDictationInputState) that treats user edits as the authoritative base for subsequent speech composition.
  • Add small helper utilities (composeDictationInput, DictationInputState) to centralize dictation string composition logic.

Comment on lines +878 to +885
// User edits are authoritative.
// Treat them as new base for upcoming speech composition.
if (currentInput !== state.previewInput) {
committedInput = currentInput;
}

const nextInput = composeDictationInput(committedInput, recognizedText);

Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

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

When user edits occur while a speech preview is visible, currentInput can still include the previously appended preview suffix (e.g. the partial recognized text). Committing currentInput as the new base means the subsequent Recognized event will append the final recognizedText again, resulting in duplicated/stale dictated text. Consider stripping the prior preview suffix (derived from the previous state.committedInput/state.previewInput) from currentInput when detecting user edits, before composing the next preview/commit, so only the authoritative user edits become the new base.

Copilot uses AI. Check for mistakes.
Comment on lines 294 to +313
@@ -297,8 +305,12 @@ class VoiceChatSessions {
case SpeechToTextStatus.Recognized:
if (text) {
session.hasRecognizedInput = true;
inputValue = inputValue ? [inputValue, text].join(' ') : text;
session.controller.updateInput(inputValue);

dictationState = applyDictationInputState(
dictationState, controller.getInput(), text, status
);

session.controller.updateInput(dictationState.committedInput);
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

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

This change introduces new dictation state handling (preserving user edits while speech-to-text is active), but there are no unit tests covering the state transitions. Since this module already has tests (voiceChatActions.test.ts) for parseNextChatResponseChunk, it would be good to add coverage for cases like: recognizing->user edit->recognized (no duplicated text), and recognizing updates that should replace (not accumulate) previews.

Copilot uses AI. Check for mistakes.
@hamirmahal
Copy link
Copy Markdown
Contributor Author

Here's a demo of production behavior (left) vs. the changes with this pull request (right), with audio.

screen_recording-2026-03-22_14.49.07_speech_to_text_fix.webm

@Dr-T0-Jerzys-solve-all
Copy link
Copy Markdown

Reported.

@jrieken jrieken modified the milestones: 1.113.0, On Deck Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Speech to text unexpectedly undoes user edits in chat sidebar

5 participants