sandy081's Description of Work
When a provider commits a draft by replacing it with a session under a different resource, the draft's side-pane tabs (Changes, Files and any opened files) were closed on submit.
Cause
SessionsService handles onDidReplaceSession first and switches the active session synchronously. The layout controller then sees an owner change from the draft key to the committed key and queues a working-set apply. Drafts never save a working set, so the apply resolves to 'empty' and closes the draft's editors. _onSessionReplaced runs only afterwards, too late to carry anything over.
Fix
BaseLayoutController._onSessionReplaced marks the committed session when it replaced the active draft under a different resource and has no saved working set. The queued apply, which runs after both listeners, skips the 'empty' apply for that session, so it keeps the editors on screen and saves them normally when the user leaves. The mark is cleared if the active session moves elsewhere, so another session's tabs can't carry over.
Unchanged: switching from a draft to another existing session still applies that session's working set (possibly empty).
Notes for reviewers
- The extension-backed Copilot Chat Sessions provider commits to a new resource and hits this path. The local Agent Host provider commits to the same resource, so the owner key doesn't change there.
- This was investigated from a report of an empty editor group (Add Tab list) next to the Files details after submitting a new session with the Agent Host Copilot CLI provider. On a dev build (isolated smoke profile, mock LLM) I could not reproduce that report, with the side pane open or closed at submit and opened right after submit or once the session view had loaded. So this PR fixes the related, test-proven defect and does not claim to fix that report. Every mock turn failed with an unrelated allowed-model policy error, and the harness can't select worktree isolation, so a successful worktree-isolated turn was not replayed.
- Likely long-standing: the owner-change "saved working set or
'empty'" apply goes back to #310225 / #315696. Existing submit tests didn't configure workspace folders, so no working-set apply ran in them.
Testing
- New test
[managed tabs / submit] a resource-replace submit keeps the draft's tabs, 4 variants (Editor visible or Details only; replace event before or after the session switch). All 4 fail without the fix and pass with it:./scripts/test.sh --run src/vs/sessions/contrib/layout/test/browser/desktopLayoutController.test.ts --grep "resource-replace submit keeps" -
./scripts/test.sh --runGlob "vs/sessions/contrib/layout/test/**/*.test.js": 291 passing -
npm run typecheck-client: passed -
npm run eslintand hygiene on the changed files: passed