---
name: Production Cutover
status: open
created: 2025-10-20T15:30:53Z
updated: 2025-10-20T19:14:47Z
github: https://github.com/BuzzTrail/video-extension/issues/163
depends_on: [160]
parallel: false
conflicts_with: []
---

# Task: Production Cutover

## Description

Deploy bot-spawner and updated slide-system to production Railway environment. Monitor for 48 hours to ensure stability and collect diagnostic data.

**Approach:**
1. Deploy bot-spawner to production Railway
2. Deploy slide-system with bot-spawner integration
3. Monitor for 48 hours
4. Collect logs and analyze findings
5. Document results: Did we learn what's broken?

**Critical:** This is a learning exercise, not a fix. Success = clear data, not working bots.

## Acceptance Criteria

- [ ] Bot-spawner deployed to production Railway
- [ ] Slide-system deployed with `BOT_SPAWNER_URL` configured
- [ ] Environment variables configured correctly on both services
- [ ] First voice demo session tested manually (creates bot successfully)
- [ ] Monitoring in place (Railway dashboards, log streaming)
- [ ] Zero downtime during deployment
- [ ] Rollback plan tested and ready
- [ ] 48-hour monitoring period completed
- [ ] Logs collected and analyzed
- [ ] Findings documented in `.claude/epics/bot-spawner-extraction/production-findings.md`

## Technical Details

### Implementation Approach

**1. Pre-Deployment Checklist:**
```bash
# Verify staging works
curl https://slide-system-staging.railway.app/health
curl https://bot-spawner-staging.railway.app/health

# Test bot spawn in staging
curl -X POST https://slide-system-staging.railway.app/api/sessions/voice-demo \
  -H "Content-Type: application/json" \
  -d '{"customerName":"Pre-Production Test"}'

# Verify rollback procedure in staging
# (revert slide-system to direct spawn, test works)
```

**2. Production Deployment Steps:**
```bash
# Step 1: Deploy bot-spawner to production
cd apps/bot-spawner
railway up --service bot-spawner --environment production

# Step 2: Configure environment variables (Railway dashboard)
# BOT_SPAWNER_URL, LIVEKIT_*, SUPABASE_*, etc.

# Step 3: Verify bot-spawner health
curl https://bot-spawner-production.railway.app/health

# Step 4: Deploy slide-system with bot-spawner integration
cd apps/slide-system
railway up --service slide-system --environment production

# Step 5: Test first voice demo session (manual)
curl -X POST https://slide-system-production-5813.up.railway.app/api/sessions/voice-demo \
  -H "Content-Type: application/json" \
  -d '{"customerName":"Production Test User"}'

# Step 6: Monitor logs
railway logs --service bot-spawner --follow &
railway logs --service slide-system --follow &
```

**3. Monitoring Strategy:**
```bash
# Track key metrics over 48 hours:
# - Bot spawn success rate
# - Service-to-service latency
# - Bot join success rate
# - Error rates
# - Railway resource usage (CPU, memory)

# Automated monitoring script:
#!/bin/bash
for i in {1..96}; do  # 48 hours, check every 30 min
  echo "=== Check $i at $(date) ==="

  # Check bot-spawner health
  curl -s https://bot-spawner-production.railway.app/health | jq

  # Check active bots count
  # (Query Supabase active_bots table)

  # Check for errors in logs
  railway logs --service bot-spawner --since 30m | grep ERROR

  sleep 1800  # 30 minutes
done
```

**4. Data Collection:**
- Bot spawn logs from bot-spawner
- HTTP call logs from slide-system
- Bot startup logs (asyncio import, event loop creation)
- Performance metrics (latency, success rates)
- Error logs and stack traces

### Key Considerations

- **Zero Downtime:** Deploy bot-spawner first, then slide-system
- **Rollback Ready:** Keep rollback script handy (< 30 min to revert)
- **Gradual Cutover:** Test with one session first, then allow normal traffic
- **Heavy Monitoring:** Watch logs closely for first 24 hours
- **Learning Focus:** Even if bots don't work, we WIN by learning WHERE/WHY they fail

### Files Affected

**Modified:**
- Railway production environment variables (both services)

**New:**
- `.claude/epics/bot-spawner-extraction/production-findings.md` (analysis)
- `.claude/epics/bot-spawner-extraction/monitoring-data/` (log archives)

## Dependencies

**Depends On:**
- [ ] Task 005: Slide-system integration complete and tested in staging

**External:**
- [ ] Railway production environment accessible
- [ ] No ongoing production incidents
- [ ] Maintenance window scheduled (optional, but recommended)

## Effort Estimate

- **Size:** M (Medium)
- **Hours:** 8-12 hours (over 3 days)
  - Pre-deployment testing: 2 hours
  - Production deployment: 2-3 hours
  - Initial monitoring (first 24h): 4-6 hours (intermittent)
  - Data collection: 2 hours
  - Analysis and documentation: 2-3 hours
- **Parallel:** false (final task before Task 007)

## Definition of Done

- [ ] Bot-spawner running in production for 48 hours
- [ ] Slide-system calling bot-spawner successfully
- [ ] Zero production incidents or rollbacks (unless data collection complete)
- [ ] Logs captured for analysis period
- [ ] Findings documented with clear answers:
  - Does bot spawning work in bot-spawner?
  - If yes: What was the issue? (Motia interaction)
  - If no: WHERE does it hang? (asyncio import, event loop, room join, etc.)
- [ ] Recommendations for next steps based on findings
- [ ] Cost analysis: Actual Railway costs vs. projected

**Validation:**
```bash
# Success criteria examples:

# Scenario 1: Bots work (BEST CASE)
✅ Bot spawns successfully
✅ Bot joins LiveKit room
✅ Screenshare stream appears
→ SUCCESS: Identified Motia interaction issue

# Scenario 2: Bots hang at asyncio import (EXPECTED)
✅ Bot-spawner logs show: "BOT STARTUP: asyncio import starting..."
❌ Bot never logs: "asyncio import SUCCESS"
→ SUCCESS: Identified exact failure point
→ Next: Try Python 3.12, different asyncio setup, etc.

# Scenario 3: Bots work sometimes (USEFUL)
✅ 3 out of 10 bots succeed
✅ 7 out of 10 hang
→ SUCCESS: It's a race condition or resource issue
→ Next: Investigate timing, resource limits, etc.
```

**Rollback Triggers:**
- Bot spawn failure rate >20% AND no useful data collected
- Service-to-service errors >5% for extended period
- Critical production bug affecting users

**Even if rollback occurs: SUCCESS if we learned something useful from logs.**
