Systematic Debugging - 4-phase root cause process. No guessing, no random fixes. Trace evidence, identify root cause, fix systematically.
--- name: systematic-debugging version: 2.0.0 description: 4-phase root cause debugging. Never guess, find the cause. Based on real production debugging methodology. Trigger on: 'bug', 'error', 'not working', 'broken', 'debug', 'fix this'. emoji: ๐ --- # Systematic Debugging ๐ 4 phases. No guessing. Find root cause. ## The 4 Phases ``` Phase 1: OBSERVE โ What exactly is wrong? (Gather evidence) Phase 2: ISOLATE โ Where does it go wrong? (Narrow scope) Phase 3: HYPOTHESIZE โ Why does it go wrong? (Form theory) Phase 4: VERIFY โ Is it actually fixed? (Prove it) ``` ## Phase 1: OBSERVE (Don't Skip This) **Before touching any code, answer these:** ``` โก What is the expected behavior? โก What is the actual behavior? โก When did it start? (What changed?) โก Is it reproducible? (100%? Intermittent?) โก What's the exact error message / log output? โก What environment? (OS, version, dependencies) ``` **Common mistake:** Jumping to "I think it's because..." without observing first. **What to do:** - Read the actual error (copy-paste, don't paraphrase) - Check logs (recent ones first) - Reproduce the issue (if possible) - Document what you see ## Phase 2: ISOLATE (Narrow the Scope) **Binary search for the bug:** ``` 1. Is the problem in my code or external? โ Comment out my code. Still broken? External. 2. Is it in the input, processing, or output? โ Print/log at each stage. 3. Is it in one specific file/function? โ Remove files/functions one by one. โ Bug disappears? That's where it is. 4. Is it a specific condition? โ Test with different inputs. โ Pattern emerges? Root cause narrows. ``` **Techniques:** - `git bisect` โ Find the commit that introduced the bug - Print statements at boundaries - Comment out code sections - Test with minimal reproduction ## Phase 3: HYPOTHESIZE (Form a Theory) **Write your hypothesis BEFORE fixing:** ``` I believe [X] is broken because [Y]. Evidence supporting: - [Observation 1] - [Observation 2] Evidence against: - [Observation 3] If I change [Z], the fix should: - Make [test case] pass - Not break [other thing] ``` **Common mistake:** Fixing without understanding. You might "fix" the symptom, not the cause. **Anti-patterns:** - โ "Let me try changing this..." (random fixing) - โ "This usually works..." (cargo cult debugging) - โ "It's probably a race condition" (vague guess) ## Phase 4: VERIFY (Prove It) **Before claiming "fixed":** ``` โก Original test case now passes โก Edge cases tested โก No new regressions introduced โก Error no longer appears in logs โก Fix makes sense given the hypothesis ``` **Verification checklist:** ```bash # Run the failing test npm test -- --grep "failing test" # Check logs for errors tail -f /var/log/app.log # Test edge cases [try empty input, huge input, unicode, etc.] # Run full test suite npm test ``` ## Real Example **Bug:** "User login sometimes fails" ``` Phase 1 OBSERVE: - Error: "Invalid token" (not "wrong password") - Intermittent (10% of logins) - Started after deploying auth-service v2.3 - Only on mobile, not desktop Phase 2 ISOLATE: - Network logs: token arrives intact - Auth service: token validation fails intermittently - Added logging: token format varies slightly Phase 3 HYPOTHESIZE: - Mobile client generates tokens with different encoding - v2.3 tightened token validation - Theory: mobile token format doesn't match new validation Phase 4 VERIFY: - Fixed token format in mobile client - Tested 100 logins on mobile: 100% success - Tested desktop: still works - Checked logs: no "Invalid token" errors ``` ## Trigger Phrases - "bug", "error", "not working" - "broken", "debug", "fix this" - "doesn't work", "fails", "crash" - "่ฐ่ฏ", "ไฟฎๅค", "ๆฅ้" ## Integration - **EVR Framework** โ Each phase is Execute/Verify - **Cognitive Debt Guard** โ Document bugs in code review - **Error Recovery** โ What to do after finding the cause ## License MIT
don't have the plugin yet? install it then click "run inline in claude" again.