Skip to content

fix(llm): take model ids from ai-kit, and try more than one - #137

Merged
github-actions[bot] merged 1 commit into
mainfrom
fix/chain-not-a-pin
Aug 26, 2026
Merged

fix(llm): take model ids from ai-kit, and try more than one#137
github-actions[bot] merged 1 commit into
mainfrom
fix/chain-not-a-pin

Conversation

@catomean

Copy link
Copy Markdown
Collaborator

fix(llm): take model ids from ai-kit, and try more than one

Both ids in API_CONFIG have been retired by their vendors:
llama-3.1-8b-instant at Groq and openai/gpt-oss-20b:free at OpenRouter. With
a valid key, this app's chatbot was answering 404.

Nothing was neglected here. The constant carried the correct instruction —
"free catalogues rot; when it does, replace it with another :free id" — and
that is precisely the maintenance that did not happen, because nothing tells a
constant when it has stopped being true. So the ids leave this repo. ai-kit
holds one list for the fleet, re-probes it against the live catalogues, and
dotfiles' daily audit asks both vendors whether those ids still exist.

One id was also not enough on its own. generateWithBestProvider picks ONE
provider and calls it exactly once, so a retirement had nothing between it and
a dead chatbot. Each vendor's call now walks that vendor's list: a 404 (retired)
or a 429 (busy or spent) steps to the next model instead of surfacing.

This is model-level fallback, not vendor-level — provider selection is untouched.
That is the smaller half of the protection, since a spent daily budget is
org-wide and kills every model at a vendor together. It is also the half that
covers rot, which is what actually happened here, twice.

An explicit caller override is still honoured as-is and alone. If someone names
a model, quietly answering from a different one is worse than failing.

The cost rule that lived in the deleted comment survives, and got stronger.
free-fallback.test.ts used to regex ONE constant; it now runs modelCost over
every OpenRouter id this app could send, using the same function the rest of the
fleet prices models with. OpenRouter is only reached when Groq's free tier is
spent — when nobody is watching — so a paid id there turns an outage into a bill.

The old tests deserve a note, because they passed throughout the outage: they
mocked llama-3.1-8b-instant and asserted it back, agreeing with production
about an id production was refusing. Worse, the OpenRouter test asserted
anthropic/claude-sonnet-5 — a paid model on the free-tier fallback path, the
exact thing the fleet rule forbids, green the whole time. They now assert
against the chain, plus two new cases: a retired first model falls through to a
different one, and exhausting the list names the whole list.

jest.config.js transforms ai-kit, which is ESM-only. The comment there says
what does NOT belong in that list, since a transitive entry would mean a package
leaking a dependency through a re-export — a bug to fix at the source.

verify: format, lint, typecheck, 232 tests, build.

🤖 Generated with Claude Code

Both ids in `API_CONFIG` have been retired by their vendors:
`llama-3.1-8b-instant` at Groq and `openai/gpt-oss-20b:free` at OpenRouter. With
a valid key, this app's chatbot was answering 404.

Nothing was neglected here. The constant carried the correct instruction —
"free catalogues rot; when it does, replace it with another `:free` id" — and
that is precisely the maintenance that did not happen, because nothing tells a
constant when it has stopped being true. So the ids leave this repo. `ai-kit`
holds one list for the fleet, re-probes it against the live catalogues, and
dotfiles' daily audit asks both vendors whether those ids still exist.

One id was also not enough on its own. `generateWithBestProvider` picks ONE
provider and calls it exactly once, so a retirement had nothing between it and
a dead chatbot. Each vendor's call now walks that vendor's list: a 404 (retired)
or a 429 (busy or spent) steps to the next model instead of surfacing.

This is model-level fallback, not vendor-level — provider selection is untouched.
That is the smaller half of the protection, since a spent daily budget is
org-wide and kills every model at a vendor together. It is also the half that
covers rot, which is what actually happened here, twice.

An explicit caller override is still honoured as-is and alone. If someone names
a model, quietly answering from a different one is worse than failing.

The cost rule that lived in the deleted comment survives, and got stronger.
`free-fallback.test.ts` used to regex ONE constant; it now runs `modelCost` over
every OpenRouter id this app could send, using the same function the rest of the
fleet prices models with. OpenRouter is only reached when Groq's free tier is
spent — when nobody is watching — so a paid id there turns an outage into a bill.

The old tests deserve a note, because they passed throughout the outage: they
mocked `llama-3.1-8b-instant` and asserted it back, agreeing with production
about an id production was refusing. Worse, the OpenRouter test asserted
`anthropic/claude-sonnet-5` — a paid model on the free-tier fallback path, the
exact thing the fleet rule forbids, green the whole time. They now assert
against the chain, plus two new cases: a retired first model falls through to a
different one, and exhausting the list names the whole list.

`jest.config.js` transforms `ai-kit`, which is ESM-only. The comment there says
what does NOT belong in that list, since a transitive entry would mean a package
leaking a dependency through a re-export — a bug to fix at the source.

verify: format, lint, typecheck, 232 tests, build.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions
github-actions Bot merged commit 967ace5 into main Aug 26, 2026
1 check passed
@github-actions
github-actions Bot deleted the fix/chain-not-a-pin branch August 26, 2026 22:07
github-actions Bot pushed a commit that referenced this pull request Aug 28, 2026
#154)

generateWithBestProvider picked ONE provider and called it once. Being
configured counted as being available, so a present-but-revoked key was
indistinguishable from a working one: botsmann's Groq key started returning
401 and the entire AI layer went down, with no attempt at anything else.

kivvi survives the same dead-Groq situation on this box because it has an
OpenRouter key and reaches it. botsmann would not have, even after adding
one -- Groq is chosen first for merely existing, and its 401 was terminal.

  getProviderChain()          every configured provider, in preference order
                              (Ollama, Groq, OpenRouter) rather than the first
  generateWithBestProvider()  walks that chain, demoting on failure, and only
                              throws once every provider has been tried

generateLLMResponse already walks the model list within a provider (#137), so
this is the layer above: models, then providers. The error now names each
provider that failed and why, instead of surfacing whichever one happened to
be first.

This does NOT restore botsmann's AI. Every working LLM key on the box belongs
to a client -- AOZ's and RevampIT's -- and botsmann is a bitbaum product, so
pointing it at one would bill a client for our usage. It needs its own key.
What this does is make sure that once a second key exists, one dead key can
never take the product down again.

verify: format, lint, typecheck, 272 tests, build -- all green.


Claude-Session: https://claude.ai/code/session_01HVwg8DKHQktxJuHeLM3xpG

Co-authored-by: Mao Nakamoto <41178744+maonakamoto@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
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