Skip to content

fix(ai): give text analysis a real multi-vendor fallback chain - #239

Merged
catomean merged 1 commit into
mainfrom
fix/ai-fallback-chain
Sep 2, 2026
Merged

fix(ai): give text analysis a real multi-vendor fallback chain#239
catomean merged 1 commit into
mainfrom
fix/ai-fallback-chain

Conversation

@catomean

@catomean catomean commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • backend/services/llm-analysis.js and backend/services/aiAnalysisService.js used to construct their own OpenAI client, hardcode model: 'gpt-4', and throw/skip outright when OPENAI_API_KEY was unset — a single vendor, single model, hardcoded. The moment OpenAI has a billing hiccup, an outage, or retires gpt-4, every text-analysis feature in this app goes dead with no recovery until someone notices and redeploys.
  • New backend/lib/aiChain.js gives both services a real multi-vendor fallback chain (Groq → OpenRouter) via ai-kit (github:bitbaum/ai-kit), the same package already adopted fleet-wide for exactly this failure mode. Includes an informational-only health tracker (never gates anything, matches the fleet convention).

Deliberately left as a documented limitation

Vision/image analysis (imageIngestionService.js, videoIngestionService.js frame analysis, frontend/.../openaiVisionService.ts) and audio transcription (Whisper) stay on OpenAI — ai-kit's free chain carries no vision- or audio-capable free models, so forcing those onto the chain would silently degrade output quality rather than provide a real fallback. Documented in aiChain.js's header comment.

Test plan

  • frontend build green (npm run build)
  • frontend lint: 0 errors (161 pre-existing warnings, none in touched files)
  • backend has no lint/test scripts configured (pre-existing — "test": "echo Error: no test specified")
  • CI green on this PR

llm-analysis.js and aiAnalysisService.js each constructed their own
OpenAI client, hardcoded model: 'gpt-4', and threw/skipped outright
whenever OPENAI_API_KEY was unset — a single vendor, single model, with
no recovery path. The moment OpenAI has a billing hiccup, an outage, or
retires gpt-4, every text-analysis feature in this app goes dead until
someone notices and redeploys.

backend/lib/aiChain.js gives both services a real chain via ai-kit
(Groq -> OpenRouter free tier, same package already adopted fleet-wide
for this exact failure mode), plus a health tracker exposed
informationally on /health (never gates the endpoint's status — a dead
vendor key can't be fixed by a restart).

Vision/image analysis (imageIngestionService.js, video frame analysis,
openaiVisionService.ts) and Whisper audio transcription stay on OpenAI
directly: ai-kit's free chain carries no vision- or audio-capable free
models, so forcing those onto it would silently degrade output quality
rather than provide a real fallback. Documented as a known limitation
in .claude/CLAUDE.md's env var list.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HVwg8DKHQktxJuHeLM3xpG
@catomean
catomean merged commit 65796bf into main Sep 2, 2026
2 checks passed
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