Skip to content

Fix #345692: Preserve draft open editors when replacing new draft session - #345807

Merged
Kyle Cutler (kycutler) merged 2 commits into
microsoft:mainfrom
genius-0963:fix-issue-345692
Nov 4, 2026
Merged

Kyle Cutler (kycutler) merged 2 commits into
microsoft:mainfrom
genius-0963:fix-issue-345692

Conversation

@genius-0963

Copy link
Copy Markdown
Contributor

Fixes #345692

Description

When changing the workspace folder of a draft session in the Agents window composer (or when a draft is replaced pre-send), onDidReplaceNewDraftSession is emitted with { from, to }.

Previously, BaseLayoutController listened to onDidReplaceNewDraftSession by calling _forgetPeerChatState(this._chatLayoutOwnerKeys.forgetSession(from.resource)). This forgot the outgoing draft's session state without transferring layout or working set state to the incoming replacement draft to. Consequently, when to was activated as the active session, BaseLayoutController's working set restore treated to as having an empty working set ('empty') and ran applyWorkingSet('empty'). This wiped all open editors in the editor group, destroying any browser tab opened from the composer before SessionBrowserNetworkContribution could reconcile and preserve it with the new folder's storage affinity.

This PR updates BaseLayoutController to route onDidReplaceNewDraftSession through _onSessionReplaced(from, to), mirroring how onDidReplaceSession handles draft graduation. This:

  • Sets _workingSetAdoptingReplacement on to.resource so the new draft adopts the active draft's open editors and layout instead of resetting with an empty working set.
  • Preserves editor-part and panel visibility and view state across draft replacement.
  • Remaps chat layout owner keys from from to to.

Verification Steps

  1. Run unit tests:
    node test/unit/browser/index.js --browser chromium --run src/vs/sessions/contrib/layout/test/browser/baseSessionLayoutController.test.ts
    node test/unit/browser/index.js --browser chromium --run src/vs/sessions/contrib/browserView/test/browser/sessionBrowserNetwork.test.ts
    node test/unit/browser/index.js --browser chromium --run src/vs/sessions/contrib/layout/test/browser/desktopLayoutController.test.ts
  2. Manual verification:
    • In the Agents window, open the new-session composer and select a remote host and folder A.
    • Open the integrated browser tab from the session activity bar and navigate to a URL.
    • Change the workspace folder to folder B in the composer.
    • Verify that the browser tab remains open, preserving its URL while updating its session storage affinity, and is not destroyed.

Copilot AI balanced review requested due to automatic review settings November 3, 2026 12:24
@genius-0963

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

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.

🟢 Approval recommended

No active review issues remain for the draft-session state-preservation change, although tests were not run during review.

No open issues 🎉

What changed in this PR

Fixes #345692 by preserving open editors and layout state when a draft session is replaced in the Agents window, preventing workspace-folder changes from closing its browser tab.

Changes:

  • Routes draft replacement through the existing session-replacement handler to transfer working-set and layout state.
  • Adds regression tests for remembered panel views and avoiding an empty working-set restore.

No actionable findings remain. Tests were not run during this review.

File Description
src/​vs/​sessions/​contrib/​layout/​test/​browser/​baseSessionLayoutController.test.ts Adds panel-state and working-set preservation tests for draft replacement.
src/​vs/​sessions/​contrib/​layout/​browser/​baseSessionLayoutController.ts Reuses session-replacement handling for new drafts and updates its explanatory comment.

Review effort: Balanced

@kycutler Kyle Cutler (kycutler) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good, thank you Saurabh Sungh (@genius-0963)!

@kycutler
Kyle Cutler (kycutler) enabled auto-merge (squash) November 3, 2026 22:36
@kycutler
Kyle Cutler (kycutler) merged commit 29085a1 into microsoft:main Nov 4, 2026
55 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.146.0 milestone Nov 4, 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.

Agents: changing a draft session folder destroys its browser tab (Dev Tunnels)

5 participants