Debugging Methodology
When This Applies
Apply this guidance when:
- Investigating a reported bug
- Troubleshooting failing tests or errors
- Diagnosing unexpected behavior
- Performing root cause analysis
Systematic Debugging Process
Step 1: Reproduce
Before fixing anything:
- Understand the expected behavior vs actual behavior
- Find the minimal steps to reproduce the issue
- Identify if it's deterministic or intermittent
- Note the environment (OS, language version, dependencies)
Step 2: Isolate
Narrow down the problem area:
- Binary search — Comment out half the code, does it still fail? Narrow further.
- Input isolation — What specific input triggers the bug?
- Component isolation — Which component is responsible?
- Version isolation — Did it work before? When did it break? (
git bisect)
Step 3: Understand
Before writing the fix:
- Read the code around the bug carefully — understand the intent
- Check if the bug is in your code or a dependency
- Understand WHY it's broken, not just WHERE
- Check for similar patterns elsewhere that might have the same bug
Step 4: Fix
Apply the minimal fix:
- Change only what's necessary to fix the root cause
- Don't refactor surrounding code in the same task
- Handle edge cases the fix might introduce
- Verify the fix resolves the original reproduction steps
Step 5: Verify
Confirm the fix is correct:
- Run the reproduction steps — the bug should be gone
- Run existing tests — nothing new should break
- Check edge cases around the fix
- Note what regression test the Integrator should add
Common Bug Categories
| Category | Symptoms | Where to Look |
|---|---|---|
| Off-by-one | Wrong count, missing first/last item | Loop boundaries, array indices |
| Null reference | Crash on property access | Uninitialized variables, optional chains |
| Race condition | Intermittent failures | Async code, shared state, parallel operations |
| Type mismatch | Wrong values, silent failures | String/number conversions, API responses |
| State mutation | Unexpected changes | Shared references, missing deep copies |
| Missing validation | Bad data propagates | Input boundaries, API contracts |
Debugging Tools
- Read the error stack trace — Start from the bottom (your code), not the top
- Add strategic logging — Log inputs, outputs, and state at key points
- Use assertions — Add temporary assertions to verify assumptions
- Check recent changes —
git logandgit difffor what changed recently - Read the docs — For library/framework issues, check documentation and changelogs
Reporting the Fix
When submitting a bug fix for review, communicate:
- What the bug was (root cause)
- How to reproduce it
- What the fix does and why
- What edge cases were considered
- What regression test should be added