feat: add fetch interceptor options#100
Merged
Merged
Conversation
chrmarti
approved these changes
May 21, 2026
deepak1556
added a commit
to microsoft/vscode
that referenced
this pull request
May 21, 2026
Adds an opportunistic cache support to the Copilot Node fetch path. The cache
is strictly opt-in per request and composes with the existing VSCode proxy
and CA-injection patch.
- `__vscodeCreateFetchPatch({ interceptors })` lets the extension host
build a second proxy-aware `fetch` with extra undici interceptors. The
default `__vscodePatchedFetch` is unchanged.
- `NodeFetchFetcher` builds an undici cache interceptor once at
construction time and uses the factory to produce a `cachedFetch` that
routes through both the proxy patch and the cache. Requests are tagged
with an internal `__copilotCachePatch` marker (stripped before fetch);
unmarked requests keep going through the regular patched fetch. When
the host lacks the factory, caching is silently disabled so requests
never bypass the proxy patch.
- `FetchOptions.cache?: boolean` — opportunistic hint. Fetchers without
cache support ignore it; fallback to other fetchers is unaffected.
- `Response.cacheStatus` and `FetchTelemetryEvent.cacheStatus`:
`'hit' | 'stale-hit' | 'revalidated' | 'miss' | 'bypass'`.
- New setting `github.copilot.advanced.debug.nodeFetchCache`:
`'off' | 'memory' | 'persistent'` (default `'memory'`). `'persistent'`
uses undici's SQLite store under the extension's global storage
(`undici-cache.v1.sqlite`) when available, otherwise falls back to
memory.
- New `taggedCacheInterceptor` wraps `undici.interceptors.cache` and
stamps a private `VSCODE_CACHE_STATUS_HEADER` on the response so the
base fetcher can read the outcome without parsing undici internals.
- `BaseFetchFetcher` exposes an overridable `_buildRequestInit` hook and
reports `cacheStatus` on `Response` and `fetchTelemetry`.
Notes
- No behavior change for callers that don't set `cache: true`.
- The cache interceptor is constructed once per fetcher instance; the
composed dispatcher chain is reused so connection pooling is preserved.
- Depends on microsoft/vscode-proxy-agent#100
For #308310
deepak1556
added a commit
to microsoft/vscode
that referenced
this pull request
May 21, 2026
Adds an opportunistic cache support to the Copilot Node fetch path. The cache
is strictly opt-in per request and composes with the existing VSCode proxy
and CA-injection patch.
- `__vscodeCreateFetchPatch({ interceptors })` lets the extension host
build a second proxy-aware `fetch` with extra undici interceptors. The
default `__vscodePatchedFetch` is unchanged.
- `NodeFetchFetcher` builds an undici cache interceptor once at
construction time and uses the factory to produce a `cachedFetch` that
routes through both the proxy patch and the cache. Requests are tagged
with an internal `__copilotCachePatch` marker (stripped before fetch);
unmarked requests keep going through the regular patched fetch. When
the host lacks the factory, caching is silently disabled so requests
never bypass the proxy patch.
- `FetchOptions.cache?: boolean` — opportunistic hint. Fetchers without
cache support ignore it; fallback to other fetchers is unaffected.
- `Response.cacheStatus` and `FetchTelemetryEvent.cacheStatus`:
`'hit' | 'stale-hit' | 'revalidated' | 'miss' | 'bypass'`.
- New setting `github.copilot.advanced.debug.nodeFetchCache`:
`'off' | 'memory' | 'persistent'` (default `'memory'`). `'persistent'`
uses undici's SQLite store under the extension's global storage
(`undici-cache.v1.sqlite`) when available, otherwise falls back to
memory.
- New `taggedCacheInterceptor` wraps `undici.interceptors.cache` and
stamps a private `VSCODE_CACHE_STATUS_HEADER` on the response so the
base fetcher can read the outcome without parsing undici internals.
- `BaseFetchFetcher` exposes an overridable `_buildRequestInit` hook and
reports `cacheStatus` on `Response` and `fetchTelemetry`.
Notes
- No behavior change for callers that don't set `cache: true`.
- The cache interceptor is constructed once per fetcher instance; the
composed dispatcher chain is reused so connection pooling is preserved.
- Depends on microsoft/vscode-proxy-agent#100
For #308310
deepak1556
added a commit
to microsoft/vscode
that referenced
this pull request
May 21, 2026
Adds an opportunistic cache support to the Copilot Node fetch path. The cache
is strictly opt-in per request and composes with the existing VSCode proxy
and CA-injection patch.
- `__vscodeCreateFetchPatch({ interceptors })` lets the extension host
build a second proxy-aware `fetch` with extra undici interceptors. The
default `__vscodePatchedFetch` is unchanged.
- `NodeFetchFetcher` builds an undici cache interceptor once at
construction time and uses the factory to produce a `cachedFetch` that
routes through both the proxy patch and the cache. Requests are tagged
with an internal `__copilotCachePatch` marker (stripped before fetch);
unmarked requests keep going through the regular patched fetch. When
the host lacks the factory, caching is silently disabled so requests
never bypass the proxy patch.
- `FetchOptions.cache?: boolean` — opportunistic hint. Fetchers without
cache support ignore it; fallback to other fetchers is unaffected.
- `Response.cacheStatus` and `FetchTelemetryEvent.cacheStatus`:
`'hit' | 'stale-hit' | 'revalidated' | 'miss' | 'bypass'`.
- New setting `github.copilot.advanced.debug.nodeFetchCache`:
`'off' | 'memory' | 'persistent'` (default `'memory'`). `'persistent'`
uses undici's SQLite store under the extension's global storage
(`undici-cache.v1.sqlite`) when available, otherwise falls back to
memory.
- New `taggedCacheInterceptor` wraps `undici.interceptors.cache` and
stamps a private `VSCODE_CACHE_STATUS_HEADER` on the response so the
base fetcher can read the outcome without parsing undici internals.
- `BaseFetchFetcher` exposes an overridable `_buildRequestInit` hook and
reports `cacheStatus` on `Response` and `fetchTelemetry`.
Notes
- No behavior change for callers that don't set `cache: true`.
- The cache interceptor is constructed once per fetcher instance; the
composed dispatcher chain is reused so connection pooling is preserved.
- Depends on microsoft/vscode-proxy-agent#100
For #308310
deepak1556
added a commit
to microsoft/vscode
that referenced
this pull request
May 21, 2026
Adds an opportunistic cache support to the Copilot Node fetch path. The cache
is strictly opt-in per request and composes with the existing VSCode proxy
and CA-injection patch.
- `__vscodeCreateFetchPatch({ interceptors })` lets the extension host
build a second proxy-aware `fetch` with extra undici interceptors. The
default `__vscodePatchedFetch` is unchanged.
- `NodeFetchFetcher` builds an undici cache interceptor once at
construction time and uses the factory to produce a `cachedFetch` that
routes through both the proxy patch and the cache. Requests are tagged
with an internal `__copilotCachePatch` marker (stripped before fetch);
unmarked requests keep going through the regular patched fetch. When
the host lacks the factory, caching is silently disabled so requests
never bypass the proxy patch.
- `FetchOptions.cache?: boolean` — opportunistic hint. Fetchers without
cache support ignore it; fallback to other fetchers is unaffected.
- `Response.cacheStatus` and `FetchTelemetryEvent.cacheStatus`:
`'hit' | 'stale-hit' | 'revalidated' | 'miss' | 'bypass'`.
- New setting `github.copilot.advanced.debug.nodeFetchCache`:
`'off' | 'memory' | 'persistent'` (default `'memory'`). `'persistent'`
uses undici's SQLite store under the extension's global storage
(`undici-cache.v1.sqlite`) when available, otherwise falls back to
memory.
- New `taggedCacheInterceptor` wraps `undici.interceptors.cache` and
stamps a private `VSCODE_CACHE_STATUS_HEADER` on the response so the
base fetcher can read the outcome without parsing undici internals.
- `BaseFetchFetcher` exposes an overridable `_buildRequestInit` hook and
reports `cacheStatus` on `Response` and `fetchTelemetry`.
Notes
- No behavior change for callers that don't set `cache: true`.
- The cache interceptor is constructed once per fetcher instance; the
composed dispatcher chain is reused so connection pooling is preserved.
- Depends on microsoft/vscode-proxy-agent#100
For #308310
deepak1556
added a commit
to microsoft/vscode
that referenced
this pull request
May 21, 2026
* feat(copilot): opt-in HTTP cache for the Node fetch fetcher
Adds an opportunistic cache support to the Copilot Node fetch path. The cache
is strictly opt-in per request and composes with the existing VSCode proxy
and CA-injection patch.
- `__vscodeCreateFetchPatch({ interceptors })` lets the extension host
build a second proxy-aware `fetch` with extra undici interceptors. The
default `__vscodePatchedFetch` is unchanged.
- `NodeFetchFetcher` builds an undici cache interceptor once at
construction time and uses the factory to produce a `cachedFetch` that
routes through both the proxy patch and the cache. Requests are tagged
with an internal `__copilotCachePatch` marker (stripped before fetch);
unmarked requests keep going through the regular patched fetch. When
the host lacks the factory, caching is silently disabled so requests
never bypass the proxy patch.
- `FetchOptions.cache?: boolean` — opportunistic hint. Fetchers without
cache support ignore it; fallback to other fetchers is unaffected.
- `Response.cacheStatus` and `FetchTelemetryEvent.cacheStatus`:
`'hit' | 'stale-hit' | 'revalidated' | 'miss' | 'bypass'`.
- New setting `github.copilot.advanced.debug.nodeFetchCache`:
`'off' | 'memory' | 'persistent'` (default `'memory'`). `'persistent'`
uses undici's SQLite store under the extension's global storage
(`undici-cache.v1.sqlite`) when available, otherwise falls back to
memory.
- New `taggedCacheInterceptor` wraps `undici.interceptors.cache` and
stamps a private `VSCODE_CACHE_STATUS_HEADER` on the response so the
base fetcher can read the outcome without parsing undici internals.
- `BaseFetchFetcher` exposes an overridable `_buildRequestInit` hook and
reports `cacheStatus` on `Response` and `fetchTelemetry`.
Notes
- No behavior change for callers that don't set `cache: true`.
- The cache interceptor is constructed once per fetcher instance; the
composed dispatcher chain is reused so connection pooling is preserved.
- Depends on microsoft/vscode-proxy-agent#100
For #308310
* fix: undici integration tests
- drop the `age` header gate from classify(): undici's cache interceptor
only adds if-modified-since / if-none-match when revalidating a stored
entry, so `state.conditional` alone is a sufficient signal. The age header
is not guaranteed on a revalidated 200, which caused 'revalidated' to be
misreported as 'miss'.
- the etag integration test used
`cache-control: max-age=0, must-revalidate`, which undici treats as
already-stale on arrival and refuses to store (cache-handler.js bails when
`now >= absoluteStaleAt`), so there was nothing to revalidate on the second
call. Switch the origin to `public, max-age=60` and pass
`cache-control: no-cache` on the second request to drive undici's
needsRevalidation() path, which dispatches with if-none-match and serves
the cached body on 304.
* chore: fix lint
* chore: cleanup cache marker in favor of function arg
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.
Expose option to enable undici interceptor composition and lay groundwork for fetch caching.
API
@vscode/proxy-agentnow exports:CreateFetchPatchOptionscreateFetchPatch(params, originalFetch, resolveProxyURL, options?)CreateFetchPatchOptionscurrently supports:interceptors?: readonly undici.Dispatcher.DispatcherComposeInterceptor[]Behavior:
options.interceptorsis omitted/empty, patched fetch behavior isunchanged.
dispatcher selected for each request path (direct CA-injection or proxied).
dispatcher within the patched fetch instance.
For microsoft/vscode#308310