# NotebookLM Video Timeout Issue - Complete Investigation

## User Report
**Issue**: "Task d3a5a760-3e49-4a1e-b080-5dfef69bfb08 timed out after 1800s" but video exists in NotebookLM

## Investigation Summary

### ✅ Confirmed Facts
1. **Notebook exists**: Notebook ID `0f38d000-7497-442c-9b67-8773b02a558b`
2. **Video generation timed out**: 30-minute timeout exceeded
3. **No local video file**: Video not downloaded to local server
4. **7 other assets successful**: All other assets created and downloaded successfully

### 🔍 Technical Analysis

**Database Record (Asset ID 28):**
- Status: `failed`
- Error: "Task d3a5a760-3e49-4a1e-b080-5dfef69bfb08 timed out after 1800s"
- File Path: `NULL`
- Created: 2026-05-03 19:51:52
- Completed: `NULL`

**Timeout Configuration:**
```python
# From notebooklm_service.py line 304-305
timeout_map = {
    "video": 1800,  # 30 minutes
    ...
}
```

**What Happened:**
1. Video generation started at 19:51:52
2. Process waited 30 minutes for completion
3. Timeout occurred at ~20:21:52
4. Video may have been created shortly after timeout
5. Download never happened due to timeout

## 🎯 Current Situation

### In NotebookLM (Cloud)
- **Status**: Unknown (requires manual verification)
- **Likely**: Video may have been created successfully after timeout
- **URL**: https://notebooklm.google.com/notebook/0f38d000-7497-442c-9b67-8773b02a558b

### On Local Server
- **Status**: No video file exists
- **Directory**: `/app/static/uploads/notebooks/35/`
- **Database**: Shows as failed

## 🔧 Solutions

### Immediate Actions (User Can Do)

1. **Check NotebookLM Directly**
   ```
   URL: https://notebooklm.google.com/notebook/0f38d000-7497-442c-9b67-8773b02a558b
   ```
   - Look for "Video Overview" or "ملخص مرئي" section
   - If video exists, can watch/download directly

2. **If Video Exists in NotebookLM**
   - Download manually from NotebookLM
   - Upload to: `app/static/uploads/notebooks/35/`
   - Run database update:
   ```sql
   UPDATE notebook_assets
   SET status = 'ready',
       file_path = 'uploads/notebooks/35/video.mp4',
       file_format = 'mp4',
       error_message = NULL,
       completed_at = NOW()
   WHERE report_id = 35 AND asset_type = 'video';
   ```

3. **If Video Doesn't Exist**
   - Retry generation from Jadwa AI interface
   - Consider off-peak hours for faster generation
   - May need to use different NotebookLM account

### Technical Solutions (Developer)

1. **Increase Video Timeout**
   ```python
   # In notebooklm_service.py, line 305
   timeout_map = {
       "video": 3600,  # Increase to 60 minutes
       ...
   }
   ```

2. **Add Post-Timeout Verification**
   ```python
   # After timeout, check if video was created anyway
   try:
       # Try download even after timeout
       file_path, format = await download_asset(...)
       if file_path:
           # Success despite timeout!
           asset.status = "ready"
           asset.error_message = None
   except:
       # Genuine failure
       asset.status = "failed"
   ```

3. **Implement Retry Logic**
   - Auto-retry after timeout
   - Exponential backoff for retries
   - Manual retry button in UI

## 📊 Statistics

### Successful Assets (7/8)
| Asset | Size | Time to Generate |
|-------|------|------------------|
| Infographic | 4.55 MB | ~2 min |
| Slide Deck | 11.02 MB | ~9 min |
| Mind Map | 2.7 KB | ~5 sec |
| Report | 8.2 KB | ~19 sec |
| Flashcards | 27 KB | ~51 sec |
| Quiz | 30 KB | ~1.5 min |
| Audio | 27.97 MB | ~23 min |

### Failed Assets (1/8)
| Asset | Issue | Time |
|-------|-------|------|
| Video | Timeout after 30 min | >30 min |

## 🔍 Root Cause Analysis

### Why Video Times Out
1. **Complex Generation**: Video creation is computationally intensive
2. **Queue System**: NotebookLM may queue video requests
3. **Size**: Large report data = longer processing time
4. **Rate Limits**: Account may have hit rate limits

### Why Other Assets Succeeded
1. **Simpler Generation**: Text/JSON generation is faster
2. **Different Endpoints**: Each asset type uses different API
3. **Shorter Time**: Less likely to hit timeouts

## 🛡️ Prevention Strategies

### 1. Increase Timeouts
```python
# Asset-specific timeouts based on complexity
timeout_map = {
    "video": 3600,      # 60 minutes (increased)
    "audio": 1800,      # 30 minutes
    "slide_deck": 1200, # 20 minutes
    ...
}
```

### 2. Better Error Handling
```python
# Don't fail immediately on timeout
try:
    await wait_for_completion(...)
except TimeoutError:
    # Check if asset was created anyway
    if await check_asset_exists():
        await download_asset(...)
    else:
        # Mark for retry
        asset.status = "retry_pending"
```

### 3. Progress Monitoring
```python
# Implement progress tracking
while not complete:
    progress = await get_progress(task_id)
    update_ui_progress(progress)
    if age > timeout:
        handle_timeout_gracefully()
```

### 4. Account Management
```python
# Use different accounts for heavy tasks
if asset_type == "video":
    account = get_video_dedicated_account()
else:
    account = get_standard_account()
```

## 📋 Implementation Priority

### High Priority (Immediate)
1. ✅ Check if video exists in NotebookLM manually
2. ✅ Create manual download process if video exists
3. ✅ Update database if video found

### Medium Priority (This Week)
1. Increase video timeout to 60 minutes
2. Add post-timeout verification
3. Implement manual retry functionality

### Low Priority (Next Sprint)
1. Add progress monitoring for long tasks
2. Implement account pooling for videos
3. Create admin tools for bulk retry

## 🎯 Next Steps for This Specific Case

1. **User Action Required**
   - Open NotebookLM URL: https://notebooklm.google.com/notebook/0f38d000-7497-442c-9b67-8773b02a558b
   - Verify if video exists
   - Report back

2. **If Video Exists**
   - Download manually
   - Update database with SQL above
   - Test video playback

3. **If Video Doesn't Exist**
   - Retry generation from Jadwa AI
   - Monitor for >60 minutes
   - Consider support ticket to NotebookLM

## 📞 Support Information

**For Manual Verification:**
- Notebook URL: https://notebooklm.google.com/notebook/0f38d000-7497-442c-9b67-8773b02a558b
- Report ID: 35
- Task ID: d3a5a760-3e49-4a1e-b080-5dfef69bfb08
- Account ID: 10

**For Technical Support:**
- Check `/home/ashraffarid2010/jadwaai.com/scripts/check_notebooklm_video.py`
- Review `/home/ashraffarid2010/jadwaai.com/scripts/retry_video_download.py`
- Monitor NotebookLM account status and rate limits

---

**Status**: 🟡 Awaiting Manual Verification
**Resolution**: Requires checking NotebookLM directly
**Impact**: Medium (1 of 8 assets affected, 7 successful)