| name | debug-workflow |
| description | Systematic debugging workflow for isolating and fixing errors. Use when troubleshooting failures, investigating stack traces, or diagnosing unexpected behavior. |
Skill: debug-workflow
Description
Provides a structured approach to debugging that emphasizes evidence collection, hypothesis testing, and minimal reproduction before attempting fixes. Reduces debugging time by following a systematic protocol.
When to Use
- Investigating error messages or stack traces
- Diagnosing test failures
- Troubleshooting service crashes or hangs
- Fixing bugs reported by users
- Investigating unexpected behavior
Debugging Protocol
Phase 1: Reproduce
Confirm the error occurs consistently before investigating.
journalctl -u <service>.service -n 50 --no-pager 2>&1 | tee /tmp/error-capture.log
<command-that-triggers-error>
echo "Exit code: $?"
Phase 2: Isolate
Find the minimal code path that triggers the error.
git log --oneline -10
git diff HEAD~5 -- <suspected-file>
git bisect start
git bisect bad HEAD
git bisect good <known-good-commit>
Phase 3: Hypothesize
List likely root causes ranked by probability:
- Configuration error - Missing env var, wrong path, permissions
- Code bug - Logic error, type mismatch, null reference
- Resource issue - Out of memory, disk full, port conflict
- External dependency - Service down, API changed, version mismatch
Phase 4: Test Each Hypothesis
env | grep -i <related-var>
ls -la <config-path>
free -h
df -h
lsof -i :<port>
systemctl status <dependency>.service
curl -sf http://127.0.0.1:<port>/health
Phase 5: Fix
Apply minimal change to resolve confirmed cause.
export VAR=value
python3 -m py_compile <file.py>
Phase 6: Verify
Confirm fix works and no regressions introduced.
<command-that-was-failing>
pytest <test-file> -v
aq-qa 0
Quick Commands
Log Analysis
journalctl --since "1 hour ago" --priority=err
journalctl -u <service>.service -f
journalctl -u <service>.service | grep -i "error\|fail\|except"
Process Inspection
pgrep -a <process-name>
top -p $(pgrep <process-name>)
lsof -p $(pgrep <process-name>)
Python Debugging
python3 -m py_compile <file.py>
python3 -m pdb <script.py>
python3 -m cProfile -s cumtime <script.py>
Network Debugging
ss -tlnp | grep <port>
curl -v http://127.0.0.1:<port>/health
host <hostname>
Token Efficiency Rules
- Always capture the exact error message first.
- Check logs before code - most issues are config/resource related.
- Use
git bisect for regressions instead of manual code review.
- Test one hypothesis at a time to avoid confusing results.
- Document findings as you go to avoid repeating work.