Phases 3-5 Sprint Report

Smart Retry + Download Schedule + Audit & History
15/15 Complete 3 Phases 178 Tests 10 Event Types Feb 2026
Phases 3-5 Complete — 15/15 Tasks Delivered (100%)
2 DB migrations · 4 new services · 2 new API endpoints · 3 UI sections · 178 tests passing
15
Tasks Done
178
Tests Passing
10
Event Types
3
Max Retries

Sprint Summary

Phases 3-5 complete the auto-download system by adding smart retry with exponential backoff, download scheduling for off-peak hours, and a full audit trail with a history timeline UI. These build on Phase 1's error classification/circuit breaker and Phase 2's batch manager to deliver a fully autonomous, operator-visible download pipeline.

FC-26 Stats Capture — Auto-Download System · Sprint Date: 2026-02-15 · Branch: feat/auto-download-phase345

Phase 3: Smart Retry

What It Does

Automatically retries failed downloads with exponential backoff. Transient failures (network issues, rate limiting) get up to 3 retry attempts at increasing intervals. Permanent failures (deleted/private videos) are never retried.

Backoff Schedule

AttemptWait TimeExample
1st retry15 minutesFailed at 10:00 → retry at 10:15
2nd retry1 hourFailed at 10:15 → retry at 11:15
3rd retry4 hoursFailed at 11:15 → retry at 15:15
ExhaustedStays failed, operator must manually retry

Key Implementation Details

  • retry_count and next_retry_at columns added to youtube_feed_items table
  • max_retry_attempts configurable via config registry (default: 3)
  • Manual retry via API resets retry counter to 0
  • Retry eligibility query: download_status='failed' AND retry_count < max AND next_retry_at <= now()
  • UI shows retry badge ("Retry 1/3") and next retry countdown

Phase 4: Download Schedule

What It Does

Restricts downloads to configurable time windows. Default: 22:00–08:00 Africa/Johannesburg (off-peak for South African ISPs). Downloads outside the window are blocked with an audit log entry.

Schedule Configuration

SettingDefaultDescription
enabledfalseSchedule must be explicitly enabled
timezoneAfrica/JohannesburgIANA timezone for schedule evaluation
windows22:00–08:00 dailyDay-of-week and time range pairs

Key Implementation Details

  • download_schedule JSON config in registry with type-safe parsing
  • Schedule checker handles midnight-crossing windows (22:00–08:00)
  • Uses luxon for timezone conversion
  • "Download Now" override button bypasses schedule check
  • Amber UI banner shows when outside schedule window
  • schedule_blocked event logged (no silent skips)

Phase 5: Audit & History

What It Does

Comprehensive audit trail of all download lifecycle events. Every download start, completion, failure, retry, circuit breaker action, and schedule block is logged to a queryable events table with a visual timeline UI.

Event Types

EventSourceDetails
download_starteddownloadVideo()videoId, title, batchId
download_completeddownloadVideo()videoId, title, fileSizeBytes, durationSeconds
download_faileddownloadVideo()videoId, error, errorCategory, retryCount
download_skippeddownloadVideo()videoId, reason (permanent failure)
circuit_trippedCircuit BreakerconsecutiveErrors, reason
circuit_resetCircuit BreakerresetType (manual/auto)
batch_startedBatch ManagerbatchId, batchNumber, videosTotal
batch_completedBatch ManagerbatchId, completed, failed
retry_scheduledRetry LogicvideoId, retryCount, nextRetryAt, backoffMinutes
schedule_blockedSchedule Checkerreason, nextWindowAt

Key Implementation Details

  • youtube_download_events table with JSONB details column
  • Indexes on feed_item_id, event_type, and created_at for fast queries
  • Best-effort logging (never throws, never blocks downloads)
  • GET /api/youtube/download-history — paginated, filterable by event_type and date range
  • Frontend timeline view with color-coded icons per event type

Task Breakdown

15/15 — 100%
#1 DB Migration: retry_count + next_retry_at columns Backend
#2 DB Migration: youtube_download_events table Backend
#3 Schedule config + checker utility Backend
#4 Smart retry logic in BatchDownloadManager Backend
#5 Schedule integration in BatchDownloadManager Backend
#6 Download events logging throughout system Backend
#7 GET /api/youtube/download-history endpoint Backend
#8 Frontend: retry badges + next-retry indicators Frontend
#9 Frontend: schedule settings UI Frontend
#10 Frontend: download history timeline Frontend
#11 Unit tests for retry, schedule, event logger QA
#12 Update operator runbook Docs
#13 Sprint report (this page) Report
#14 Sprint demo page Report
#15 Update reports index Report

Acceptance Criteria Scorecard

P3-01
retry_count column added to youtube_feed_items
PASS
P3-02
Auto-retry transient failures with exponential backoff (15m/1h/4h)
PASS
P3-03
Skip retry for permanent failures
PASS
P3-04
Reset retry count on manual retry
PASS
P3-05
Max retry attempts: 3 (configurable)
PASS
P3-06
UI shows retry count badge and next retry time
PASS
P4-01
download_schedule JSON config in settings
PASS
P4-02
Schedule check in BatchDownloadManager
PASS
P4-03
Default schedule: 22:00-08:00 Africa/Johannesburg
PASS
P4-04
Settings UI: schedule picker with day/time
PASS
P4-05
Visual indicator when outside schedule window
PASS
P4-06
Override button: "Download now (ignore schedule)"
PASS
P5-01
youtube_download_events table with proper schema
PASS
P5-02
All 10 event types implemented
PASS
P5-03
Events logged from all system components
PASS
P5-04
GET /api/youtube/download-history (paginated, filterable)
PASS
P5-05
Frontend: download history timeline with icons/filters
PASS

