TradingAgents/frontend/lib
MarkLo127 42b5b8dab8 Implement Plan C3: Cloud Sync Retry with Local Caching
Features:
- Add cloud sync retry service for failed report uploads
- Automatic retry loop that runs every 30 seconds
- Exponential backoff: 1 attempt per 30s with max 5 retries per report
- Reports always saved locally (IndexedDB) - cloud sync failures don't block user
- SyncInitializer component starts retry loop on app startup

Changes:
- frontend/lib/sync-retry.ts: New service for managing cloud sync retries
  - retryPendingSyncs(): Attempt to sync all pending reports
  - markForRetry(): Mark a report for retry
  - startRetryLoop(): Start automatic retry background task
  - stopRetryLoop(): Clean up retry loop on app shutdown
  - getPendingSyncCount(): Get number of reports awaiting sync

- frontend/components/providers/SyncInitializer.tsx: Client component that:
  - Initializes retry loop only when user is authenticated
  - Cleans up on component unmount
  - Logs retry service startup/shutdown

- frontend/app/layout.tsx: Add SyncInitializer to root layout
  - Ensure retry loop starts automatically for authenticated users

- frontend/app/analysis/page.tsx: Improve error handling
  - Log warning when cloud sync fails
  - Report remains safely in IndexedDB even if cloud save fails

Impact:
- Reports never get lost even if cloud save fails temporarily
- Automatic retry ensures eventual consistency with cloud
- User experience improved: no more "report deleted" after 1 hour
- Network issues no longer result in data loss
- Addresses original issue: reports now persists locally indefinitely

Technical Design:
- Retry tracking uses in-memory Map (resets on page refresh)
- Future enhancement: could persist retry state to localStorage
- Cloud sync becomes eventual consistency rather than immediate

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-03-12 21:35:29 +08:00
..
i18n 2026-03-11 18:38:42 +08:00
api-helpers.ts 2025-12-11 00:06:09 +08:00
api.ts 2026-03-10 17:00:32 +08:00
backend-url.ts Fix Railway ECONNREFUSED error by unifying backend URL resolution 2026-03-12 11:03:05 +08:00
crypto.ts 2025-12-13 01:54:47 +08:00
pending-task.ts feat: recover pending analysis tasks after page close 2025-12-14 03:55:12 +08:00
report-utils.ts 2026-03-12 09:30:42 +08:00
reports-db.ts 2026-03-12 09:30:42 +08:00
storage.ts 2026-01-16 00:56:14 +08:00
sync-retry.ts Implement Plan C3: Cloud Sync Retry with Local Caching 2026-03-12 21:35:29 +08:00
types.ts Implement Plan A1: Fast Mode Analysis 2026-03-12 21:33:23 +08:00
user-api.ts 2026-03-11 20:26:37 +08:00
utils.ts 2025-11-20 21:56:47 +08:00