---
name: Python Environment Validation
status: closed
created: 2025-10-20T15:30:53Z
updated: 2025-10-20T21:26:15Z
github: https://github.com/BuzzTrail/video-extension/issues/157
depends_on: []
parallel: true
conflicts_with: []
---

# Task: Python Environment Validation

## Description

Deploy a minimal Python diagnostic script to Railway to validate that Python 3.11 works correctly in the bot-spawner environment, specifically testing the `asyncio` import that's been causing hangs.

**Goal:** Prove Python 3.11 can import asyncio and create event loops on Railway BEFORE building the full bot-spawner service.

Create and deploy a simple diagnostic script that:
1. Prints Python version
2. Imports asyncio (with instrumentation)
3. Creates an event loop
4. Reports success or failure with clear logging

**This is Phase 0 validation - runs in parallel with Task 001.**

## Acceptance Criteria

- [ ] Diagnostic Python script created with heavy instrumentation
- [ ] Script tests asyncio import and event loop creation
- [ ] Deployed to Railway with Python 3.11 (Ubuntu 24.04 + deadsnakes)
- [ ] Script executes successfully and logs captured
- [ ] Findings documented: Does asyncio work in isolated Railway environment?
- [ ] Results saved in `.claude/epics/bot-spawner-extraction/phase0-python-results.md`

## Technical Details

### Implementation Approach

**Diagnostic Script (`diagnostic.py`):**
```python
#!/usr/bin/env python3
import sys
import os
from datetime import datetime

def log(msg):
    print(f"[{datetime.utcnow().isoformat()}] {msg}", flush=True)

log(f"DIAGNOSTIC START")
log(f"Python version: {sys.version}")
log(f"Python executable: {sys.executable}")
log(f"Platform: {sys.platform}")

# Critical test: asyncio import
log("Attempting asyncio import...")
try:
    import asyncio
    log("✅ SUCCESS: asyncio imported")
except Exception as e:
    log(f"❌ FAILED: asyncio import failed: {e}")
    sys.exit(1)

# Test event loop creation
log("Creating event loop...")
try:
    loop = asyncio.new_event_loop()
    log("✅ SUCCESS: Event loop created")
    asyncio.set_event_loop(loop)
    log("✅ SUCCESS: Event loop set")
except Exception as e:
    log(f"❌ FAILED: Event loop creation failed: {e}")
    sys.exit(1)

# Test basic async operation
async def test_async():
    log("Testing async function...")
    await asyncio.sleep(0.1)
    log("✅ SUCCESS: Async function completed")

log("Running async test...")
try:
    loop.run_until_complete(test_async())
    log("✅ SUCCESS: Async execution works")
except Exception as e:
    log(f"❌ FAILED: Async execution failed: {e}")
    sys.exit(1)

log("DIAGNOSTIC COMPLETE - All tests passed! 🎉")
```

**Minimal Dockerfile:**
```dockerfile
FROM ubuntu:24.04

# Install Python 3.11 via deadsnakes
RUN apt-get update && apt-get install -y software-properties-common
RUN add-apt-repository ppa:deadsnakes/ppa
RUN apt-get update && apt-get install -y python3.11

COPY diagnostic.py /app/diagnostic.py
CMD ["python3.11", "/app/diagnostic.py"]
```

### Key Considerations

- Use **exact same base image** as planned bot-spawner (Ubuntu 24.04)
- Use **same Python version** (3.11 from deadsnakes)
- Keep it minimal - no extra dependencies
- Heavy logging to see exactly where failure occurs (if any)
- Compare behavior to voice-agent (which works on Railway)

### Files Affected

**New files:**
- `.claude/epics/bot-spawner-extraction/diagnostic/diagnostic.py`
- `.claude/epics/bot-spawner-extraction/diagnostic/Dockerfile`
- `.claude/epics/bot-spawner-extraction/phase0-python-results.md` (findings)

## Dependencies

**External:**
- [ ] Railway platform supports Ubuntu 24.04 containers
- [ ] deadsnakes PPA accessible from Railway

**Blockers:**
- This task runs in parallel with Task 001 (no dependencies)
- Results inform Task 003 (bot-spawner Dockerfile decisions)

## Effort Estimate

- **Size:** S (Small)
- **Hours:** 2-4 hours
  - Create diagnostic script: 1 hour
  - Create Dockerfile: 0.5 hours
  - Deploy to Railway: 0.5 hours
  - Analyze logs: 1-2 hours
- **Parallel:** true (can run alongside Task 001)

## Definition of Done

- [ ] Diagnostic script deployed to Railway
- [ ] Script logs captured and analyzed
- [ ] Clear verdict: Does Python 3.11 asyncio work on Railway?
- [ ] If FAILS: Document exact failure point for debugging
- [ ] If SUCCEEDS: Confirms bot-spawner approach is viable
- [ ] Findings documented with next steps

**Success Criteria:**
- **PASS:** Script completes successfully → Proceed with bot-spawner
- **FAIL:** Script hangs at asyncio import → Deeper investigation needed (try Python 3.12, different base image, etc.)
