Add Gemini AI resilience: error handling, response caching, and fallback mode#64
Draft
Add Gemini AI resilience: error handling, response caching, and fallback mode#64
Conversation
…k mode, and tests Co-authored-by: Stacey77 <54900383+Stacey77@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Improve resilience of AI features in budgeting app
Add Gemini AI resilience: error handling, response caching, and fallback mode
Feb 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The app had no handling for Gemini API quota exhaustion (429/
RESOURCE_EXHAUSTED), causing crashes and blank UI. This PR builds out the full budgeting app with resilient AI integration: typed error classification, localStorage caching, and a local-computation fallback when AI is unavailable.Error handling (
services/aiErrors.ts,services/geminiService.ts)AIErrortype withkind: 'quota' | 'invalid_key' | 'network' | 'server' | 'unknown'classifyHttpError()detects 429,RESOURCE_EXHAUSTEDpayloads, auth failures, and 5xx separatelyserver/network) errors; no retry onquota/invalid_keyhasAIStudioKey()/openAIStudioKeySelector()— safe whenwindow.aistudiois absentResponse caching (
services/aiCache.ts)localStoragecache with versioned keys (rag7:ai-cache:v1:...), 12 h default TTLFallback mode (
services/localInsights.ts,components/FallbackInsights.tsx)FallbackInsightsrenders reason-specific messages (quota/network/disabled) with recovery CTAlocalStorageComponents
Dashboard: fingerprint-based deduplication prevents redundant API calls on re-render; shows cached badge (⚡) when served from cacheAIAdvisor: cache-first with manual cache clear and fallback on errorChatWidget: floating chat with per-message cache hits and quota error barTests (Vitest)
26 unit tests covering:
kindvariantsOriginal prompt
Goal
Create a pull request that improves resilience of the AI features in the budgeting/bill paying app by adding:
Repository
Work in
Stacey77/rag7.Context
The app currently integrates Gemini (Gemini 3 Flash Preview) via
services/geminiService.tsand AI UI components such ascomponents/AIAdvisor.tsx, and possiblycomponents/ChatWidget.tsx/ voice-related components.Users can hit the error:
The app should gracefully handle this state and guide users to connect/select their own API key where applicable.
Requirements
A) Robust error handling + quota management
status: "RESOURCE_EXHAUSTED".geminiServiceinto a typed error structure (e.g.,AIErrorwithkind: 'quota' | 'network' | 'server' | 'invalid_key' | 'unknown',message, and raw info).window.aistudio.hasSelectedApiKey()/window.aistudio.openSelectKey()), surface a clear CTA button to select/connect a key when quota is exhausted.window.aistudiois absent.B) Response caching to reduce API calls
localStorage(or another simple client-side store) with versioned keys.C) Fallback mode (No-AI mode)
D) Testing & quality
E) Documentation
Implementation hints (not strict)
services/aiCache.tsandservices/aiErrors.ts.geminiService.tsto use these utilities and return typed results.AIAdvisor, Dashboard AI card, ChatWidget/VoiceCoach if they call AI) to:Acceptance criteria
This pull request was created from Copilot chat.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.