Skip to content

agentHost: refresh expiring GitHub credentials - #334418

Merged
TylerLeonhardt merged 1 commit into
mainfrom
copilot-sdk-token-refresh
Sep 9, 2026
Merged

TylerLeonhardt merged 1 commit into
mainfrom
copilot-sdk-token-refresh

Conversation

@TylerLeonhardt

@TylerLeonhardt TylerLeonhardt commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Add the proposed AuthenticationSession.expiresIn API and report relative expiry for Microsoft-brokered GitHub sessions.
  • Proactively renew Entra-backed GitHub sessions before the Copilot SDK's one-hour credential threshold while retaining still-valid tokens after transient renewal failures.
  • Propagate remaining lifetime through AHP authentication, reconnect, and replay.
  • Use static SDK credentials when expiry is unknown and provider-backed credentials when expiry is known, with credential mode and refresh state owned by one abstraction.

Testing

  • npm run compile
  • npm run typecheck-client
  • Targeted ESLint for changed implementation and test files
  • Affected core unit tests: 1,378 passing
  • GitHub Authentication extension compile
  • GitHub Authentication extension-host suite: 59 passing
  • git diff --check
  • Manually validated a fresh Agents sign-in, initial SDK token-provider acquisition, forced synchronized expiry, SDK refresh callback, Entra token renewal, and successful chat resumption

Tracking Issues

Copilot AI balanced review requested due to automatic review settings September 4, 2026 05:11

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

Review tier: Lite
Findings: 2 High severity · 2 Medium severity

New issues introduced by this change (4)
Severity Finding
High severity extensions/​github-authentication/​src/​github.ts — AuthenticationSession.expiresIn is documented (in the proposed d.ts added by this PR) as a…
High severity src/​vs/​platform/​agentHost/​node/​copilot/​copilotGitHubTokenProvider.ts — This implementation can (a) block indefinitely on _requestRefresh() if no refresh completion…
Medium severity src/​vs/​platform/​agentHost/​node/​copilot/​copilotAgent.ts — When tokenProviderModeChanged is true, a client restart is already required (`restartRequired =…
Medium severity src/​vs/​workbench/​contrib/​chat/​browser/​agentSessions/​agentHost/​agentHostAuth.ts — Returning false here silently suppresses forwarding any auth state update (including the token)…
What changed in this PR

This PR adds expiry-aware GitHub authentication to Agent Host / Copilot flows by introducing an AuthenticationSession.expiresIn surface, propagating remaining lifetime through AHP authenticate/reconnect/replay, and enabling refreshable Copilot SDK GitHub credentials via a coalescing token provider.

Changes:

  • Introduce AuthenticationSession.expiresIn (proposed API + internal auth session type) and thread it through AHP authenticate, replay, and reconnect.
  • Update agent-host auth resolution to forward full sessions (token + expiresIn) instead of only bearer tokens.
  • Add a Copilot GitHub token provider that coalesces refresh requests and switch Copilot session launch to use either a static token or a provider (mutually exclusive).
File Description
src/​vscode-dts/​vscode.proposed.authSessionExpiration.d.ts Adds proposed AuthenticationSession.expiresIn API contract.
src/​vs/​workbench/​services/​authentication/​common/​authentication.ts Adds expiresIn to internal AuthenticationSession.
src/​vs/​workbench/​contrib/​chat/​browser/​agentSessions/​agentHost/​agentHostAuth.ts Resolves/forwards full auth sessions including expiresIn.
src/​vs/​workbench/​contrib/​chat/​test/​browser/​agentSessions/​agentHostAuth.test.ts Updates chat auth tests for session-based resolution and expiresIn forwarding.
src/​vs/​platform/​extensions/​common/​extensionsApiProposals.ts Registers new authSessionExpiration proposal.
src/​vs/​platform/​agentHost/​common/​state/​protocol/​common/​commands.ts Extends AHP authenticate params with optional expiresIn.
src/​vs/​platform/​agentHost/​common/​state/​protocol/​common/​notifications.ts Clarifies AuthRequiredReason.Expired semantics in docs.
src/​vs/​platform/​agentHost/​common/​state/​protocol/​.ahp-version Bumps protocol version.
src/​vs/​platform/​agentHost/​common/​agent.ts Adds expiresIn to auth params and agent authenticate signature.
src/​vs/​platform/​agentHost/​node/​agentHostAuthenticationService.ts Stores token expiry, filters expired tokens, and replays with remaining lifetime.
src/​vs/​platform/​agentHost/​browser/​agentHostProtocolClient.ts Persists/restores auth with expiry and prunes expired auth during reconnect.
src/​vs/​base/​common/​date.ts Adds getRemainingTimeInSeconds helper.
src/​vs/​base/​test/​common/​date.test.ts Adds unit тест for getRemainingTimeInSeconds.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotGitHubTokenProvider.ts Introduces coalescing, expiry-aware Copilot SDK GitHub token provider.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotSessionLauncher.ts Switches Copilot SDK session credentials to token vs provider union.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotAgent.ts Threads expiry-aware creds into sessions and handles provider refresh requests.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotAgentSession.ts Tracks static vs provider token usage and uses current token for telemetry.
src/​vs/​platform/​agentHost/​test/​node/​copilotGitHubTokenProvider.test.ts Adds tests for provider refresh coalescing and preflight refresh behavior.
src/​vs/​platform/​agentHost/​test/​node/​mockAgent.ts Extends mock agent authenticate calls to include expiresIn.
src/​vs/​platform/​agentHost/​test/​node/​agentService.test.ts Updates dispatcher tests to forward expiresIn.
src/​vs/​platform/​agentHost/​test/​electron-browser/​agentHostProtocolClient.test.ts Ensures restored auth has valid remaining lifetime.
src/​vs/​platform/​agentHost/​test/​node/​copilotSessionLauncher.test.ts Updates tests for githubCredentials union.
src/​vs/​platform/​agentHost/​test/​node/​copilotAgentSession.test.ts Updates tests to use provider credentials (replacing launch-token-current checks).
src/​vs/​platform/​agentHost/​test/​node/​copilotAgent.test.ts Updates tests for credential mode switching and refreshable credential materialization.
extensions/​github-authentication/​tsconfig.json Includes proposed authSessionExpiration d.ts for extension build.
extensions/​github-authentication/​package.json Enables authSessionExpiration proposal.
extensions/​github-authentication/​src/​github.ts Computes/propagates expiresIn and renews Microsoft-brokered sessions proactively.
extensions/​github-authentication/​src/​test/​github.test.ts Adds/updates tests around expiresIn, proactive renewal, and failure retention.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Propagate authentication session lifetimes through AHP and use the Copilot SDK token provider for renewable Entra-backed GitHub sessions. Centralize static and provider-backed credential behavior behind one owner and reuse shared expiry helpers throughout authentication replay.

Co-authored-by: Copilot <[email protected]>
@TylerLeonhardt
TylerLeonhardt marked this pull request as ready for review September 9, 2026 00:47
@TylerLeonhardt
TylerLeonhardt force-pushed the copilot-sdk-token-refresh branch from d910706 to ac43f52 Compare September 9, 2026 00:47
@TylerLeonhardt
TylerLeonhardt enabled auto-merge (squash) September 9, 2026 01:44
@TylerLeonhardt
TylerLeonhardt merged commit b4e90b1 into main Sep 9, 2026
54 of 55 checks passed
@TylerLeonhardt
TylerLeonhardt deleted the copilot-sdk-token-refresh branch September 9, 2026 02:57
@vs-code-engineering vs-code-engineering Bot added this to the 1.138.0 milestone Sep 9, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Oct 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

3 participants