Skip to content

fix: add timeout to chat control data fetch request (fixes #317337)#317342

Open
vs-code-engineering[bot] wants to merge 1 commit into
mainfrom
fix/chat-control-fetch-timeout-f46ea533acfbc203
Open

fix: add timeout to chat control data fetch request (fixes #317337)#317342
vs-code-engineering[bot] wants to merge 1 commit into
mainfrom
fix/chat-control-fetch-timeout-f46ea533acfbc203

Conversation

@vs-code-engineering
Copy link
Copy Markdown
Contributor

🔧 Error Fix

Summary

The _fetchChatControlData function in the chat language models service makes a periodic network request (every 5 minutes) to fetch chat control data without a request timeout. When the network is slow or unresponsive, the native fetch call hangs indefinitely, causing the CPU profiler to sample it and generate a PerfSampleError: by <> in fetch that reaches error telemetry.

This is a new anomaly in stable 1.120.0, affecting 3,958 users with 6,332 hits across all platforms (Mac, Windows, Linux).

Fixes #317337

Recommended reviewer: @lramos15

Culprit Commit

Commit range narrowing was inconclusive per the regression scan. The _fetchChatControlData function existed prior to 1.120.0, but the absence of a timeout has always been latent. The anomaly likely appeared due to changes in the performance sampling infrastructure or increased server latency in 1.120.0.

Code Flow

sequenceDiagram
    participant LM as languageModels.ts
    participant RS as requestService
    participant RI as requestImpl.ts
    participant Net as Network/fetch
    participant Prof as Profiler

    LM->>LM: _refreshChatControlData() [every 5 min]
    LM->>RS: request({url, callSite, NO timeout})
    RS->>RI: logAndRequest -> request()
    RI->>Net: fetch(url, {signal})
    Note over Net: Network slow/unresponsive
    Prof->>Prof: CPU sample detects fetch on stack
    Prof->>Prof: Creates PerfSampleError
    Prof->>Prof: errorHandler.onUnexpectedError()
    Note over Prof: Error reaches telemetry
Loading

Affected Files

File Role
src/vs/workbench/contrib/chat/common/languageModels.ts Producer of the unbounded fetch call
src/vs/base/parts/request/common/requestImpl.ts Crash site — where fetch executes (not modified)
src/vs/platform/profiling/common/profilingTelemetrySpec.ts PerfSampleError generation (not modified)

Repro Steps

  1. Open VS Code 1.120.0 on any platform
  2. Ensure network conditions are degraded (slow DNS, throttled connection, or unresponsive chat control endpoint)
  3. Wait for the 5-minute _refreshChatControlData cycle to fire
  4. The fetch call hangs; the CPU profiler samples it and emits a PerfSampleError
  5. Error appears in telemetry as unhandlederror-PerfSampleError: by <> in fetch

How the Fix Works

Chosen approach (src/vs/workbench/contrib/chat/common/languageModels.ts):

Added timeout: 30_000 (30 seconds) to the request options passed to this._requestService.request() in _fetchChatControlData. This causes requestImpl.ts to use AbortSignal.timeout(30000) which aborts the fetch after 30 seconds. The abort throws a TimeoutError which is caught by the existing try/catch in _fetchChatControlData (line 1929), logged as a warning, and the function returns gracefully. The next retry happens in 5 minutes via _refreshChatControlData.

This fixes the issue at the data producer level — the unbounded request that causes the profiler to flag the slow fetch. The fix prevents the fetch from hanging long enough to be profiled as a performance problem, without silencing any errors or removing telemetry logging.

Recommended Owner

@lramos15 — most active recent contributor to languageModels.ts with model management and picker changes.

Generated by errors-fix · ● 48.8M ·

The _fetchChatControlData function makes a periodic network request
without a timeout, causing it to hang indefinitely on slow networks.
This triggers PerfSampleError telemetry when the profiler detects the
long-running fetch call.

Add a 30-second timeout so the request aborts cleanly on slow networks.
The existing error handling catches the timeout and retries in 5 minutes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 19, 2026 16:37
@vs-code-engineering vs-code-engineering Bot requested a review from Copilot May 19, 2026 16:37
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.

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 Copilot and lramos15 May 19, 2026 16:43
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 19, 2026 16:43
@vs-code-engineering vs-code-engineering Bot enabled auto-merge (squash) May 19, 2026 16:43
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-PerfSampleError: by <<renderer>> in fetch

2 participants