hermes - ✅(Solved) Fix Bug: _try_openrouter() returns (None,None) when credential pool is exhausted, blocking env var fallback [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#23452Fetched 2026-05-11 03:29:26
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Timeline (top)
labeled ×4commented ×1cross-referenced ×1

When the OpenRouter credential pool has entries but all of them are exhausted/rate-limited (e.g. HTTP 429), _try_openrouter() returns (None, None) without falling back to the OPENROUTER_API_KEY environment variable, even when that env var is valid and usable.

This causes auxiliary tasks (title_generation, compression, session_search, vision, etc.) to fail with:

No LLM provider configured for task=<task> provider=auto

Meanwhile the main agent continues to work fine because it uses a different code path.

Error Message

  1. Observe the error: "No LLM provider configured for task=title_generation provider=auto"

Root Cause

In agent/auxiliary_client.py, _try_openrouter():

def _try_openrouter(explicit_api_key=None):
    pool_present, entry = _select_pool_entry("openrouter")
    if pool_present:                          # True — pool has entries, all exhausted
        or_key = explicit_api_key or _pool_runtime_api_key(entry)  # entry=None → ""
        if not or_key:
            return None, None                 # ← returns early, never reaches env var
    
    # This code is unreachable when pool_present=True but all entries exhausted:
    or_key = explicit_api_key or os.getenv("OPENROUTER_API_KEY")

The _select_pool_entry() helper returns (True, None) when the pool exists but all entries are in cooldown (pool.select() returns None). Since pool_present=True, the function bails out without ever checking os.getenv("OPENROUTER_API_KEY").

Fix Action

Fix / Workaround

Workaround (no source changes)

PR fix notes

PR #23495: fix(auxiliary): fall back to env when openrouter pool is exhausted

Description (problem / solution / changelog)

What does this PR do?

Fixes the OpenRouter auxiliary client fallback path so a cooled-down/exhausted credential pool no longer blocks OPENROUTER_API_KEY from being used. This keeps auxiliary tasks on the expected env-var fallback path instead of returning (None, None) early.

Related Issue

Fixes #23452

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • update agent/auxiliary_client.py so _try_openrouter() only returns the pool-backed client when a usable pooled key exists
  • fall through to OPENROUTER_API_KEY env lookup when the pool exists but currently has no selectable entry
  • add a regression test in tests/agent/test_auxiliary_client.py covering the exhausted-pool + env-fallback case

How to Test

  1. uv run --frozen pytest -q -o addopts='' tests/agent/test_auxiliary_client.py -k 'openrouter and (pool_exhausted or env_keeps_not_set_warning or falls_back_to_env)'
  2. uv run --frozen ruff check agent/auxiliary_client.py tests/agent/test_auxiliary_client.py
  3. env -i HOME="$HOME" PATH="$PATH" TERM="${TERM:-xterm-256color}" UV_CACHE_DIR="$HOME/.cache/uv" uv run --frozen pytest -q -o addopts='' --collect-only tests/agent/test_auxiliary_client.py -k 'openrouter and (pool_exhausted or env_keeps_not_set_warning or falls_back_to_env)'

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS 15.x

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

  • targeted pytest: 4 passed, 138 deselected
  • ruff check: passed
  • collect-only smoke: 4 tests collected
  • repo-wide pytest tests/ -q was not used as the merge gate here because the same clean origin/main baseline currently shows unrelated collection failures outside this change scope

Changed files

  • agent/auxiliary_client.py (modified, +5/-6)
  • tests/agent/test_auxiliary_client.py (modified, +18/-0)

Code Example

No LLM provider configured for task=<task> provider=auto

---

def _try_openrouter(explicit_api_key=None):
    pool_present, entry = _select_pool_entry("openrouter")
    if pool_present:                          # True — pool has entries, all exhausted
        or_key = explicit_api_key or _pool_runtime_api_key(entry)  # entry=None""
        if not or_key:
            return None, None                 # ← returns early, never reaches env var
    
    # This code is unreachable when pool_present=True but all entries exhausted:
    or_key = explicit_api_key or os.getenv("OPENROUTER_API_KEY")

---

def _try_openrouter(explicit_api_key=None):
    pool_present, entry = _select_pool_entry("openrouter")
    if pool_present:
        or_key = explicit_api_key or _pool_runtime_api_key(entry)
        if or_key:
            base_url = _pool_runtime_base_url(entry, OPENROUTER_BASE_URL) or OPENROUTER_BASE_URL
            return OpenAI(api_key=or_key, base_url=base_url,
                          default_headers=build_or_headers()), _OPENROUTER_MODEL
        # Fall through to env var fallback when pool entries are exhausted
        logger.info("OpenRouter pool exhausted, falling back to OPENROUTER_API_KEY env var")
    
    or_key = explicit_api_key or os.getenv("OPENROUTER_API_KEY")
    ...

---

hermes auth reset openrouter
RAW_BUFFERClick to expand / collapse

Description

When the OpenRouter credential pool has entries but all of them are exhausted/rate-limited (e.g. HTTP 429), _try_openrouter() returns (None, None) without falling back to the OPENROUTER_API_KEY environment variable, even when that env var is valid and usable.

This causes auxiliary tasks (title_generation, compression, session_search, vision, etc.) to fail with:

No LLM provider configured for task=<task> provider=auto

Meanwhile the main agent continues to work fine because it uses a different code path.

Root Cause

In agent/auxiliary_client.py, _try_openrouter():

def _try_openrouter(explicit_api_key=None):
    pool_present, entry = _select_pool_entry("openrouter")
    if pool_present:                          # True — pool has entries, all exhausted
        or_key = explicit_api_key or _pool_runtime_api_key(entry)  # entry=None → ""
        if not or_key:
            return None, None                 # ← returns early, never reaches env var
    
    # This code is unreachable when pool_present=True but all entries exhausted:
    or_key = explicit_api_key or os.getenv("OPENROUTER_API_KEY")

The _select_pool_entry() helper returns (True, None) when the pool exists but all entries are in cooldown (pool.select() returns None). Since pool_present=True, the function bails out without ever checking os.getenv("OPENROUTER_API_KEY").

Steps to Reproduce

  1. Have OpenRouter credential pool with at least one entry that gets rate-limited (429)
  2. All pool entries enter cooldown
  3. Run any auxiliary task (e.g. title generation after a chat response)
  4. Observe the error: "No LLM provider configured for task=title_generation provider=auto"

Expected Behavior

When the credential pool exists but has no usable entries, _try_openrouter() should fall back to the OPENROUTER_API_KEY environment variable, which is the same behavior as when no pool is configured at all.

Suggested Fix

In _try_openrouter(), when pool_present=True but no usable entry is found, fall through to the env var check instead of returning early:

def _try_openrouter(explicit_api_key=None):
    pool_present, entry = _select_pool_entry("openrouter")
    if pool_present:
        or_key = explicit_api_key or _pool_runtime_api_key(entry)
        if or_key:
            base_url = _pool_runtime_base_url(entry, OPENROUTER_BASE_URL) or OPENROUTER_BASE_URL
            return OpenAI(api_key=or_key, base_url=base_url,
                          default_headers=build_or_headers()), _OPENROUTER_MODEL
        # Fall through to env var fallback when pool entries are exhausted
        logger.info("OpenRouter pool exhausted, falling back to OPENROUTER_API_KEY env var")
    
    or_key = explicit_api_key or os.getenv("OPENROUTER_API_KEY")
    ...

Workaround (no source changes)

hermes auth reset openrouter

This clears the cooldown state on all pool entries.

Environment

  • Hermes Agent version: latest (main)
  • File: agent/auxiliary_client.py function _try_openrouter()
  • Provider: OpenRouter

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - ✅(Solved) Fix Bug: _try_openrouter() returns (None,None) when credential pool is exhausted, blocking env var fallback [1 pull requests, 1 comments, 2 participants]