chat - prevent race conditions in loadSession#303244
Conversation
There was a problem hiding this comment.
Pull request overview
This PR targets chat session stability by ensuring overlapping ChatViewPane.loadSession() calls don’t race, so that newer session loads take precedence over older in-flight loads.
Changes:
- Introduces a per-
ChatViewPanecancellation token source to cancel previousloadSessioncalls when a new one starts. - Passes the cancellation token through to
chatService.acquireOrLoadSession(...)and adds cancellation checks to avoid showing/discarding the wrong model.
src/vs/workbench/contrib/chat/browser/widgetHosts/viewPane/chatViewPane.ts
Show resolved
Hide resolved
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent race conditions in the Chat view pane’s loadSession flow by ensuring that newer session-load requests cancel older in-flight ones, reducing UI flicker and incorrect model application when switching sessions quickly.
Changes:
- Introduce a per-view
CancellationTokenSourceto cancel priorloadSession()calls (“last call wins”). - Thread cancellation into
chatService.acquireOrLoadSession(...)and gate delayed widget-clearing on the active token. - Avoid error recovery/logging when cancellation is the reason the load was interrupted.
src/vs/workbench/contrib/chat/browser/widgetHosts/viewPane/chatViewPane.ts
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
This PR hardens the Chat view pane’s session switching logic by ensuring loadSession is cancellation-aware, preventing older/in-flight loads from overwriting newer user actions (a “last call wins” model). This fits into the workbench chat UI by improving reliability when restoring/opening sessions (especially slower contributed/cloud session types).
Changes:
- Introduces a per-
ChatViewPanecancellation token source to cancel in-flightloadSessioncalls. - Threads a
CancellationTokenthroughshowModeland intoacquireOrLoadSession, adding cancellation checkpoints and cleanup (dispose) when canceled. - Avoids clearing the widget for stale/canceled loads and suppresses error UI when cancellation is the cause.
No description provided.