# CC MISSION: Ralph WSL Networking Resolution
**Date:** 2025-01-16  
**Priority:** HIGH  
**Status:** DECISION REQUIRED  
**Context:** Ralph orchestrator WSL network instability (15/18 user stories failed)

---

## SITUATION ANALYSIS

**Current State:**
- Ralph orchestrator running on WSL
- 3 successes (US-005, US-006, US-007) 
- 15 failures (US-002 through US-018)
- Root cause: WSL network layer instability with Anthropic API

**Failure Pattern:**
```
ConnectionError: ('Connection aborted.', ConnectionResetError(10054))
Max retries exceeded with url: /v1/messages
```

**Proven Success:**
- US-005: FastAPI endpoint generated successfully
- Architecture works when network cooperates
- Quality output confirmed

---

## OPTION 1: Harden Ralph for WSL (Quick Fix)

### Strategy
Add aggressive retry logic + connection pooling to ralph_orchestrator.py

### Implementation Code
```python
# Add to ralph_orchestrator.py (before API calls)
import urllib3
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry

# Aggressive retry strategy
retry_strategy = Retry(
    total=5,
    backoff_factor=2,
    status_forcelist=[429, 500, 502, 503, 504],
    allowed_methods=["POST"]
)

adapter = HTTPAdapter(
    max_retries=retry_strategy,
    pool_connections=1,
    pool_maxsize=1
)

session = requests.Session()
session.mount("https://", adapter)

# Replace all requests.post() calls with:
response = session.post(url, headers=headers, json=payload, timeout=60)
```

### Execution Steps
1. Locate ralph_orchestrator.py in E:\genesis-system\
2. Add retry logic after imports
3. Replace requests.post() with session.post()
4. Test on US-002 (simplest story)
5. If successful, batch process remaining 14 stories

### Success Criteria
- US-002 completes without ConnectionError
- 3+ consecutive successful API calls
- Generated code quality matches US-005 baseline

### Resource Requirements
- **Time:** 1 hour (30min implementation + 30min testing)
- **Cost:** ~$15 Anthropic API credits (15 stories × $1 avg)
- **Risk:** Medium (WSL may still intermittently fail)

### Pros/Cons
✅ Keeps existing architecture  
✅ Fast implementation (30 minutes)  
✅ No infrastructure changes  
❌ Doesn't solve root cause  
❌ WSL may still fail under load  
❌ API costs continue  

---

## OPTION 2: Switch to AIVA NOW (Recommended)

### Strategy
Test local Ollama (QwenLong) on Elestio AIVA instance, bypass WSL networking entirely

### Why This Works
- **Local inference** = No external network calls
- **No WSL layer** = HTTP to localhost:11434 only
- **Already deployed** = AIVA instance running
- **Zero API cost** = Free local execution

### Execution Steps

**Phase 1: AIVA Capability Testing (1 hour)**
```bash
# SSH to Elestio AIVA instance
ssh [credentials provided by Kinan]

# Test context window limits
ollama run qwen2.5-coder:32b-instruct-q5_K_M "Generate FastAPI CRUD endpoint" 
# Measure: 32k, 64k, 128k token inputs

# Test concurrent capacity
# Run 1x, 2x, 4x simultaneous generations
# Measure: Response time, quality consistency

# Quality benchmark against US-005
# Generate same story, compare outputs
```

**Phase 2: Quality Comparison**
1. Read US-005 Claude Sonnet 4 output (baseline)
2. Generate US-002 with AIVA QwenLong
3. Score comparison:
   - Code correctness (compiles, runs)
   - Architecture quality (RESTful, clean)
   - Documentation completeness

**Phase 3: Decision Matrix**
```
IF QwenLong quality ≥ 80% of Claude Sonnet 4:
  → Execute 15 stories with AIVA (local)
  → Reserve Opus 4 for 3 critical stories only
  → Architecture: Hybrid Trinity (Opus + AIVA)

IF QwenLong quality < 80% of Claude Sonnet 4:
  → Fall back to Option 1 (harden Ralph)
  → OR proceed to Option 3 (Elestio Ralph)
```

### Success Criteria
- QwenLong generates compilable FastAPI code
- Architecture quality ≥ 80% of Claude baseline
- No network failures (local inference)
- Concurrent processing: 2-4 stories simultaneously

### Resource Requirements
- **Time:** 2 hours (1hr testing + 1hr decision)
- **Cost:** $0 (local inference)
- **Risk:** Low (worst case, fall back to other options)

### Pros/Cons
✅ Eliminates WSL network issues completely  
✅ Zero API costs (local inference)  
✅ Tests hybrid architecture viability  
✅ Determines long-term Genesis strategy  
❌ 1-2 hour testing phase required  
❌ Quality unknown until tested  
❌ May need fallback if quality insufficient  

### Required Information from Kinan
```
Need when ready to execute:
- Elestio AIVA SSH credentials
- Confirm: Skip Phase 1 system specs (already known)
- Confirm: US-005 output location for comparison
```

---

## OPTION 3: Run Ralph on Elestio (Nuclear Option)

### Strategy
Move ralph_orchestrator.py to Elestio instance, run in native Linux environment

