---
name: "cicd-failure-diagnostician"
description: "Paste a failed CI log (GitHub Actions, CircleCI, etc.) and get: failure category, root cause in plain English, exact fix command or code change, and flaky test detection."
metadata:
  version: "1.0.0"
disable-model-invocation: true
---

# CI/CD Failure Diagnostician

> **Purpose:** Diagnose a failed CI/CD pipeline from raw logs. Takes a GitHub Actions, CircleCI, GitLab CI, or any other CI log output. Returns: failure category, root cause explanation in plain English, exact fix (command, code change, or env var), and whether it looks like a flaky test. Turns 20 minutes of log-reading into 20 seconds.

---

## Invocation

```
/ci-fix <paste-log-output>
```

Or: `/ci-fix` then paste the log when prompted.

---

## Failure Categories

Classify the failure into exactly one category:

| Category | Indicators |
|----------|-----------|
| **Test failure** | `FAIL`, `AssertionError`, `expect(x).toBe(y)`, test name in output |
| **Build error** | TypeScript error, compilation failure, syntax error |
| **Lint error** | ESLint, Prettier, Ruff, golangci-lint rule violation |
| **Missing env var** | `undefined`, `Cannot read properties of undefined (reading 'env')`, `process.env.X is not defined` |
| **Dependency install failure** | `npm ERR!`, `pip install failed`, `Cannot find module` |
| **Permission error** | `EACCES`, `403 Forbidden`, `permission denied` |
| **Timeout** | Job exceeded `N` minutes, `ETIMEDOUT`, hanging process |
| **Out of memory** | `ENOMEM`, `JavaScript heap out of memory`, OOM killed |
| **Network error** | DNS resolution failed, connection refused, rate limited |
| **Flaky test** | Timing assertions, random/date-dependent values, race conditions |

---

## Diagnosis Process

### Step 1: Find the Failure Point

Scan the log for the FIRST error line — most CI logs dump a long stack trace but the real error is near the top of the first `ERROR` block.

Common patterns to scan for:
```
✗ FAILED
Error: ...
× ...
FAILED: ...
error[...]: ...
exit code: 1 (immediately after the relevant command)
```

### Step 2: Explain in Plain English

One paragraph: what failed, why it failed, and what the system was trying to do when it failed. No jargon that isn't in the original log.

### Step 3: Provide the Fix

The fix must be one of:
- **A command to run** (with the exact command, ready to copy-paste)
- **A code change** (file:line, old code, new code)
- **An env var to add** (variable name + where to add it)
- **A CI config change** (which job/step to modify and how)

### Step 4: Flaky Test Detection

Flag as **possibly flaky** if the failure involves:
- `setTimeout` / `sleep` / date-based assertions without mocking
- Race conditions (async test with no proper await)
- External service calls in unit tests
- File system state left from a previous test
- Random or time-dependent data generation

If flaky: suggest `--retry=3` as a short-term bandage + the proper fix (mock the external dependency).

---

## Output Format

```
## CI Failure Diagnosis

**Job:** [job name from log]
**Step:** [step that failed]
**Category:** [one of the 10 categories above]

---

### Root Cause

[Plain-English explanation, 2-4 sentences]

---

### Fix

[Exact command OR code change OR env var to add]

```bash
# Run this locally to reproduce and verify the fix:
[reproduction command]
```

---

### Flaky Test?

[Yes / No / Possibly — with brief reason]

---

### Prevention

[One-line suggestion to prevent this class of failure in the future]
```

---

## Rules

- Always find the FIRST error line, not the last — stack traces cascade from the origin
- Never say "the issue is complex" — give a specific diagnosis even if uncertain (flag uncertainty)
- If `Missing env var`: specify the exact variable name found in the log, not a guess
- If flaky: never just say "add a retry" — explain the actual race condition or timing issue
- If you cannot determine the cause: output "Inconclusive — please provide more log context" with specific questions about what's missing

## Playground

<!DOCTYPE html><html><head><meta charset='utf-8'><style>*{box-sizing:border-box;margin:0;padding:0}body{background:#0d1117;color:#e6edf3;font-family:monospace;font-size:12px;height:100vh;display:flex;flex-direction:column;overflow:hidden}.header{background:#161b22;border-bottom:1px solid #30363d;padding:8px 14px;font-size:11px;color:#8b949e;display:flex;justify-content:space-between;align-items:center;flex-shrink:0}.title{color:#58a6ff;font-weight:bold;font-size:13px}.panels{display:flex;flex:1;overflow:hidden}.panel{flex:1;overflow:auto;padding:12px;border-right:1px solid #30363d}.panel:last-child{border-right:none}.label{font-size:10px;color:#8b949e;text-transform:uppercase;letter-spacing:.08em;margin-bottom:6px}pre{white-space:pre-wrap;word-break:break-word;line-height:1.5}</style></head><body><div class='header'><span class='title'>CI/CD Failure Diagnostician</span><span>Example · SkillSlap</span></div><div class='panels'><div class='panel'><div class='label'>Input: CI log excerpt</div><pre><span style='color:#8b949e'>FAIL src/auth/session.test.ts</span>
<span style='color:#8b949e'>  ● Session › persists after reload</span>

<span style='color:#8b949e'>    Expected: "active"</span>
<span style='color:#8b949e'>    Received: undefined</span>

<span style='color:#8b949e'>    at Object.expect (session.test.ts:47)</span>

<span style='color:#8b949e'>Tests: 1 failed, 147 passed</span></pre></div><div class='panel'><div class='label'>Output: Diagnosis</div><pre><span style='color:#f85149'>Root cause</span>
<span style='color:#8b949e'>session.test.ts:47 — `status` field is</span>
<span style='color:#8b949e'>`undefined` after reload. The test</span>
<span style='color:#8b949e'>creates a session then reads it before</span>
<span style='color:#8b949e'>the write propagates to the store.</span>

<span style='color:#e3b341'>Likely fix</span>
<span style='color:#8b949e'>1. Add `await session.save()` before</span>
<span style='color:#8b949e'>   the reload assertion.</span>
<span style='color:#8b949e'>2. Or mock the session store so reads</span>
<span style='color:#8b949e'>   are synchronous in tests.</span>

<span style='color:#58a6ff'>Verify</span>
<span style='color:#8b949e'>npx vitest run src/auth/session</span>
<span style='color:#8b949e'>Add: console.log(session) after reload</span></pre></div></div></body></html>