# Screenshare Bot Deployment Guide

Production deployment procedures and rollout strategy for Railway platform.

## Table of Contents

- [Prerequisites](#prerequisites)
- [Environment Variables](#environment-variables)
- [Pre-Deployment Checklist](#pre-deployment-checklist)
- [Deployment Steps](#deployment-steps)
- [Post-Deployment Verification](#post-deployment-verification)
- [Rollback Procedures](#rollback-procedures)
- [Gradual Rollout Strategy](#gradual-rollout-strategy)

---

## Prerequisites

### Required Access

Before deploying, ensure you have:

- [ ] Railway account with access to `slide-system` project
- [ ] Railway CLI installed (`npm install -g @railway/cli`)
- [ ] Railway CLI authenticated (`railway login`)
- [ ] Access to Daily.co API dashboard
- [ ] Access to Supabase project dashboard
- [ ] GitHub repository push access (for code changes)

### Required Tools

```bash
# Railway CLI
npm install -g @railway/cli
railway login

# Verify access
railway list
# Should show: slide-system project

# Link to project
cd apps/slide-system
railway link
```

### System Requirements

**Railway Service Configuration:**
- **Platform:** Railway (PaaS)
- **Runtime:** Node.js 18+ (for API) + Python 3.9+ (for bots)
- **Memory:** 2GB minimum, 4GB recommended
- **CPU:** Shared (scales automatically)
- **Region:** US West (or closest to Daily.co servers)

---

## Environment Variables

### Required Environment Variables

All environment variables must be set in Railway dashboard before deployment.

**Access Railway Variables:**
```bash
# View all variables
railway vars --service slide-system

# Set a variable
railway vars --service slide-system set KEY=value

# Delete a variable
railway vars --service slide-system delete KEY
```

**Or via Railway Dashboard:**
1. Go to https://railway.app/project/YOUR_PROJECT
2. Select `slide-system` service
3. Click "Variables" tab
4. Add/edit variables

---

### Variable Reference Table

| Variable Name | Purpose | Required | Example | Where to Get |
|---------------|---------|----------|---------|--------------|
| `DAILY_API_KEY` | Authenticate with Daily.co API | **Yes** | `abc123xyz...` | Daily.co Dashboard > API Keys |
| `SUPABASE_URL` | Supabase project URL | **Yes** | `https://xxx.supabase.co` | Supabase Dashboard > Settings > API |
| `SUPABASE_KEY` | Supabase service role key | **Yes** | `eyJhbG...` | Supabase Dashboard > Settings > API |
| `MOTIA_API_URL` | Internal API base URL | **Yes** | `https://slide-system.railway.app` | Railway service URL |
| `DAILY_DOMAIN` | Daily.co domain for rooms | No | `tavus.daily.co` | Your Daily.co subdomain |
| `SLIDEV_BASE_URL` | Base URL for slide decks | No | `https://buzztrail.github.io/buzztrail-presentations` | GitHub Pages URL |
| `PYTHON_VERSION` | Python version for bots | No | `3.9` | Use Railway default |
| `NODE_ENV` | Node.js environment | No | `production` | Set automatically |

---

### Variable Details

#### DAILY_API_KEY

**Purpose:** Authenticate bot spawn requests and room management with Daily.co

**How to Get:**
1. Go to https://dashboard.daily.co
2. Navigate to "Developers" > "API Keys"
3. Click "Create API Key"
4. Copy the key (starts with `d_api_key_...`)
5. Store securely - this cannot be viewed again

**Set in Railway:**
```bash
railway vars --service slide-system set DAILY_API_KEY=d_api_key_abc123xyz...
```

**Security:**
- Never commit to source control
- Rotate every 90 days
- Use read/write scope (bots need to create meeting tokens)

---

#### SUPABASE_URL

**Purpose:** Connect to Supabase database for slide control realtime messaging

**How to Get:**
1. Go to https://app.supabase.com
2. Open your project
3. Navigate to "Settings" > "API"
4. Copy "Project URL"

**Example:** `https://abcdefghijklmnop.supabase.co`

**Set in Railway:**
```bash
railway vars --service slide-system set SUPABASE_URL=https://YOUR_PROJECT.supabase.co
```

---

#### SUPABASE_KEY

**Purpose:** Authenticate with Supabase using service role key (bypasses RLS)

**How to Get:**
1. Go to https://app.supabase.com
2. Open your project
3. Navigate to "Settings" > "API"
4. Copy "service_role key" (under "Project API keys")
5. **Important:** Use service_role key, not anon key

**Set in Railway:**
```bash
railway vars --service slide-system set SUPABASE_KEY=eyJhbG...
```

**Security:**
- Never commit to source control
- Never expose in client-side code
- Rotate if compromised

---

#### MOTIA_API_URL

**Purpose:** Base URL for internal API calls (bot lifecycle, slide generation)

**How to Get:**
- This is your Railway service public URL
- Format: `https://YOUR_SERVICE-production.up.railway.app`

**Find Your URL:**
```bash
# Method 1: Railway CLI
railway status --service slide-system
# Look for "Public URL"

# Method 2: Railway Dashboard
# Open service > "Settings" tab > "Domains" section
```

**Set in Railway:**
```bash
railway vars --service slide-system set MOTIA_API_URL=https://slide-system-production-5813.up.railway.app
```

**Note:** Update this if you change your Railway domain or use a custom domain.

---

#### Optional Variables

**DAILY_DOMAIN** (Optional)
- Default: Uses domain from room URLs
- Set if you want to restrict to specific Daily.co subdomain
- Example: `tavus.daily.co`

**SLIDEV_BASE_URL** (Optional)
- Default: `https://buzztrail.github.io/buzztrail-presentations`
- Set if hosting slide decks on different CDN/domain
- Used for deck URL construction

---

### Verify Variables Set Correctly

```bash
# Check all variables are present
railway vars --service slide-system | grep -E "DAILY_API_KEY|SUPABASE_URL|SUPABASE_KEY|MOTIA_API_URL"

# Expected output (values redacted):
# DAILY_API_KEY=d_api_key_***
# SUPABASE_URL=https://***.supabase.co
# SUPABASE_KEY=eyJ***
# MOTIA_API_URL=https://***.railway.app

# Test connectivity with variables
railway run --service slide-system "curl -H 'Authorization: Bearer $DAILY_API_KEY' https://api.daily.co/v1/rooms"
# Should return JSON list of rooms
```

---

## Pre-Deployment Checklist

Before deploying to production, verify:

### Code Readiness

```bash
# 1. All tests pass
cd apps/slide-system/bots/screenshare-bot
pytest tests/ -v

# 2. No uncommitted changes
git status
# Expected: nothing to commit, working tree clean

# 3. Code is merged to main branch
git branch
# Expected: * main

# 4. Latest code pulled
git pull origin main
```

### Dependency Readiness

```bash
# 1. Python dependencies up to date
cd apps/slide-system/bots/screenshare-bot
cat requirements.txt
# Verify all dependencies have pinned versions

# 2. Node.js dependencies up to date
cd apps/slide-system
npm install
npm audit fix

# 3. No security vulnerabilities
npm audit
# Expected: 0 vulnerabilities
```

### Environment Readiness

```bash
# 1. All required env vars set
railway vars --service slide-system | wc -l
# Should be >= 4 (minimum required vars)

# 2. Railway service is healthy
railway status --service slide-system
# Expected: Status: RUNNING

# 3. No ongoing incidents
# Check: https://railway.app/status
# Check: https://status.daily.co
```

### Testing Readiness

```bash
# 1. Local testing completed
python bot.py "https://test.daily.co/test-room"
# Bot should join and stream successfully

# 2. Load testing completed (if major changes)
cd apps/slide-system/bots/screenshare-bot/scripts
python load_test.py --bots 3 --duration 60

# 3. Manual test room created
python create_test_rooms.py --count 3
# Save room URLs for post-deployment testing
```

### Documentation Readiness

- [ ] CHANGELOG.md updated with changes
- [ ] README.md updated if usage changed
- [ ] RUNBOOK.md updated if new issues discovered
- [ ] Team notified of deployment window

---

## Deployment Steps

### Step 1: Deploy to Railway

Railway automatically deploys on git push to connected branch.

```bash
# Ensure you're on main branch
git checkout main
git pull origin main

# Deploy to Railway (auto-deploy on push)
git push origin main

# Watch deployment progress
railway logs --service slide-system --tail
```

**Alternative: Manual Deploy**

If auto-deploy is disabled:

```bash
# Deploy from CLI
railway up --service slide-system

# Or trigger from Railway dashboard
# Go to service > Deployments tab > "Deploy Now" button
```

### Step 2: Monitor Deployment

```bash
# Watch deployment logs in real-time
railway logs --service slide-system --tail

# Look for these success indicators:
# ✓ Build successful
# ✓ Dependencies installed
# ✓ Service started
# ✓ Health check passed
```

**Expected Log Output:**

```
[Build] Installing dependencies...
[Build] ✓ npm install completed
[Build] ✓ pip install completed
[Build] Build successful
[Deploy] Starting service...
[Deploy] Service listening on port 3000
[Health] Health check passed
[Status] Deployment successful
```

**Deployment Failures:**

If deployment fails, check logs for:

```bash
# Build failures
railway logs --service slide-system | grep "ERROR\|Failed"

# Common issues:
# - Missing dependencies (check package.json/requirements.txt)
# - Syntax errors (run linter locally)
# - Build timeout (optimize build process)
```

### Step 3: Wait for Service to be Healthy

```bash
# Check service status
railway status --service slide-system

# Expected output:
# Status: RUNNING
# Health: Healthy
# Uptime: 0m 30s

# If status is not RUNNING after 2 minutes:
railway logs --service slide-system --tail
# Check for errors
```

### Step 4: Verify Deployment Success

```bash
# Get service URL
railway status --service slide-system | grep "Public URL"

# Test health endpoint (if implemented)
curl https://YOUR_SERVICE.railway.app/health

# Expected: {"status": "ok"}

# Test bot status endpoint
curl https://YOUR_SERVICE.railway.app/api/tavus/bot/status

# Expected: {"activeCount": 0, "bots": []}
```

---

## Post-Deployment Verification

### Smoke Test Procedures

Run these tests immediately after deployment to verify basic functionality.

#### Test 1: API Endpoints Respond

```bash
# Set your Railway URL
export API_URL="https://YOUR_SERVICE.railway.app"

# Test bot status endpoint
curl -s "$API_URL/api/tavus/bot/status" | jq
# Expected: {"activeCount": 0, "bots": []}

# Test bot spawn endpoint (with test data)
curl -X POST "$API_URL/api/tavus/bot/spawn" \
  -H "Content-Type: application/json" \
  -d '{
    "conversation_id": "smoke-test-'$(date +%s)'",
    "room_url": "https://test.daily.co/smoke-test-room"
  }'

# Expected: {"success": true, "message": "Bot spawned for conversation smoke-test-..."}
```

#### Test 2: Bot Can Spawn

```bash
# 1. Create a test Daily.co room
cd apps/slide-system/bots/screenshare-bot
python create_test_room.py

# Output example:
# Room created: https://tavus.daily.co/test-abc123
# Room URL: https://tavus.daily.co/test-abc123

# 2. Spawn bot in test room
curl -X POST "$API_URL/api/tavus/bot/spawn" \
  -H "Content-Type: application/json" \
  -d '{
    "conversation_id": "smoke-test-'$(date +%s)'",
    "room_url": "YOUR_TEST_ROOM_URL"
  }'

# 3. Check logs for successful spawn
railway logs --service slide-system | grep "Bot spawned" | tail -1
# Expected: Bot spawned for conversation smoke-test-... (PID: 12345)

# 4. Verify bot joined Daily room
railway logs --service slide-system | grep "Successfully joined Daily.co room" | tail -1

# 5. Verify bot is streaming
railway logs --service slide-system | grep "Frames:" | tail -1
# Expected: Frames: 100, Actual FPS: 10.02, Target FPS: 10
```

#### Test 3: Bot Performance Metrics

```bash
# Wait 60 seconds for metrics to accumulate
sleep 60

# Check performance metrics in logs
railway logs --service slide-system | grep "Performance -" | tail -5

# Expected output:
# Bot smoke-test-123 Performance - Memory: 280.5MB, CPU: 22.3%, FPS: 10.0, Frame Capture: 35.2ms, Command Latency: 0.0ms

# Verify metrics are healthy:
# ✓ Memory: < 500MB
# ✓ CPU: < 30%
# ✓ FPS: 9.5-10.5
# ✓ Frame Capture: < 50ms
```

#### Test 4: Bot Lifecycle

```bash
# 1. Get active bots
curl -s "$API_URL/api/tavus/bot/status" | jq '.bots[0].conversationId'
# Save conversation ID

# 2. Kill the bot
curl -X POST "$API_URL/api/tavus/bot/kill" \
  -H "Content-Type: application/json" \
  -d '{"conversation_id": "YOUR_CONVERSATION_ID"}'

# Expected: {"success": true, "message": "Bot killed"}

# 3. Verify bot terminated
railway logs --service slide-system | grep "Bot killed" | tail -1
# Expected: Bot killed for YOUR_CONVERSATION_ID

# 4. Verify bot count back to zero
curl -s "$API_URL/api/tavus/bot/status" | jq '.activeCount'
# Expected: 0
```

### Smoke Test Checklist

```
□ API endpoints respond (200 OK)
□ Bot spawn endpoint works
□ Bot process spawns (PID logged)
□ Bot joins Daily.co room
□ Bot streams frames (FPS logged)
□ Performance metrics healthy
□ Bot can be killed gracefully
□ No error logs in deployment
```

---

## Rollback Procedures

### When to Rollback

Rollback immediately if:

- Bot spawn success rate < 50% for 5 minutes
- All bots crashing on spawn (exit code != 0)
- Service returning 500 errors consistently
- Critical security vulnerability discovered
- Data corruption detected

### Emergency Rollback (Fast Path)

Use this for critical production issues requiring immediate action.

```bash
# Step 1: List recent deployments
railway deployments --service slide-system | head -10

# Example output:
# ID              Status    Created             Branch
# dep-new123      ACTIVE    2025-10-12 14:00    main
# dep-old456      SUCCESS   2025-10-12 13:00    main
# dep-prev789     SUCCESS   2025-10-11 16:00    main

# Step 2: Identify last known good deployment
# (Usually the deployment before current ACTIVE)

# Step 3: Rollback to previous deployment
railway rollback --service slide-system dep-old456

# Step 4: Verify rollback initiated
railway logs --service slide-system --tail

# Expected: Service redeploying with previous version

# Step 5: Wait for deployment (1-2 minutes)
watch -n 5 'railway status --service slide-system'

# Step 6: Verify service is healthy
curl https://YOUR_SERVICE.railway.app/api/tavus/bot/status
```

**Rollback Time:** ~2-3 minutes

### Standard Rollback (Safe Path)

Use this when time permits for safer rollback.

```bash
# Step 1: Kill all active bots (prevent data corruption)
curl -X POST "$API_URL/api/tavus/bot/kill-all"

# Step 2: Verify all bots terminated
railway logs --service slide-system | grep "Bot process exited" | tail -10

# Step 3: Identify rollback target
railway deployments --service slide-system | head -10

# Step 4: Rollback
railway rollback --service slide-system dep-PREVIOUS_ID

# Step 5: Monitor rollback
railway logs --service slide-system --tail

# Step 6: Run smoke tests (see Post-Deployment Verification)
# Verify basic functionality before resuming traffic

# Step 7: Update team
# Post in #ops-alerts: "Rolled back slide-system to dep-XXXX due to [reason]"
```

**Rollback Time:** ~5-10 minutes (includes bot cleanup and verification)

### Post-Rollback Actions

After successful rollback:

```bash
# 1. Document the incident
cat > incident-$(date +%Y%m%d-%H%M).md <<EOF
# Incident Report: slide-system Rollback

**Date:** $(date)
**Rolled Back From:** dep-NEW_ID
**Rolled Back To:** dep-OLD_ID
**Duration:** X minutes
**Reason:** [Brief description]

## Timeline
- [Time]: Deployment deployed
- [Time]: Issue detected: [Description]
- [Time]: Rollback initiated
- [Time]: Rollback completed
- [Time]: Service verified healthy

## Root Cause
[What caused the issue]

## Resolution
[How it was fixed]

## Action Items
- [ ] Fix root cause in dev
- [ ] Add test to prevent regression
- [ ] Update deployment checklist
EOF

# 2. Create bug ticket
# Document issue with reproduction steps

# 3. Notify stakeholders
# Post in #engineering and #ops-alerts

# 4. Schedule post-mortem (if major incident)
# Invite: Team leads, on-call engineer, deployment author
```

### Rollback Decision Tree

```
                    [Issue Detected]
                           |
                           v
                 Is service responding?
                    /            \
                  NO              YES
                  /                \
                 v                  v
     [EMERGENCY ROLLBACK]    Is spawn rate < 50%?
            |                    /            \
            v                  YES            NO
     [Done in 2 min]            /              \
                               v                v
                    [STANDARD ROLLBACK]   [Monitor 5 min]
                          |                      |
                          v                      v
                   [Done in 5 min]    Issue persists?
                                           /        \
                                         YES         NO
                                         /            \
                                        v              v
                              [STANDARD ROLLBACK]  [Continue]
```

---

## Gradual Rollout Strategy

For major changes, use a phased rollout to minimize risk.

### Phase 1: Single Bot (4 Hours)

**Goal:** Verify basic functionality with minimal traffic

```bash
# Time: T+0 (Deployment)
# Deploy to Railway (normal deployment process)

# Time: T+5 minutes
# Spawn a single test bot
curl -X POST "$API_URL/api/tavus/bot/spawn" \
  -H "Content-Type: application/json" \
  -d '{
    "conversation_id": "rollout-phase1-'$(date +%s)'",
    "room_url": "YOUR_TEST_ROOM_URL"
  }'

# Monitor for 4 hours
# Check logs every 30 minutes for issues

# Time: T+30 minutes
railway logs --service slide-system | grep "Performance -" | tail -1
# Verify: Memory < 500MB, CPU < 30%, FPS ~10

# Time: T+1 hour
railway logs --service slide-system | grep "ERROR\|❌" | wc -l
# Verify: Error count = 0 or minimal

# Time: T+2 hours
# Check bot hasn't crashed
railway logs --service slide-system | grep "Bot process exited"
# Verify: No unexpected exits (or only exit code 0)

# Time: T+4 hours
# Phase 1 complete - verify success criteria
```

**Phase 1 Success Criteria:**

- [ ] Bot spawns successfully (PID logged)
- [ ] Bot runs for 4 hours without crash
- [ ] Memory usage < 500MB throughout
- [ ] CPU usage < 30% throughout
- [ ] FPS stable (9.5-10.5) throughout
- [ ] No error logs except deck validation warnings
- [ ] Bot responds to kill command gracefully

**Phase 1 Failure - Rollback:**

If any success criteria not met:
```bash
# Rollback immediately
railway rollback --service slide-system dep-PREVIOUS_ID

# Document issue and fix before retry
```

---

### Phase 2: Three Bots (4 Hours)

**Goal:** Verify concurrent bot handling and resource management

**Prerequisites:**
- Phase 1 completed successfully
- Team monitoring during business hours

```bash
# Time: T+0 (Phase 2 Start)
# Create 3 test rooms
cd apps/slide-system/bots/screenshare-bot
python scripts/create_test_rooms.py --count 3
# Save room URLs

# Spawn 3 bots (staggered by 30 seconds)
for room in $(cat test_rooms.txt); do
  curl -X POST "$API_URL/api/tavus/bot/spawn" \
    -H "Content-Type: application/json" \
    -d "{
      \"conversation_id\": \"rollout-phase2-$(date +%s)\",
      \"room_url\": \"$room\"
    }"
  sleep 30
done

# Verify all 3 bots active
curl -s "$API_URL/api/tavus/bot/status" | jq '.activeCount'
# Expected: 3

# Monitor for 4 hours
# Check logs every 30 minutes

# Time: T+30 minutes
railway logs --service slide-system | grep "Performance -" | tail -10
# Verify each bot: Memory < 500MB, CPU < 30%

# Check total resource usage
railway logs --service slide-system | grep "Memory:" | \
  awk '{sum+=$NF} END {print "Total Memory: " sum " MB"}'
# Verify: Total < 1500MB (3 bots × 500MB)

# Time: T+1 hour, T+2 hours, T+3 hours
# Repeat monitoring checks

# Time: T+4 hours
# Phase 2 complete - verify success criteria
```

**Phase 2 Success Criteria:**

- [ ] All 3 bots spawn successfully
- [ ] All 3 bots run for 4 hours without crash
- [ ] Total memory usage < 1500MB
- [ ] Total CPU usage < 90%
- [ ] Each bot maintains FPS 9.5-10.5
- [ ] No bot crashes or OOM kills
- [ ] Bot manager tracks all 3 correctly
- [ ] All bots respond to kill commands

**Phase 2 Monitoring Dashboard:**

```bash
# Create monitoring script for Phase 2
cat > monitor_phase2.sh <<'EOF'
#!/bin/bash
while true; do
  echo "=== $(date) ==="

  # Bot count
  echo "Active Bots:"
  curl -s "$API_URL/api/tavus/bot/status" | jq '.activeCount'

  # Recent performance
  echo "Recent Performance:"
  railway logs --service slide-system | grep "Performance -" | tail -3

  # Error count
  echo "Error Count (last 30 min):"
  railway logs --service slide-system --since 30m | grep "ERROR" | wc -l

  echo ""
  sleep 300  # Check every 5 minutes
done
EOF

chmod +x monitor_phase2.sh
./monitor_phase2.sh
```

**Phase 2 Failure - Rollback:**

```bash
# If any bot crashes or performance degrades:
# Kill all test bots
curl -X POST "$API_URL/api/tavus/bot/kill-all"

# Rollback
railway rollback --service slide-system dep-PREVIOUS_ID

# Document issues for investigation
```

---

### Phase 3: Five Bots - Production Ready (Ongoing)

**Goal:** Verify production-scale concurrent handling

**Prerequisites:**
- Phase 2 completed successfully
- Stakeholders notified of production rollout
- Monitoring alerts configured

```bash
# Time: T+0 (Phase 3 Start)
# Create 5 test rooms
python scripts/create_test_rooms.py --count 5

# Spawn 5 bots
for room in $(cat test_rooms.txt); do
  curl -X POST "$API_URL/api/tavus/bot/spawn" \
    -H "Content-Type: application/json" \
    -d "{
      \"conversation_id\": \"rollout-phase3-$(date +%s)\",
      \"room_url\": \"$room\"
    }"
  sleep 30
done

# Verify all 5 bots active
curl -s "$API_URL/api/tavus/bot/status" | jq '.activeCount'
# Expected: 5

# Monitor continuously for first 4 hours
# Then periodic checks for 24 hours

# Time: T+30 minutes
# Check total resource usage
railway logs --service slide-system | grep "Performance -" | tail -15

# Time: T+1 hour
# Run load test to verify
cd apps/slide-system/bots/screenshare-bot/scripts
python load_test.py --bots 5 --duration 300
# 5 minute load test

# Time: T+4 hours
# Phase 3 initial period complete

# Time: T+24 hours
# Phase 3 complete - verify success criteria
```

**Phase 3 Success Criteria:**

- [ ] All 5 bots spawn successfully
- [ ] All 5 bots run for 24 hours without crash
- [ ] Total memory usage < 2500MB (500MB × 5)
- [ ] Total CPU usage < 150%
- [ ] Each bot maintains FPS 9.5-10.5
- [ ] Spawn success rate > 95%
- [ ] No OOM kills or resource exhaustion
- [ ] All bots respond to kill commands
- [ ] Bot manager state consistent
- [ ] No performance degradation over 24 hours

**Phase 3 Go-Live Checklist:**

```
□ Phase 1 success criteria met
□ Phase 2 success criteria met
□ Phase 3 initial monitoring (4 hours) completed
□ Load testing passed (5 bots, 5 minutes)
□ No critical issues in 24 hour observation
□ Monitoring alerts configured
□ RUNBOOK.md reviewed by team
□ Rollback plan tested
□ On-call rotation scheduled
□ Stakeholders notified of go-live
```

**Go-Live Announcement:**

```bash
# When all criteria met, announce in #engineering:
cat <<EOF
🚀 Screenshare Bot v2.0 - Production Ready

Gradual rollout complete:
✅ Phase 1: Single bot (4 hours) - Success
✅ Phase 2: 3 bots (4 hours) - Success
✅ Phase 3: 5 bots (24 hours) - Success

Deployment is now live for production traffic.
- Monitoring: [Link to Railway dashboard]
- Runbook: apps/slide-system/bots/screenshare-bot/RUNBOOK.md
- On-call: [Name/rotation]

Please report any issues to #ops-alerts.
EOF
```

---

## Deployment Checklist (Summary)

### Pre-Deployment

```
□ All tests pass (pytest)
□ Code merged to main
□ Dependencies updated
□ Environment variables set
□ Railway service healthy
□ Team notified
□ Deployment window scheduled
```

### Deployment

```
□ Deploy to Railway (git push or railway up)
□ Monitor deployment logs
□ Wait for service healthy
□ Verify deployment success
```

### Post-Deployment

```
□ Run smoke tests
□ Verify API endpoints
□ Spawn test bot
□ Check performance metrics
□ Test bot lifecycle
□ Monitor for 30 minutes
```

### Gradual Rollout (Major Changes)

```
□ Phase 1: Single bot (4 hours)
□ Phase 1 success criteria met
□ Phase 2: Three bots (4 hours)
□ Phase 2 success criteria met
□ Phase 3: Five bots (24 hours)
□ Phase 3 success criteria met
□ Go-live announcement
```

---

## Quick Reference

### Essential Commands

```bash
# Deploy to Railway
git push origin main

# Watch deployment
railway logs --service slide-system --tail

# Check service status
railway status --service slide-system

# Rollback deployment
railway rollback --service slide-system dep-PREVIOUS_ID

# Test spawn endpoint
curl -X POST "$API_URL/api/tavus/bot/spawn" \
  -H "Content-Type: application/json" \
  -d '{"conversation_id": "test-123", "room_url": "https://test.daily.co/room"}'

# Check bot status
curl "$API_URL/api/tavus/bot/status" | jq

# Kill all bots
curl -X POST "$API_URL/api/tavus/bot/kill-all"
```

### Deployment Timelines

- **Standard deployment:** 5-10 minutes (build + deploy + smoke tests)
- **Emergency rollback:** 2-3 minutes (immediate rollback)
- **Standard rollback:** 5-10 minutes (with bot cleanup)
- **Gradual rollout:** 32+ hours (Phase 1: 4h + Phase 2: 4h + Phase 3: 24h)

### Support

```
Railway Dashboard: https://railway.app/project/YOUR_PROJECT
Railway Status: https://railway.app/status
Railway Docs: https://docs.railway.app
Team Slack: #ops-alerts
Runbook: RUNBOOK.md
Monitoring: MONITORING.md
```

---

**Document Version:** 1.0
**Last Updated:** 2025-10-12
**Maintained By:** DevOps Team
