feat(recommender): LLM schema validation + hardcoded fallback tips on AI failure (#90)

Python (ml/serving):
- Validate tip item after JSON parse: non-empty content, valid kind
- Retry on schema failure with a targeted clarification prompt, same 2× retry budget
- JSON parse failures keep the existing retry suffix

TypeScript (recommender):
- Add TipSource 'fallback' to shared-types
- FALLBACK_TIPS: 12 general-purpose life tips (hardcoded, no DB read)
- fetchOrchestratorTip returns {ok} discriminated union instead of null
- On !res.ok or fetch error: serve a random fallback tip with rationale 'AI service issues'
- Update tests: 204 path removed; both failure cases now expect source='fallback'

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-12 15:21:03 +00:00
parent 772bb6e194
commit 85a332b22b
4 changed files with 85 additions and 30 deletions

View File

@@ -2,7 +2,7 @@
export type TipKind = 'task' | 'advice' | 'insight' | 'reminder';
/** Where the tip content originated */
export type TipSource = 'todoist' | 'llm' | 'advice';
export type TipSource = 'todoist' | 'llm' | 'advice' | 'fallback';
/** A single recommendation surfaced to the user */
export interface Tip {