### Why This Works
- **Native Linux networking** = No WSL translation layer
- **Stable internet** = Direct connection, no Windows routing
- **Same architecture** = No code changes to Ralph
- **Proven environment** = Linux reliability

### Execution Steps

**Step 1: Upload Ralph to Elestio**
```bash
# From Windows machine (PowerShell/WSL):
scp E:\genesis-system\ralph_orchestrator.py kinan@[elestio-IP]:/root/genesis/

# Upload dependencies:
scp E:\genesis-system\requirements.txt kinan@[elestio-IP]:/root/genesis/
```

**Step 2: Setup Environment**
```bash
# SSH to Elestio:
ssh kinan@[elestio-IP]

# Navigate to Genesis directory:
cd /root/genesis

# Install dependencies:
pip3 install -r requirements.txt

# Set Anthropic API key:
export ANTHROPIC_API_KEY="sk-ant-..."
```

**Step 3: Execute Ralph**
```bash
# Test single story:
python3 ralph_orchestrator.py --stories US-002 --model sonnet-4

# If successful, batch all remaining stories:
for story in US-{002..018}; do
  python3 ralph_orchestrator.py --stories $story --model sonnet-4
  sleep 5  # Rate limiting courtesy
done
```

### Success Criteria
- US-002 completes without network errors
- Consistent API connectivity (no ConnectionError)
- All 15 stories process successfully
- Output quality matches US-005 baseline

### Resource Requirements
- **Time:** 1.5 hours (30min setup + 1hr execution)
- **Cost:** ~$15 Anthropic API credits (same as Option 1)
- **Risk:** Low (native Linux networking very stable)

### Pros/Cons
✅ Eliminates WSL networking completely  
✅ Stable Linux environment (proven)  
✅ No architecture changes needed  
✅ Can run unattended overnight  
❌ Requires file transfer setup  
❌ API costs same as Option 1  
❌ Adds deployment step to workflow  

### Required Information from Kinan
```
Need when ready to execute:
- Elestio instance IP address
- SSH credentials (user@host)
- Anthropic API key
- Confirm ralph_orchestrator.py location
```

---

## RECOMMENDATION: Cascading Approach

### Execute in This Order

**Step 1: AIVA Testing (Option 2) - FIRST**
```
Rationale:
- Determines if local inference viable (solves WSL + cost)
- 1-2 hour investment reveals long-term strategy
- Zero cost to test
- No risk (can fall back)

Timeline: 1-2 hours
Cost: $0
```

**Step 2: Decision Point**
```
IF AIVA quality ≥ 80%:
  → Execute 15 stories with AIVA
  → Use Opus 4 for 3 critical stories only
  → DONE (WSL issue eliminated)

IF AIVA quality < 80%:
  → Proceed to Step 3
```

**Step 3: Elestio Ralph (Option 3) - FALLBACK**
```
Rationale:
- More reliable than hardening WSL
- Native Linux > patched WSL
- Same API costs as Option 1 but higher success rate

Timeline: 1.5 hours
Cost: ~$15 API credits
```

**Step 4: WSL Hardening (Option 1) - LAST RESORT**
```
Only if:
- Cannot access Elestio instance
- AIVA quality insufficient
- Need immediate local execution

Timeline: 1 hour
Cost: ~$15 API credits
Risk: Highest failure rate
```

---

## IMMEDIATE NEXT ACTION

### Execute This Now

```
CC, read CC_MISSION_AIVA_INVESTIGATION_UPDATED.md

Skip Phase 1 (system specs known)

Execute:
- Phase 2: Context window testing (32k, 64k, 128k)
- Phase 3: Concurrent capacity (1x, 2x, 4x)
- Phase 4: Quality comparison vs US-005 Claude output

I will provide Elestio SSH credentials when you request them.

Goal: Determine if AIVA QwenLong ≥ 80% of Claude Sonnet 4 quality.

If yes → Use AIVA for bulk work (eliminates WSL + saves $)
If no → We'll execute Option 3 (Ralph on Elestio)
```

---

## SUCCESS METRICS

**Option 1 Success:**
- 15/15 stories complete without ConnectionError
- Output quality matches US-005 baseline
- Total execution time < 4 hours

**Option 2 Success:**
- QwenLong quality ≥ 80% of Claude
- Context window handles 64k+ tokens
- Concurrent processing: 2-4 stories simultaneously
- Zero network failures (local)

**Option 3 Success:**
- 15/15 stories complete on Elestio
- Zero network errors (native Linux)
- Output quality matches US-005 baseline
- Can run unattended

---

## CONTINGENCY PLAN

**If All Options Fail:**
1. Use Gemini Flash 2.0 (free tier, 1M tokens/min)
2. Switch to Claude via web interface (manual but reliable)
3. Reduce batch size (1 story at a time, confirm each)

**Escalation Path:**
1. Test AIVA (2 hours max)
2. If fail → Elestio Ralph (1.5 hours max)
3. If fail → WSL hardening (1 hour max)
4. If fail → Gemini fallback

**Total contingency time:** 4.5 hours maximum

---

**END OF MISSION BRIEF**

*Awaiting Kinan's decision: Which option to execute first?*
