feat: add auth credential switching - #17527
Conversation
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the credential-pool switching implementation. The capability is still absent from current main, but this version needs rework before salvage.
Problems
agent/credential_pool.py:1097calls_save_provider_stateduring Codex synchronization. That helper setsactive_provider(hermes_cli/auth.py:1222-1228), so switching one Codex credential can unexpectedly change the user's global default provider.hermes_cli/auth_commands.py:378warns forround_robinandrandomonly.least_usedchooses by request count before priority (agent/credential_pool.py:1496-1502), so the command can report an active credential that is not selected next.- Current auth parsing is in
hermes_cli/subcommands/auth.py:12-98, rather than thehermes_cli/main.pyparser block this PR edits. The PR is also currently conflicting.
Suggested changes
- Port the command to the current parser, preserve
active_provider, and update pool plus Codex singleton under one auth-store lock. - Include
least_usedin the strategy warning and add documentation coverage. - PR #45513 is a related refreshed alternative that already addresses the Codex active-provider handling and parser/docs migration.
Automated hermes-sweeper review.
| state["base_url"] = entry.base_url | ||
| if entry.last_refresh: | ||
| state["last_refresh"] = entry.last_refresh | ||
| _save_provider_state(auth_store, "openai-codex", state) |
There was a problem hiding this comment.
_save_provider_state() sets auth_store["active_provider"] to openai-codex. Switching one credential within a provider pool should not change the user's global default provider; use a state write that preserves the existing active-provider value.
| raise SystemExit(f'No credential matching "{target}" for provider {provider}.') | ||
| print(f"Switched {provider} active credential to #{1} ({active.label})") | ||
| strategy = get_pool_strategy(provider) | ||
| if strategy in {STRATEGY_ROUND_ROBIN, STRATEGY_RANDOM}: |
There was a problem hiding this comment.
least_used can also select a different credential after this reorder because it chooses by request count before priority. Include it in this warning, or limit the active/default claim to fill_first.
|
A current- |
Summary
Adds
hermes auth switch <provider> <target>for making a pooled credential the active/default credential for any provider with entries in Hermes' credential pool.The command reorders the selected provider's credential pool so the chosen credential becomes priority
0, preserving existing priority-based selection behavior used by the default/fill-first flow and priority tie-breaks.For
openai-codex, switching also keeps the selected pooled OAuth credential synchronized with the existingproviders.openai-codexauth state, because some Codex paths still read that singleton state. This keeps Codex switching consistent across both auth-store representations.Details
CredentialPool.activate_index()hermes auth switch <provider> <target>round_robinorrandom, since explicit active ordering may be overridden by that selection strategyTest Plan
python -m pytest -q tests/hermes_cli/test_auth_commands.py::test_auth_switch_reorders_provider_pool tests/hermes_cli/test_auth_commands.py::test_auth_switch_syncs_codex_singletonpython -m pytest -q tests/hermes_cli/test_auth_commands.pypython -m pytest -q tests/hermes_cli/test_runtime_provider_resolution.pygit diff --check origin/main...HEAD