Skip to content

fix: retain Copilot pool grants during runtime renewal - #77

Draft
paulorha wants to merge 5 commits into
NousResearch:mainfrom
paulorha:fix/copilot-pool-runtime
Draft

paulorha wants to merge 5 commits into
NousResearch:mainfrom
paulorha:fix/copilot-pool-runtime

Conversation

@paulorha

@paulorha paulorha commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Keep the durable GitHub grant in Copilot pool rows and exchange only the selected row. The exchanged bearer and endpoint go back to core as a PoolRuntimeCredential instead of overwriting entry.access_token and entry.base_url (the corruption in NousResearch/hermes-agent#155441).

refresh_pool_runtime_credentials renews only the failed row's grant and never substitutes an ambient account or the raw grant. Initial resolution keeps the existing same-account raw fallback; catalog source ordering is unchanged.

Changes

  • Seed env rows with the raw grant; prepare_pool_entry exchanges at selection and returns a typed pair.
  • refresh_pool_runtime_credentials: exact-row renewal. A fine-grained PAT is declined before any cache eviction or exchange; it is the bearer itself and is never exchanged.
  • api_mode_for_model reads the catalog with a pooled grant's exchanged bearer. Core resolves a row's api_mode before preparing it, so it otherwise received the raw grant.
  • credential_pool_base_urls lists the four official *.githubcopilot.com origins. Relays, ports, paths and lookalikes are refused at selection and at renewal.
  • Feature-detect the SDK: on an older core the plugin stays inactive and logs one warning.
  • Tests: persistence/reload, selected-only exchange, refused routes, PAT decline, and an offline 401-recovery harness for copilot and github-copilot with one and two rows, adapted from @recoilburner's review on fix: keep derived pool credentials runtime-only hermes-agent#154360.

Before this leaves Draft

  1. Core SDK: fix: keep derived pool credentials runtime-only hermes-agent#154360 (PoolRuntimeCredential, refresh_pool_runtime_credentials, credential_pool_base_urls) must land first. No catalog repin before a compatible core release.
  2. GHEC pool rows: copilot-api.<enterprise>.ghe.com can't be listed in a static credential_pool_base_urls, so core refuses that endpoint for a hermes auth add copilot row. With only COPILOT_GH_HOST set, the request then goes to api.githubcopilot.com with the GHEC bearer; with COPILOT_API_BASE_URL or model.base_url set it reaches GHEC but isn't renewed after a 401. (On main such rows reach GHEC, but the exchanged bearer overwrites the saved grant.) The env-token setup (COPILOT_GH_HOST + COPILOT_API_BASE_URL) keeps working through core's env path and re-exchanges after a 401. Fixing this needs core to accept one exact per-user origin for the profile; asked on fix: keep derived pool credentials runtime-only hermes-agent#154360. The README documents the gap, and tests pin that neither selection nor renewal moves a row to an unlisted origin.

The github-copilot spelling recovers only once core keeps the pool for a declared alias: NousResearch/hermes-agent#160726. Without it those four cases skip; the gate probes credential_pool_matches_provider, not a version. The replay track (#78, landed via #99; core NousResearch/hermes-agent#154361) is independent.

A grant that an older derived bearer already overwrote can't be recovered; that account must sign in again. No installed plugin, account or profile changes here.

Validation

Rebased onto main at af1cb017. One conflict, in seed_pool_credentials: kept the raw-grant seeding; #55's PAT guard in prepare_pool_entry and #96's auxiliary refresh came through unchanged.

Plugin head ee9740c, offline, synthetic credentials, isolated HOME/HERMES_HOME, Python 3.14.9:

From github-copilot/:

HERMES_AGENT_REPO="$CORE" PYTHONPATH="$CORE" "$HERMES_PYTHON" -m pytest -q

CI

The workflow checks out core main, which lacks the SDK, so the three Copilot jobs stop at manifest validation (registered no ProviderProfile at import) before pytest. This is the dependency gate, not a test failure; no test or validator was weakened to get past it.

@paulorha

Copy link
Copy Markdown
Contributor Author

Moved to Draft: the three Copilot platform failures are the expected manifest check (model-provider plugin registered no ProviderProfile at import) because the SDK from NousResearch/hermes-agent#154360 is not in core main yet. Against the companion core branch, the plugin suite passes (169 passed). I will mark this ready and rerun CI once #154360 merges.

@recoilburner

Copy link
Copy Markdown

I tested this head (c7bff1fd) with core NousResearch/hermes-agent#154360 (c0bbbe86). Setup and per-tree results are on the core PR: NousResearch/hermes-agent#154360 (comment)

With provider copilot and synthetic pool-only credentials, the paired PR heads recovered from a mocked 401 IDE token expired with one renewal after startup. The selected grant stayed unchanged on disk with one and with two rows; on paired main, the selected row ended up holding the rejected bearer. PR #77's own plugin suite also passed (180 tests) on the core PR head.

Sessions whose provider is the alias github-copilot still failed. Core drops the pool for that spelling at agent creation, so the 401 reaches the non-pool refresh_runtime_credentials path, which has no row identity. I'd fix the binding in core rather than have that row-less refresher pick a saved grant.

A fine-grained PAT is the bearer itself and is never exchanged (_is_fine_grained_pat).
refresh_pool_runtime_credentials now declines a PAT row before it evicts the exchange
caches or calls exchange_copilot_token, matching the other 'never exchanged by design'
branches.
…arer

Pool rows now keep the raw GitHub grant, and core resolves a row's api_mode before it
prepares the row, so api_mode_for_model received the grant and read the catalog with it.
Exchange a GitHub grant first (the cached exchange that preparation reuses); exchanged
tokens and fine-grained PATs are used as given. Restores main's
test_copilot_wire_runtime expectations after the rebase.
…llings

Run one- and two-row pool-only sign-ins through core's runtime resolver and AIAgent for
copilot and github-copilot: an expired exchanged token renews the selected grant once,
saved grants stay unchanged, a refused renewal ends the turn, and an exchange outage
never sends the GitHub grant as a bearer. The github-copilot cases skip while core drops
the pool for an alias spelling (probed through credential_pool_matches_provider).

Harness adapted from @recoilburner's review on NousResearch/hermes-agent#154360.
copilot-api.<enterprise>.ghe.com is not in credential_pool_base_urls, and core's admission
only trusts that static list, so a GHEC exchange cannot move a pool row there. Document the
limitation and pin today's behaviour: the env-token setup still resolves to the enterprise
endpoint through core's env path and re-exchanges after a 401, and neither selection nor
renewal retargets a pool row to the GHEC origin.
@paulorha

Copy link
Copy Markdown
Contributor Author

Rebased onto main (af1cb017, after the #99 slate) and pushed as ee9740c. Still Draft until NousResearch/hermes-agent#154360 lands. Since c7bff1f:

The earlier 180-pass result was for c7bff1f/c0bbbe86 only. No catalog repin before a compatible core release.

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.

2 participants