Skip to content

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

Description

@snoopier

To upvote this issue, give it a thumbs up. See this list for the most upvoted issues.

Description:**

When GitHub's /copilot_internal/v2/token endpoint returns a 5xx error (the "Unicorn" HTML error page), oauth-renew-token in copilot.clj does not check the HTTP status code before attempting to extract :token from the response body. Since clj-http with :as :json falls back to returning the raw string when the response isn't valid JSON, (:token body) evaluates to nil, and the function throws an ex-info containing the entire HTML page as the error message.

This causes two user-visible issues:

  1. The log is flooded with a massive HTML dump instead of a concise error message.
  2. There is no retry logic for transient GitHub failures — if the token renewal happens to hit a temporary 5xx during startup (renew-expiring-auth-tokens!) or at prompt time (maybe-renew-auth-token), the chat prompt fails immediately with Auth token renew failed.

Steps to reproduce:

  1. Have a valid Copilot access-token stored in the auth cache.
  2. Start ECA while GitHub's Copilot token endpoint is returning 5xx (or simulate by e.g. blocking the endpoint temporarily).
  3. Observe the WARN log containing the full Unicorn HTML and the subsequent ERROR Auth token renew failed.

Expected behavior:

  • oauth-renew-token should check the HTTP status before parsing the body.
  • On 5xx or non-JSON responses, it should throw a concise error like "GitHub Copilot token endpoint returned HTTP <status>".
  • renew-expiring-auth-tokens! (and ideally maybe-renew-auth-token) should retry at least once with a short backoff for transient (5xx) errors before giving up.

Relevant code:

  • src/eca/llm_providers/copilot.cljoauth-renew-token (line ~66)
  • src/eca/features/login.cljrenew-auth! / renew-expiring-auth-tokens!

Logs:

WARN  [LOGIN] Could not renew 'github-copilot' auth token before sync: Error on copilot login: <!DOCTYPE html>... [full Unicorn HTML page]
WARN  [MODELS] Provider 'github-copilot': /models endpoint returned status 401: IDE token expired
ERROR Auth token renew failed

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions