Skip to content

Fix release review findings: per-model notes, Bedrock fallback logging and reporting, tests - #565

Merged
neuromechanist merged 14 commits into
developfrom
fix/release-0.8.16-routing
Sep 30, 2026
Merged

neuromechanist merged 14 commits into
developfrom
fix/release-0.8.16-routing

Conversation

@neuromechanist

Copy link
Copy Markdown
Member

Fixes the findings of the five-reviewer review of release PR #562 (develop -> main). Each was reproduced or confirmed against the code first.

Changes

  • 1. Per-model prompt notes on OpenRouter. _route_request computes the offered model id once (_offered_model_id) and RequestRoute.offered_model_id carries it; create_community_assistant passes it as model_id. Before, the OpenRouter slug (openai/gpt-6-luna) found neither the built-in anti-search-loop note nor a community model_instructions entry (Claude slugs included). Confirmed by failing tests on the old line (9 failures).
  • 2. RequestRoute invariants. __post_init__ refuses a provider_hint off OpenRouter, a Bedrock model off the bedrock provider (or the reverse), and an offered id that is not the one the model stands for.
  • 3. ProviderChoice. provider="bedrock" requires api_key=None and key_source="platform"; ProviderChoice("bedrock", "sk-user", "byok") now raises.
  • 4. model_instructions blank key is a config error (an empty key normalized to Haiku).
  • 5. default_model: openai/gpt-oss-120b (an offered model's OpenRouter slug, or that slug with a routing variant) now warns at load and names the id to write. The slug table moved to anthropic_models.py (no third-party imports) so config validation can use it on a CLI-only install; litellm_llm re-exports it.
  • 6. GET /{community}/ reports what a platform request runs: the Claude fallback (and the platform's routing hint) when Bedrock cannot be served or nothing can run the model, the community's own default when Bedrock serves it or OpenRouter runs it (no Anthropic key: the model runs under its slug).
  • 7. Fallback log. ERROR only when the deployment lacks the Bedrock key, WARNING when the caller's own key is the cause; /chat/resume's route probe no longer logs (log_fallback=False), so a request logs once. Record fields: community_id, model, fallback, key_source, cause.
  • 8. Startup check. log_unserved_bedrock_defaults runs in the app lifespan: one record per community whose default is a Bedrock model the deployment cannot serve, each naming AWS_BEARER_TOKEN_BEDROCK and ANTHROPIC_API_KEY. ERROR when requests run Claude or fail with 500; WARNING when OpenRouter runs the model (see 9).
  • 9. Key combinations. Bedrock key only: the 500 "No API key configured" is now logged at its raise site (ERROR, community id, says a Bedrock key alone serves nothing). The load-time warning text now says exactly what happens per key combination.
  • 10. Types. REASONING_LEVELS, REASONING_SCALE, DEFAULT_REASONING_EFFORT typed with ReasoningEffort; return types follow. One ProviderName alias replaces the three spellings (ReasoningProvider is gone). SAMPLING_MODELS is a frozenset.
  • 11. Comments. Haiku has levels; Bedrock waits at high or above; cost.py names the us. profile premium; OFFERED_MODELS points at anthropic_models; _warn_retired_env_vars documents that it reads os.environ only; the stray dash is gone; CACHEABLE_MODELS and is_cacheable_model (unreferenced, contradicted takes_cache_markers) are deleted.
  • 12. Test gaps. (a) NEMAR through the real routing plus a rule that communities with client tools or MCP servers do not default to Bedrock; (b) Luna communities derived from the registry; (c) Haiku thinking budget handled; (d) OpenRouter-only platform; (e) /chat/resume with a Bedrock default (real routing at both call sites, provider factories scripted); (f) offered-models test sets the keys; (g) timing test compares scaling; (h) loopback server fixtures are context managers with robust teardown.

Not changed

  • 9, first half (Bedrock and OpenRouter keys, no Anthropic key). Luna runs on the platform's OpenRouter key. That is the existing _platform_choice fallback for a deployment with no Anthropic key (it warns on every such request), and _serves_bedrock_models hiding the Bedrock models from the menu there is deliberate and tested (Bedrock is reached only from the Anthropic provider). ADR 0004 calls OpenRouter retired as a platform route; the fallback is the documented exception in code, and the ADR 0014 text does not cover this combination. Behavior kept; the new startup WARNING and the corrected load-time text make it visible.
  • 13. boto3/botocore floor. The Dockerfile (uv sync --frozen --no-dev --extra server) and every CI job (uv sync --frozen) install from uv.lock, which pins boto3 and botocore 1.43.104. No floor added.
  • The src/assistants/hed/config.yaml and bids/config.yaml comments still say anthropic_llm.OFFERED_MODELS; those files are owned elsewhere.

Tested

  • uv run ruff check . && uv run ruff format --check .
  • uv run pytest --ignore=tests/test_integration -m "not integration and not llm and not network" -q -p no:cacheprovider --color=no: 4046 passed, 14 skipped, 75 deselected (ruff clean).
  • New and changed tests run against the real registry, real routers and real config; only provider model factories are scripted (resume test). Tests for findings 1, 6, 7 and the resume double-log were confirmed to fail without the fix.

OPENROUTER_MODEL_IDS, OPENROUTER_ROUTING_VARIANTS and openrouter_model_id move
to anthropic_models.py, which has no third-party imports, so community config
validation can use them on a CLI-only install. litellm_llm re-exports them.
No behavior change. Tested: litellm and reasoning-effort unit tests.
provider='bedrock' with a key, or with a key source other than 'platform', is
refused at construction. A byok Bedrock choice would spend the platform's
Bedrock token while _check_model_cost skips byok requests entirely.
Tested: test_bedrock_routing.py.
The notes and a community's model_instructions are keyed by offered id, but the
OpenRouter path passed the provider's slug (openai/gpt-6-luna), so both missed.
_route_request now computes the offered id once and RequestRoute carries it;
create_community_assistant passes that as model_id.

RequestRoute also refuses contradictory parts: a provider_hint off OpenRouter,
a Bedrock model off the bedrock provider (or the reverse), and an offered id
that is not the one the model stands for.

Tested: new test_request_route.py (HED, BYOK OpenRouter and platform paths);
the notes tests fail without the fix.
normalize_model reads an empty id as the default model, so a key of '' filed the
text under Haiku without a word. A falsy or blank key is now a config error.
Tested: test_community.py (blank keys).
…a Bedrock default does

A default_model of openai/gpt-oss-120b (an offered model's OpenRouter slug) loaded
silently and answered 400 on the Anthropic and Bedrock path; it now warns and names
the id to write. The Bedrock-default warning lists what each key combination does
(Claude fallback, OpenRouter, HTTP 500) instead of 'the Claude default' alone, and
names OFFERED_MODELS where it is defined.
Tested: test_community.py (slug warnings, warning text).
The fallback to Claude logged ERROR on every BYOK and CLI request, which are
expected, and twice per /chat/resume, burying the real misconfiguration. It is
now ERROR only when the deployment lacks the Bedrock key, WARNING when the
caller's own key is the cause, and /chat/resume's route probe does not log.
The fallback record carries community_id, model, fallback, key_source, cause.

The HTTP 500 for a deployment with no platform key is now logged at its raise
site with the community id, and says a Bedrock key alone serves nothing.

Tested: test_bedrock_routing.py (levels, extra fields, every shipped Bedrock
community without a Bedrock key, no-key 500, OpenRouter-only fallback).
GET /{community}/ reported the community's Bedrock default_model even on a
deployment that cannot run it (and omits it from offered_models), so the widget
showed 'Community default: GPT-6 Luna' while the server ran the Claude fallback.
It now reports what a platform request runs: the Claude fallback when Bedrock
cannot be served, the model itself when OpenRouter runs it (no Anthropic key).

At startup the app logs one record per shipped community whose Bedrock default
cannot be served: ERROR when requests run Claude or fail, WARNING when OpenRouter
runs it, each naming AWS_BEARER_TOKEN_BEDROCK and ANTHROPIC_API_KEY.

Tested: new test_bedrock_deployments.py over eight key combinations, the real
registry and routers, and the app lifespan; tests/helpers/deployment.py shares
the key setup with test_bedrock_routing.py.
…MODELS

REASONING_LEVELS, REASONING_SCALE and DEFAULT_REASONING_EFFORT are typed with
ReasoningEffort, and resolve_reasoning_effort and friends return it. The provider
Literal was spelled three times; ProviderName in anthropic_models.py is the one
spelling (it replaces ReasoningProvider). SAMPLING_MODELS is a frozenset.
No behavior change. Tested: core and routing suites; ruff.
Haiku has reasoning levels; Bedrock waits at high effort or above, not only
maximum; the Luna registry id is served through the us. profile at a 10% premium
over the global rate OpenRouter matches; OFFERED_MODELS is defined in
anthropic_models, not anthropic_llm; _warn_retired_env_vars reads os.environ only.
CACHEABLE_MODELS and is_cacheable_model claimed caching for all models, contradict
takes_cache_markers and are referenced nowhere, so they are deleted.
No behavior change. Tested: litellm unit tests; ruff.
… handling

NEMAR is routed through the real code (Claude Platform, Sonnet, native blocks,
effort high). The Luna test derives its communities from the registry. The
dynamic level test handles Haiku's thinking budget as well as Sonnet's
output_config, and a new rule keeps communities with client tools or MCP servers
off Bedrock defaults (their figures need image blocks). Tested: this file.
…efault

An OpenRouter-only deployment runs hed and nwb as openai/gpt-6-luna and nemar as
anthropic/claude-sonnet-5.5 through real model construction. /chat/resume with no
model on a Bedrock-default community is driven through the real endpoint with
real routing at both call sites: one fallback log, and the image decision agrees
with the model that runs. Tested: these files.
… set

The test set no keys, so the menu left the Bedrock ids out and the loop skipped
them silently. It now sets the keys and asserts they were checked.
Tested: test_community_router.py.
Four times the whitespace must cost under eight times as much: linear reading
passes at about four, quadratic reading shows about sixteen. Best of three runs
each. Tested: passes; a quadratic pattern fails it.
FakeOpenRouter is a context manager, switches garbage collection off only after
the server is up, and restores it even if stopping the server raises. The three
fixtures use it, so a failing setup or teardown cannot leave collection off or
the server running. Tested: the fixtures' suites and new cases in
test_fake_openrouter_gc.py.
@neuromechanist
neuromechanist merged commit c3f1e61 into develop Sep 30, 2026
9 checks passed
@neuromechanist
neuromechanist deleted the fix/release-0.8.16-routing branch September 30, 2026 21:38
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.

1 participant