Found by driving the Lex demo in production: the chat answered "I'm sorry,
I encountered an error processing your request." Behind it, every AI feature
on the site is down and has been invisible.
The box has an invalid Groq key, no other provider key, and no Ollama:
Groq API error: 401 (model openai/gpt-oss-120b) {"code":"invalid_api_key"}
Groq API error: 401 (model openai/gpt-oss-20b) {"code":"invalid_api_key"}
Every endpoint answered HTTP 200 anyway:
/api/demo/chat {"success":true,"data":{"response":""}}
/api/quick-chat {"success":true,"data":{"response":"I'm having a moment..."}}
/api/professional-chat same
/api/health {"success":true,"data":{"status":"healthy"}}
Green everywhere, product dead. demo/chat was the worst of the three: its
catch returns `content: context`, and a bot demo has no context, so a failed
generation became a successful empty string.
- demo/chat throws LLMUnavailableError when there is nothing to fall back
on; the knowledge-base demo still serves its retrieved passage
- quick-chat and professional-chat return 503 LLM_UNAVAILABLE instead of
apologising with 200
- lib/llm-health.ts records what generations actually did; /api/health
reports it and returns 503 once the chain is consistently failing, so
"healthy" stops meaning "the database answered"
tests/__tests__/api/professional-chat.test.ts asserted the bug -- 200, the
word "moment", provider 'fallback'. It now asserts 503 LLM_UNAVAILABLE. A
test that pins broken behaviour is worse than no test.
Never-twice: tests/__tests__/lib/llm-health.test.ts covers the tracker's
state machine and asserts at source level that no chat route answers an LLM
failure with success, and that health consults the LLM chain.
This makes the outage visible. It does NOT fix it -- that needs a valid
GROQ_API_KEY (or OPENROUTER_API_KEY) in /opt/botsmann/shared/.env on the box.
Until then these endpoints will correctly return 503.
verify: format, lint, typecheck, 268 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>
Add Cache-Control header support to API response utilities:
- NONE: no-store for mutations and sensitive data
- PRIVATE_SHORT: 1 minute for user-specific data
- PRIVATE_MEDIUM: 5 minutes for less frequent user data
- PUBLIC_SHORT: 5 minutes for public data
- PUBLIC_MEDIUM: 1 hour for semi-static data
- IMMUTABLE: 1 day for truly static data
Apply caching to key routes:
- GET /api/settings: private, 1 min cache
- GET /api/health: public, 5 min cache
- GET /api/documents: private, 1 min cache
- GET /api/stats: private, 1 min cache
- GET /api/conversations: private, 1 min cache
- All mutations (POST/PUT/DELETE): no-store
- All errors: no-store (automatic)
Expected impact: 2-3x reduction in database queries for
repeated requests within cache window.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Refactored multiple API routes and components to improve code organization and reduce duplication:
- Simplified API route implementations across chat, documents, consultations, and other endpoints
- Reorganized navigation components for better maintainability
- Added shared utility functions and hooks
- Created reusable Avatar and Logo components
- Added validation schemas and API utilities
- Improved type definitions and constants management
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>