eca icon indicating copy to clipboard operation
eca copied to clipboard

Github copilot token does not renew, after it expires

Open mspik opened this issue 1 year ago • 8 comments

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

Describe the bug Github copilot token does not renew, after it expires I need to /login again.

To Reproduce Steps to reproduce the behavior (linux):

  1. open eca in emacs
  2. enter /login + github-copilot
  3. authenticate with browser and confirm new token with new expires-at is present under ~/.cache/eca/db.transit.json
  4. After expires-at eca chat window returns "invalid token 401" and I need to authenticate again

Expected behavior

  • token is refreshed after refresh_in, value returned from https://api.github.com/copilot_internal/v2/token when eca daemon is running.
  • https://api.github.com/copilot_internal/v2/token is used to issue new token (using access token) if we're past expires_at

Doctor

> /doctor

ECA version: 0.56.2

Server cmd: /home/user/.emacs.d/eca/eca server

Default model: github-copilot/gpt-5

Login providers:
anthropic: {}
azure: {}
deepseek: {}
github-copilot: {:step :login/done, :device-code "ec7*****009", :access-token
"ghu*****jhK", :api-key "tid*****4c5", :expires-at 1758357397}
openai: {}
openrouter: {}
z-ai: {}

Relevant env vars:
DEBUGINFOD_URLS=https://debuginfod.ubuntu.com

Additional context I'm honestly not sure if this is a bug or missing feature. I reported this as a bug because I found this commit: https://github.com/editor-code-assistant/eca/commit/1ad87dceaf8fd55adeb7a95c7065fb092d137225 commit message says: Fix token expiration for copilot and anthropic., but no copilot files were modified.

mspik avatar Sep 20 '25 08:09 mspik

@mspik that's weird, I just tested that and it's working as expected, one easy way to repro the expiration is to edit ~/.cache/eca/db.transit.json, and remove some numbers from expires_at at github-copit section, then restart ECA and on next request ECA will check and see timestamp has passed and renew the token here

ericdallo avatar Sep 20 '25 17:09 ericdallo

Ah I managed to repro the issue, it seems to happen only with native image compiled ECA, I will take a look how to fix

ericdallo avatar Sep 20 '25 17:09 ericdallo

@mspik it was related to a bug I already had fixed on master, just released 0.56.3, which fixes that, LMK otherwise.

ericdallo avatar Sep 20 '25 17:09 ericdallo

@ericdallo I can confirm it works for me now, but with one minor issue (which does not bother much to be honest), my scenario:

  • /login + github-copilot
  • 30 minut passes, my token expires, I check db.transit.json, expires-at stays unchanged
  • I send another prompt and I get LLM response status: 401 body: unauthorized: token expired
  • now I check db.transit.json again and I see new token with new expires-at
  • I repeat the same prompt and it works

thank you for your quick response and new version 0.56.3

mspik avatar Sep 20 '25 19:09 mspik

@mspik thanks for the feedback, I fixed this other issue on 0.56.4!

ericdallo avatar Sep 21 '25 01:09 ericdallo

I confirm, works perfect now, thank you!

mspik avatar Sep 22 '25 07:09 mspik

I'm still getting this error, and it tends to occur in the middle of long agentic workflows:

LLM response status: 401 body: unauthorized: token expired

It interrupts the task, but the session remains intact so that I can ask the agent to continue. Could it be that token is checked and refreshed on user input but not on intermediate steps during the process?

itkonen avatar Mar 13 '26 14:03 itkonen

@itkonen Yeah, I mentioend about it here, I believe github has a limit of how much can use the x-initiator as agent until needs to consume other premium request (x-initiator: user), that's why you sending the prompt works because user prompt goes as user.

We should double check how copilot does on their side and do the same here, but my guess ist that use user when get that 401, feel free to open a new issue about it to help track/prioritize

ericdallo avatar Mar 13 '26 14:03 ericdallo