Skip to content

Agents web: improve connection stability and terminal reconnection#312189

Merged
osortega merged 3 commits intomainfrom
osortega/disconnect-recovery
Apr 23, 2026
Merged

Agents web: improve connection stability and terminal reconnection#312189
osortega merged 3 commits intomainfrom
osortega/disconnect-recovery

Conversation

@osortega
Copy link
Copy Markdown
Contributor

  • WebSocketClientTransport: fail-fast on send to dead socket with force-close and _closeFired guard to prevent double onClose events
  • AgentHostPty: add reconnect() method with 10s hydration timeout and buffer clear before snapshot replay
  • AgentHostTerminalService: add reconnectTerminals() scoped by oldClientId, track active ptys with dispose cleanup
  • RemoteAgentHostContribution: trigger terminal reconnection on clientId change during reconnect
  • Telemetry: add socket/close, socket/sendDropped, socket/visibilityResumed, terminal/recovery events
  • Fix isMeasurement on boolean fields in existing telemetry

- WebSocketClientTransport: fail-fast on send to dead socket with
  force-close and _closeFired guard to prevent double onClose events
- AgentHostPty: add reconnect() method with 10s hydration timeout
  and buffer clear before snapshot replay
- AgentHostTerminalService: add reconnectTerminals() scoped by
  oldClientId, track active ptys with dispose cleanup
- RemoteAgentHostContribution: trigger terminal reconnection on
  clientId change during reconnect
- Telemetry: add socket/close, socket/sendDropped,
  socket/visibilityResumed, terminal/recovery events
- Fix isMeasurement on boolean fields in existing telemetry
Copilot AI review requested due to automatic review settings April 23, 2026 18:17
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

Improves Agents web reliability by making agent-host WebSocket connections fail fast on zombie sockets and enabling reconnection of agent-host-backed terminals after a client reconnect.

Changes:

  • Add AgentHostPty.reconnect() and IAgentHostTerminalService.reconnectTerminals() to rehydrate/replay terminal state after reconnect.
  • Trigger terminal reconnection from the sessions-side RemoteAgentHostContribution when a connection is re-registered.
  • Extend sessions telemetry with socket lifecycle + terminal recovery events and adjust boolean classifications.
Show a summary per file
File Description
src/vs/workbench/contrib/terminal/browser/agentHostTerminalService.ts Tracks active PTYs per clientId and adds reconnectTerminals() to retarget PTYs to a new connection.
src/vs/workbench/contrib/terminal/browser/agentHostPty.ts Adds reconnect() to resubscribe and replay terminal content after disconnect/reconnect.
src/vs/sessions/contrib/remoteAgentHost/browser/remoteAgentHost.contribution.ts Invokes terminal reconnection when a remote agent host connection’s clientId changes.
src/vs/sessions/common/sessionsTelemetry.ts Adds new telemetry events for socket lifecycle and terminal recovery; fixes boolean field classification.
src/vs/platform/agentHost/browser/webSocketClientTransport.ts Adds send fail-fast behavior and guards to avoid double onClose firing.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 4

Comment thread src/vs/sessions/contrib/remoteAgentHost/browser/remoteAgentHost.contribution.ts Outdated
Comment thread src/vs/platform/agentHost/browser/webSocketClientTransport.ts
Comment thread src/vs/sessions/common/sessionsTelemetry.ts Outdated
Comment thread src/vs/workbench/contrib/terminal/browser/agentHostPty.ts
osortega and others added 2 commits April 23, 2026 11:43
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@osortega osortega marked this pull request as ready for review April 23, 2026 19:02
@osortega osortega enabled auto-merge (squash) April 23, 2026 19:02
if (newConnection) {
this._agentHostTerminalService.reconnectTerminals(newConnection, oldClientId).then(
({ recovered, total }) => {
if (total > 0) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: what if total == 0

@osortega osortega merged commit dcc7279 into main Apr 23, 2026
26 checks passed
@osortega osortega deleted the osortega/disconnect-recovery branch April 23, 2026 20:58
@vs-code-engineering vs-code-engineering Bot added this to the 1.118.0 milestone Apr 23, 2026
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.

3 participants