Best for
- Test failures
- Bugs in production
- Unexpected behavior
magnus919/agent-skills/systematic-debugging/SKILL.md
4-phase root cause debugging protocol: understand bugs before fixing. Use for ANY technical issue — test failures, production bugs, unexpected behavior, performance problems, build failures, or integration issues. ESPECIALLY when under time pressure, when "one quick fix" seems obvious, or when previous fix attempts have failed.
Decision brief
4-phase root cause debugging protocol: understand bugs before fixing. Use for ANY technical issue — test failures, production bugs, unexpected behavior, performance problems, build failures, or integration issues.
Compatibility matrix
| Platform | Status | Evidence | What to check |
|---|---|---|---|
| Codex | Not declared | No explicit evidence | Portability before use |
| Claude Code | Not declared | No explicit evidence | Portability before use |
| Cursor | Not declared | No explicit evidence | Portability before use |
| Gemini CLI | Not declared | No explicit evidence | Portability before use |
Installation
The source command is displayed only when detected. A safe inspection prompt is always available so your agent can explain every action before execution.
npx skills add https://github.com/magnus919/agent-skills --skill "systematic-debugging"Inspect the Agent Skill "systematic-debugging" from https://github.com/magnus919/agent-skills/blob/a4db8e7d4350816f02515bac12d91c8050db1e58/systematic-debugging/SKILL.md at commit a4db8e7d4350816f02515bac12d91c8050db1e58. List every install step, command, network request, credential, file read/write, external action, and rollback step. Explain whether it fits my task. Do not install or execute anything until I approve.
Workflow
BEFORE attempting ANY fix:
STOP: Do not proceed to Phase 2 until you understand WHY it's happening.
Find the pattern before fixing:
State clearly: "I think X is the root cause because Y"
Fix the root cause, not the symptom:
Permission review
The documentation asks the agent to run terminal commands or scripts.
git log --oneline -10The documentation asks the agent to run terminal commands or scripts.
git diffThe documentation asks the agent to read local files, directories, or repositories.
If `open -b bundle-id file.ext` works from Downloads but not Desktop, it's likely a TCC/tiered-access issue (macOS gives Downloads more permissive access).Evidence record
| Signal | Value | Evidence type | Meaning |
|---|---|---|---|
| Quality score | 95/100 | Computed | Documentation, specificity, maintenance, and trust rules |
| Repository stars | 34 | Source | Repository attention, not individual Skill quality |
| Compatibility | 0 platforms | Source | Declared in the catalog source record |
| Usage guide | automated source guide | Editorial | Generated or reviewed according to the visible evidence level |
Pinned source
Random fixes waste time and create new bugs. Quick patches mask underlying issues.
Core principle: ALWAYS find root cause before attempting fixes. Symptom fixes are failure.
NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST
If you haven't completed Phase 1, you cannot propose fixes.
Use for ANY technical issue:
ESPECIALLY when:
Don't skip when:
Complete each phase before proceeding to the next.
BEFORE attempting ANY fix:
pytest tests/test_module.py::test_name -v --tb=long
git log --oneline -10
git diff
git log -p --follow src/problematic_file.py | head -100
WHEN system has multiple components (API → service → database, CI → build → deploy):
Add diagnostic instrumentation BEFORE proposing fixes. For EACH component boundary:
Run once to gather evidence showing WHERE it breaks. THEN analyze to identify the failing component.
WHEN a bug reproduces in production but not in tests:
PRAGMA table_info(), \\.schema, or equivalentSimplified test schemas are a common source of hidden bugs. If the production table has model TEXT NOT NULL but the test table only has vector BLOB, a bug that only fires on NOT NULL violation will pass tests cleanly.
Action: Run PRAGMA table_info(table_name) against both databases side-by-side and diff the output.
WHEN a try/except fallback isn't catching the error you see in logs:
try:
# Primary path — can raise OperationalError
conn.execute("INSERT INTO t (model_name) VALUES (?)", ...)
except sqlite3.OperationalError:
# Fallback — can raise IntegrityError (sibling, not child)
conn.execute("INSERT INTO t (vector) VALUES (?)", ...)
OperationalError and IntegrityError are siblings — both inherit from DatabaseError, which inherits from Error. Catching one does NOT catch the other.
The fix is either:
except sqlite3.DatabaseError) if both paths can fail with different subtypesException as last resort (broader but safer than a gap)WHEN investigating a retrieval system, API, or knowledge graph that returns empty or inconsistent results:
Start from what works and expand until it breaks. This isolates the variable causing failure.
| Input | Expected | Actual | Diagnosis |
|---|---|---|---|
Single known term (e.g. python) | Hits | Hits | Tool works, connection OK |
Two-word phrase from same doc (type safety) | Hits | Hits | Short phrase retrieval works |
Related two-word phrase (generic types) | Hits | 0 hits | Boundary found — issue is phrase-specific |
| Longer query with same terms | 0 hits | 0 hits | Confirms: not a fluke |
Do NOT skip characterization: Jumping straight to "the embedding model is broken" is guessing. The grid eliminates variables one at a time.
WHEN you trace a bug into a third-party dependency:
Before patching the library code, verify WHERE it's installed from:
pip show <package-name>
Key fields:
pip install -e dev copy. Was this intentional?pip index versions <package-name>The rule: If the package is installed as an editable dev copy and you didn't put it there intentionally, STOP and ask. The symptom may be caused by code diverging from upstream — and the right fix is to switch to the production package, not to patch the fork.
Example: A background worker crashed with table X has no column named Y. Investigation traced it to an editable install from /private/tmp/some-fork/. A dev fork had added the column name to INSERT statements but never added the schema migration. The correct fix wasn't to add the migration to the fork — it was to switch to the production PyPI package and delete the dev copy.
WHEN you've gathered all local evidence but still don't understand the root cause:
Do NOT guess solutions. Use structured web research:
WHEN debugging a macOS app (especially sandboxed ones like Books, Music, or App Store apps):
The app is confined to a sandbox container under ~/Library/Containers/<bundle-id>/.
ls ~/Library/Containers/<bundle-id>/
# Data/Library/ — preferences, caches, databases
# Data/Documents/ — user-visible content, import queues
Many Apple apps use a background XPC service for file operations:
# XPC services live in the framework bundle or app bundle:
/System/Library/PrivateFrameworks/<Framework>.framework/XPCServices/
/System/Applications/<App>.app/Contents/XPCServices/
ps aux | grep -i "<service-name>"
Sandboxed apps often use SQLite/CoreData:
sqlite3 ~/Library/Containers/<bundle-id>/Data/Documents/<path>.sqlite ".tables"
sqlite3 ~/Library/Containers/<bundle-id>/Data/Documents/<path>.sqlite "SELECT * FROM ZTABLE LIMIT 10;"
log show --predicate 'process == "AppName"' --last 10m --style compact
log stream --predicate 'process == "AppName"' --style compact
If the app can't access files outside its sandbox (silent import failures):
tccutil reset All com.apple.bundle-id
open command) are one-time-use. If the import fails, the bookmark is consumed and subsequent attempts fail silently.open -b bundle-id file.ext works from Downloads but not Desktop, it's likely a TCC/tiered-access issue (macOS gives Downloads more permissive access).Container resets fix local state but NOT iCloud sync corruption. Signs of cloud issues:
Action: If local reset doesn't fix it, the iCloud sync state may be corrupted. System Settings → Apple ID → iCloud → Manage Storage → [App] → Delete All Data is the nuclear option.
kill -9 <PID>) — temporary, XPC respawnsrm -rf ~/Library/Containers/<bundle-id>/)tccutil reset All <bundle-id>)WHEN error is deep in the call stack:
Action: Search the codebase for function references and variable assignments to trace the data path.
STOP: Do not proceed to Phase 2 until you understand WHY it's happening.
Find the pattern before fixing:
Scientific method:
Fix the root cause, not the symptom:
# Run the specific regression test
pytest tests/test_module.py::test_name -v
# Run full suite — no regressions
pytest tests/ -q
Pattern indicating an architectural problem:
STOP and question fundamentals:
Discuss before attempting more fixes. This is NOT a failed hypothesis — this is a wrong architecture.
If you catch yourself thinking:
ALL of these mean: STOP. Return to Phase 1.
If 3+ fixes failed: Question the architecture (Phase 4, step 5).
When the investigation is active and the user says things like "we made progress but we're not done":
Do NOT break flow by asking clarifying questions. Keep pushing — gather more evidence, try the next diagnostic step, check another angle. A paused investigation that asks "what happened when you tried X?" wastes the user's attention.
Signals to keep pushing:
What to do instead: Derive information from logs, databases, or file state — don't ask the user to be your instrumentation layer. Only ask questions when you genuinely cannot proceed without input AND you've exhausted all self-service options.
| Excuse | Reality |
|---|---|
| "Issue is simple, don't need process" | Simple issues have root causes too. Process is fast for simple bugs. |
| "Emergency, no time for process" | Systematic debugging is FASTER than guess-and-check thrashing. |
| "Just try this first, then investigate" | First fix sets the pattern. Do it right from the start. |
| "I'll write test after confirming fix works" | Untested fixes don't stick. Test first proves it. |
| "Multiple fixes at once saves time" | Can't isolate what worked. Causes new bugs. |
| "I see the problem, let me fix it" | Seeing symptoms ≠ understanding root cause. |
| "One more fix attempt" (after 2+ failures) | 3+ failures = architectural problem. Question the pattern. |
| Phase | Key Activities | Success Criteria |
|---|---|---|
| 1. Root Cause | Read errors, reproduce, check changes, gather evidence, trace data flow | Understand WHAT and WHY |
| 2. Pattern | Find working examples, compare, identify differences | Know what's different |
| 3. Hypothesis | Form theory, test minimally, one variable at a time | Confirmed or new hypothesis |
| 4. Implementation | Create regression test, fix root cause, verify | Bug resolved, all tests pass |
Alternatives
mateaix/mateclaw
4-phase root cause debugging: understand bugs before fixing.
obra/superpowers
Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes
rpamis/comet
Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes
aAAaqwq/AGI-Super-Team
Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes