๐ŸŽ Get the FREE AI Skills Starter Guide โ€” Subscribe โ†’
BytesAgainBytesAgain
๐Ÿฆ€ ClawHub

Debug Methodology

by @abczsl520

Systematic debugging and problem-solving methodology. Activate when encountering unexpected errors, service failures, regression bugs, deployment issues, or...

Versionv1.2.0
Downloads2,876
TERMINAL
clawhub install debug-methodology

๐Ÿ“– About This Skill


name: debug-methodology description: Systematic debugging and problem-solving methodology. Activate when encountering unexpected errors, service failures, regression bugs, deployment issues, or when a fix attempt has failed twice. Also activate when proposing ANY fix to verify it addresses root cause (not a workaround). Prevents patch-chaining, wrong-environment restarts, workaround addiction, and "drunk man" random fixes.

Debug Methodology

Systematic approach to debugging and problem-solving. Distilled from real production incidents and industry best practices.

โš ๏ธ The Root Cause Imperative

Every fix MUST target the root cause. Workarounds are forbidden unless explicitly approved.

Before proposing ANY solution, pass the Root Cause Gate:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚            ROOT CAUSE GATE                  โ”‚
โ”‚                                             โ”‚
โ”‚  1. What is the ACTUAL problem?             โ”‚
โ”‚  2. WHY does it happen? (not just WHAT)     โ”‚
โ”‚  3. Does my fix eliminate the WHY?           โ”‚
โ”‚     YES โ†’ proceed                           โ”‚
โ”‚     NO  โ†’ this is a workaround โ†’ STOP       โ”‚
โ”‚                                             โ”‚
โ”‚  Workaround test:                           โ”‚
โ”‚  "If I remove my fix, does the bug return?" โ”‚
โ”‚     YES โ†’ workaround (fix the cause instead)โ”‚
โ”‚     NO  โ†’ genuine fix โœ…                    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The 5 Whys โ€” Mandatory for Non-Obvious Problems

