Skip to content

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

Open
LeonSGP43 wants to merge 1 commit into
NousResearch:mainfrom
LeonSGP43:codex/23452-openrouter-env-fallback
Open

fix(auxiliary): fall back to env when openrouter pool is exhausted#23495
LeonSGP43 wants to merge 1 commit into
NousResearch:mainfrom
LeonSGP43:codex/23452-openrouter-env-fallback

Conversation

@LeonSGP43

Copy link
Copy Markdown
Contributor

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

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder provider/openrouter OpenRouter aggregator labels May 11, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Competing fix with #10655 — both address the same OpenRouter pool exhaustion fallback bug (#23452/#10149).

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

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists provider/openrouter OpenRouter aggregator type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: _try_openrouter() returns (None,None) when credential pool is exhausted, blocking env var fallback

2 participants