Skip to content

Fix BYOK regression for non-OAuth Copilot token pathways (eval proxy)#318092

Merged
dmitrivMS merged 2 commits into
mainfrom
dev/dmitriv/fix-byok-eval-regression
May 23, 2026
Merged

Fix BYOK regression for non-OAuth Copilot token pathways (eval proxy)#318092
dmitrivMS merged 2 commits into
mainfrom
dev/dmitriv/fix-byok-eval-regression

Conversation

@dmitrivMS

Copy link
Copy Markdown
Contributor

Fixes microsoft/vscode-copilot-evaluation#3977

Problem

PR #317428 added anyGitHubSession guards in front of several Copilot token pathways to handle the air-gapped/BYOK case. That works for end-user OAuth scenarios, but it conflates "has a cached GitHub OAuth session" with "can obtain a Copilot token". In eval-harness/proxy/HMAC scenarios these are uncorrelated: getCopilotToken() resolves successfully via the alternate auth path, but anyGitHubSession is undefined, so the new guard short-circuits before the real auth pathway runs and the copilot/* LM provider publishes zero models.

Fix

Add a hasCopilotTokenSource: boolean predicate to IAuthenticationService. It is defaulted on BaseAuthenticationService to !!this._anyGitHubSession (so the real AuthenticationService keeps existing behavior) and overridden to true on StaticGitHubAuthenticationService, which exists precisely to represent non-OAuth Copilot token pathways (proxy/HMAC, eval harness). Group-A call sites that gate on "can we mint a Copilot token?" are switched to hasCopilotTokenSource:

  • languageModelAccess._getToken (the original eval regression site)
  • authentication.contribution.waitForChatEnabled
  • copilotCli (_fetchAndCacheModels, getModels, provideLanguageModelChatInformation)
  • remoteEmbeddingsComputer

Group-B sites that intentionally gate on a real signed-in GitHub user keep using anyGitHubSession (they pair with copilotToken?.isNoAuthUser and are explicitly about Copilot-as-signed-in-user):

  • conversationFeature AI search / settings-search / participant-detection provider registration
  • byokUtilityModel.contribution (the whole notification is about being signed out)

Tests

Added a test in authentication.spec.ts verifying StaticGitHubAuthenticationService.hasCopilotTokenSource === true even when anyGitHubSession is undefined. Updated test doubles (mockAuthenticationService, getInlineCompletions.spec, copilotCliModels.spec) to expose the new property.

All impacted vitest specs pass; 0 TypeScript errors.

Introduce hasCopilotTokenSource on IAuthenticationService, defaulted to !!anyGitHubSession in BaseAuthenticationService and overridden to true in StaticGitHubAuthenticationService (proxy/HMAC, eval harness).

Replace PR-introduced anyGitHubSession guards added in #317428 at sites that gate on 'can we mint a Copilot token?' so the eval proxy pathway is no longer short-circuited:

- languageModelAccess._getToken

- authentication.contribution.waitForChatEnabled

- copilotCli (3 sites)

- remoteEmbeddingsComputer

Group-B sites that intentionally gate on a real signed-in GitHub user (conversationFeature search/intent provider registration, byokUtilityModel notification) keep using anyGitHubSession.
Copilot AI review requested due to automatic review settings May 23, 2026 09:02
@dmitrivMS dmitrivMS self-assigned this May 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 fixes a BYOK regression where several Copilot token-dependent pathways were incorrectly gated on the presence of a cached GitHub OAuth session (anyGitHubSession), preventing model publication in non-OAuth/proxy/HMAC/eval-harness scenarios where getCopilotToken() can still succeed.

Changes:

  • Introduces IAuthenticationService.hasCopilotTokenSource (defaulting to !!anyGitHubSession in BaseAuthenticationService) and overrides it to true in StaticGitHubAuthenticationService.
  • Switches key “can we mint a Copilot token?” gates from anyGitHubSession to hasCopilotTokenSource (LM access, chat enablement waiting, Copilot CLI model publishing, remote embeddings).
  • Adds/updates tests and test doubles/mocks to include the new predicate.
Show a summary per file
File Description
extensions/copilot/src/platform/authentication/common/authentication.ts Adds hasCopilotTokenSource to the auth interface and a default implementation on BaseAuthenticationService.
extensions/copilot/src/platform/authentication/common/staticGitHubAuthenticationService.ts Overrides hasCopilotTokenSource to support non-OAuth token pathways.
extensions/copilot/src/extension/conversation/vscode-node/languageModelAccess.ts Updates token gating to use hasCopilotTokenSource before calling getCopilotToken().
extensions/copilot/src/extension/authentication/vscode-node/authentication.contribution.ts Uses hasCopilotTokenSource to avoid waiting for a token in BYOK/air-gapped scenarios.
extensions/copilot/src/extension/chatSessions/copilotcli/node/copilotCli.ts Uses hasCopilotTokenSource to gate CLI model fetching/publishing.
extensions/copilot/src/platform/embeddings/common/remoteEmbeddingsComputer.ts Uses hasCopilotTokenSource to gate embeddings computation.
extensions/copilot/src/platform/authentication/test/node/authentication.spec.ts Adds coverage ensuring static auth reports a token source even without a GitHub session.
extensions/copilot/src/platform/ignore/node/test/mockAuthenticationService.ts Updates mock auth service to include hasCopilotTokenSource.
extensions/copilot/src/lib/vscode-node/test/getInlineCompletions.spec.ts Updates test auth service to include hasCopilotTokenSource.
extensions/copilot/src/extension/chatSessions/copilotcli/node/test/copilotCliModels.spec.ts Updates test double to expose hasCopilotTokenSource.

Copilot's findings

  • Files reviewed: 10/10 changed files
  • Comments generated: 2

Comment thread extensions/copilot/src/extension/conversation/vscode-node/languageModelAccess.ts Outdated
…oxy scenarios

- Update languageModelAccess log to say 'Copilot token source' (matches the new gate).

- In remoteEmbeddingsComputer, return empty embeddings instead of throwing when the Dotcom path lacks a GitHub access token (proxy/HMAC eval harness), matching the rest of the function's empty-fallback behavior.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 10/10 changed files
  • Comments generated: 1

@dmitrivMS

Copy link
Copy Markdown
Contributor Author

/requires-eval-assessment

@dmitrivMS dmitrivMS added the ~requires-eval-assessment Evals will be run and will generate a report upon completion label May 23, 2026
@dmitrivMS dmitrivMS marked this pull request as ready for review May 23, 2026 09:27
@dmitrivMS dmitrivMS merged commit 3405918 into main May 23, 2026
26 checks passed
@dmitrivMS dmitrivMS deleted the dev/dmitriv/fix-byok-eval-regression branch May 23, 2026 17:30
@vs-code-engineering vs-code-engineering Bot added this to the 1.122.0 milestone May 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

model-byok ~requires-eval-assessment Evals will be run and will generate a report upon completion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants