mirror of
https://github.com/bitbaum/botsmann.git
synced 2026-12-04 05:08:02 +01:00
On 2026-08-28 /api/health reported "healthy" while every AI feature on
this site was failing on an invalid Groq key. Carrying `llm` in that body
fixed the REPORTING. It did not make the state observable before a user
hit it, because nothing calls a provider until somebody uses the bot — so
straight after a deploy the field reads "unknown", and unknown is what it
stays.
GET /api/health/ai free. What the last real call did.
GET /api/health/ai?probe=1 a real call. 200 or 503. Needs the secret.
Opposite contract to /api/health on purpose: that route is LIVENESS and
must stay 200 while the LLM is down, because restarting does not fix an
expired key and failing on it would get a healthy process killed. This
one is the inverse, so an uptime monitor can page on a real AI outage
without paging on every deploy.
It probes THIS app's chain: `ask` (ai-kit 0.15.0) calls
generateWithBestProvider, the same function the chat routes use. A probe
built from its own provider list would test a path nothing else takes and
would drift from this one the first time the chain changed.
The secret is a GETTER — the handler is built once and reused, so a
captured string would be whatever the environment held on the first
request: un-rotatable without a restart, and untestable.
TWO THINGS THE TESTS TAUGHT ME, both about this app rather than the
probe:
- generateWithBestProvider goes through getServerEnv(), which validates
the WHOLE server env and throws on the first missing var. A probe
test that sets only the AI keys fails on SUPABASE_SERVICE_ROLE_KEY,
nowhere near the chain.
- Ollama is tried first and its availability is a LIVE PING, so a fetch
mock that answers every URL makes a local runtime appear to exist and
win the chain. The mock now refuses :11434, which is prod's real
shape — and the "which vendor served it" assertion looks at every
call rather than calls[0], because calls[0] is that ping.
verify green — 301 tests.
Claude-Session: https://claude.ai/code/session_01NHDLTKGirKU7He8q2YR2y4
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>