|
| 1 | +--- |
| 2 | +name: ce-pipeline-doctor |
| 3 | +description: Diagnoses pipeline problems and outputs actionable fix commands. Combines insights from status-report, code-quality, task-audit, and health-check into concrete recommendations with copy-paste-ready commands. Answers "what should I do next?" and "why is generation stuck?" |
| 4 | +trigger: When user asks "what's wrong", "fix the pipeline", "what should I do next", "why is it stuck", "diagnose", "doctor", "help me fix this" |
| 5 | +--- |
| 6 | + |
| 7 | +# ce-pipeline-doctor — Pipeline Diagnosis & Action Plan |
| 8 | + |
| 9 | +Run a full diagnosis, then output a prioritized action plan with ready-to-execute commands. |
| 10 | + |
| 11 | +## Phase 1: Quick Triage (10 seconds) |
| 12 | + |
| 13 | +Run these checks to classify the problem: |
| 14 | + |
| 15 | +```bash |
| 16 | +# ONE-SHOT TRIAGE |
| 17 | +echo "=== CONTAINERS ===" && docker ps -a --format "{{.Names}} {{.Status}}" | grep coding-engine | sort |
| 18 | +echo "=== API HEALTH ===" && curl -s --max-time 3 http://localhost:8000/health 2>&1 || echo "API DOWN" |
| 19 | +echo "=== GENERATION ===" && docker top coding-engine-api 2>/dev/null | grep run_generation | head -1 || echo "NOT RUNNING" |
| 20 | +echo "=== DB TASKS ===" && docker exec coding-engine-postgres psql -U postgres -d coding_engine -t -c "SELECT status, COUNT(*) FROM tasks WHERE job_id=(SELECT MAX(id) FROM jobs) GROUP BY status ORDER BY status;" 2>&1 |
| 21 | +echo "=== LAST ERROR ===" && docker exec coding-engine-api bash -c "grep 'ERROR\|OOM\|Kill\|Exit\|FAILED' /app/output/*/generation.log 2>/dev/null | grep -v 'subscriber\|entity_req\|_initialized\|enrichment' | tail -3" 2>&1 |
| 22 | +echo "=== STALE RUNNING ===" && docker exec coding-engine-postgres psql -U postgres -d coding_engine -t -c "SELECT COUNT(*) FROM tasks WHERE job_id=(SELECT MAX(id) FROM jobs) AND status='RUNNING';" 2>&1 |
| 23 | +echo "=== MEMORY ===" && docker stats coding-engine-api --no-stream --format "{{.MemUsage}}" 2>/dev/null || echo "Container not running" |
| 24 | +``` |
| 25 | + |
| 26 | +## Phase 2: Classify Problem |
| 27 | + |
| 28 | +Based on triage results, classify into one of these categories: |
| 29 | + |
| 30 | +### Category A: Container Down |
| 31 | +- Symptom: API/Bot/Sandbox container Exited |
| 32 | +- Check exit code: 137=OOM, 139=SIGSEGV, 255=restart-failure |
| 33 | + |
| 34 | +### Category B: Generation Stuck/Dead |
| 35 | +- Symptom: `run_generation.py` not in process list but RUNNING tasks in DB |
| 36 | +- Stale RUNNING tasks = generation crashed mid-execution |
| 37 | + |
| 38 | +### Category C: Cascade Failure |
| 39 | +- Symptom: Many CANCELLED/SKIPPED tasks, few FAILED |
| 40 | +- Root cause: One upstream task failed → all dependents cancelled |
| 41 | + |
| 42 | +### Category D: LLM Issues |
| 43 | +- Symptom: 402 Payment Required, 429 Rate Limit, timeouts |
| 44 | +- Check which LLM backend and if credits are available |
| 45 | + |
| 46 | +### Category E: Task Explosion |
| 47 | +- Symptom: 2000+ PENDING tasks, generation runs but completes quickly with few results |
| 48 | +- Root cause: Tasks too granular, LLM calls wasted on tiny files |
| 49 | + |
| 50 | +### Category F: Code Quality Issues |
| 51 | +- Symptom: Build fails, wrong imports, empty generated files |
| 52 | +- Check: react-native in backend, missing prisma client, etc. |
| 53 | + |
| 54 | +## Phase 3: Generate Action Plan |
| 55 | + |
| 56 | +For each problem found, output a **numbered action** with the **exact command** to fix it. |
| 57 | + |
| 58 | +### Template Actions: |
| 59 | + |
| 60 | +#### Fix A: Container Down (OOM) |
| 61 | +``` |
| 62 | +ACTION 1: Restart container with memory limit |
| 63 | + docker compose up -d api |
| 64 | +
|
| 65 | +ACTION 2: Set memory limit in docker-compose.yml |
| 66 | + deploy: |
| 67 | + resources: |
| 68 | + limits: |
| 69 | + memory: 4G |
| 70 | +
|
| 71 | +ACTION 3: Reduce parallelism to lower memory usage |
| 72 | + # In engine_settings.yml: generation.parallelism: 2 (was 3) |
| 73 | +``` |
| 74 | + |
| 75 | +#### Fix B: Generation Stuck |
| 76 | +``` |
| 77 | +ACTION 1: Reset stale RUNNING tasks |
| 78 | + docker exec coding-engine-postgres psql -U postgres -d coding_engine -c "UPDATE tasks SET status='PENDING' WHERE job_id=(SELECT MAX(id) FROM jobs) AND status='RUNNING';" |
| 79 | +
|
| 80 | +ACTION 2: Remove stale lock file |
| 81 | + docker exec coding-engine-api bash -c "rm -f /app/output/*/.generation_running" |
| 82 | +
|
| 83 | +ACTION 3: Restart generation |
| 84 | + docker exec -d coding-engine-api bash -c "cd /app && python run_generation.py --project-path /app/Data/all_services/whatsapp-messaging-service_20260211_025459 --output-dir /app/output/whatsapp-messaging-service_20260211_025459 --project-id whatsapp-messaging-service --db-schema whatsapp_app --parallelism 2 --max-rounds 10 >> /app/output/whatsapp-messaging-service_20260211_025459/generation.log 2>&1" |
| 85 | +``` |
| 86 | + |
| 87 | +#### Fix C: Cascade Failure |
| 88 | +``` |
| 89 | +ACTION 1: Find cascade roots |
| 90 | + docker exec coding-engine-postgres psql -U postgres -d coding_engine -c "SELECT task_id, status, status_message FROM tasks WHERE job_id=(SELECT MAX(id) FROM jobs) AND status='FAILED' LIMIT 10;" |
| 91 | +
|
| 92 | +ACTION 2: Fix root failures (usually schema/migration) |
| 93 | + # If migrations: mark as COMPLETED (schema already synced) |
| 94 | + docker exec coding-engine-postgres psql -U postgres -d coding_engine -c "UPDATE tasks SET status='COMPLETED', status_message='Schema already synced' WHERE job_id=(SELECT MAX(id) FROM jobs) AND task_id LIKE '%migration%' AND status='FAILED';" |
| 95 | +
|
| 96 | +ACTION 3: Reset cancelled tasks and regenerate |
| 97 | + docker exec coding-engine-postgres psql -U postgres -d coding_engine -c "UPDATE tasks SET status='PENDING' WHERE job_id=(SELECT MAX(id) FROM jobs) AND status IN ('CANCELLED','SKIPPED');" |
| 98 | +``` |
| 99 | + |
| 100 | +#### Fix D: LLM Issues |
| 101 | +``` |
| 102 | +ACTION 1: Check API key balance |
| 103 | + curl -s https://openrouter.ai/api/v1/auth/key -H "Authorization: Bearer $OPENROUTER_API_KEY" | python3 -c "import sys,json; print(json.load(sys.stdin)['data']['usage'])" |
| 104 | +
|
| 105 | +ACTION 2: Switch to OpenAI if OpenRouter empty |
| 106 | + # In docker-compose.yml: LLM_BACKEND=openai |
| 107 | + docker compose up -d api |
| 108 | +
|
| 109 | +ACTION 3: Use free models as fallback |
| 110 | + # In engine_settings.yml: models.fixing.model: qwen/qwen3-coder:free |
| 111 | +``` |
| 112 | + |
| 113 | +#### Fix E: Task Explosion |
| 114 | +``` |
| 115 | +ACTION 1: Count the damage |
| 116 | + docker exec coding-engine-postgres psql -U postgres -d coding_engine -t -c "SELECT 'API tasks: ' || COUNT(*) FROM tasks WHERE job_id=(SELECT MAX(id) FROM jobs) AND task_id LIKE '%API%';" |
| 117 | +
|
| 118 | +ACTION 2: Mark redundant sub-tasks as COMPLETED |
| 119 | + # Keep only -controller tasks, mark -guard, -validation as done |
| 120 | + docker exec coding-engine-postgres psql -U postgres -d coding_engine -c "UPDATE tasks SET status='COMPLETED', status_message='Consolidated: generated with controller' WHERE job_id=(SELECT MAX(id) FROM jobs) AND (task_id LIKE '%-guard' OR task_id LIKE '%-validation') AND status='PENDING';" |
| 121 | +
|
| 122 | +ACTION 3: For future projects: modify epic_task_generator.py |
| 123 | + # Change _generate_api_tasks() to create 1 task per endpoint group instead of 5 |
| 124 | +``` |
| 125 | + |
| 126 | +#### Fix F: Code Quality |
| 127 | +``` |
| 128 | +ACTION 1: Remove react-native imports from backend |
| 129 | + docker exec coding-engine-api bash -c "cd /app/output/*/ && rm -f src/api/loginpageAPI.ts src/api/registerpageAPI.ts src/api/twofactorauthAPI.ts" |
| 130 | +
|
| 131 | +ACTION 2: Generate prisma client |
| 132 | + docker exec coding-engine-api bash -c "cd /app/output/*/ && DATABASE_URL='postgresql://postgres:postgres@postgres:5432/whatsapp_app?schema=public' npx prisma generate" |
| 133 | +
|
| 134 | +ACTION 3: Run build check |
| 135 | + docker exec coding-engine-api bash -c "cd /app/output/*/ && npx tsc --noEmit 2>&1 | head -20" |
| 136 | +``` |
| 137 | + |
| 138 | +## Phase 4: Priority Matrix |
| 139 | + |
| 140 | +After generating actions, present them in priority order: |
| 141 | + |
| 142 | +``` |
| 143 | +# 🏥 Pipeline Doctor — Diagnosis |
| 144 | +
|
| 145 | +## Problem: [Category Name] |
| 146 | +[One sentence description] |
| 147 | +
|
| 148 | +## Action Plan (in order): |
| 149 | +
|
| 150 | +| # | Action | Impact | Command Ready? | |
| 151 | +|---|--------|--------|----------------| |
| 152 | +| 1 | [Most urgent] | HIGH | ✅ | |
| 153 | +| 2 | [Next] | HIGH | ✅ | |
| 154 | +| 3 | [Nice to have] | MEDIUM | ✅ | |
| 155 | +
|
| 156 | +## Commands to Execute: |
| 157 | +[Copy-paste ready block of all commands in sequence] |
| 158 | +
|
| 159 | +## Expected Outcome: |
| 160 | +- After Action 1: [what changes] |
| 161 | +- After Action 2: [what changes] |
| 162 | +- After all actions: [final state] |
| 163 | +``` |
| 164 | + |
| 165 | +## Phase 5: Verify |
| 166 | + |
| 167 | +After actions are executed, re-run Phase 1 triage to confirm fixes worked. |
0 commit comments