Skip to content

[codex] Gate providers and add Bedrock discovery#37

Merged
jmlago merged 5 commits into
mainfrom
codex/provider-availability-bedrock
Jun 30, 2026
Merged

[codex] Gate providers and add Bedrock discovery#37
jmlago merged 5 commits into
mainfrom
codex/provider-availability-bedrock

Conversation

@MuncleUscles

@MuncleUscles MuncleUscles commented Jun 29, 2026

Copy link
Copy Markdown
Member

Summary

  • gate providers with missing credentials and filter OpenRouter endpoint details that are unavailable
  • replace the provisional Bedrock OpenAI-compatible/Mantle setup with native Amazon Bedrock Runtime routing
  • discover Bedrock foundation models + inference profiles dynamically, filter unavailable account models, and ingest public AWS Bedrock pricing across current Bedrock offer files
  • add static/native Bedrock routes for working cost-saving families while preserving OpenRouter fallbacks

Core dependency

Validation

  • .venv/bin/python -m pytest tests/test_native_providers.py tests/test_sources.py tests/test_live_wiring.py -q
  • .venv/bin/python -m pytest tests --ignore=tests/test_auth_proxy_dashboard_full.py -q
  • lua tests/run_lua.lua in core
  • local AWS smoke with AWS_PROFILE=DEV-DevExp AWS_REGION=us-east-1: Bedrock Qwen, Claude Sonnet, GPT OSS, and Gemma invoked successfully; Opus is filtered because the account reports it unavailable.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@jmlago, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 44 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8325ed79-9d72-42cf-8ecb-f2b9b65d2338

📥 Commits

Reviewing files that changed from the base of the PR and between a718b30 and 84ac4cd.

📒 Files selected for processing (17)
  • .env.example
  • config.live.lua
  • core
  • docs/DEPLOY.md
  • llm_router_host.py
  • provider_adapters/bedrock.py
  • requirements.txt
  • serve.py
  • shell.nix
  • sources/__init__.py
  • sources/bedrock.py
  • sources/openrouter.py
  • tests/test_async_concurrency.py
  • tests/test_live_wiring.py
  • tests/test_native_providers.py
  • tests/test_provider_filter_flow.py
  • tests/test_sources.py
📝 Walkthrough

Walkthrough

Adds Bedrock model discovery and AWS pricing support, wires Bedrock providers into the registry and live config, adds provider-auth enforcement to LLMRouterHost, and filters OpenRouter models without usable endpoints.

Changes

Bedrock Source, Auth Enforcement, and OpenRouter Filtering

Layer / File(s) Summary
Bedrock provider config and env vars
.env.example, config.live.lua
Adds Bedrock env defaults and updates the live Bedrock provider entries to use the shared base URL and marketplace discovery settings.
BedrockSource implementation
sources/bedrock.py
Implements BedrockSource model discovery, AWS price ingestion, offer caching, market-book conversion, and empty balances output.
BedrockSource registry wiring
sources/__init__.py
build_registry() detects Bedrock providers and appends BedrockSource to the refresh registry.
OpenRouter endpoint availability filtering
sources/openrouter.py
Adds endpoint-detail availability checks, refreshes the cache during pricing, and skips unavailable OpenRouter models from pricing and discovery offers.
LLMRouterHost provider-auth enforcement
llm_router_host.py
Adds provider-auth classification, enforcement selection, disabled-provider syncing, and hook-driven enforcement tracking in LLMRouterHost.
Tests: Bedrock, OpenRouter, auth enforcement, env wiring
tests/test_sources.py, tests/test_live_wiring.py, tests/test_async_concurrency.py, tests/test_provider_filter_flow.py
Adds Bedrock registry and source tests, OpenRouter endpoint-filter coverage, live wiring auth-key tests, and explicit env injection for host construction in existing tests.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • genlayerlabs/unhardcoded#25: Touches config.live.lua Bedrock Mantle provider wiring, which this PR extends with Bedrock source registration and marketplace configuration.

Poem

🐇 I hop through clouds with a Bedrock tune,
Pricing from AWS, fetched by moonlight soon.
Keys come in, placeholders stay out of sight,
OpenRouter skips the endpoints not right.
A tiny burrow of configs and care,
And routing now knows what’s really there.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 17.46% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly captures the two main changes: provider gating and Bedrock discovery.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/provider-availability-bedrock

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@MuncleUscles MuncleUscles marked this pull request as ready for review June 29, 2026 11:57

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
sources/openrouter.py (1)

139-155: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Compute inline benchmark ranks from routable models only.

_live_traits is ranked before the unavailable models are filtered out. Those dropped models still consume bench_*_rank slots, so top-k policies can reject a live offer solely because an unavailable model ranked ahead of it in the discarded set.

