Skip to content

fix(auth): honor per-entry key_env when resolving fallback providers (salvage #43861) - #65682

Merged
teknium1 merged 1 commit into
mainfrom
salvage/43861-fallback-key-env
Jul 16, 2026
Merged

fix(auth): honor per-entry key_env when resolving fallback providers (salvage #43861)#65682
teknium1 merged 1 commit into
mainfrom
salvage/43861-fallback-key-env

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

A fallback chain entry that names its API key via key_env (or api_key_env) now resolves on every surface — previously only the gateway runner honored it, so a fallback provider whose key lives in a non-standard env var silently failed to resolve on TUI/desktop, cron, and CLI setup fallbacks.

Salvages the remaining half of #43861 by @VrtxOmega (the provider/model fallback half was superseded by #65656). Surgical reapply with authorship credited — the original branch predates the #65264 fallback restructuring.

Changes

  • hermes_cli/fallback_config.py: new resolve_entry_api_key() — inline api_key first, then key_env/api_key_env env lookup, None otherwise (falls through to the provider's standard credential resolution)
  • tui_gateway/server.py, cron/scheduler.py, hermes_cli/cli_agent_setup_mixin.py: use the shared helper (CLI mixin also gains the base_url passthrough the other surfaces already had)
  • gateway/run.py: inline copy replaced with the shared helper (behavior unchanged)
  • Tests: 8 key-resolution cases + a TUI fallback behavior test asserting the env-resolved key reaches resolve_runtime_provider

Validation

Surface key_env before key_env after
gateway runner resolved (inline copy) resolved (shared helper)
TUI/desktop ignored resolved
cron scheduler ignored resolved
CLI setup mixin ignored (no api_key/base_url either) resolved

565/565 targeted tests (test_fallback_config, test_tui_gateway_server, test_scheduler); ruff clean.

Closes #43861.

Infographic

fallback-key-env-resolution

A fallback chain entry can name its API key via key_env (or the
api_key_env alias) per the fallback-providers docs, but only the gateway
path resolved it — TUI/desktop, cron, and CLI setup fallbacks ignored it,
so a fallback provider whose key lives in a non-standard env var never
resolved on those surfaces.

Centralize the inline-api_key-then-key_env lookup in
hermes_cli/fallback_config.resolve_entry_api_key() and use it at all four
fallback resolution sites (tui_gateway, cron scheduler, gateway runner,
CLI setup mixin); the CLI mixin also gains the base_url passthrough the
other surfaces already had.

Salvaged from PR #43861 (surgical reapply — the original branch predates
the #65264 fallback restructuring).
@alt-glitch alt-glitch added type/bug Something isn't working comp/cron Cron scheduler and job management comp/gateway Gateway runner, session dispatch, delivery comp/cli CLI entry point, hermes_cli/, setup wizard comp/tui Terminal UI (ui-tui/ + tui_gateway/) area/auth Authentication, OAuth, credential pools P2 Medium — degraded but workaround exists sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades labels Jul 16, 2026
@teknium1
teknium1 merged commit 998e353 into main Jul 16, 2026
33 checks passed
@teknium1
teknium1 deleted the salvage/43861-fallback-key-env branch July 16, 2026 14:19

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review Summary

Verdict: Comment

Overview

  • Auth fix: honor per-entry key_env when resolving fallback providers
  • 118 additions, 13 deletions
  • Salvage of PR #43861

Assessment

  • Per-entry key_env resolution is a good improvement for auth flexibility
  • No obvious security concerns
  • Clean diff

Reviewed by Hermes Agent

Copy link
Copy Markdown
Contributor

Man, thank you. This honestly means more to me than you probably realize. I opened that fix months ago after a lot of digging, testing, and trying to prove that I could contribute something real upstream.

Seeing the original branch become impossible to cherry-pick, but the actual engineering survive the restructuring, get extracted, centralized, expanded across all four fallback surfaces, and still carry my authorship is about the best outcome I could have hoped for.

I really appreciate you taking the time to trace the work, preserve the credit, and explain exactly what landed. I was never just chasing a green merge badge—I wanted to find and fix something that actually mattered. Knowing both halves made it into Hermes is a huge moment for me. Thank you.

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 comp/cron Cron scheduler and job management comp/gateway Gateway runner, session dispatch, delivery comp/tui Terminal UI (ui-tui/ + tui_gateway/) P2 Medium — degraded but workaround exists sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants