fix: reduce /enabled endpoint traffic and surface unexpected status codes#308879
Merged
joshspicer merged 3 commits intomainfrom Apr 9, 2026
Merged
fix: reduce /enabled endpoint traffic and surface unexpected status codes#308879joshspicer merged 3 commits intomainfrom
joshspicer merged 3 commits intomainfrom
Conversation
…ffic The checkCCAEnabled() method previously only cached enabled=true results (introduced in 19541d7). For the majority of users whose repos have CCA disabled, every provideChatSessionProviderOptions() call bypassed the cache and hit the jobs/:owner/:repo/enabled CAPI endpoint unconditionally. With growing adoption, this became significant upstream traffic. Fix: cache all /enabled results. enabled=true keeps the 30-min TTL. enabled=false/undefined uses a new 5-min TTL (CCA_DISABLED_CACHE_TTL_MS), short enough that users who just enabled CCA won't wait long, but long enough to dramatically reduce repeated calls. To support the shorter TTL for disabled entries without changing the enabled TTL, TtlCache.set() now accepts an optional per-entry ttlMs override that takes precedence over the cache-wide TTL. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Previously, isCCAEnabled's default case returned { enabled: undefined }
with no statusCode, swallowing 429 rate-limit and 5xx responses.
Changes:
- Widen CCAEnabledResult.statusCode from 401|403|422 to number so
unexpected codes can be propagated
- Return statusCode: response.status in isCCAEnabled's default case
- Add sendTelemetryErrorEvent('copilot.codingAgent.CCAIsEnabledUnexpectedStatus')
in checkCCAEnabled for any status code outside {401, 403, 422}, with
isRateLimited flag for quick 429 filtering in dashboards
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces traffic to the Copilot Cloud Agent /jobs/:owner/:repo/enabled endpoint by caching negative/indeterminate enablement checks, and improves observability by propagating unexpected HTTP status codes into telemetry.
Changes:
- Add per-entry TTL overrides to
TtlCacheand test the behavior. - Cache
enabled=false/enabled=undefinedresults for a shorter TTL to avoid refetching on every chat session start. - Propagate unexpected
/enabledstatus codes and emit a dedicated telemetry error event for them.
Show a summary per file
| File | Description |
|---|---|
| extensions/copilot/src/platform/github/common/octoKitServiceImpl.ts | Preserve unexpected /enabled HTTP status codes in isCCAEnabled results. |
| extensions/copilot/src/platform/github/common/githubService.ts | Widen CCAEnabledResult.statusCode type and clarify semantics in docs. |
| extensions/copilot/src/extension/chatSessions/vscode-node/copilotCloudSessionsProvider.ts | Cache disabled/undetermined results with shorter TTL; emit telemetry for unexpected status codes. |
| extensions/copilot/src/extension/chatSessions/common/ttlCache.ts | Support per-entry TTL override in TtlCache.set(). |
| extensions/copilot/src/extension/chatSessions/common/test/ttlCache.spec.ts | Add unit test verifying per-entry TTL behavior. |
Copilot's findings
- Files reviewed: 5/5 changed files
- Comments generated: 2
- Extract CCA_KNOWN_STATUS_CODES to file-level Set to avoid re-creating it on every call and centralize the list of handled status codes - Add __GDPR__ comment block for the new copilot.codingAgent.CCAIsEnabledUnexpectedStatus telemetry error event Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
connor4312
approved these changes
Apr 9, 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.
Problem
The
jobs/:owner/:repo/enabled(CCA /enabled) endpoint was seeing unexpectedly increased traffic. Two root causes:No caching for disabled repos:
checkCCAEnabled()only cachedenabled=trueresults. For repos where CCA is disabled, everyprovideChatSessionProviderOptions()call (invoked on every chat session start) made a fresh network request.Unexpected status codes swallowed: The
isCCAEnabledimplementation returned{ enabled: undefined }with no status code for unexpected responses (429, 5xx etc.), so they were invisible in telemetry.Changes
Caching fix
enabled=trueresults: cached for 30 min (unchanged)enabled=false/ undetermined results: now cached for 5 min (CCA_DISABLED_CACHE_TTL_MS)TtlCache.set()to support two TTLs in one cache instanceTelemetry fix
CCAEnabledResult.statusCodefrom401 | 403 | 422tonumberisCCAEnableddefault case now propagatesresponse.statusinstead of dropping itcheckCCAEnabledfires a dedicatedsendTelemetryErrorEvent('copilot.codingAgent.CCAIsEnabledUnexpectedStatus')for any code outside{401, 403, 422}, with anisRateLimitedflag for easy 429 filteringFiles changed
extensions/copilot/src/extension/chatSessions/common/ttlCache. per-entry TTL override onset()tsextensions/copilot/src/extension/chatSessions/common/test/ttlCache.spec. test for per-entry TTLtsextensions/copilot/src/extension/chatSessions/vscode-node/copilotCloudSessionsProvider. cache disabled results, fire error telemetry for unexpected codestsextensions/copilot/src/platform/github/common/githubService. widenstatusCodetypetsextensions/copilot/src/platform/github/common/octoKitServiceImpl. propagate unexpected status codests