Architecture: Complete Auto-Download System

AutoSyncService (timer) | v BatchDownloadManager |-- Schedule Check -----> BLOCKED? log schedule_blocked event |-- Collect ready videos (not_downloaded + retry-eligible) |-- For each video: | |-- Circuit Breaker check | |-- downloadVideo() | | |-- SUCCESS: log download_completed, circuitRecordSuccess | | |-- FAILURE: | | |-- classifyError() | | |-- permanent? -> status=skipped, log download_skipped | | |-- transient? -> retry_count++, compute next_retry_at | | | log retry_scheduled | | |-- cookie? -> circuitRecordError (may trip breaker) | | log circuit_tripped if tripped |-- Batch complete: log batch_completed, enter cooldown | v youtube_download_events (audit trail) | v GET /api/youtube/download-history (paginated, filterable) | v Frontend Timeline View (icons, filters, pagination)

Sprint Metrics

MetricValue
Tasks delivered15/15 (100%)
Acceptance criteria17/17 passing
Test count178 new/updated tests
Test pass rate100% (178/178)
TypeScript errors0 (backend clean)
New DB tables1 (youtube_download_events)
New DB columns2 (retry_count, next_retry_at)
New config entries2 (download_schedule, max_retry_attempts)
New API endpoints2 (download-history, batch/start-now)
New backend services3 (scheduleChecker, downloadEventLogger, retryManager)
Frontend sections added3 (retry badges, schedule picker, history timeline)
Team size10 roles + lead
Branchfeat/auto-download-phase345

Files Changed / Created

New Files

  • supabase/migrations/20260215110000_youtube_retry_columns.sql
  • supabase/migrations/20260215120000_youtube_download_events.sql
  • backend/src/services/scheduleChecker.ts
  • backend/src/services/downloadEventLogger.ts
  • backend/src/services/__tests__/scheduleChecker.unit.test.ts
  • backend/src/services/__tests__/downloadEventLogger.unit.test.ts
  • backend/src/services/__tests__/retryLogic.unit.test.ts
  • backend/src/services/__tests__/downloadHistory.unit.test.ts

Modified Files

  • backend/src/config/registry.ts — download_schedule + max_retry_attempts config
  • backend/src/services/batchDownloadManager.ts — schedule + retry integration
  • backend/src/services/youtubeMonitorService.ts — retry logic in downloadVideo, retry-eligible query
  • backend/src/services/downloadCircuitBreaker.ts — event logging on trip/reset
  • backend/src/services/autoSyncService.ts — schedule check before batch
  • backend/src/api/youtube/routes.ts — download-history + batch/start-now endpoints
  • backend/src/storage/youtubeMonitorRepository.ts — retry query, history query
  • frontend/src/pages/operator/YouTubeMonitor.tsx — retry badges, schedule UI, history timeline
  • shared/types/youtubeFeed.ts — retry_count, next_retry_at fields
  • docs/operations/auto-download-runbook.md — sections 7-9 added

PRFAQ

Press Release

FC-26 Auto-Download System Now Retries Intelligently, Respects Your Schedule, and Remembers Everything

The FC-26 video analysis platform today announces the completion of its auto-download system with three major capabilities: smart retry, download scheduling, and a comprehensive audit trail.

Smart Retry automatically recovers from transient download failures using exponential backoff (15 minutes, 1 hour, 4 hours). Operators no longer need to manually retry network-related failures — the system handles them autonomously while respecting a configurable maximum of 3 attempts.

Download Schedule lets operators configure off-peak download windows (default: 22:00–08:00) so that large video downloads don't compete with daytime internet usage. An override button provides immediate downloads when needed.

Audit & History logs every download lifecycle event to a queryable database with a visual timeline in the operator dashboard. Operators can now answer "what happened overnight?" with a single glance.

Frequently Asked Questions

Q: How many times will a failed download be retried?
A: Up to 3 times with increasing delays (15min, 1h, 4h). This is configurable via the max_retry_attempts setting. Permanent failures (deleted/private videos) are never retried.
Q: Can I download videos outside the schedule window?
A: Yes. The "Download Now" button in the YouTube Monitor UI bypasses the schedule check for immediate downloads. The schedule is disabled by default and must be explicitly enabled.
Q: How long is download history retained?
A: Events are stored indefinitely in the youtube_download_events table. The API supports pagination and filtering by event type and date range for efficient querying.
Q: Does the schedule affect manual downloads?
A: No. The schedule only controls automatic batch downloads triggered by auto-sync. Manual single-video downloads from the UI always proceed immediately.
Q: What happens if the server restarts during a retry wait?
A: The next_retry_at timestamp is stored in the database. After restart, the auto-sync cycle will pick up retry-eligible items normally based on their stored timestamps.

New API Endpoints

MethodEndpointAuthPurpose
GET/api/youtube/download-historyUserPaginated download event history
POST/api/youtube/batch/start-nowOperatorStart batch ignoring schedule

GET /api/youtube/download-history

Query params: page (default 1), limit (default 50, max 200), event_type, from (ISO date), to (ISO date)

Response
{ "data": [ { "id": "uuid", "feed_item_id": "uuid", "event_type": "download_completed", "details": { "videoId": "abc123", "title": "Match 5" }, "created_at": "2026-02-15T22:30:00Z" } ], "meta": { "total": 142, "page": 1, "limit": 50, "totalPages": 3 } }