Fix Changes view stuck empty after first message in new agent host session#316088
Closed
roblourens wants to merge 5 commits into
Closed
Fix Changes view stuck empty after first message in new agent host session#316088roblourens wants to merge 5 commits into
roblourens wants to merge 5 commits into
Conversation
…ssion
The "New Session" skeleton (NewSession.session) and the AgentHostSessionAdapter
that the AHP server eventually creates for the same chat URI are two distinct
ISession instances that share the same sessionId — the skeleton's UUID is
intentionally reused as the committed session's URI path so the chat URI stays
stable across the swap.
When sendAndCreateChat fired _onDidReplaceSession({from: skeleton, to: adapter}),
SessionsManagementService.setActiveSession(adapter) hit the
`previousSession?.sessionId === session?.sessionId` early-return and silently
skipped the swap. The active session kept holding the spread-copy of the
skeleton, whose `changes` observable is a separate instance from the adapter's,
so diffs that landed in the adapter never reached subscribers (notably the
Changes view).
Switching to a different session and back used to fix it because the
intermediate session had a different sessionId, breaking the early-return
both times.
Track the underlying ISession instance alongside _activeSession and require
both sessionId equality AND instance identity to early-return, so a same-id
replace actually rewires the active session to the new instance.
Fixes #315936
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes an Agents window regression where the Changes view could remain empty after the first message in a newly created agent host session, due to the active session not being rewired when the provider replaces a “skeleton” session instance with a committed adapter that shares the same sessionId.
Changes:
- Track the underlying
ISessioninstance used to build the currentIActiveSession. - Update
setActiveSessionto early-return only when bothsessionIdand underlying session instance are unchanged, allowing same-sessionIdreplacements to rebind observables.
Show a summary per file
| File | Description |
|---|---|
| src/vs/sessions/services/sessions/browser/sessionsManagementService.ts | Ensures active session rewires on same-sessionId instance swaps so downstream observers (e.g. Changes view) see updates. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 1
Verified that the test fails without the early-return instance check in setActiveSession, then passes with it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comparing only `changes` was fragile — if any other observable later gets shared between instances the same bug returns silently. Track the underlying ISession reference alongside _activeSession.set so identity comparison covers any future field. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This reverts commit 3d92e6b.
auto-merge was automatically disabled
May 13, 2026 16:30
Pull request was closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix
In the agents/sessions code, the "New Session" picker (
NewSession.sessioninbaseAgentHostSessionsProvider.ts) and theAgentHostSessionAdapterthat the AHP server eventually creates for the same chat URI are two distinctISessioninstances that share the samesessionId. The skeleton's UUID is intentionally reused as the committed session's URI path so the chat URI stays stable across the swap and the chat widget doesn't have to be re-opened against a different URI.When
sendAndCreateChatfired_onDidReplaceSession({from: skeleton, to: adapter}),SessionsManagementService.setActiveSession(adapter)hit this early-return:…and silently skipped the swap. The active session kept holding the spread-copy of the skeleton, whose
changesobservable is a separate instance from the adapter's, so diffs that landed in the adapter (AgentHostSessionAdapter.changes) never reached subscribers — notably the Changes view, which stayed empty after the first message.Switching to a different session and back was the only workaround, because the intermediate session has a different
sessionId, breaking the early-return both times.This change tracks the underlying
ISessioninstance alongside_activeSessionand requires bothsessionIdequality AND instance identity to early-return, so a same-id replace actually rewires the active session to the new instance.A more invasive follow-up would unify
NewSessionandAgentHostSessionAdapterso a single instance gets "promoted" instead of replaced, but this fix is contained to the management service and addresses the symptom.Validation
_handleDiffsChangedwrites diffs intocached.changes,sessionFileChangesEqualreturnsfalse,_onDidReplaceSessionfires withfrom.sessionId === to.sessionId, andsetActiveSessionearly-returns.changesobservable.npm run compile-check-ts-nativepasses.SessionsManagementServiceunit tests pass (./scripts/test.sh --grep deduplicateSessions).Fixes #315936