Systematic debugging

From ROCm/rocm-systems · View interactive version

Systematic debugging is an AI agent skill from the GitHub repository ROCm/rocm-systems. Use when encountering any bug, test failure, build failure, or unexpected behavior in amd-smi — before proposing any fix. Enforces root-cause investigation before symptom patching.

How to use this skill

Skill file

Systematic Debugging — amd-smi

Random fixes waste time and create new bugs. Quick patches mask underlying issues.

Core principle: ALWAYS find the root cause before attempting a fix. Symptom fixes are failure.

Violating the letter of this process is violating the spirit of debugging.

The Iron Law

NO FIXES WITHOUT ROOT-CAUSE INVESTIGATION FIRST

If you haven't completed Phase 1, you cannot propose a fix.

When to Use

Use for any technical issue:

Especially when:

The Four Phases

Complete each phase before proceeding to the next.

Phase 1: Root-Cause Investigation

  1. Read error messages carefully
  1. Reproduce consistently
  1. Check recent changes
  1. Gather evidence across cascade layers

amd-smi bugs often span layers. Add instrumentation at every boundary:

```bash

# Layer 1: CLI argparse

echo "argparse args: $@"

# Layer 2: Python interface

python3 -c "import amdsmi; print(amdsmi.amdsmi_get_lib_version())"

# Layer 3: C wrapper loaded

python3 -c "from amdsmi import amdsmi_wrapper; print(amdsmi_wrapper.libamd_smi._name)"

# Layer 4: Actual C call return value

strace -e trace=openat python3 -c "import amdsmi; amdsmi.amdsmi_init()" 2>&1 | grep libamd_smi

```

This reveals which layer breaks, not just that something breaks.

  1. Trace data flow backward

Phase 2: Pattern Analysis

  1. Find a working example — locate the closest-working similar function/command/test
  2. Compare against the reference — read it completely, line by line; don't skim
  3. List every difference — however small. Don't assume "that can't matter"
  4. Understand dependencies — what config, environment, build flags does the working version need?

Phase 3: Hypothesis and Testing

  1. Form a single hypothesis — "I think X is the root cause because Y." Write it down.
  2. Test minimally — the smallest possible change. One variable at a time. No "while I'm here" fixes.
  3. Verify before continuing — worked? Phase 4. Didn't? Form a NEW hypothesis. Don't pile fixes.
  4. When you don't know — say "I don't understand X". Don't pretend. Ask the user or research more.

Phase 4: Implementation

  1. Create a failing test that reproduces the bug
  1. Implement a single fix — address the root cause. One change. No bundled refactors.
  2. Verify
  1. If the fix doesn't work — STOP. Count attempts.
  1. If 3+ fixes failed: question the architecture

Pattern indicating an architectural problem:

Stop. Discuss with the user. This is not a failed hypothesis — this is a wrong architecture.

Red Flags — STOP and Follow Process

All of these mean: stop, return to Phase 1.

If 3+ fixes failed: question the architecture (Phase 4 step 5).

Common Rationalizations

| Excuse | Reality |

|--------|---------|

| "Issue is simple, no process needed" | 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, then investigate" | First fix sets the pattern. Do it right from the start. |

| "I'll write the test after the fix works" | Untested fixes don't stick. Test-first proves the fix actually addresses the bug. |

| "Multiple fixes at once saves time" | Can't isolate what worked. Causes new bugs. |

| "Reference is too long, I'll adapt the pattern" | Partial understanding guarantees more bugs. Read it fully. |

| "I see the problem, let me fix it" | Seeing the symptom ≠ understanding the cause. |

| "One more fix attempt" (after 2+ failures) | 3+ failures = architectural problem. Question the pattern. |

Quick Reference

| Phase | Activities | Done When |

|-------|-----------|-----------|

| 1. Root cause | Read errors, reproduce, check changes, instrument layers | You understand WHAT and WHY |

| 2. Pattern | Find working examples, compare differences | You can list every relevant difference |

| 3. Hypothesis | State theory, test minimally | Confirmed, or new hypothesis formed |

| 4. Implementation | Failing test → single fix → verify | Bug resolved, tests green |

amd-smi-Specific Investigation Tips

Required Companion Skills

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.