Skip to content

feat: add auth credential switching - #17527

Open
zychenzy wants to merge 1 commit into
NousResearch:mainfrom
zychenzy:feat/auth-credential-switch
Open

feat: add auth credential switching#17527
zychenzy wants to merge 1 commit into
NousResearch:mainfrom
zychenzy:feat/auth-credential-switch

Conversation

@zychenzy

Copy link
Copy Markdown

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 existing providers.openai-codex auth state, because some Codex paths still read that singleton state. This keeps Codex switching consistent across both auth-store representations.

Details

  • Adds CredentialPool.activate_index()
  • Adds hermes auth switch <provider> <target>
  • Supports target resolution by:
    • 1-based index
    • credential id
    • exact label
  • Keeps non-selected credentials in the pool and reindexes priorities
  • Warns when a provider uses round_robin or random, since explicit active ordering may be overridden by that selection strategy
  • Keeps Codex pool state and singleton auth state aligned without creating duplicate singleton-derived pool entries on reload

Test 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_singleton
  • python -m pytest -q tests/hermes_cli/test_auth_commands.py
  • python -m pytest -q tests/hermes_cli/test_runtime_provider_resolution.py
  • git diff --check origin/main...HEAD

@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/cli CLI entry point, hermes_cli/, setup wizard area/auth Authentication, OAuth, credential pools labels Apr 29, 2026

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:1097 calls _save_provider_state during Codex synchronization. That helper sets active_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:378 warns for round_robin and random only. least_used chooses 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 the hermes_cli/main.py parser 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_used in 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.

Comment thread agent/credential_pool.py
state["base_url"] = entry.base_url
if entry.last_refresh:
state["last_refresh"] = entry.last_refresh
_save_provider_state(auth_store, "openai-codex", state)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_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}:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@teknium1 teknium1 added sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 12, 2026
@eonewg

eonewg commented Jul 19, 2026

Copy link
Copy Markdown

A current-main salvage is now available in #67285. It follows the sweeper recommendation to use the refreshed #45513 design, preserves the original #45513 author attribution, and includes the missing Codex synchronization, strategy warnings, current parser/docs integration, and regression coverage. #67285 explicitly supersedes both stale/conflicting implementations so review can continue in one place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/auth Authentication, OAuth, credential pools comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants