Skip to content

Reconnect to in-progress remote agent host chat sessions#304589

Merged
rzhao271 merged 9 commits intomainfrom
roblou/reconnect-active-ah-session
Mar 26, 2026
Merged

Reconnect to in-progress remote agent host chat sessions#304589
rzhao271 merged 9 commits intomainfrom
roblou/reconnect-active-ah-session

Conversation

@roblourens
Copy link
Copy Markdown
Member

When opening a remote agent host session that has an active (in-progress) turn, the chat UI now reconnects to it and streams ongoing progress instead of only showing completed turns as history.

Changes

agentHostSessionHandler.ts

  • AgentHostChatSession: Accepts initialProgress for reconnection. Sets isCompleteObs=false and seeds progressObs when reconnecting. Exposes appendProgress() and complete() for the reconnect flow. interruptActiveResponseCallback is mutable so reconnection can replace it with a real cancel callback.
  • provideChatSessionContent: Detects sessionState.activeTurn, includes the active turn's request in history with an empty response placeholder, generates initial progress via activeTurnToProgress(), and calls _reconnectToActiveTurn().
  • _reconnectToActiveTurn() (new): Streams incremental state changes into progressObs. Extracts live ChatToolInvocation objects from initialProgress (same instances the chat UI holds). Handles text/reasoning deltas, tool call lifecycle, permission resolution, turn completion/error. Dispatches session/turnCancelled on interrupt. Immediately reconciles after listener registration to close the snapshot-to-listener race.
  • _wireUpPermissionConfirmation() (new): Shared helper for interactive permission confirmation with CancellationTokenSource cleanup.

stateToProgressAdapter.ts

  • activeTurnToProgress(): Converts an IActiveTurn's accumulated state (reasoning, streaming text, tool calls, permissions) into IChatProgress[] items suitable for initial replay.

Tests

  • 7 new tests for activeTurnToProgress in stateToProgressAdapter.test.ts
  • 10 new reconnection integration tests in agentHostChatContribution.test.ts covering: history loading, progressObs/isCompleteObs state, interrupt callback dispatch, live streaming, turn completion, tool calls, permissions, reasoning, and no-active-turn baseline

(Written by Copilot)

When opening a remote agent host session that has an active (in-progress)
turn, the chat UI now reconnects to it and streams ongoing progress
instead of only showing completed turns as history.

Key changes:
- activeTurnToProgress() converts accumulated active turn state into
  IChatProgress[] for initial replay
- provideChatSessionContent detects activeTurn on session state, includes
  it in history, and wires up live streaming via progressObs
- _reconnectToActiveTurn(): streams incremental text/reasoning/tool
  call/permission updates, handles turn completion, dispatches
  turnCancelled on interrupt, resolves pending permissions interactively
- Fixes live object identity (reuses ChatToolInvocation instances from
  initial progress), snapshot-to-listener race (immediate reconciliation),
  and proper cancellation dispatch

(Written by Copilot)
Copilot AI review requested due to automatic review settings March 24, 2026 22:41
@vs-code-engineering vs-code-engineering bot added this to the 1.114.0 milestone Mar 24, 2026
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

This PR enables the chat UI to reconnect to an in-progress remote agent host session turn, replaying accumulated partial output and then continuing to stream live progress (text/reasoning/tool activity/permissions) instead of showing only completed turns.

Changes:

  • Added activeTurnToProgress() to convert an IActiveTurn snapshot into replayable IChatProgress[] (including live ChatToolInvocations where applicable).
  • Updated AgentHostSessionHandler.provideChatSessionContent and session plumbing to seed progressObs/isCompleteObs when an active turn exists and to attach a reconnection listener that streams incremental state changes.
  • Added unit tests for activeTurnToProgress and integration tests for reconnection behavior (history seeding, streaming deltas, cancellation dispatch, tool calls, permissions, reasoning).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/vs/workbench/contrib/chat/test/browser/agentSessions/stateToProgressAdapter.test.ts Adds unit tests covering activeTurnToProgress behavior and ordering.
src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostChatContribution.test.ts Adds integration tests validating reconnection to an active turn and live streaming behavior.
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/stateToProgressAdapter.ts Introduces activeTurnToProgress() to replay active turn state into chat progress items.
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostSessionHandler.ts Implements reconnection flow: seeds session observables, streams live state updates, and wires permission confirmation + cancellation for active turns.

…mpleted tool calls between snapshots

(Written by Copilot)
joshspicer
joshspicer previously approved these changes Mar 25, 2026
@roblourens roblourens enabled auto-merge (squash) March 25, 2026 16:09
@roblourens roblourens force-pushed the roblou/reconnect-active-ah-session branch from cb56b55 to 6c2aa29 Compare March 25, 2026 22:27
@rzhao271 rzhao271 closed this Mar 26, 2026
auto-merge was automatically disabled March 26, 2026 00:10

Pull request was closed

@rzhao271 rzhao271 reopened this Mar 26, 2026
@rzhao271 rzhao271 enabled auto-merge (squash) March 26, 2026 00:10
rzhao271
rzhao271 previously approved these changes Mar 26, 2026
@rzhao271
Copy link
Copy Markdown
Collaborator

Looks like an actual build error.
Error: [core-ci ] src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostChatContribution.test.ts(1730,6): error TS2353: Object literal may only specify known properties, and 'confirmed' does not exist in type 'IToolCallPendingConfirmationState'.

@roblourens
Copy link
Copy Markdown
Member Author

lmao thanks

…ve-ah-session

# Conflicts:
#	src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostSessionHandler.ts
#	src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostChatContribution.test.ts
@rzhao271 rzhao271 merged commit d260229 into main Mar 26, 2026
18 checks passed
@rzhao271 rzhao271 deleted the roblou/reconnect-active-ah-session branch March 26, 2026 23:22
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.

5 participants