fix: retry Copilot token renewal server errors - #591
Open
emecii wants to merge 1 commit into
Open
Conversation
zikajk
reviewed
Sep 10, 2026
| (let [{:keys [status body]} (http/get token-url request-options)] | ||
| (cond | ||
| (and (number? status) (<= 200 status 299)) | ||
| (if-let [token (when (map? body) (:token body))] |
Member
There was a problem hiding this comment.
There is no reason to check for map here, it is ok to just check the :token like it did before.
| {:status status}))) | ||
|
|
||
| (and (number? status) | ||
| (<= 500 status 599) |
Member
There was a problem hiding this comment.
Does this really make a sense? E.g. I am not sure if it should retry on 511.
| (< attempt token-renew-max-attempts)) | ||
| (do | ||
| (Thread/sleep (long token-renew-retry-delay-ms)) | ||
| (recur (inc attempt))) |
Member
There was a problem hiding this comment.
Are you sure this really helps? Have you experienced getting the error and fixing it by the retry mechanism?
| (recur (inc attempt))) | ||
|
|
||
| :else | ||
| (throw (ex-info (if (number? status) |
Member
There was a problem hiding this comment.
Why do you think it is bad idea to get the full body in the log?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #551.
GitHub's Copilot token endpoint can return an HTML 5xx response. The renewal path currently includes that full body in its exception and does not retry, which floods logs and immediately fails startup or a prompt-time refresh.
This change retries one 5xx response after a short backoff, then reports only the HTTP status if renewal still fails. Successful responses and non-retriable statuses keep a single request. Regression tests cover recovery on the second request and verify that HTML response content is absent from both the exception message and data.
Validation:
bb test— 929 tests, 5,276 assertionsclj-kondoon changed source and testsImplementation assistance: OpenAI Codex.