Skip to content

voice: honor the new_session flag on send_to_chat - #330859

Merged
Megan Rogge (meganrogge) merged 3 commits into
microsoft:mainfrom
mirimadahmed:voice-new-session-flag
Aug 14, 2026
Merged

Megan Rogge (meganrogge) merged 3 commits into
microsoft:mainfrom
mirimadahmed:voice-new-session-flag

Conversation

@mirimadahmed

Copy link
Copy Markdown
Contributor

Problem

The voice backend advertises a new_session boolean on the send_to_chat tool and sets it when the user explicitly asks for a fresh session ("start a new session and refactor the upload service"). The controller's send_to_chat branch never read the flag, so those requests were submitted into the current session instead.

Separately, voiceToolDispatchService still carried a new_sessions handler. It is not in the controller's allowedTools list, so the backend can never reach it.

Solution

Read new_session in the controller's send_to_chat branch. When set, clear any pinned submit session and then create and target a new one. Pin clearing has to come first: _sendTranscriptionToChat resolves its target as _consumePinnedSubmitSession() ?? _targetSession, so a pin left by an earlier focus change would otherwise outrank the session just created.

Empty text with new_session: true creates and focuses a session without sending, which is what the backend emits for a bare "start a new session".

This lives in the controller rather than the dispatch service on purpose: send_to_chat is routed through the controller so it honors _targetSession, the workbench chat commands, stop-phrase stripping and send suppression. The old new_sessions handler bypassed all of them, so it and its action label are removed.

Keeping the new session alive

newSessionAsTarget() previously disposed its only model reference synchronously and then fired switchToSession. ChatModelStore.destroyReferencedObject is asynchronous - it marks the key pending, awaits willDisposeModel, then disposes - and createReferencedObject cancels that via _modelsToDispose.delete(key). So the old code survived by racing: the pane re-acquired the model before the await resolved.

It does not survive when nothing re-acquires. willDisposeModel deletes empty untitled local sessions with no custom title, so if switchToSession is unavailable or fails, the model is disposed, the session row is deleted, and _targetSession points at a URI that no longer exists. For the text form _sendTranscriptionToChat re-acquires via acquireOrLoadSession; for the empty-text form there is no send path at all, so the bare "start a new session" is silently lost.

The reference is now retained in a MutableDisposable and released only once switchToSession confirms a host adopted the session, on retarget, on replacement, or on controller disposal. It errs toward holding: too long is a bounded cost, too early is the bug.

Test plan

node test/unit/browser/index.js --browser chromium \
  --run src/vs/workbench/contrib/chat/test/browser/voiceClient/voiceSessionController.test.ts
# 181 passing

node test/unit/browser/index.js --browser chromium \
  --run src/vs/workbench/contrib/chat/test/browser/voiceClient/voiceToolDispatchService.test.ts
# 22 passing

ESLint clean on the touched files; tsc --noEmit -p src/tsconfig.json reports 0 errors.

Both new tests were mutation-checked rather than trusted green:

  • reverting retention to ref.dispose() fails the lifecycle test with targetStillExists: false
  • deleting the _consumePinnedSubmitSession() line fails the pin test, sending to the pinned URI instead of the new one

The lifecycle test uses a refcounting fake that drops the session at zero, mirroring willDisposeModel, rather than a shallow mock.

Risks

newSessionAsTarget() now holds a reference, so its other callers keep the created session alive longer. That is the intended fix - it is what stops the session being deleted underneath them too - and MutableDisposable means at most one is retained at a time.

Removing new_sessions is a behavior change only if something outside allowedTools was dispatching it. Nothing in the tree references the name after this change.

Non-goals

Model selection and file attachment are out of scope.

No structured verdict is added for send_to_chat. The controller answers every send_to_chat from a shared sendPromise.finally(() => sendToolResult(callId, 'ok')), so changing it to report failure is an all-calls contract change with its own blast radius across every voice tool. This PR leaves that .finally() untouched, so the verdict can be threaded through the same place later. Noting it as a known owed follow-up: #329490's "tool failures cause an honest failure response" criterion is not fully closed by this PR alone.


Supersedes #330682 by Arthur Cnops (@accnops) (re-opened from a fork we can push to). Original commit authorship preserved.

Arthur Cnops and others added 2 commits August 14, 2026 18:03
The voice backend advertises a `new_session` boolean on `send_to_chat` and
sets it when the user explicitly asks for a fresh session, but the controller
never read it, so those requests landed in the current session.

Read the flag in the `send_to_chat` branch: clear any pinned submit session
(an explicit "new session" outranks a pin left by a focus change), then create
and target a new session. An empty `text` creates and focuses without sending,
which is what the backend emits for a bare "start a new session".

Also drop the `new_sessions` dispatch handler and its action label. It is not
in the controller's allowedTools list, so it is unreachable, and it bypassed
the target session, stop-phrase stripping and send suppression that
`send_to_chat` goes through.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: c568e3e0-eabb-48db-84a4-a7976df7c474
`newSessionAsTarget()` disposed the only model reference immediately, and
`ChatService` deletes empty untitled local sessions once their last reference
goes away (`willDisposeModel`). Disposal is deferred behind an await, so a chat
pane re-acquiring the model usually revived it in time — but when
`_chat.voice.switchToSession` is unavailable or fails, nothing re-acquires. For
`send_to_chat(new_session=true)` with empty text there is no send path to
reacquire either, so the session was deleted and `_targetSession` was left
pointing at a resource that no longer exists, silently losing a bare
"start a new session".

Retain the reference in a `MutableDisposable` and release it only once the
switch reports a host has adopted the session, when voice retargets elsewhere,
when another new session replaces it, or on disposal. Holding it slightly
longer than necessary is harmless; releasing it early is the bug.

Cover both directions with a chat service fake that refcounts references and
drops the session at zero, mirroring `willDisposeModel`, plus a test that seeds
`_pinnedSubmitSession` so the pin-clearing order in the `send_to_chat` branch
is actually exercised.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings August 14, 2026 13:41

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

Honors send_to_chat.new_session while preserving newly created sessions until adopted.

Changes:

  • Routes explicit new-session requests to a fresh chat session.
  • Retains new session model references during adoption.
  • Removes the unreachable new_sessions dispatch handler and adds tests.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
voiceSessionController.ts Handles new-session routing and reference lifecycle.
voiceToolDispatchService.ts Removes obsolete new_sessions support.
voiceSessionController.test.ts Tests routing, pin precedence, and lifecycle behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Ensure explicit new-session sends bypass focused Omni and centralize target mutations so retained model references are released on retarget and disconnect.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 8758b568-a297-46b1-a605-b85a60efac1f
@meganrogge

Copy link
Copy Markdown
Collaborator

Addressed all review findings in 25597d8:

  • pins explicit new-session submissions to bypass focused Omni
  • uses isEqual for retained-resource comparison
  • centralizes every target mutation through release-aware cleanup
  • adds focused-Omni, retarget, and disconnect regression tests

Validation: 184 targeted voice controller tests pass; ESLint is clean on both changed files.

@meganrogge Megan Rogge (meganrogge) added this to the 1.134.0 milestone Aug 14, 2026
@meganrogge
Megan Rogge (meganrogge) enabled auto-merge (squash) August 14, 2026 16:13
@meganrogge
Megan Rogge (meganrogge) merged commit bffa771 into microsoft:main Aug 14, 2026
27 checks passed
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Sep 28, 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.

4 participants