{"record":{"id":"824cb5ebc76fd8e5","repo":"github/copilot-sdk","slug":"unknown-github-token-request-reason-request-reas","errorCode":null,"errorMessage":"Unknown GitHub token request reason '{request.Reason}'.","messagePattern":"Unknown GitHub token request reason '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"warning","filePath":"dotnet/src/Client.cs","lineNumber":2105,"sourceCode":"    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();\n            }\n            if (result?.Token is not { } token)\n            {\n                throw new InvalidOperationException(\n                    \"GitHub token provider returned neither a token nor cancellation.\");\n            }\n            return new GitHubTokenAcquireResultToken\n            {","sourceCodeStart":2087,"sourceCodeEnd":2123,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/dotnet/src/Client.cs#L2087-L2123","documentation":"Thrown as InvalidOperationException when the CLI's GitHub token acquire request carries a Reason value that the client cannot map to a known GitHubTokenRequestReason (only Initial and Refresh are recognized). This protects against forward/backward version drift where the CLI introduces a new acquire reason the library doesn't understand.","triggerScenarios":"The CLI sends a GitHubTokenAcquireRequest whose request.Reason enum value is neither Initial nor Refresh — typically a newer CLI introducing a new reason (e.g. renewal/rotation) used with an older client library.","commonSituations":"Copilot CLI auto-updated to a version newer than the .NET SDK; mismatched pinned versions in CI; a custom/proxying layer injecting an unexpected reason value.","solutions":["Upgrade the dotnet client library to a version matching (or newer than) the CLI so the new reason is supported","Pin the Copilot CLI version to one compatible with your client library version","Log the raw request.Reason value from the exception message and check release notes for the new enum member","Wrap provider dispatch in try-catch and report/handle unknown reasons gracefully if you must tolerate version drift"],"exampleFix":"// before\n// older SDK: throws on new CLI reason values\n// after\ndotnet add package GitHub.Copilot.SDK --version <latest>  # support new GitHubTokenAcquireReason values\n# and/or pin CLI:\ncopilot --version  # pin to version matching the SDK","handlingStrategy":"try-catch","validationCode":"// preflight version compatibility\nvar cliVersion = await GetCliVersionAsync();\nif (!IsCompatibleWithSdk(cliVersion)) throw new InvalidOperationException(\"Upgrade SDK or pin CLI version\");","typeGuard":null,"tryCatchPattern":"try { await sessionOp(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Unknown GitHub token request reason\"))\n{ logger.LogWarning(ex, \"CLI sent unsupported token reason; upgrade SDK\"); /* fail over or re-auth */ }","preventionTips":["Keep the dotnet SDK at or above the CLI version","Pin CLI versions in CI to a tested combination","Subscribe to SDK release notes for new enum members","Log the offending reason value for diagnostics"],"tags":["enum","version-mismatch","github-token","rpc","dotnet"],"backgroundTag":"invalid-enum-value","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"}