Skip to content

Add session-scoped GitHub token providers - #2412

Queued
roji wants to merge 4 commits into
mainfrom
roji-github-credential-callback
Queued

Add session-scoped GitHub token providers#2412
roji wants to merge 4 commits into
mainfrom
roji-github-credential-callback

Conversation

@roji

@roji roji commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Why

The runtime now supports a session-scoped GitHub credential authority backed by either the existing static gitHubToken or an expiry-aware callback. SDK users need an idiomatic callback API without handling registration IDs or raw JSON-RPC dispatch.

Runtime context: https://github.com/github/copilot-agent-runtime/pull/16381

What

  • Expose async session GitHub token providers in TypeScript, Python, Go, .NET, Rust, and Java.
  • Map the public host/session/reason request to tagged token or cancelled responses while keeping registration IDs internal.
  • Preserve static gitHubToken and reject configuring static and callback credentials together.
  • Register before create/resume and provide transactional rollback, replacement, concurrent-session isolation, delete/disconnect/client-close cleanup, and token-safe diagnostics.
  • Document positive remaining-lifetime expiresIn semantics, typical eight-hour GitHub tokens, cancellation, and the intentionally absent retry/challenge/upscope behavior.
  • Add representative tests and an Unreleased changelog entry.

Testing

  • TypeScript: ESLint, typecheck, provider tests (6 passed)
  • Python: Ruff, targeted ty, provider tests (6 passed)
  • Go: go test . and go test -race .
  • .NET: targeted lifetime/provider tests (33 passed; DOTNET_ROLL_FORWARD=Major because only .NET 10 is installed locally)
  • Rust: format, check, Clippy, library tests (223 passed), provider integration tests (2 passed)
  • Java: Spotless and focused Maven verify -DskipITs (7 passed)
  • Documentation: extraction plus TypeScript, Go, C#, Java, and changed authentication examples passed validation
  • git diff --check

Validation notes

  • The full docs validator reached one unchanged Python 3.10 match example using the machine's older system Python; mypy is also unavailable in that interpreter.
  • A broader Java verify attempt passed the selected unit tests, then an unrelated ErgonomicToolDefinitionIT timed out; the focused verify gate passed.
  • Full Go E2E discovery remains environment-blocked by the local harness's missing openai dependency. Repository-wide Python ty check retains unrelated pre-existing diagnostics; changed Python files pass.

Expose lifecycle-safe GitHub credential callbacks across all six SDKs, with idiomatic APIs, tagged results, tests, and documentation.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a447a8bc-8687-47ea-a545-4370979e8128
Copilot AI balanced review requested due to automatic review settings August 26, 2026 14:39
@roji
roji requested a review from a team as a code owner August 26, 2026 14:39
Comment thread python/test_github_token_provider.py
Comment thread python/test_github_token_provider.py

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

Adds session-scoped rotating GitHub token providers across all six SDKs, including JSON-RPC routing, lifecycle management, documentation, and tests.

Changes:

  • Adds provider APIs and token/cancellation response mapping.
  • Adds registration, rollback, replacement, and cleanup logic.
  • Documents expiry semantics and adds cross-language tests.
Show a summary per file
File Description
rust/tests/session_test.rs Tests provider routing and rollback.
rust/src/wire.rs Adds registration IDs to wire requests.
rust/src/types.rs Adds provider configuration APIs.
rust/src/session.rs Manages registration ownership.
rust/src/router.rs Routes token requests.
rust/src/lib.rs Exposes APIs and registry lifecycle.
rust/src/github_token.rs Implements Rust provider support.
rust/src/errors.rs Adds provider error kind.
rust/README.md Documents Rust usage.
python/test_github_token_provider.py Tests Python provider behavior.
python/README.md Documents Python usage.
python/copilot/session.py Adds disconnect cleanup callback.
python/copilot/client.py Implements registration and dispatch.
python/copilot/__init__.py Exports provider types.
nodejs/test/github-token-provider.test.ts Tests TypeScript provider behavior.
nodejs/src/types.ts Defines provider types and configuration.
nodejs/src/session.ts Adds disconnect cleanup hook.
nodejs/src/index.ts Exports provider types.
nodejs/src/client.ts Implements provider lifecycle and dispatch.
nodejs/README.md Documents TypeScript usage.
java/sdk/src/test/java/com/github/copilot/SessionRequestBuilderTest.java Tests wire casing and redaction.
java/sdk/src/test/java/com/github/copilot/RpcHandlerDispatcherTest.java Tests callback dispatch.
java/sdk/src/test/java/com/github/copilot/JsonRpcClientTest.java Tests diagnostic redaction.
java/sdk/src/test/java/com/github/copilot/GitHubTokenProviderRegistryTest.java Tests registry ownership.
java/sdk/src/main/java/com/github/copilot/RpcHandlerDispatcher.java Dispatches provider callbacks.
java/sdk/src/main/java/com/github/copilot/rpc/SessionConfig.java Adds create provider configuration.
java/sdk/src/main/java/com/github/copilot/rpc/ResumeSessionRequest.java Adds resume registration field.
java/sdk/src/main/java/com/github/copilot/rpc/ResumeSessionConfig.java Adds resume provider configuration.
java/sdk/src/main/java/com/github/copilot/rpc/GitHubTokenProviderResult.java Defines provider results.
java/sdk/src/main/java/com/github/copilot/rpc/GitHubTokenProviderArgs.java Defines callback arguments.
java/sdk/src/main/java/com/github/copilot/rpc/GitHubTokenProvider.java Defines provider interface.
java/sdk/src/main/java/com/github/copilot/rpc/CreateSessionRequest.java Adds create registration field.
java/sdk/src/main/java/com/github/copilot/JsonRpcClient.java Redacts credential diagnostics.
java/sdk/src/main/java/com/github/copilot/GitHubTokenProviderRegistry.java Implements provider registry.
java/sdk/src/main/java/com/github/copilot/CopilotSession.java Owns registration cleanup.
java/sdk/src/main/java/com/github/copilot/CopilotClient.java Integrates provider lifecycle.
java/README.md Documents Java usage.
go/types.go Adds provider configuration and wire fields.
go/session.go Releases session registrations.
go/README.md Documents Go usage.
go/github_token_provider.go Defines Go provider API.
go/github_token_provider_test.go Tests Go provider lifecycle.
go/client.go Implements provider dispatch and ownership.
dotnet/test/Unit/ClientSessionLifetimeTests.cs Tests .NET provider behavior.
dotnet/src/Types.cs Adds provider configuration.
dotnet/src/Session.cs Owns registration cleanup.
dotnet/src/JsonRpc.cs Supports polymorphic callback responses.
dotnet/src/GitHubTokenProvider.cs Defines .NET provider API.
dotnet/src/Client.cs Implements provider registration and dispatch.
dotnet/README.md Documents .NET usage.
docs/setup/multi-tenancy.md Recommends rotating credentials.
docs/auth/authenticate.md Adds cross-language guidance.
CHANGELOG.md Records the new feature.

