Skip to content

fix: return noop subscription from rootState when no protocol client (fixes #318222)#318233

Open
vs-code-engineering[bot] wants to merge 1 commit into
mainfrom
fix/agent-host-rootstate-throw-318222-5440c82c65c14cab
Open

fix: return noop subscription from rootState when no protocol client (fixes #318222)#318233
vs-code-engineering[bot] wants to merge 1 commit into
mainfrom
fix/agent-host-rootstate-throw-318222-5440c82c65c14cab

Conversation

@vs-code-engineering
Copy link
Copy Markdown
Contributor

🔧 Error Fix

Summary

The EditorRemoteAgentHostServiceClient.rootState getter unconditionally called _requireClient() which throws Error: Remote agent host is not enabled or no remote connection is available. when the agent host is disabled or no remote connection exists. The agentHostSandboxForwarder (introduced in f32c055) subscribes to rootState.onDidChange and reads rootState.value on configuration changes, triggering this unhandled error in telemetry across all platforms.

Fixes #318222
Recommended reviewer: @chrmarti

Culprit Commit

  • Commit: f32c0553 "Sandboxing for Copilot SDK integration (Support sandboxing for the Copilot SDK integration #317981)" by @chrmarti (2026-05-22)
  • Why: Introduced agentHostSandboxForwarder.ts which eagerly accesses rootState on the injected IRemoteAgentHostService (backed by EditorRemoteAgentHostServiceClient) without handling the no-client case. Combined with b4b5c20c ("Enable agent host by default for insiders") which increased the surface area.

Code Flow

sequenceDiagram
    participant CS as ConfigurationService
    participant SF as SandboxForwarder
    participant RAHSC as EditorRemoteAgentHostServiceClient
    CS->>SF: onDidChangeConfiguration (sandbox key)
    SF->>SF: _pushToAllConnections()
    SF->>RAHSC: connection.rootState (getter)
    RAHSC->>RAHSC: _requireClient()
    Note over RAHSC: _protocolClient is undefined (disabled/no remote)
    RAHSC-->>SF: throws Error
    Note over SF: Unhandled error reaches telemetry
Loading

Affected Files

File Role
src/vs/workbench/services/agentHost/browser/editorRemoteAgentHostServiceClient.ts Producer of the error — rootState getter throws instead of returning a safe fallback
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/agentHostSandboxForwarder.ts Consumer that triggers the throw via config-change subscription

Repro Steps

  1. Open VS Code Insiders (1.122.0+) on desktop without a remote connection
  2. An extension registers default configurations (experimental settings) triggering onDidChangeConfiguration
  3. agentHostSandboxForwarder._pushToAllConnections() fires
  4. Accessing rootState on the EditorRemoteAgentHostServiceClient throws because _protocolClient is undefined

How the Fix Works

Chosen approach (editorRemoteAgentHostServiceClient.ts): Replace the throwing _requireClient() call in the rootState getter with this._protocolClient?.rootState ?? this._noopRootState, where _noopRootState is a static object implementing IAgentSubscription<RootState> with value: undefined and all events as Event.None. This fixes the error at the data producer — the getter that produces an exception instead of the safe fallback that the interface contract allows (.value can be undefined per the interface docs). The consumer (_pushToConnection) already guards against undefined values at line 92, so it correctly no-ops.

Alternatives considered: Adding a try/catch in _pushToConnection would mask the error at the crash site without fixing the inconsistency in the service client; the getter is the only one among its siblings (clientId, onDidNotification, onDidAction) that throws instead of returning a safe default.

Recommended Owner

@chrmarti — authored the agentHostSandboxForwarder.ts that exposed this latent bug, and owns the sandboxing integration for Copilot SDK.

Generated by errors-fix · ● 27.7M ·

…ixes #318222)

The EditorRemoteAgentHostServiceClient.rootState getter unconditionally
called _requireClient() which throws when the agent host is disabled or
no remote connection exists. Other getters (clientId, onDidNotification,
onDidAction) already handle this gracefully with ?. and ??.

When the agentHostSandboxForwarder subscribes to rootState.onDidChange
or reads rootState.value on a config change, the throw becomes an
unhandled error in telemetry.

Return a static noop IAgentSubscription (value: undefined, events:
Event.None) when _protocolClient is absent, matching the existing
guard in _pushToConnection that early-returns on undefined values.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 25, 2026 15:59
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@vs-code-engineering vs-code-engineering Bot requested review from chrmarti and Copilot May 25, 2026 16:01
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@vs-code-engineering vs-code-engineering Bot marked this pull request as ready for review May 25, 2026 16:02
@vs-code-engineering vs-code-engineering Bot enabled auto-merge (squash) May 25, 2026 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Error] unhandlederror-Remote agent host is not enabled or no remote connection is available.

2 participants