Problem: API returns 524 timeout
  Why? โ†’ Cloudflare cuts connections >100s
  Why? โ†’ The API call takes >100s
  Why? โ†’ Using non-streaming request, server holds connection silent
  Why? โ†’ Code uses regular fetch, not streaming
  Fix: โ†’ Use streaming (server sends data continuously, Cloudflare won't cut)

โŒ WRONG: Switch to faster model (workaround โ€” avoids the timeout instead of fixing it) โœ… RIGHT: Use streaming API (root cause โ€” Cloudflare needs ongoing data)

Common Workaround Traps

| Problem | Workaround (โŒ) | Root Cause Fix (โœ…) | |---------|----------------|-------------------| | API timeout | Switch to faster model | Use streaming / fix the slow query | | Data precision loss | Search by name instead of ID | Fix BigInt parsing | | Search returns nothing | Try different search strategy | Fix the search implementation | | Dependency conflict | Downgrade / pin version | Use correct environment (venv) | | Feature doesn't work | Remove the feature | Debug why it fails |

Self-check question: "Am I solving the problem, or avoiding it?"

Phase 1: STOP โ€” Assess Before Acting

Before ANY fix attempt:

โ–ก What is the EXACT symptom? (error message, behavior, screenshot)
โ–ก When did it last work? What changed since then?
โ–ก How is the service running? (process, env, startup command)

For running services:

ps -p  -o command=        # How was it started?
ls .venv/ venv/ env/           # Virtual environment?
which python3 && python3 --version
which node && node --version

NEVER restart a service without first recording its original startup command.

Phase 2: Hypothesize โ€” Form ONE Theory

Priority order: 1. Did I change something? โ†’ diff/revert first 2. Did the environment change? โ†’ versions, deps, configs 3. Did external inputs change? โ†’ API responses, data formats 4. Genuine new bug? โ†’ only after ruling out 1-3

Phase 3: Test โ€” One Change at a Time

Change X โ†’ Test โ†’ Works? โ†’ Done
                โ†’ Fails? โ†’ REVERT X โ†’ new hypothesis

Do NOT stack changes.

Phase 4: Patch-Chain Detection

2 fix attempts failed โ†’ STOP. Revert ALL. Back to Phase 1.

You are likely:

  • Fixing symptoms of a wrong fix
  • In the wrong environment entirely
  • Misunderstanding the architecture
  • Phase 5: Post-Fix Verification

    After any fix, verify:

    โ–ก Does it solve the ORIGINAL problem? (not just silence the error)
    โ–ก Did I introduce new issues? (regression check)
    โ–ก Would removing my fix bring the bug back? (confirms causality)
    โ–ก Is the fix in the right layer? (not patching symptoms upstream)
    

    Anti-Patterns

    ๐Ÿšจ Workaround Addiction (NEW โ€” Most Common!)

    Bypassing the problem instead of fixing it. "It's slower but works" / "Use a different approach". โ†’ Ask: "Am I solving or avoiding?" If avoiding โ†’ find the real fix. โ†’ Workarounds are ONLY acceptable when: (1) explicitly approved by user, (2) clearly labeled as temporary, (3) a TODO is created for the real fix.

    ๐Ÿšจ Drunk Man Anti-Pattern

    Randomly changing things until the problem disappears. โ†’ Each change needs a hypothesis.

    ๐Ÿšจ Streetlight Anti-Pattern

    Looking where comfortable, not where the problem is. โ†’ "Is this where the bug IS, or where I KNOW HOW TO LOOK?"

    ๐Ÿšจ Cargo Cult Fix

    Copying a fix without understanding why it works. โ†’ Understand the mechanism first.

    ๐Ÿšจ Ignoring the User

    User says "it broke after you changed X" โ†’ immediately diff X. โ†’ User observations are the most valuable data.

    Environment Checklist

    โ–ก Runtime: system or venv/nvm?
    โ–ก Dependencies: match expected versions?
    โ–ก Config: .env, config.json โ€” recent changes?
    โ–ก Process manager: PM2/systemd โ€” restart method?
    โ–ก Logs: tail -f before reproducing
    โ–ก Backup: snapshot before any change
    

    Deployment Safety (Hardened SCP Flow)

    Iron Rule: NEVER edit files directly on the server. NEVER overwrite server files without backup.

    Standard deployment (every time, no exceptions):

    1. PULL scp server:/opt/apps/้กน็›ฎ/ ./local-้กน็›ฎ/ (pull the files you need + related files)

    2. EDIT Make changes locally (complex multi-line โ†’ write full file, never sed)

    3. VERIFY node -c *.js # syntax check node -e "require('./file')" # module load check (STOP if verification fails โ€” do not proceed)

    4. BACKUP ssh server "cp file file.bak.$(date +%s)"

    5. PUSH scp ./local-file server:/opt/apps/้กน็›ฎ/file

    6. RESTART pm2 restart (use SAME method as original โ€” check ps/pm2 show first)

    7. HEALTH curl -s http://localhost:/health pm2 logs --lines 5 --nostream (if unhealthy โ†’ revert backup immediately)

    Pull Scope Rules

    Changing 1 file    โ†’ pull that file + its imports/importers
    Changing routes    โ†’ also pull server.js (check mount points)
    Changing frontend  โ†’ also pull index.html (check script tags)
    Changing config    โ†’ also pull code that reads the config
    Unsure what to pull โ†’ pull the whole project directory
    

    What NOT to Do

    โŒ sed -i for multi-line code on server
    โŒ Skip node -c after editing .js
    โŒ pm2 restart before syntax verification
    โŒ Tell user to refresh before health check passes
    โŒ Push without backup
    

    ๐Ÿšจ Server Code Modification Rules

    Every code change on a server MUST be syntax-verified before restart/reload.

    After editing .js files:
      โ–ก node -c                           # Syntax check
      โ–ก node -e "require('./')"           # Module load check (for route files)
      โ–ก FAIL โ†’ DO NOT restart. DO NOT tell user to refresh. Fix first.

    After editing .html files: โ–ก Check critical tag closure (div/script/style) โ–ก grep -c '

    Complex multi-line changes: โ–ก Write complete file locally โ†’ scp upload โ–ก NEVER use sed for multi-line code insertion (newlines get swallowed) โ–ก If sed is unavoidable โ†’ verify with node -c immediately after

    Restart sequence: โ–ก node -c *.js passes โ†’ pm2 restart โ–ก Check pm2 logs --lines 5 for startup errors โ–ก curl health endpoint to confirm service is up

    Why: sed -i multi-line insertion silently corrupts JS (newlines become single line), causing syntax errors that break the entire page with no visible error to the user.

    Decision Tree

    Problem appears
      โ”œโ”€ I just edited something? โ†’ DIFF โ†’ REVERT if suspect
      โ”œโ”€ Service won't start? โ†’ CHECK startup command + env
      โ”œโ”€ New error after fix? โ†’ STOP (patch chain!) โ†’ Revert โ†’ Phase 1
      โ”œโ”€ User reports regression? โ†’ DIFF before/after
      โ”œโ”€ Tempted to work around? โ†’ ROOT CAUSE GATE โ†’ fix the real issue
      โ””โ”€ Intermittent? โ†’ CHECK logs + external deps + timing