Skip to content

Avoid stale active client updates after session disposal - #332458

Open
Dmitriy Vasyura (dmitrivMS) wants to merge 1 commit into
mainfrom
dev/dmitriv/avoid-stale-active-client-dispatch
Open

Avoid stale active client updates after session disposal#332458
Dmitriy Vasyura (dmitrivMS) wants to merge 1 commit into
mainfrom
dev/dmitriv/avoid-stale-active-client-dispatch

Conversation

@dmitrivMS

Copy link
Copy Markdown
Collaborator

Regression from #330378.

Regression details

A scan of recent Insiders logs found 41 instances of this Agent Host error signature across three sessions:

[AgentService] async dispatchAction failed: Session was explicitly deleted: copilotcli:/<session>

AHP traffic for the latest non-shutdown occurrence showed the deterministic sequence:

  1. The client successfully published its initial session/activeClientSet.
  2. The session was deleted with disposeSession.
  3. The workbench-side ActiveClientEntry remained attached to its customization scope.
  4. A customization refresh 94 minutes later caused another session/activeClientSet for the deleted backend session.
  5. The Agent Host correctly rejected that stale action because the session was tombstoned.

The reconciler retained _claimRequested after its first successful publication, so missing backend state was indistinguishable from the pre-hydration state where an initial claim is valid.

Fix

Track the backend session whose state has already been observed. If that same session state later disappears, stop reconciliation instead of publishing a new active-client claim. Initial claims before hydration and rebinding to a different backend session remain supported.

Tests

  • Added does not republish activeClientSet after backend session state is removed, which models the claim echo, backend state removal, and later customization refresh.
  • Ran the new regression test and seven adjacent active-client reconciliation tests: 8/8 passed.
  • npm run transpile-client
  • Editor diagnostics on both changed files
  • git diff --check
  • Pre-commit hygiene checks

A fresh Insiders runtime log reproduction was not performed; the focused test covers the observed AHP sequence.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dmitrivMS Dmitriy Vasyura (dmitrivMS) added the bug Issue identified by VS Code Team member as probable bug label Aug 25, 2026
Copilot AI balanced review requested due to automatic review settings August 25, 2026 00:16
@dmitrivMS Dmitriy Vasyura (dmitrivMS) added chat agent-host Issues for the agent-host implementation (not the protocol) bug Issue identified by VS Code Team member as probable bug labels Aug 25, 2026

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.

Pull request overview

Prevents stale active-client updates after an Agent Host session is deleted.

Changes:

  • Tracks previously observed backend sessions during reconciliation.
  • Stops publishing when an observed session state disappears.
  • Adds regression coverage for deletion followed by customization refresh.
Show a summary per file
File Description
agentHostSessionHandler.ts Guards reconciliation for removed backend sessions.
agentHostChatContribution.test.ts Tests stale publication prevention.

Review details

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

this._state.set(true, undefined);
this._publishDelayer.trigger(async () => {
try {
if (this._cancellation.token.isCancellationRequested) {

@connor4312 Connor Peet (connor4312) Aug 25, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If the session is disposed, the ActiveClientEntry should also be disposed which should be triggering cancellation here

this._register(toDisposable(() => this._cancellation.dispose(true)));

If the hypothesis on the root cause is correct, that is the underlying bug we should fix instead imo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-host Issues for the agent-host implementation (not the protocol) bug Issue identified by VS Code Team member as probable bug chat

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants