Skip to content

sessions: clean up ISessionsProvider chat API#317875

Merged
sandy081 merged 3 commits into
mainfrom
sandy081/sessions-provider-cleanup
May 21, 2026
Merged

sessions: clean up ISessionsProvider chat API#317875
sandy081 merged 3 commits into
mainfrom
sandy081/sessions-provider-cleanup

Conversation

@sandy081
Copy link
Copy Markdown
Member

Cleans up ISessionsProvider and the management-service send flow so providers own only backend chat lifecycle, and the management service is the sole owner of widget opening.

Provider API

  • Remove sendAndCreateChat and addChat from ISessionsProvider.
  • Add createNewChat(sessionId) that returns the committed IChat, so the management service can open the widget on the real backend resource before sending.
  • sendRequest(sessionId, chatResource, options) now handles both first-send (new session) and subsequent-send paths; providers dispatch internally based on _currentNewSession.
  • For multi-chat sessions, createNewChat on an existing session gates on _isMultiChatEnabled() and creates a fresh chat in the group.

Session model

  • ISession.mainChat changes from IChat to IObservable<IChat> so providers can swap the chat when an untitled new session commits to a real backend resource (e.g. Claude).
  • ICopilotChatSession owns its own ISettableObservable<IChat> mainChat field; the provider no longer keeps a parallel _mainChatBySessionId map.

Management service

  • sendNewChatRequest (renamed from sendAndCreateChat) calls createNewChat, opens the widget on the returned chat.resource, then calls sendRequest.
  • openNewChatInSession is now async and opens the widget after createNewChat returns.

Copilot provider

  • Drops the IChatWidgetService injection — the provider never opens widgets directly.
  • Drops userSelectedTools from the local send path (no widget available there).

Spec updates

  • SESSIONS.md: documents two new interface-design rules:
    1. ISessionsProvider must have no optional methods.
    2. Every addition to ISession or ISessionsProvider must be consumed in the agents-window core workbench (anything outside contrib/providers/).
  • COPILOT_CHAT_SESSIONS_PROVIDER.md: send-flow section rewritten to describe the new createNewChat + sendRequest two-step contract.

Validation

  • npm run compile-check-ts-native — clean (sessions code; only pre-existing unrelated proxyResolver.ts errors remain).
  • npm run valid-layers-check — clean.
  • scripts/test.sh --glob "**/sessions/**/*.test.js" — 753 passing.

Simplify the provider contract and remove provider access to the chat
widget service so widget opening is owned exclusively by the management
service.

Provider API
- Remove `sendAndCreateChat` and `addChat` from `ISessionsProvider`.
- Add `createNewChat(sessionId)` returning the committed `IChat` so
  the management service can open the widget on the real backend
  resource before sending.
- `sendRequest(sessionId, chatResource, options)` now handles both
  the first-send (new session) and subsequent-send paths; providers
  dispatch internally based on `_currentNewSession`.
- For multi-chat sessions, `createNewChat` on an existing session
  gates on `_isMultiChatEnabled()` and creates a fresh chat in the
  group.

Session model
- `ISession.mainChat` changes from `IChat` to `IObservable<IChat>`
  so providers can swap the chat when an untitled new session commits
  to a real backend resource (e.g. Claude).
- `ICopilotChatSession` owns its own `ISettableObservable<IChat>`
  `mainChat` field; the provider no longer maintains a parallel map.

Management service
- `sendNewChatRequest` (renamed from `sendAndCreateChat`) calls
  `createNewChat`, opens the widget on the returned chat resource,
  then calls `sendRequest`.
- `openNewChatInSession` is now async and opens the widget after
  `createNewChat` returns.

Copilot provider
- Drops the `IChatWidgetService` injection; the provider never
  opens widgets directly.
- Drops `userSelectedTools` from the local send path (no widget
  available there).

Spec
- `SESSIONS.md`: document that `ISessionsProvider` must not have
  optional methods and that every addition to `ISession` or
  `ISessionsProvider` must be consumed by the agents-window core
  workbench (outside `contrib/providers/`).
- `COPILOT_CHAT_SESSIONS_PROVIDER.md`: update the send-flow section
  to describe the new `createNewChat` + `sendRequest` two-step
  contract.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 21, 2026 22:38
@sandy081 sandy081 enabled auto-merge (squash) May 21, 2026 22:38
roblourens
roblourens previously approved these changes May 21, 2026
@vs-code-engineering
Copy link
Copy Markdown
Contributor

vs-code-engineering Bot commented May 21, 2026

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@lszomoru

Matched files:

  • src/vs/sessions/services/sessions/browser/sessionsManagementService.ts
  • src/vs/sessions/services/sessions/common/session.ts
  • src/vs/sessions/services/sessions/common/sessionsManagement.ts
  • src/vs/sessions/services/sessions/common/sessionsProvider.ts
  • src/vs/sessions/services/sessions/test/browser/sessionNavigation.test.ts
  • src/vs/sessions/services/sessions/test/browser/sessionsManagementService.test.ts

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

This pull request refactors the Agents Window sessions/provider chat contract so providers own backend chat lifecycle while SessionsManagementService becomes the sole owner of opening chat widgets. It updates the session model to allow providers to swap the “main chat” when an untitled session commits to a real backend resource.

Changes:

  • Replaces ISessionsProvider.sendAndCreateChat/addChat with a two-step createNewChat + sendRequest flow.
  • Changes ISession.mainChat from IChat to IObservable<IChat> to support main-chat replacement on commit.
  • Updates management-service send/open flows plus broad test and documentation updates to match the new contract.
