Skip to content

sessions: refactor branch/isolation pickers to use session as source of truth#305128

Merged
sandy081 merged 5 commits intomainfrom
copilot/naval-boa
Mar 26, 2026
Merged

sessions: refactor branch/isolation pickers to use session as source of truth#305128
sandy081 merged 5 commits intomainfrom
copilot/naval-boa

Conversation

@sandy081
Copy link
Copy Markdown
Member

Summary

Refactors the branch picker and isolation picker in the Copilot Chat sessions provider so that CopilotCLISession is the single source of truth for all branch and isolation state.

What changed

CopilotCLISession — now owns branch loading

  • Branches are loaded inside the session object after git repository resolves (moved from BranchPicker)
  • Added branches (observable list), branchesLoading (observable), and _defaultBranch fields
  • setBranch() now updates _branchObservable so the picker reacts
  • setIsolationMode() resets branch to _defaultBranch when switching to folder mode
  • _isolationModeObservable initialized to 'worktree' to match the internal default

BranchPicker — simplified to a pure view

  • Removed all local state (_branches, _selectedBranch, _loading, _disabled, CTS, event emitters)
  • Reads everything from session observables (branches, branchesLoading, branchObservable, isolationModeObservable)
  • Disables itself when isolation mode is 'workspace' (folder)

IsolationPicker — no longer duplicates state

  • Removed local _isolationMode field; reads from session via session.isolationMode
  • No longer writes back to session during initialization (which was causing the reset bug)
  • Only writes to session on explicit user selection

Why

Previously, pickers maintained their own local state and wrote it back to the session. This caused several bugs:

  1. Isolation reset: Changing isolation to "Folder" triggered a context key change → toolbar recreation → new IsolationPicker with default 'worktree', overwriting the user's selection
  2. Branch state duplication: Branch loading logic lived in the UI widget, making it hard to coordinate with isolation mode changes
  3. Observable not updated: _isolationModeObservable and _branchObservable were never set, so reactive consumers couldn't track changes

Copilot AI review requested due to automatic review settings March 26, 2026 11:20
@sandy081 sandy081 self-assigned this Mar 26, 2026
@vs-code-engineering vs-code-engineering bot added this to the 1.114.0 milestone Mar 26, 2026
@sandy081 sandy081 enabled auto-merge (squash) March 26, 2026 11:21
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

Refactors the Copilot Chat sessions new-session UI pickers so that CopilotCLISession becomes the single source of truth for isolation mode and branch state, with the pickers acting as reactive views over session observables.

Changes:

  • Move git branch loading/state (branches, branchesLoading, default branch selection) into CopilotCLISession.
  • Update CopilotCLISession to keep _branchObservable / _isolationModeObservable in sync when setters are called.
  • Simplify BranchPicker and IsolationPicker to read/write session state rather than duplicating local state.

Reviewed changes

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

File Description
src/vs/sessions/contrib/copilotChatSessions/browser/copilotChatSessionsProvider.ts Adds branch-loading + branch/isolation observables to CopilotCLISession and updates setters to keep observables synchronized.
src/vs/sessions/contrib/copilotChatSessions/browser/branchPicker.ts Removes local loading/branch state and renders purely from session observables; disables interaction when isolation is folder mode.
src/vs/sessions/contrib/copilotChatSessions/browser/isolationPicker.ts Removes local isolation state/event emission and updates the picker to use session as the source of truth.

@sandy081 sandy081 merged commit 8de7f23 into main Mar 26, 2026
59 of 66 checks passed
@sandy081 sandy081 deleted the copilot/naval-boa branch March 26, 2026 13:45
mjbvz pushed a commit to mjbvz/vscode that referenced this pull request Mar 26, 2026
…of truth (microsoft#305128)

* add isolation mode handling to branch picker and session actions

* restore session's isolation mode on picker recreation

* remove unused isolation context key from session actions

* set default isolation mode to 'worktree' in CopilotCLISession and update isolation mode handling in IsolationPicker

* refactor: streamline BranchPicker and CopilotCLISession for improved branch handling and loading logic
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.

3 participants