Skip to content

fix(copilot): keep the selected pool token through mid-turn refresh - #91

Closed
salch-cred wants to merge 1 commit into
NousResearch:mainfrom
salch-cred:fix/87-pool-refresh-token
Closed

salch-cred wants to merge 1 commit into
NousResearch:mainfrom
salch-cred:fix/87-pool-refresh-token

Conversation

@salch-cred

Copy link
Copy Markdown
Contributor

What

With multiple Copilot accounts in credential_pool, turn start correctly exchanges the selected row's raw ghu_ token. But the mid-turn recovery seams — _refresh_exchanged_token(), _reexchange_stale_token(), _revalidate_in_memory_token(), and runtime_base_url() — called resolve_copilot_token(), which reads only COPILOT_GITHUB_TOKEN / GH_TOKEN / GITHUB_TOKEN.

Two consequences (#87):

  • A multi-account turn with a .env token silently switches to that account when the exchanged ~30-minute token expires.
  • A pool-only login (hermes auth add copilot, no env token) cannot refresh at all — resolution returns ("", "").

Fix

prepare_pool_entry() now pins the selected row's raw token in a module slot. A new resolve_copilot_runtime_token() prefers that pin and falls back to the env resolution. All four runtime seams use it, so refresh and base-URL reconstruction stay on the account the turn started with; existing env-only setups are unchanged when no pool entry was prepared.

Verification

tests/test_copilot_pool_refresh.py (4 tests): pin preference, env fallback, pinning on prepare_pool_entry, and a 401 refresh that evicts/re-exchanges the pinned token rather than the env one — 4 passed.

Fixes #87

prepare_pool_entry exchanges the chosen pool row's raw GitHub token, but
the 401/400/expiry refresh helpers resolved only from environment vars.
A multi-account turn could silently switch to an env account after 30
minutes; a pool-only login (hermes auth add copilot) could not refresh
at all. Pin the selected raw token when the pool entry is prepared and
have the refresh and base-URL seams use it first, falling back to env.

Fixes NousResearch#87
@teknium1

Copy link
Copy Markdown
Contributor

Thanks @salch-cred — the diagnosis in #87 is right, but a process-wide pin means the last account selected wins for every session in a multi-profile gateway, and the suite is red on this head (3 failures). The row-scoped version is #77 (waits on core hermes-agent#154360); we'll land that instead.

@teknium1 teknium1 closed this Nov 19, 2026
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.

github-copilot: runtime token refresh & setup flows ignore credential pool / priority, and auth add hardcodes priority=0

2 participants