Suggested fix
-        live = {m["id"]: self._traits_for(m) for m in self._models_snapshot if m.get("id")}
+        live = {
+            m["id"]: self._traits_for(m)
+            for m in self._models_snapshot
+            if m.get("id") and self._model_available(m["id"])
+        }
         self._add_ranks(live)
         self._live_traits = live
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@sources/openrouter.py` around lines 139 - 155, The `pricing` flow in
`sources.openrouter.py` builds and ranks `_live_traits` from the full snapshot
before unavailable models are removed, which lets unroutable models consume
`bench_*_rank` slots. Filter the snapshot to routable/available models first,
then build `live` and call `_add_ranks` on that filtered set so ranks used by
`_offer_for`, `offers_sync`, and `market_book` only reflect models that can
actually be served.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@config.live.lua`:
- Around line 96-97: The fallback `base_url` in `config.live.lua` is hardcoded
to `us-east-1`, which can mismatch `BEDROCK_REGION`. Update the `base_url`
fallback to be derived from `BEDROCK_REGION` so model discovery and pricing stay
in the same region. Use the existing `BEDROCK_MANTLE_BASE_URL` override in the
same config block, and make the fallback construction align with the region used
by `BedrockSource`.

In `@llm_router_host.py`:
- Around line 603-619: The auth-unconfigured handling in llm_router_host.py is
overwriting and later deleting existing disable states for providers that were
disabled for other reasons. Update the missing-provider loop and the cleanup
loop around the disabled map so _AUTH_UNCONFIGURED is only added when no other
disable reason exists, and only removed when the current entry was created by
this auth marker. Keep the logic scoped to the existing disabled dictionary
entries and preserve any non-auth disable reason unchanged.

In `@sources/bedrock.py`:
- Around line 220-223: The fallback in the Bedrock refresh flow is too broad:
when `_prices_by_family()` fails, `prices` is replaced with an empty dict and
every discovered model is treated as unpriced. Update the logic in the Bedrock
pricing refresh path (around `Bedrock` and `_prices_by_family`) so a pricing
fetch failure does not clear the catalog; instead preserve the last known
pricing data or skip the refresh for that region and surface the failure without
dropping existing Bedrock rows/offers.

In `@sources/openrouter.py`:
- Around line 65-79: The `_url_for` helper currently accepts any absolute URL,
which allows `links.details` from the `/models` payload to redirect requests off
OpenRouter. Update `_url_for` in `sources.openrouter.py` to only allow absolute
URLs that match the OpenRouter origin/base host, and reject or ignore foreign
hosts; keep the existing normalization for relative `/api/v1/...` paths before
joining with `self._base_url`. Ensure `_get` continues to call `_url_for` so the
refresh flow only fetches same-origin detail links.

---

Outside diff comments:
In `@sources/openrouter.py`:
- Around line 139-155: The `pricing` flow in `sources.openrouter.py` builds and
ranks `_live_traits` from the full snapshot before unavailable models are
removed, which lets unroutable models consume `bench_*_rank` slots. Filter the
snapshot to routable/available models first, then build `live` and call
`_add_ranks` on that filtered set so ranks used by `_offer_for`, `offers_sync`,
and `market_book` only reflect models that can actually be served.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bdf7c567-bbf5-4be8-9157-69d6a387d875

📥 Commits

Reviewing files that changed from the base of the PR and between 86d0d89 and 9c7cd27.

📒 Files selected for processing (10)
  • .env.example
  • config.live.lua
  • llm_router_host.py
  • sources/__init__.py
  • sources/bedrock.py
  • sources/openrouter.py
  • tests/test_async_concurrency.py
  • tests/test_live_wiring.py
  • tests/test_provider_filter_flow.py
  • tests/test_sources.py

Comment thread config.live.lua Outdated
Comment thread llm_router_host.py
Comment thread sources/bedrock.py Outdated
Comment thread sources/openrouter.py

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/test_sources.py`:
- Around line 537-544: The cache-retention check around source.pricing() and
source.offers_sync("bedrock_mantle_market") is currently vacuous if the first
refresh returns no offers. Add a precondition in this test after the initial
refresh and before simulating the 500 response so it verifies the cached offers
are non-empty (or otherwise meaningfully populated) before asserting they are
preserved after the failed refresh. Use the existing source.pricing(),
source.offers_sync(), and pytest.raises(RuntimeError) flow to keep the test
focused on cache retention.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8b4ccc65-de36-4869-b41e-23a31e49926b

📥 Commits

Reviewing files that changed from the base of the PR and between 9c7cd27 and 2523de8.

📒 Files selected for processing (6)
  • config.live.lua
  • llm_router_host.py
  • sources/bedrock.py
  • sources/openrouter.py
  • tests/test_live_wiring.py
  • tests/test_sources.py
🚧 Files skipped from review as they are similar to previous changes (4)
  • config.live.lua
  • llm_router_host.py
  • sources/openrouter.py
  • sources/bedrock.py

Comment thread tests/test_sources.py Outdated
@MuncleUscles MuncleUscles force-pushed the codex/provider-availability-bedrock branch 2 times, most recently from 8cdf6fc to 42bdeb0 Compare June 30, 2026 11:58
@MuncleUscles MuncleUscles force-pushed the codex/provider-availability-bedrock branch from 42bdeb0 to 81aed10 Compare June 30, 2026 12:17
@jmlago jmlago merged commit b0dfdf3 into main Jun 30, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants