Files
PROJECT-CONTORL/openspec/changes/archive/2025-12-30-fix-realtime-notifications/tasks.md
beabigegg 64874d5425 feat: enhance weekly report and realtime notifications
Weekly Report (fix-weekly-report):
- Remove 5-task limit, show all tasks per category
- Add blocked tasks with blocker_reason and blocked_since
- Add next week tasks (due in coming week)
- Add assignee_name, completed_at, days_overdue to task details
- Frontend collapsible sections for each task category
- 8 new tests for enhanced report content

Realtime Notifications (fix-realtime-notifications):
- SQLAlchemy event-based notification publishing
- Redis Pub/Sub for multi-process broadcast
- Fix soft rollback handler stacking issue
- Fix ping scheduling drift (send immediately when interval expires)
- Frontend NotificationContext with WebSocket reconnection

Spec Fixes:
- Add missing ## Purpose sections to 5 specs

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-30 20:52:08 +08:00

1.8 KiB

Phase 1: WebSocket Infrastructure

1.1 Connection Manager

  • 1.1.1 建立 backend/app/core/websocket.py
  • 1.1.2 實作 ConnectionManager class
  • 1.1.3 實作 connect/disconnect/send_to_user 方法
  • 1.1.4 加入心跳偵測機制

1.2 WebSocket Endpoint

  • 1.2.1 新增 WS /ws/notifications endpoint
  • 1.2.2 實作 WebSocket token 驗證
  • 1.2.3 連線時查詢並推送未讀通知
  • 1.2.4 處理 WebSocket 異常與斷線

1.3 Testing - Phase 1

  • 1.3.1 WebSocket 連線測試
  • 1.3.2 未讀通知補送測試
  • 1.3.3 斷線處理測試

Phase 2: Redis Pub/Sub Integration

2.1 Redis Pub/Sub Service

  • 2.1.1 建立 backend/app/core/redis_pubsub.py
  • 2.1.2 實作 publish_notification 函數
  • 2.1.3 實作 subscribe_user_channel 函數
  • 2.1.4 訊息 JSON 序列化處理

2.2 Cross-Process Broadcasting

  • 2.2.1 WebSocket endpoint 訂閱 user channel
  • 2.2.2 收到 Redis 訊息時推送給連線
  • 2.2.3 處理訂閱錯誤與重連

2.3 Testing - Phase 2

  • 2.3.1 Redis Pub/Sub 單元測試
  • 2.3.2 跨 process 通知測試(手動驗證)

Phase 3: Service Integration

3.1 NotificationService 整合

  • 3.1.1 create_notification 後呼叫 publish_notification
  • 3.1.2 確保所有通知類型都即時推播
  • 3.1.3 處理 Redis 連線失敗 gracefully

3.2 Frontend WebSocket Client

  • 3.2.1 建立 frontend/src/services/websocket.ts
  • 3.2.2 實作 WebSocket 連線與重連邏輯
  • 3.2.3 訊息處理與分發

3.3 NotificationContext 整合

  • 3.3.1 修改 NotificationContext 使用 WebSocket
  • 3.3.2 收到通知時更新未讀數量
  • 3.3.3 收到 unread_sync 時同步狀態

3.4 Testing - Phase 3

  • 3.4.1 完整即時通知流程測試
  • 3.4.2 前端 WebSocket 整合測試