Anthropic (and other providers') pre-key model list drifts because recommended_models_from_registry() exists but has no callers
- Lenguaje dominante
- Rust
- Estrellas
- 54.2k
- Forks
- 6.2k
- Merge medio
- 3 d 2 h
- PR fusionados (30 d)
- 262
Descripción
**Describe the bug**
`ANTHROPIC_KNOWN_MODELS` (`crates/goose-providers/src/anthropic.rs:32`) is a hand-maintained list that backs `ProviderDescriptor::metadata()` — what the model picker shows before an API key is configured. It has drifted twice in two months:
- `#10864` (resolved by #10865): `claude-sonnet-5` and `claude-fable-5` were missing.
- Right now, on current `main`: `claude-opus-4-1` is in the bundled canonical registry but **not** in the hardcoded list — the same gap, recurring.
Every entry is also hardcoded to a `context_limit` of `200_000`, though the registry reports up to `1_000_000` for several of these models (noted in #10864, not yet fixed).
`crates/goose-provider-types/src/canonical.rs` already has `recommended_models_from_registry(provider: &str) -> Vec` — fully implemented (filters by text-input + tool-calling support, sorts by release date, reads only the bundled registry, no network call) — with **zero callers** in the codebase. It reads as though it was written for exactly this and never wired up.
This isn't Anthropic-specific. The same `KNOWN_MODELS`-style hand-maintained pattern exists in 20+ provider files (`cursor_agent.rs`, `openai.rs`, `google.rs`, `bedrock.rs`, `xai.rs`, `openrouter.rs`, and more) — all subject to the same drift. This issue scopes to Anthropic only, as a template for the rest.
---
**To Reproduce**
1. Check the bundled canonical registry for Anthropic: `recommended_models_from_registry("anthropic")` (currently uncalled, but easy to invoke from a test) returns 11 models including `claude-opus-4-1`.
2. Compare against `ANTHROPIC_KNOWN_MODELS` in `crates/goose-providers/src/anthropic.rs` — `claude-opus-4-1` is absent.
3. Start goose with no `ANTHROPIC_API_KEY` configured — the pre-key model picker is driven by `ANTHROPIC_KNOWN_MODELS` and will not offer `claude-opus-4-1`, despite it being a valid, known Anthropic model in the bundled registry.
---
**Expected behavior**
The pre-key model picker for Anthropic should stay in sync with the bundled canonical registry automatically, instead of relying on a manually-maintained array that requires a human to notice and patch every time a new model ships (as happened with `#10864`/`#10865`, and again now with `claude-opus-4-1`).
---
**Please provide the following information**
- **OS & Arch:** N/A — code-level defect, not environment-specific
- **Interface:** UI / CLI (both consume `ProviderDescriptor::metadata()`)
- **Version:** current `main`
- **Extensions enabled:** N/A
- **Provider & Model:** Anthropic — affects the full known-model list, e.g. `claude-opus-4-1`
---
**Additional context**
Proposed approach (Anthropic first, as a template), in `AnthropicProvider::metadata()`:
1. Call `recommended_models_from_registry("anthropic")` for the primary list, sorted newest-first.
2. For each name, resolve `context_limit` via the existing `maybe_get_canonical_model("anthropic", name)` helper (already used the same way in `model.rs::with_canonical_limits`) instead of the current blanket `200_000`.
3. **Fall back to `ANTHROPIC_KNOWN_MODELS`** if the registry call returns empty (bundled registry failed to load) — no regression risk if the registry is ever unavailable.
4. **Keep legacy dated aliases** that have no registry counterpart (`claude-sonnet-4-0`, `claude-sonnet-4-20250514`, `claude-opus-4-0`, `claude-opus-4-20250514` — confirmed via a local diagnostic, verifiable via `cargo test -p goose-provider-types`) merged in alongside the registry-derived list, so existing users pinned to them don't lose them from the picker.
Net effect: the static-list-drift bug class closes for Anthropic permanently, using code that already exists and is already tested elsewhere in the same crate. Rolling the same pattern out to the other 20+ providers is a natural follow-up once this lands and the approach is validated — not proposed here.
**Verification plan**
- `cargo test -p goose-provider-types` / `-p goose-providers`
- `cargo clippy --all-targets -- -D warnings`
- Manual: start goose with no `ANTHROPIC_API_KEY` configured, confirm the model picker shows the registry-derived list plus the 4 legacy aliases, with correct per-model context limits.
Do not begin implementation until the issue reaches **Ready** on the [Goose Issues board](https://github.com/orgs/aaif-goose/projects/1).
Guía de contribución
Evaluación
Este issue todavía no se ha evaluado.