Skip to content

Propagate agent session hydration cancellation - #328342

Draft
Rob Lourens (roblourens) wants to merge 2 commits into
microsoft:mainfrom
roblourens:roblou/agents/session-hydration-cancellation
Draft

Propagate agent session hydration cancellation#328342
Rob Lourens (roblourens) wants to merge 2 commits into
microsoft:mainfrom
roblourens:roblou/agents/session-hydration-cancellation

Conversation

@roblourens

Copy link
Copy Markdown
Member

Summary

  • reject session hydration waits when their cancellation token is cancelled
  • avoid converting cancelled loads into empty contributed chat sessions
  • add regression coverage for cancellation followed by a clean retry

Validation

  • targeted AgentHostChatContribution tests
  • npm run typecheck-client
  • npm run valid-layers-check
  • hygiene checks

(Written by Copilot)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 31, 2026 03:02

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

Note

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

This PR improves cancellation behavior during agent session hydration so cancelled loads fail fast and don’t get converted into empty chat sessions, and it adds regression coverage for cancellation followed by a successful retry.

Changes:

  • Propagate cancellation by rejecting hydration waits with a cancellation error.
  • Avoid swallowing cancellation errors during subscription so callers can abort cleanly.
  • Add a regression test covering cancellation and subsequent retry.
Show a summary per file
File Description
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostSessionHandler.ts Changes hydration/cancellation semantics to reject on cancellation and rethrow cancellation errors.
src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostChatContribution.test.ts Adds a regression test ensuring cancellation rejects and retry works after a delayed subscription error.

Review details

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

Comment on lines +3587 to +3603
test('cancelling session hydration rejects without creating an empty session', async () => {
const sessionResource = URI.from({ scheme: 'agent-host-copilot', path: '/cancelled-hydration' });
const backendSession = AgentSession.uri('copilot', 'cancelled-hydration');
const { sessionHandler, agentHostService } = createContribution(disposables);
agentHostService.makePendingErrorSub(backendSession.toString());

const cancellation = disposables.add(new CancellationTokenSource());
const loadPromise = sessionHandler.provideChatSessionContent(sessionResource, cancellation.token);
cancellation.cancel();

await assert.rejects(loadPromise, isCancellationError);

agentHostService.firePendingSubError(backendSession.toString(), new Error('Delayed subscription failed'));
const retriedSession = await sessionHandler.provideChatSessionContent(sessionResource, CancellationToken.None);
disposables.add(toDisposable(() => retriedSession.dispose()));
assert.deepStrictEqual(retriedSession.history, []);
});
Comment on lines 5227 to 5231
/**
* Resolves once a subscription has received its first snapshot (its
* `value` is no longer `undefined`) — i.e. it has hydrated with state or
* an error. Resolves immediately if already hydrated or if cancellation
* is requested.
* an error. Rejects with a cancellation error if cancellation is requested.
*/
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

2 participants