Skip to content

fix: retry Copilot token renewal server errors - #591

Open
emecii wants to merge 1 commit into
editor-code-assistant:masterfrom
emecii:fix/copilot-token-renewal-errors
Open

fix: retry Copilot token renewal server errors#591
emecii wants to merge 1 commit into
editor-code-assistant:masterfrom
emecii:fix/copilot-token-renewal-errors

Conversation

@emecii

@emecii emecii commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

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 assertions
  • Focused red/green regression — 1 error and 5 failures before; 2 tests and 6 assertions pass after
  • clj-kondo on changed source and tests

Implementation assistance: OpenAI Codex.

  • I added a entry in changelog under unreleased section.
  • This is not an AI slop.

(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))]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you think it is bad idea to get the full body in the log?

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.

oauth-renew-token` crashes with full HTML body when GitHub returns 5xx Unicorn page

2 participants