{"record":{"id":"bb0d75a20a8242a6","repo":"github/copilot-sdk","slug":"unknown-github-token-provider-registration-id-re","errorCode":null,"errorMessage":"Unknown GitHub token provider registration ID '{request.RegistrationId}'.","messagePattern":"Unknown GitHub token provider registration ID '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Client.cs","lineNumber":2097,"sourceCode":"            throw new InvalidOperationException(\"Failed to register GitHub token provider.\");\n        }\n        return registrationId;\n    }\n\n    internal void UnregisterGitHubTokenProvider(string registrationId)\n        => _gitHubTokenProviders.TryRemove(registrationId, out _);\n\n    private void ClearGitHubTokenProviders() => _gitHubTokenProviders.Clear();\n\n    private sealed class GitHubTokenAdapter(CopilotClient client) : IGitHubTokenHandler\n    {\n        public async Task<GitHubTokenAcquireResult> GetTokenAsync(\n            GitHubTokenAcquireRequest request,\n            CancellationToken cancellationToken = default)\n        {\n            if (!client._gitHubTokenProviders.TryGetValue(request.RegistrationId, out var provider))\n            {\n                throw new InvalidOperationException(\n                    $\"Unknown GitHub token provider registration ID '{request.RegistrationId}'.\");\n            }\n\n            var reason = request.Reason == GitHubTokenAcquireReason.Initial\n                ? GitHubTokenRequestReason.Initial\n                : request.Reason == GitHubTokenAcquireReason.Refresh\n                    ? GitHubTokenRequestReason.Refresh\n                    : throw new InvalidOperationException($\"Unknown GitHub token request reason '{request.Reason}'.\");\n            var result = await provider(new GitHubTokenProviderArgs\n            {\n                Host = request.Host,\n                SessionId = request.SessionId,\n                Reason = reason,\n            }).ConfigureAwait(false);\n\n            if (result is { Cancelled: true })\n            {\n                return new GitHubTokenAcquireResultCancelled();","sourceCodeStart":2079,"sourceCodeEnd":2115,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/dotnet/src/Client.cs#L2079-L2115","documentation":"Thrown as InvalidOperationException when the CLI requests a GitHub token using a registration ID that the client does not recognize — i.e. GetTokenAsync receives request.RegistrationId with no matching entry in the client's token-provider registry. This means the server is asking for credentials from a provider that was never registered (or has been removed) on this client instance.","triggerScenarios":"The CLI sends a GitHubTokenAcquireRequest with a RegistrationId after the client restarted/recreated the session, after UnregisterGitHubTokenProvider ran, or if the session was created without the provider but the server still has a stale registration reference.","commonSituations":"Client process restarted while the CLI process (with the old registration ID) kept running; session config changed between runs (provider removed) but the CLI cached the old registration; multiple CopilotClient instances where the CLI contacts the wrong one.","solutions":["Re-create the session with the GitHubTokenProvider configured so a fresh registration ID is issued to the CLI","Ensure the same CopilotClient instance (and connection) that registered the provider serves the session — don't restart the client without restarting the CLI session","Check that no code calls UnregisterGitHubTokenProvider (or disposes the client) while the session is still active","If the CLI persisted the registration across restarts, clear/refresh CLI state or upgrade CLI"],"exampleFix":"// before\n// client restarted; CLI still uses old registrationId -> error on token acquire\nclient = new CopilotClient(options); // old sessions orphaned\n// after\nclient = new CopilotClient(options);\nawait client.CreateSessionAsync(new SessionConfig { GitHubTokenProvider = myProvider }); // re-register via new session","handlingStrategy":"try-catch","validationCode":"// keep provider registered for the whole session lifetime\nif (sessionDisposed) throw new InvalidOperationException(\"provider unregistered with session; recreate session first\");","typeGuard":null,"tryCatchPattern":"client.TokenProviderError += (_, e) => logger.LogError(e.Exception, \"token acquire failed: {Msg}\", e.Exception?.Message);\ntry { await sessionOp(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Unknown GitHub token provider registration\"))\n{ await RecreateSessionWithProviderAsync(); }","preventionTips":["Don't restart/dispose the CopilotClient without recreating its sessions","Keep GitHubTokenProvider registered until the session ends","Use one client instance per CLI connection","Recreate the session after any client restart"],"tags":["github-token","registration","rpc","dotnet"],"backgroundTag":"resource-not-found","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}