Skip to content

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

Merged
github-actions[bot] merged 1 commit into
mainfrom
fix/ai-fallback-chain
Sep 2, 2026
Merged

fix(ai): give text analysis a real multi-vendor fallback chain#238
github-actions[bot] 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 each hardcoded a single OpenAI client (model: 'gpt-4') with no fallback — threw/skipped outright if OPENAI_API_KEY was unset, and would go fully dead on any OpenAI outage/billing hiccup/model retirement.
  • New backend/lib/aiChain.js gives both services a real chain via ai-kit (Groq → OpenRouter free tier), plus a health tracker exposed informationally on /health (never gates the endpoint's status).
  • databaseController.js's analyzeDatabase no longer accepts a client-supplied model (gpt-4 vs gpt-3.5 was never a real fallback, just two names for the same vendor) — old clients sending it are unaffected, the field is just ignored now.

Deliberately left as a documented limitation

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

Test plan

  • npm run verify green (format, lint 0 errors, typecheck, 46 tests, build)
  • Confirmed no remaining direct api.openai.com chat-completion calls outside the vision/audio paths noted above

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
@github-actions
github-actions Bot merged commit 9628b5f into main Sep 2, 2026
1 check passed
@github-actions
github-actions Bot deleted the fix/ai-fallback-chain branch September 2, 2026 09:16
@catomean
catomean restored the fix/ai-fallback-chain branch September 2, 2026 09:19
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