Review details

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Suppressed comments (3)

nodejs/src/client.ts:2039

  • A failed resume removes the newly registered session from this.sessions but does not restore the session object that was there before the attempt. The new provider registration is rolled back here, while the previous provider remains registered but its session can no longer receive routed callbacks/events. Preserve the prior session before replacement and restore it conditionally on failure, as the Go and Java paths do.
    python/copilot/client.py:3583
  • The rollback removes the new registration, but the resume path overwrote _sessions[session_id] before the RPC and then pops that entry on failure without restoring the prior session. Consequently a failed provider replacement leaves the old provider registered but drops routing for the still-valid old session. Save and conditionally restore the previous session as part of this rollback.
    dotnet/src/Client.cs:1517
  • The resume path has no transactional ownership handoff for an existing session. On success this transfers the new registration but never retires the replaced session's registration, leaving the old callback callable; on failure session?.RemoveFromClient() removes the new entry without restoring the prior session mapping. Track the replaced session and commit or roll back both the session map and provider ownership together.
            if (registrationId is not null)
            {
                session.SetGitHubTokenProviderRegistration(registrationId);
                registrationTransferred = true;
  • Files reviewed: 53/53 changed files
  • Comments generated: 7
  • Review effort level: Balanced

Comment thread nodejs/src/client.ts
Comment thread python/copilot/client.py
Comment thread dotnet/src/Client.cs
Comment thread dotnet/src/Client.cs Outdated
Comment thread java/sdk/src/main/java/com/github/copilot/CopilotClient.java
Comment thread rust/src/lib.rs
Comment thread docs/auth/authenticate.md
@github-actions

This comment has been minimized.

roji added 2 commits August 26, 2026 18:03
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a447a8bc-8687-47ea-a545-4370979e8128
Release session-owned provider registrations after successful session deletion and treat empty static .NET tokens as configured for mutual-exclusion validation.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a447a8bc-8687-47ea-a545-4370979e8128
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@SteveSandersonMS SteveSandersonMS 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.

Looks great. I did a review pass and it didn't come up with anything other than commentary on the design tradeoffs, all of which look very reasonable.

@roji
roji enabled auto-merge August 26, 2026 18:48
Order the new GitHub token re-export according to the nightly rustfmt configuration used by CI.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a447a8bc-8687-47ea-a545-4370979e8128
@github-actions

Copy link
Copy Markdown
Contributor

Cross-SDK Consistency Review ✅

This PR adds session-scoped GitHub token providers to .NET, Go, and Java — completing the feature across all six SDKs (Node.js, Python, and Rust already had the feature).

API surface consistency check:

SDK Provider type Args fields Mutual exclusion
Node.js GitHubTokenProvider (function type) host, sessionId, reason
Python GitHubTokenProvider (Callable) host, session_id, reason
Go GitHubTokenProvider (func type) Host, SessionID, Reason
.NET Func<GitHubTokenProviderArgs, Task<GitHubTokenProviderResult>> Host, SessionId, Reason
Java GitHubTokenProvider (interface) host, sessionId, reason
Rust GitHubTokenProvider (trait) host, session_id, reason

All implementations:

  • Accept equivalent GitHubTokenProviderArgs with host, sessionId, and reason fields
  • Return an equivalent result type (token or cancelled)
  • Enforce mutual exclusivity with the static gitHubToken option
  • Use idiomatic naming for the respective language

No cross-SDK consistency issues found.

Generated by SDK Consistency Review Agent for #2412 · sonnet46 41.1 AIC · ⌖ 8.26 AIC · ⊞ 6.6K ·

@roji
roji added this pull request to the merge queue Aug 26, 2026
Any commits made after this event will not be merged.
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.

4 participants