Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR cherry-picks changes from PR #4160 to add WebSocket request/response header support. It enables WebSocket connections to send full authentication and intent headers (matching the HTTP path), captures response headers from the HTTP upgrade handshake, and propagates request IDs to telemetry events.
Changes:
- Introduces
HeadersImpl(a reusableIHeadersimplementation),WebSocketConnection, andWebSocketConnectOptionstypes; addscreateWebSocketto theIFetcherServiceinterface - Replaces the ad-hoc secret key parameter in WebSocket connection creation with a flexible
headersmap, and captures server response headers via a monkey-patched undici agent - Extends all WebSocket telemetry events with
requestIdandgitHubRequestIdfields from the handshake response headers
Reviewed changes
Copilot reviewed 14 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/platform/networking/common/fetcherService.ts |
Adds HeadersImpl, WebSocketConnection, WebSocketConnectOptions and createWebSocket to IFetcherService |
src/platform/networking/vscode-node/fetcherServiceImpl.ts |
Implements createWebSocket using undici to intercept HTTP 101 response headers |
src/platform/networking/node/chatWebSocketManager.ts |
Refactors connection creation to use headers map; exposes responseHeaders on connections |
src/platform/networking/node/chatWebSocketTelemetry.ts |
Adds requestId/gitHubRequestId to all WebSocket telemetry events |
src/platform/networking/node/nodeFetcher.ts |
Replaces inline anonymous IHeaders implementation with new HeadersImpl |
src/platform/networking/node/test/nodeFetcherService.ts |
Adds stub createWebSocket to implement updated interface |
src/extension/prompt/node/chatMLFetcher.ts |
Builds and passes full header set to WebSocket connection; reads response x-request-id |
src/lib/node/chatLibMain.ts |
Stub createWebSocket in SingleFetcherService |
src/platform/networking/test/node/networking.spec.ts |
Stub createWebSocket in test fetcher |
src/platform/endpoint/node/test/routerDecisionFetcher.spec.ts |
Stub createWebSocket in test fetcher |
src/platform/authentication/test/node/copilotToken.spec.ts |
Stub createWebSocket in test fetcher |
src/extension/mcp/test/vscode-node/util.ts |
Stub createWebSocket in fixture fetcher |
package.json / package-lock.json / chat-lib/package.json / chat-lib/package-lock.json |
Bumps @vscode/copilot-api from 0.2.13 to 0.2.15 |
Files not reviewed (1)
- chat-lib/package-lock.json: Language not supported
Comments suppressed due to low confidence (1)
src/platform/networking/node/chatWebSocketManager.ts:304
- In the
onClosehandler during the connection setup phase (the close-before-open scenario),this._responseHeadersis not updated fromconnection.responseHeadersbefore calling the telemetry sender. By contrast, theonErrorhandler does updatethis._responseHeaders = connection.responseHeadersbefore accessingthis._requestIdandthis._gitHubRequestId. If the server sends response headers before closing (e.g., in an HTTP 401/403 upgrade rejection), those headers won't be available in thecloseDuringSetuptelemetry. The fix is to addthis._responseHeaders = connection.responseHeaders;at the beginning of theonClosehandler in the setup phase, just like it's done inonError.
const onClose = (event: CloseEvent) => {
cleanup();
this._state = ConnectionState.Closed;
const connectDurationMs = Date.now() - (this._connectStartTime ?? Date.now());
const closeCodeDescription = wsCloseCodeToString(event.code);
this._logService.debug(`[ChatWebSocketManager] Connection closed during setup for conversation ${this._conversationId} turn ${this._turnId} (code: ${event.code} ${closeCodeDescription}, reason: ${event.reason || '<empty>'}, wasClean: ${event.wasClean})`);
ChatWebSocketTelemetrySender.sendCloseDuringSetupTelemetry(this._telemetryService, {
conversationId: this._conversationId,
turnId: this._turnId,
requestId: this._requestId,
gitHubRequestId: this._gitHubRequestId,
closeCode: event.code,
closeReason: closeCodeDescription,
closeEventReason: event.reason,
closeEventWasClean: String(event.wasClean),
connectDurationMs,
});
reject(new Error('WebSocket closed during connection setup'));
joaomoreno
approved these changes
Mar 3, 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.
Cherry-picking #4160