Skip to content

fix: reduce /enabled endpoint traffic and surface unexpected status codes#308879

Merged
joshspicer merged 3 commits intomainfrom
agents/okay-takin
Apr 9, 2026
Merged

fix: reduce /enabled endpoint traffic and surface unexpected status codes#308879
joshspicer merged 3 commits intomainfrom
agents/okay-takin

Conversation

@joshspicer
Copy link
Copy Markdown
Member

Problem

The jobs/:owner/:repo/enabled (CCA /enabled) endpoint was seeing unexpectedly increased traffic. Two root causes:

  1. No caching for disabled repos: checkCCAEnabled() only cached enabled=true results. For repos where CCA is disabled, every provideChatSessionProviderOptions() call (invoked on every chat session start) made a fresh network request.

  2. Unexpected status codes swallowed: The isCCAEnabled implementation returned { enabled: undefined } with no status code for unexpected responses (429, 5xx etc.), so they were invisible in telemetry.

Changes

Caching fix

  • enabled=true results: cached for 30 min (unchanged)
  • enabled=false / undetermined results: now cached for 5 min (CCA_DISABLED_CACHE_TTL_MS)
  • Added per-entry TTL override to TtlCache.set() to support two TTLs in one cache instance

Telemetry fix

  • Widened CCAEnabledResult.statusCode from 401 | 403 | 422 to number
  • isCCAEnabled default case now propagates response.status instead of dropping it
  • checkCCAEnabled fires a dedicated sendTelemetryErrorEvent('copilot.codingAgent.CCAIsEnabledUnexpectedStatus') for any code outside {401, 403, 422}, with an isRateLimited flag for easy 429 filtering

Files changed

  • extensions/copilot/src/extension/chatSessions/common/ttlCache. per-entry TTL override on set()ts
  • extensions/copilot/src/extension/chatSessions/common/test/ttlCache.spec. test for per-entry TTLts
  • extensions/copilot/src/extension/chatSessions/vscode-node/copilotCloudSessionsProvider. cache disabled results, fire error telemetry for unexpected codests
  • extensions/copilot/src/platform/github/common/githubService. widen statusCode typets
  • extensions/copilot/src/platform/github/common/octoKitServiceImpl. propagate unexpected status codests

joshspicer and others added 2 commits April 9, 2026 13:35
…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>
Copilot AI review requested due to automatic review settings April 9, 2026 21:30
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.

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 TtlCache and test the behavior.
  • Cache enabled=false / enabled=undefined results for a shorter TTL to avoid refetching on every chat session start.
  • Propagate unexpected /enabled status 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>
@joshspicer joshspicer marked this pull request as ready for review April 9, 2026 21:58
@joshspicer joshspicer merged commit 47a6692 into main Apr 9, 2026
26 checks passed
@joshspicer joshspicer deleted the agents/okay-takin branch April 9, 2026 23:38
@vs-code-engineering vs-code-engineering bot added this to the 1.116.0 milestone Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants