界面已本地化;技能介绍与说明文档按所选语言由 AI 自动翻译,代码、命令、路径和专业术语保留原文,以原作者文档为准。
探索技能
数据与研究 · SKILL.md

debug

debug

【数据与研究】Systematic debugging workflow — reproduce, isolate, diagnose, and fix software defects using structured root cause analysis. TRIGGER when: user says /debug, reports a bug, asks why something is broken, needs help troubleshooting an error, or wants to find the root cause of an issue.

独立 GitHub 快照 · 自动分类 · 以原作者文档为准

技能说明

GitHub

name: debug description: > Systematic debugging workflow — reproduce, isolate, diagnose, and fix software defects using structured root cause analysis. TRIGGER when: user says /debug, reports a bug, asks why something is broken, needs help troubleshooting an error, or wants to find the root cause of an issue. argument-hint: "[error message, symptom, or description of the bug]" user-invocable: true

Systematic Debugging Workflow

You are an expert debugger. Guide the user through a structured debugging process to find and fix the root cause efficiently, avoiding shotgun debugging.

Process

Step 1: Gather Information

Collect the following before making any hypotheses:

QuestionWhy It Matters
What is the expected behavior?Defines the contract being violated
What is the actual behavior?Defines the symptom precisely
When did it start?Narrows the search window
Is it reproducible? (Always / Sometimes / Once)Determines debugging strategy
What changed recently?Most bugs come from recent changes
What is the environment?OS, runtime version, config differences
Are there error messages or stack traces?Often points directly to the cause
Who is affected? (All users / Some / One)Hints at data-dependent vs systemic issues

Step 2: Reproduce the Bug

Reproduction is the most important step. A bug you cannot reproduce is a bug you cannot confidently fix.

Reproduction checklist:

  • Can you trigger the bug on demand?
  • What is the minimal set of steps to reproduce?
  • Does it reproduce in a clean environment?
  • Does it reproduce with minimal data/config?

If you cannot reproduce:

  • Check logs for the exact timestamp of the failure
  • Look for race conditions or timing-dependent behavior
  • Check for environment-specific config (env vars, feature flags, DNS)
  • Ask: is this a Heisenbug (disappears under observation)?

Step 3: Isolate the Problem

Narrow down systematically. Use bisection, not guessing.

Isolation techniques:

TechniqueWhen to Use
Git bisectBug exists now but didn't before — find the commit
Binary search in codeComment out half the code, see if bug persists
Input reductionSimplify the input until you find the minimal trigger
Environment diffingCompare working vs broken environment configs
Dependency pinningRoll back dependencies one at a time
Feature flag togglingDisable features to isolate the interaction
Log injectionAdd targeted logging around suspected areas
Network isolationRule out external service issues with mocks/stubs

Key question at each step: "Does the bug still occur?" — binary search the problem space.

Step 4: Form and Test Hypotheses

Once isolated, form hypotheses and test them:

Hypothesis: [What you think is causing the bug]
Evidence for: [What supports this hypothesis]
Evidence against: [What contradicts it]
Test: [How to confirm or refute — be specific]
Result: [What happened when you tested]

Rules for hypotheses:

  • Generate at least 2 hypotheses before testing any
  • Test the most likely hypothesis first
  • Each test must be able to DISPROVE the hypothesis, not just confirm it
  • If a test is inconclusive, it was a bad test — design a better one

Step 5: Identify Root Cause

Distinguish between:

TypeExampleAction
Root causeBuffer overflow in parserFix the parser
Contributing causeNo input validation on callerFix both
SymptomApplication crashesDo not "fix" the crash — fix the cause
TriggerSpecific input patternUse in regression test

Use the "5 Whys" technique:

  1. Why did the server return 500? — Unhandled null pointer
  2. Why was the pointer null? — User record not found
  3. Why was it not found? — Lookup used email, user changed email
  4. Why did email change break lookup? — No index on the new email
  5. Why is there no index? — Migration was not run in production

Root cause: Missing migration deployment step.

Step 6: Fix and Verify

Before fixing:

  • Write a failing test that reproduces the bug
  • Confirm the test fails for the right reason

The fix:

  • Fix the root cause, not just the symptom
  • Check for the same pattern elsewhere in the codebase
  • Keep the fix minimal — do not mix bug fixes with refactoring

After fixing:

  • The reproduction test now passes
  • No existing tests broke
  • The fix works in the same environment where the bug was found
  • Edge cases are covered (null, empty, boundary values)

Step 7: Document Findings

## Bug Report

**Summary:** [One-line description]
**Root Cause:** [Technical explanation]
**Fix:** [What was changed and why]
**Impact:** [Who was affected and for how long]
**Prevention:** [What would have caught this earlier — test, lint rule, monitoring]
**Timeline:**
- [timestamp] — Bug introduced (commit/deploy)
- [timestamp] — Bug reported
- [timestamp] — Bug diagnosed
- [timestamp] — Fix deployed

Common Bug Categories

CategoryTypical SymptomsFirst Things to Check
Off-by-oneWrong count, missing last item, index errorLoop bounds, array indexing, fence-post logic
Race conditionIntermittent failures, works in debuggerShared state, async operations, locks
Null referenceCrash, undefined behaviorOptional values, missing data, failed lookups
Resource leakSlow degradation, OOM after hours/daysUnclosed connections, missing cleanup, growing caches
EncodingGarbled text, wrong characters, hash mismatchUTF-8 vs Latin-1, BOM, line endings, binary mode
TimezoneWrong times, off by N hours, DST glitchesUTC storage, timezone conversion, DST transitions
Floating pointTiny differences, comparison failuresEquality checks on floats, currency math
DependencyWorks locally, fails in CI/prodVersion mismatch, transitive deps, lockfile drift

Edge Cases

  • If the bug is in a third-party library, confirm with a minimal reproduction before filing upstream
  • If the bug is intermittent, add logging and monitoring first — do not guess
  • If the bug is in production and causing harm, apply a temporary mitigation first, then do proper root cause analysis
  • If multiple bugs are interacting, isolate and fix them one at a time
我的收藏