Comprehensive Debugging Skill
Core Principle: ALWAYS find root cause before attempting fixes. Symptom fixes are failure.
The Iron Law of Debugging
NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST
When to Use / Not Use
Use when:
- Test failures (unit, integration, E2E)
- Bugs in production or development
- Unexpected behavior or performance problems
- Build failures or CI/CD pipeline issues
- Browser/UI issues
- ESPECIALLY when under time pressure, "just one quick fix" seems obvious, or you've already tried multiple fixes
Do NOT use when:
- Writing new tests or setting up test frameworks -> use
testing-framework
- TDD methodology or writing tests before code -> use
test-driven-development
- Reviewing code quality or PRs -> use
code-review
- Designing CI/CD pipelines -> use
cicd-pipelines
Decision Tree
What type of issue are you debugging?
├── Test failure
│ ├── Always fails (deterministic) -> Phase 1-4 systematic debugging
│ ├── Intermittently fails (flaky) -> find-polluter.sh + timing analysis
│ └── Only fails in CI, not locally -> Environment audit (OS, runtime, services)
├── Browser/UI bug
│ ├── Visual/layout issue -> Chrome DevTools scripts + screenshot
│ ├── Console errors -> console.js monitoring
│ ├── Network/API issue -> network.js tracking
│ └── Performance issue -> performance.js + Core Web Vitals
├── CI/CD pipeline failure
│ ├── Build error (module not found, etc.) -> Root cause tracing + cache check
│ ├── Timeout -> Pipeline analyzer + caching optimization
│ ├── Permission error -> Permissions block audit
│ └── Docker connection issue -> Runner/DinD configuration
├── Performance regression
│ ├── Known when it started -> Git diff between good and current deploy
│ └── Unknown source -> Performance profiler + trace recording
├── 3+ fix attempts have failed
│ └── STOP. Question the architecture. Return to Phase 1.
└── Not a debugging problem? -> See related skills
Quick Decision Matrix
| Issue Type |
Primary Tool |
Reference |
| Test failures |
Systematic Debugging |
references/systematic-debugging/ |
| Browser/UI bugs |
Chrome DevTools + E2E Testing |
references/cdp-domains.md, references/e2e-workflow/ |
| CI/CD failures |
Pipeline Analyzer |
scripts/cicd/, references/cicd-troubleshooting.md |
| Performance issues |
Performance Profiler |
references/performance-guide.md |
| Build errors |
Root Cause Tracing |
references/root-cause-tracing.md |
| Flaky tests |
Find Polluter Script |
scripts/find-polluter.sh |
The Four Phases
You MUST complete each phase before proceeding to the next.
Phase 1: Root Cause Investigation
BEFORE attempting ANY fix:
- Read Error Messages Carefully — Don't skip past errors; they often contain the exact solution. Read stack traces completely. Note line numbers, file paths, error codes.
- Reproduce Consistently — Can you trigger it reliably? If not reproducible, gather more data, don't guess.
- Check Recent Changes — Git diff, recent commits, new dependencies, config changes, environmental differences.
- Gather Evidence in Multi-Component Systems — For each component boundary: log data in, log data out, verify config propagation, check state at each layer.
- Trace Data Flow — Where does the bad value originate? Keep tracing up until you find the source. Fix at source, not at symptom.
See references/root-cause-tracing.md for detailed backward tracing technique.
Phase 2: Pattern Analysis
- Find working examples in same codebase
- Compare against reference implementation COMPLETELY
- List every difference, however small
- Understand dependencies: settings, config, environment
Phase 3: Hypothesis and Testing
- Form single hypothesis: "I think X is the root cause because Y"
- Test minimally — smallest possible change to test hypothesis
- Verify before continuing — Did it work? Yes = Phase 4, No = new hypothesis
- When you don't know — Say "I don't understand X", don't pretend
Phase 4: Implementation
- Create failing test case — simplest possible reproduction
- Implement single fix — address the root cause, ONE change at a time
- Verify fix — Test passes? No other tests broken?
- If 3+ fixes failed — STOP and question the architecture
Browser Debugging Tools
Installation:
cd scripts/chrome-devtools && npm install
Available Scripts:
| Script |
Purpose |
navigate.js |
Navigate to URLs |
screenshot.js |
Capture screenshots (auto-compresses >5MB) |
click.js |
Click elements |
fill.js |
Fill form fields |
evaluate.js |
Execute JavaScript in page context |
snapshot.js |
Extract interactive elements with metadata |
console.js |
Monitor console messages/errors |
network.js |
Track HTTP requests/responses |
performance.js |
Measure Core Web Vitals + record traces |
Usage:
cd scripts/chrome-devtools
node screenshot.js --url https://example.com --output ./page.png
node console.js --url https://example.com --types error,warn --duration 5000
E2E Testing Workflow
8-phase visual debugging with Playwright:
- Discovery — Detect app type, framework (
references/e2e-workflow/phase-1-discovery.md)
- Setup — Install Playwright, generate config
- Preflight — Validate app loads correctly
- Generation — Create screenshot-enabled tests
- Capture — Run tests and capture visual data
- Analysis — LLM-powered visual analysis
- Regression — Compare screenshots against baselines
- Export — Package production-ready test suite
Templates: templates/e2e-testing/ | Examples: examples/e2e-testing/
CI/CD Pipeline Debugging
python3 scripts/cicd/ci_health.py --platform github --repo owner/repo
python3 scripts/cicd/pipeline_analyzer.py --platform github --workflow .github/workflows/ci.yml
| Error Pattern |
Common Cause |
Quick Fix |
| "Module not found" |
Missing dependency or cache issue |
Clear cache, run npm ci |
| "Timeout" |
Job taking too long |
Add caching, increase timeout |
| "Permission denied" |
Missing permissions |
Add to permissions: block |
| "Cannot connect to Docker" |
Docker not available |
Use correct runner or DinD |
| Intermittent failures |
Flaky tests or race conditions |
Add retries, fix timing issues |
Debug logging: GitHub Actions: ACTIONS_RUNNER_DEBUG=true | GitLab CI: CI_DEBUG_TRACE: "true"
Test Pollution Detection
./scripts/find-polluter.sh '.git' 'src/**/*.test.ts'
Runs tests one-by-one, stops at first polluter.
Defense-in-Depth Validation
After fixing a bug, add validation at EVERY layer:
- Entry Point — Reject obviously invalid input at API boundary
- Business Logic — Ensure data makes sense for this operation
- Environment Guards — Prevent dangerous operations in specific contexts
- Debug Instrumentation — Capture context for forensics
See references/defense-in-depth.md for complete pattern.
Verification Before Completion
NO COMPLETION CLAIMS WITHOUT FRESH VERIFICATION EVIDENCE
- IDENTIFY: What command proves this claim?
- RUN: Execute the FULL command (fresh, complete)
- READ: Full output, check exit code, count failures
- VERIFY: Does output confirm the claim?
- ONLY THEN: Make the claim
Anti-Patterns
| Anti-Pattern |
Problem |
Solution |
| "Quick fix for now, investigate later" |
Creates more bugs than it resolves; root cause remains |
Iron Law: no fixes without Phase 1. Always complete root cause investigation first |
| Guessing at fixes without understanding |
40% first-time fix rate vs 95% systematic; 2-3 hours vs 15-30 min |
Follow all 4 phases; form single hypothesis and test minimally |
| "Just try changing X and see if it works" |
Random changes compound problems; introduce new bugs |
Test ONE hypothesis at a time with smallest possible change |
| Adding multiple changes at once |
Cannot identify which change fixed (or broke) what |
One change at a time; verify after each |
| Skipping the test / manual verification only |
No regression protection; bug will recur |
Always create failing test case first (Phase 4, Step 1) |
| 3+ failed fix attempts without stopping |
Indicates wrong root cause hypothesis |
STOP after 3 failures; question the architecture; return to Phase 1 |
| Trusting "API returns 200" as success |
200 status doesn't mean response shape is correct for consumer |
Check actual response data, not just status; validate contracts |
| Proposing fixes before investigation |
"I think the fix is X" skips root cause analysis |
Let Phase 1 complete before suggesting any fix |
| Omitting the stack trace |
Most information-dense debugging input discarded |
Always paste exact error message, stack trace, file paths, line numbers |
|
Fixing at symptom, not source |
Bad value originates elsewhere; symptom fix masks real problem |
|
Assuming "it works" after one test passes |
Fix may not cover edge cases; other components may break |
|
Debugging without a failing test |
No reproducibility; can't verify fix works or stays fixed |
|
Ignoring environment differences |
Bug appears only in CI/production but not locally |
Red Flags — STOP and Follow Process
If you catch yourself thinking:
- "Quick fix for now, investigate later"
- "Just try changing X and see if it works"
- "Add multiple changes, run tests"
- "Skip the test, I'll manually verify"
- "It's probably X, let me fix that"
- "I don't fully understand but this might work"
- "One more fix attempt" (when already tried 2+)
ALL of these mean: STOP. Return to Phase 1.
Resource Directory
References
references/systematic-debugging/ — Core debugging methodology
references/root-cause-tracing.md — Backward tracing technique
references/defense-in-depth.md — Multi-layer validation
references/verification-before-completion.md — Verification checklist
references/cdp-domains.md — Chrome DevTools Protocol (47 domains)
references/puppeteer-reference.md — Puppeteer API patterns
references/performance-guide.md — Performance debugging
references/cicd-*.md — CI/CD specific references
references/e2e-workflow/ — E2E testing workflow phases
references/workflow-modules/ — AI-powered debugging modules
Scripts
scripts/chrome-devtools/ — Browser automation scripts
scripts/cicd/ — CI/CD analysis tools
scripts/find-polluter.sh — Test pollution finder
Templates
templates/e2e-testing/ — Playwright test templates
templates/cicd/ — GitHub Actions + GitLab CI templates
Integration
- testing-framework — Set up test infrastructure debugging depends on
- test-driven-development — Write tests first; debugging handles what gets through
- code-review — Catch bugs before they reach debugging
- cicd-pipelines — Design CI/CD pipelines; debugging handles when they break
- docker-containerization — Container environments where many CI/CD bugs originate
1---2name: debugging3description: Finds and fixes bugs through systematic root cause analysis, stack trace interpretation, browser DevTools automation, CI/CD pipeline debugging, performance profiling, test pollution detection, and AI-powered error analysis. Use when the user asks to debug, fix a bug, investigate an error, analyze a stack trace, find root cause of a failure, profile performance, diagnose test failures (unit/integration/E2E), troubleshoot CI/CD pipelines, debug flaky tests, use Chrome DevTools, or trace data flow to source. NOT for writing new tests or setting up test frameworks (use testing-framework), NOT for TDD methodology or writing tests before code (use test-driven-development), NOT for reviewing code quality or PRs (use code-review), NOT for designing CI/CD pipelines (use cicd-pipelines), NOT for feature development or refactoring (use language-specific plugins).4license: Apache-2.05---67# Comprehensive Debugging Skill89**Core Principle:** ALWAYS find root cause before attempting fixes. Symptom fixes are failure.1011## The Iron Law of Debugging1213```14NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST15```1617## When to Use / Not Use1819**Use when:**20- Test failures (unit, integration, E2E)21- Bugs in production or development22- Unexpected behavior or performance problems23- Build failures or CI/CD pipeline issues24- Browser/UI issues25- ESPECIALLY when under time pressure, "just one quick fix" seems obvious, or you've already tried multiple fixes2627**Do NOT use when:**28- Writing new tests or setting up test frameworks -> use `testing-framework`29- TDD methodology or writing tests before code -> use `test-driven-development`30- Reviewing code quality or PRs -> use `code-review`31- Designing CI/CD pipelines -> use `cicd-pipelines`3233## Decision Tree3435```36What type of issue are you debugging?37├── Test failure38│ ├── Always fails (deterministic) -> Phase 1-4 systematic debugging39│ ├── Intermittently fails (flaky) -> find-polluter.sh + timing analysis40│ └── Only fails in CI, not locally -> Environment audit (OS, runtime, services)41├── Browser/UI bug42│ ├── Visual/layout issue -> Chrome DevTools scripts + screenshot43│ ├── Console errors -> console.js monitoring44│ ├── Network/API issue -> network.js tracking45│ └── Performance issue -> performance.js + Core Web Vitals46├── CI/CD pipeline failure47│ ├── Build error (module not found, etc.) -> Root cause tracing + cache check48│ ├── Timeout -> Pipeline analyzer + caching optimization49│ ├── Permission error -> Permissions block audit50│ └── Docker connection issue -> Runner/DinD configuration51├── Performance regression52│ ├── Known when it started -> Git diff between good and current deploy53│ └── Unknown source -> Performance profiler + trace recording54├── 3+ fix attempts have failed55│ └── STOP. Question the architecture. Return to Phase 1.56└── Not a debugging problem? -> See related skills57```5859## Quick Decision Matrix6061| Issue Type | Primary Tool | Reference |62|------------|--------------|-----------|63| Test failures | Systematic Debugging | `references/systematic-debugging/` |64| Browser/UI bugs | Chrome DevTools + E2E Testing | `references/cdp-domains.md`, `references/e2e-workflow/` |65| CI/CD failures | Pipeline Analyzer | `scripts/cicd/`, `references/cicd-troubleshooting.md` |66| Performance issues | Performance Profiler | `references/performance-guide.md` |67| Build errors | Root Cause Tracing | `references/root-cause-tracing.md` |68| Flaky tests | Find Polluter Script | `scripts/find-polluter.sh` |6970## The Four Phases7172You MUST complete each phase before proceeding to the next.7374### Phase 1: Root Cause Investigation7576**BEFORE attempting ANY fix:**77781. **Read Error Messages Carefully** — Don't skip past errors; they often contain the exact solution. Read stack traces completely. Note line numbers, file paths, error codes.792. **Reproduce Consistently** — Can you trigger it reliably? If not reproducible, gather more data, don't guess.803. **Check Recent Changes** — Git diff, recent commits, new dependencies, config changes, environmental differences.814. **Gather Evidence in Multi-Component Systems** — For each component boundary: log data in, log data out, verify config propagation, check state at each layer.825. **Trace Data Flow** — Where does the bad value originate? Keep tracing up until you find the source. Fix at source, not at symptom.8384See `references/root-cause-tracing.md` for detailed backward tracing technique.8586### Phase 2: Pattern Analysis87881. Find working examples in same codebase892. Compare against reference implementation COMPLETELY903. List every difference, however small914. Understand dependencies: settings, config, environment9293### Phase 3: Hypothesis and Testing94951. Form single hypothesis: "I think X is the root cause because Y"962. Test minimally — smallest possible change to test hypothesis973. Verify before continuing — Did it work? Yes = Phase 4, No = new hypothesis984. When you don't know — Say "I don't understand X", don't pretend99100### Phase 4: Implementation1011021. Create failing test case — simplest possible reproduction1032. Implement single fix — address the root cause, ONE change at a time1043. Verify fix — Test passes? No other tests broken?1054. If 3+ fixes failed — STOP and question the architecture106107## Browser Debugging Tools108109**Installation:**110```bash111cd scripts/chrome-devtools && npm install112```113114**Available Scripts:**115| Script | Purpose |116|--------|---------|117| `navigate.js` | Navigate to URLs |118| `screenshot.js` | Capture screenshots (auto-compresses >5MB) |119| `click.js` | Click elements |120| `fill.js` | Fill form fields |121| `evaluate.js` | Execute JavaScript in page context |122| `snapshot.js` | Extract interactive elements with metadata |123| `console.js` | Monitor console messages/errors |124| `network.js` | Track HTTP requests/responses |125| `performance.js` | Measure Core Web Vitals + record traces |126127**Usage:**128```bash129cd scripts/chrome-devtools130node screenshot.js --url https://example.com --output ./page.png131node console.js --url https://example.com --types error,warn --duration 5000132```133134## E2E Testing Workflow1351368-phase visual debugging with Playwright:1371. **Discovery** — Detect app type, framework (`references/e2e-workflow/phase-1-discovery.md`)1382. **Setup** — Install Playwright, generate config1393. **Preflight** — Validate app loads correctly1404. **Generation** — Create screenshot-enabled tests1415. **Capture** — Run tests and capture visual data1426. **Analysis** — LLM-powered visual analysis1437. **Regression** — Compare screenshots against baselines1448. **Export** — Package production-ready test suite145146Templates: `templates/e2e-testing/` | Examples: `examples/e2e-testing/`147148## CI/CD Pipeline Debugging149150```bash151python3 scripts/cicd/ci_health.py --platform github --repo owner/repo152python3 scripts/cicd/pipeline_analyzer.py --platform github --workflow .github/workflows/ci.yml153```154155| Error Pattern | Common Cause | Quick Fix |156|---------------|-------------|-----------|157| "Module not found" | Missing dependency or cache issue | Clear cache, run `npm ci` |158| "Timeout" | Job taking too long | Add caching, increase timeout |159| "Permission denied" | Missing permissions | Add to `permissions:` block |160| "Cannot connect to Docker" | Docker not available | Use correct runner or DinD |161| Intermittent failures | Flaky tests or race conditions | Add retries, fix timing issues |162163**Debug logging:** GitHub Actions: `ACTIONS_RUNNER_DEBUG=true` | GitLab CI: `CI_DEBUG_TRACE: "true"`164165## Test Pollution Detection166167```bash168./scripts/find-polluter.sh '.git' 'src/**/*.test.ts'169```170Runs tests one-by-one, stops at first polluter.171172## Defense-in-Depth Validation173174After fixing a bug, add validation at EVERY layer:1751. **Entry Point** — Reject obviously invalid input at API boundary1762. **Business Logic** — Ensure data makes sense for this operation1773. **Environment Guards** — Prevent dangerous operations in specific contexts1784. **Debug Instrumentation** — Capture context for forensics179180See `references/defense-in-depth.md` for complete pattern.181182## Verification Before Completion183184```185NO COMPLETION CLAIMS WITHOUT FRESH VERIFICATION EVIDENCE186```1871881. IDENTIFY: What command proves this claim?1892. RUN: Execute the FULL command (fresh, complete)1903. READ: Full output, check exit code, count failures1914. VERIFY: Does output confirm the claim?1925. ONLY THEN: Make the claim193194## Anti-Patterns195196| Anti-Pattern | Problem | Solution |197|---|---|---|198| "Quick fix for now, investigate later" | Creates more bugs than it resolves; root cause remains | Iron Law: no fixes without Phase 1. Always complete root cause investigation first |199| Guessing at fixes without understanding | 40% first-time fix rate vs 95% systematic; 2-3 hours vs 15-30 min | Follow all 4 phases; form single hypothesis and test minimally |200| "Just try changing X and see if it works" | Random changes compound problems; introduce new bugs | Test ONE hypothesis at a time with smallest possible change |201| Adding multiple changes at once | Cannot identify which change fixed (or broke) what | One change at a time; verify after each |202| Skipping the test / manual verification only | No regression protection; bug will recur | Always create failing test case first (Phase 4, Step 1) |203| 3+ failed fix attempts without stopping | Indicates wrong root cause hypothesis | STOP after 3 failures; question the architecture; return to Phase 1 |204| Trusting "API returns 200" as success | 200 status doesn't mean response shape is correct for consumer | Check actual response data, not just status; validate contracts |205| Proposing fixes before investigation | "I think the fix is X" skips root cause analysis | Let Phase 1 complete before suggesting any fix |206| Omitting the stack trace | Most information-dense debugging input discarded | Always paste exact error message, stack trace, file paths, line numbers |207|| Fixing at symptom, not source | Bad value originates elsewhere; symptom fix masks real problem | Trace data flow upstream to source; fix at origin (Phase 1, Step 5) |208|| Assuming "it works" after one test passes | Fix may not cover edge cases; other components may break | Run full test suite after fix; verify at each defense layer |209|| Debugging without a failing test | No reproducibility; can't verify fix works or stays fixed | Create failing test first (Phase 4, Step 1); it's proof the fix is correct |210|| Ignoring environment differences | Bug appears only in CI/production but not locally | Audit OS, runtime version, env vars, services, network before assuming code is the cause |211212## Red Flags — STOP and Follow Process213214If you catch yourself thinking:215- "Quick fix for now, investigate later"216- "Just try changing X and see if it works"217- "Add multiple changes, run tests"218- "Skip the test, I'll manually verify"219- "It's probably X, let me fix that"220- "I don't fully understand but this might work"221- "One more fix attempt" (when already tried 2+)222223**ALL of these mean: STOP. Return to Phase 1.**224225## Resource Directory226227### References228- `references/systematic-debugging/` — Core debugging methodology229- `references/root-cause-tracing.md` — Backward tracing technique230- `references/defense-in-depth.md` — Multi-layer validation231- `references/verification-before-completion.md` — Verification checklist232- `references/cdp-domains.md` — Chrome DevTools Protocol (47 domains)233- `references/puppeteer-reference.md` — Puppeteer API patterns234- `references/performance-guide.md` — Performance debugging235- `references/cicd-*.md` — CI/CD specific references236- `references/e2e-workflow/` — E2E testing workflow phases237- `references/workflow-modules/` — AI-powered debugging modules238239### Scripts240- `scripts/chrome-devtools/` — Browser automation scripts241- `scripts/cicd/` — CI/CD analysis tools242- `scripts/find-polluter.sh` — Test pollution finder243244### Templates245- `templates/e2e-testing/` — Playwright test templates246- `templates/cicd/` — GitHub Actions + GitLab CI templates247248## Integration249250- testing-framework — Set up test infrastructure debugging depends on251- test-driven-development — Write tests first; debugging handles what gets through252- code-review — Catch bugs before they reach debugging253- cicd-pipelines — Design CI/CD pipelines; debugging handles when they break254- docker-containerization — Container environments where many CI/CD bugs originate