Show a summary per file
File Description
src/vs/sessions/SESSIONS.md Updates conceptual model and documents new provider/management responsibilities and interface design rules.
src/vs/sessions/services/sessions/test/browser/sessionsManagementService.test.ts Updates test provider stubs for createNewChat and mainChat observable.
src/vs/sessions/services/sessions/test/browser/sessionNavigation.test.ts Updates management service mock to new method names/async signatures and mainChat observable.
src/vs/sessions/services/sessions/common/sessionsProvider.ts Replaces provider API with createNewChat(sessionId, prompt?) and updated sendRequest contract.
src/vs/sessions/services/sessions/common/sessionsManagement.ts Renames/adjusts management service APIs (sendNewChatRequest, async openNewChatInSession).
src/vs/sessions/services/sessions/common/session.ts Updates ISession.mainChat to IObservable<IChat> and documents replacement semantics.
src/vs/sessions/services/sessions/browser/sessionsManagementService.ts Moves new-chat send flow to createNewChat → open widget → sendRequest; makes openNewChatInSession async.
src/vs/sessions/contrib/terminal/test/browser/sessionsTerminalContribution.test.ts Updates session stubs to mainChat observable.
src/vs/sessions/contrib/terminal/test/browser/agentHostSessionTaskRunner.test.ts Updates session stubs to mainChat observable.
src/vs/sessions/contrib/sessions/test/browser/sessionsListModelService.test.ts Adjusts tests for mainChat observable usage.
src/vs/sessions/contrib/sessions/test/browser/sessionsList.test.ts Updates session test helper to provide observable mainChat.
src/vs/sessions/contrib/sessions/browser/views/sessionsViewActions.ts Updates rename/add-chat actions for observable mainChat and async openNewChatInSession.
src/vs/sessions/contrib/providers/remoteAgentHost/test/browser/remoteAgentHostSessionsProvider.test.ts Updates provider tests to the new createNewChat + sendRequest flow.
src/vs/sessions/contrib/providers/copilotChatSessions/test/browser/copilotChatSessionsProvider.test.ts Updates Copilot provider tests for new chat creation and observable mainChat.
src/vs/sessions/contrib/providers/copilotChatSessions/COPILOT_CHAT_SESSIONS_PROVIDER.md Rewrites send-flow documentation to match createNewChat + sendRequest contract.
src/vs/sessions/contrib/providers/copilotChatSessions/browser/copilotChatSessionsProvider.ts Refactors Copilot provider to support createNewChat, observable main-chat replacement, and management-owned widget opening.
src/vs/sessions/contrib/providers/agentHost/test/browser/localAgentHostSessionsProvider.test.ts Updates agent-host provider tests to the new chat API.
src/vs/sessions/contrib/providers/agentHost/test/browser/agentHostSkillButtons.test.ts Updates session stubs to mainChat observable.
src/vs/sessions/contrib/providers/agentHost/browser/baseAgentHostSessionsProvider.ts Implements createNewChat and shifts widget opening out of the provider; updates ISession.mainChat.
src/vs/sessions/contrib/layout/test/browser/sessionLayoutController.test.ts Updates session stubs to mainChat observable.
src/vs/sessions/contrib/github/test/browser/githubContribution.test.ts Updates test session implementation for observable mainChat.
src/vs/sessions/contrib/chat/test/browser/worktreeCreatedTaskDispatcher.test.ts Updates session stubs to mainChat observable.
src/vs/sessions/contrib/chat/test/browser/workbenchSessionTaskRunner.test.ts Updates session stubs to mainChat observable.
src/vs/sessions/contrib/chat/test/browser/sessionWorkspacePicker.test.ts Updates provider mock to include createNewChat and new sendRequest signature.
src/vs/sessions/contrib/chat/test/browser/sessionsTaskService.test.ts Updates session stubs to mainChat observable.
src/vs/sessions/contrib/chat/browser/runScriptAction.ts Updates widget lookup and send flow to use observable mainChat and sendNewChatRequest.
src/vs/sessions/contrib/chat/browser/newChatViewPane.ts Updates send path to call sendNewChatRequest.
src/vs/sessions/browser/parts/chatCompositeBar.ts Updates reactive tab rebuild logic to read mainChat via observable.

Copilot's findings

  • Files reviewed: 28/28 changed files
  • Comments generated: 5

Comment thread src/vs/sessions/services/sessions/browser/sessionsManagementService.ts Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
- sessionsManagementService.sendNewChatRequest: open the chat widget
  with ChatViewPaneTarget so it lands in the chat view (matches the
  other openSession call sites in this service).
- copilotChatSessionsProvider.createNewChat & _createNewSubsequentChat:
  dispose the IDisposable returned by _createChatSession so the model
  reference acquired via acquireOrLoadSession is not leaked.
- copilotChatSessionsProvider._sendExistingChat: capture the disposable
  from _updateChatSessionState and release it in a finally so the model
  reference does not leak on every send.
- copilotChatSessionsProvider._sendFirstChat: when chatService.sendRequest
  returns kind 'rejected', clean up the temp session (cache, group cache,
  current-new-session, fire removed event, dispose) before throwing so
  the UI does not keep showing a stuck InProgress session.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sandy081 sandy081 merged commit de1cfec into main May 21, 2026
25 checks passed
@sandy081 sandy081 deleted the sandy081/sessions-provider-cleanup branch May 21, 2026 23:27
@vs-code-engineering vs-code-engineering Bot added this to the 1.122.0 milestone May 21, 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.

4 participants