Agents web: improve connection stability and terminal reconnection#312189
Merged
Agents web: improve connection stability and terminal reconnection#312189
Conversation
Contributor
osortega
commented
Apr 23, 2026
- 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
Contributor
There was a problem hiding this comment.
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()andIAgentHostTerminalService.reconnectTerminals()to rehydrate/replay terminal state after reconnect. - Trigger terminal reconnection from the sessions-side
RemoteAgentHostContributionwhen 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
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
rzhao271
reviewed
Apr 23, 2026
| if (newConnection) { | ||
| this._agentHostTerminalService.reconnectTerminals(newConnection, oldClientId).then( | ||
| ({ recovered, total }) => { | ||
| if (total > 0) { |
rzhao271
approved these changes
Apr 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.