Commit Graph

35 Commits

Author SHA1 Message Date
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
MarkLo127 9c0a9819e6 Implement Plan A1: Fast Mode Analysis
Features:
- Add analysis_mode parameter (fast/deep) to AnalysisRequest
- Fast mode (15-25 min): Disables investment and risk debates (max_debate_rounds=0)
- Deep mode (60 min): Default mode with debates enabled
- Update backend TradingService to handle analysis_mode
- Add analysis_mode form field to frontend with dropdown selector
- Update TypeScript interfaces to include analysis_mode

Changes:
- backend/app/models/schemas.py: Add analysis_mode field to AnalysisRequest
- backend/app/services/trading_service.py: Handle analysis_mode in create_config()
- backend/app/api/routes.py: Pass analysis_mode parameter to run_analysis()
- frontend/components/analysis/AnalysisForm.tsx: Add analysis_mode dropdown (fast/deep)
- frontend/lib/types.ts: Add analysis_mode to AnalysisRequest interface

When users select "fast mode", the system will:
1. Skip investment debate (max_debate_rounds = 0)
2. Skip risk debate (max_risk_discuss_rounds = 0)
3. Reduce analysis time from ~60 minutes to ~15-25 minutes
4. Still run all analyst reports with proper 500-1000 word counts
5. Provide initial decision without debate refinement

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-03-12 21:33:23 +08:00
MarkLo127 ffc36edb97 Fix Railway ECONNREFUSED error by unifying backend URL resolution
Problem: Next.js frontend in production mode falls back to http://backend:8000
(Docker Compose internal hostname) when BACKEND_URL env var is not set.
In Railway's distributed environment, this hostname doesn't exist, causing
ECONNREFUSED errors.

Solution: Create unified getBackendUrl() function with consistent fallback
priority across all server-side proxying files:
1. Explicit BACKEND_URL (for Railway / custom deployment)
2. Development mode -> http://localhost:8000
3. NEXT_PUBLIC_API_URL (may be set in Railway)
4. Docker Compose default -> http://backend:8000

Changes:
- New: frontend/lib/backend-url.ts - centralized URL resolution
- Updated: frontend/next.config.ts - use getBackendUrl()
- Updated: frontend/app/api/chat/route.ts - use getBackendUrl()
- Updated: frontend/app/api/auth/google/token/route.ts - use getBackendUrl()

Railway users must set BACKEND_URL=https://<backend-service>.up.railway.app

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-03-12 11:03:05 +08:00
MarkLo127 69eba15bbb 2026-03-12 09:30:42 +08:00
MarkLo127 62b82788b8 2026-03-11 20:26:37 +08:00
MarkLo127 6802731507 2026-03-11 19:15:24 +08:00
MarkLo127 c305ea5d3b 2026-03-11 18:38:42 +08:00
MarkLo127 92c2a84b83 2026-03-10 17:00:32 +08:00
MarkLo127 d58e80a962 2026-01-27 13:22:52 +08:00
MarkLo127 0bdb3fb774 2026-01-16 00:56:14 +08:00
MarkLo 9c7b1f7903 2025-12-24 04:45:12 +08:00
MarkLo 16e513a921 新增英文語系支援 2025-12-24 01:20:33 +08:00
MarkLo c4fc8904eb 2025-12-20 07:41:05 +08:00
MarkLo 4bbeaa8e18 2025-12-17 05:41:30 +08:00
MarkLo 5569f1097c 2025-12-16 18:31:24 +08:00
MarkLo 22f57a8674 feat: recover pending analysis tasks after page close
Added task recovery system that allows users to recover and save
analysis results even if they accidentally close the page:

1. New pending-task.ts utility:
   - Saves task info to localStorage when analysis starts
   - Clears after task completes/fails
   - 24-hour expiry for old tasks

2. PendingTaskRecovery component:
   - Shows on history page if pending task found
   - Polls API for task status
   - Saves result to IndexedDB + cloud upon completion

3. Updated useAnalysis hook:
   - Tracks pending tasks in localStorage
   - Clears on completion/failure

Now users visiting /history after closing the page during analysis
will see a prompt to recover and save their completed report.
2025-12-14 03:55:12 +08:00
MarkLo bddcca3ebb 2025-12-13 16:19:46 +08:00
MarkLo 5d3751602e 2025-12-13 06:00:19 +08:00
MarkLo 8204aff28b 2025-12-13 01:54:47 +08:00
MarkLo 4269fdec26 2025-12-12 19:01:49 +08:00
MarkLo da7d05ecc9 2025-12-12 05:30:04 +08:00
MarkLo 138cd922c6 2025-12-11 00:06:09 +08:00
MarkLo 33e58ff389 2025-12-07 21:40:58 +08:00
MarkLo c2b8706bf2 2025-12-07 17:13:57 +08:00
MarkLo 43658df2a0 2025-12-06 02:28:43 +08:00
MarkLo a0e4365fc3 2025-12-06 01:50:41 +08:00
MarkLo 8d679007bf 2025-11-25 17:03:17 +08:00
MarkLo 6c5a505282 2025-11-23 10:47:41 +08:00
MarkLo 4ce2a96956 2025-11-21 23:34:39 +08:00
MarkLo d3ab03ccd9 2025-11-21 13:16:04 +08:00
MarkLo 710ff8c855 2025-11-21 10:17:55 +08:00
MarkLo aef7b5942d 2025-11-21 03:57:08 +08:00
MarkLo 44fd92850d 2025-11-20 23:19:22 +08:00
MarkLo 0a203fa475 2025-11-20 22:36:58 +08:00
MarkLo 2872f18b47 2025-11-20 21:56:47 +08:00