Skip to content

Fix Changes view stuck empty after first message in new agent host session#316088

Closed
roblourens wants to merge 5 commits into
mainfrom
roblou/fix-ah-diffs-after-first-message
Closed

Fix Changes view stuck empty after first message in new agent host session#316088
roblourens wants to merge 5 commits into
mainfrom
roblou/fix-ah-diffs-after-first-message

Conversation

@roblourens
Copy link
Copy Markdown
Member

Fix

In the agents/sessions code, the "New Session" picker (NewSession.session in baseAgentHostSessionsProvider.ts) 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 and the chat widget doesn't have to be re-opened against a different URI.

When sendAndCreateChat fired _onDidReplaceSession({from: skeleton, to: adapter}), SessionsManagementService.setActiveSession(adapter) hit this early-return:

if (previousSession?.sessionId === session?.sessionId) 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 (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 ISession instance alongside _activeSession and requires both sessionId equality 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 NewSession and AgentHostSessionAdapter so a single instance gets "promoted" instead of replaced, but this fix is contained to the management service and addresses the symptom.

Validation

  • Reproduced AgentHost: Diffs missing after first message #315936 with a fresh new local agent host session and an "append a single line to README.md" message — Changes view stayed empty.
  • Confirmed the trace matches the diagnosis: _handleDiffsChanged writes diffs into cached.changes, sessionFileChangesEqual returns false, _onDidReplaceSession fires with from.sessionId === to.sessionId, and setActiveSession early-returns.
  • After the fix the active session is rewired on replace and the view derived re-evaluates against the adapter's changes observable.
  • npm run compile-check-ts-native passes.
  • Existing SessionsManagementService unit tests pass (./scripts/test.sh --grep deduplicateSessions).

Fixes #315936

…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>
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

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 ISession instance used to build the current IActiveSession.
  • Update setActiveSession to early-return only when both sessionId and underlying session instance are unchanged, allowing same-sessionId replacements 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

Comment thread src/vs/sessions/services/sessions/browser/sessionsManagementService.ts Outdated
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>
@roblourens roblourens marked this pull request as ready for review May 12, 2026 22:22
@roblourens roblourens requested a review from sandy081 as a code owner May 12, 2026 22:22
@roblourens roblourens enabled auto-merge (squash) May 12, 2026 22:22
roblourens and others added 3 commits May 12, 2026 15:38
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>
@roblourens roblourens closed this May 13, 2026
auto-merge was automatically disabled May 13, 2026 16:30

Pull request was closed

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.

AgentHost: Diffs missing after first message

2 participants