fix(copilot): normalize credential pool priorities by token source - #32311
fix(copilot): normalize credential pool priorities by token source#32311dandomin wants to merge 1 commit into
Conversation
|
Thanks for isolating the Copilot source-ordering gap. Current main still has the premise: Problems
Suggested changes
Automated hermes-sweeper review. |
_normalize_pool_priorities only handled the 'anthropic' provider, so Copilot
pool entries kept their insertion-order priorities. An older gh_cli token from
a different GitHub account could outrank a freshly seeded
env:COPILOT_GITHUB_TOKEN, producing confusing auth state.
Extend the helper to also normalize 'copilot' entries using the same source
precedence that hermes_cli/copilot_auth.py:resolve_copilot_token already
enforces at token resolution time:
env:COPILOT_GITHUB_TOKEN > env:GH_TOKEN > env:GITHUB_TOKEN > gh_cli
Manual entries continue to outrank auto-seeded singletons (unchanged).
Skip normalization entirely under the round_robin strategy. That strategy
encodes its rotation in the persisted priority order (select() moves the used
entry to the end and renumbers), so re-applying static source precedence on
every load_pool() would reset the rotation and pin the pool to a single
credential.
Tests:
- test_copilot_pool_priority_normalization_honors_token_source_precedence
covers the helper's ordering directly.
- test_load_pool_copilot_env_token_outranks_persisted_gh_cli exercises the
real load_pool("copilot") path with a persisted stale gh_cli row and a
resolver-returned COPILOT_GITHUB_TOKEN, asserting actual pool selection.
- test_load_pool_copilot_round_robin_rotation_is_preserved selects, reloads
via load_pool(), and asserts the rotation advanced — it fails if the
round_robin guard is removed.
8f3b109 to
e942eca
Compare
|
Thanks for the review — rebased onto current 1. round_robin conflict — fixed. 2. Helper-only test — added two end-to-end regressions against the real
Worth flagging: my first version of that rotation test rotated twice within a single in-memory pool and passed even with the guard removed — the regression only surfaces across a reload, which is where normalization re-runs. The test now reloads between selections and does fail without the guard. Verification: |
Summary
_normalize_pool_prioritiesonly handledanthropic. For Copilot, that meant pool ordering was whatever insertion order produced, so an oldergh_clitoken from a different GitHub account could outrank a freshenv:COPILOT_GITHUB_TOKENobtained byhermes model— leading to confusing auth state where the picker showed one identity but the runtime used another.Fix
Extend
_normalize_pool_prioritiesto also normalizecopilotentries, using the same source precedence thathermes_cli/copilot_auth.py:resolve_copilot_tokenalready enforces at token resolution time:Manual entries continue to outrank auto-seeded singletons (unchanged behavior).
Test
test_copilot_pool_priority_normalization_honors_token_source_precedenceexercises the three-entry case (manual + COPILOT_GITHUB_TOKEN + gh_cli) and asserts the resulting priorities. Passes locally: