--- name: issue-resolution description: Systematically diagnose and fix bugs through triage, reproduction, root cause analysis, and verified fixes. Use when resolving bugs, errors, failing tests, or investigating unexpected behavior. --- # Issue Resolution Pipeline Systematically resolve issues through iterative diagnosis and verified fixes. ## Pipeline Overview ``` INPUT → Triage → Reproduction → Root Cause Analysis → Impact → Fix → Verify ◄──────────────►◄────────────────────► (Iterative loops allowed) ``` | Phase | Purpose | Output | | ---------------------- | ---------------------------------- | ------------------- | | 0. Triage | Normalize input, classify severity | Issue Brief | | 1. Reproduction | Prove the bug, trace code path | Repro Report + Test | | 2. Root Cause Analysis | Find WHY, not just WHERE | RCA Report | | 3. Impact Assessment | Blast radius, regression risk | Impact Report | | 4. Fix Decomposition | Break into beads | .beads/\*.md | | 5. Verification | Prove fix works, no regressions | Passing tests | ## Phase 0: Triage Normalize different input types to a structured Issue Brief. ### Input Types | Type | Triage Strategy | | --------------------- | ------------------------------------- | | **Vague report** | Clarify → Explore → Reproduce | | **Error/Stack trace** | Parse trace → Locate code → Reproduce | | **Failing test** | Run test → Extract assertion → Trace | ### Vague Report Triage ``` User: "Login is broken" │ ▼ Ask clarification questions: • What error do you see? • When did it start working / stop working? • What steps trigger it? • Specific user/browser/environment? │ ▼ (if user can't clarify) Explore: • mcp__gkg__search_codebase_definitions: Find auth/login related code • git log: Recent changes in area • Check logs if available ``` ### Error/Stack Trace Triage ``` Parse the stack trace: • Extract file:line locations • mcp__gkg__get_definition on functions in trace • Read surrounding context │ ▼ Identify reproduction conditions: • What input caused this? • Can we write a test? ``` ### Failing Test Triage ``` Run test in isolation: • bun test --filter "" • Read test file for setup/assertions • Check git log: was it passing before? │ ▼ Trace implementation: • What code does test exercise? • mcp__gkg__get_references on tested function • Recent changes to implementation? ``` ### Severity Classification Determines reproduction requirements: | Severity | Reproduction Required | | ----------------------------------- | ---------------------- | | **CRITICAL** (production, security) | Failing test REQUIRED | | **REGRESSION** (was working) | Failing test REQUIRED | | **RACE CONDITION** (timing) | Failing test REQUIRED | | **LOGIC BUG** | Failing test PREFERRED | | **UI/VISUAL** | Manual + screenshot OK | | **PERFORMANCE** | Benchmark/profile OK | | **QUICK FIX** (obvious cause) | Manual repro OK | ### Issue Brief Template Save to `history/issues//brief.md`: ```markdown # Issue Brief: **Severity**: CRITICAL / HIGH / MEDIUM / LOW **Type**: Regression / Edge case / Race condition / UI / Performance / Other **Repro Required**: Failing test / Manual OK ## Symptom ## Expected Behavior ## Reproduction ## Evidence ## Affected Area ## Timeline ``` ## Phase 1: Reproduction Prove the bug exists and trace the code path. ### If Failing Test Required ```bash # Create test file # packages//src/__tests__/.regression.test.ts # Test should: # 1. Set up conditions that trigger bug # 2. Assert expected behavior (currently fails) # 3. Be deterministic ``` ### Reproduction Checklist - [ ] Bug is reproducible on demand - [ ] Exact error/behavior captured - [ ] Minimal reproduction (simplest case that fails) - [ ] Code path identified (stack trace or tracing) ### Code Path Tracing ``` mcp__gkg__get_definition → Find where error originates mcp__gkg__get_references → Find callers git blame → Who changed it, when git log -p → What changed recently ``` ### Repro Report Template Save to `history/issues//repro.md`: ```markdown # Reproduction Report: ## Reproduction Method ☐ Failing test: `` ☐ Manual: ## Error/Behavior Captured ## Code Path 1. Entry: `:` - 2. Calls: `:` - 3. Fails at: `:` - ## Recent Changes (if relevant) - : ``` ## Phase 2: Root Cause Analysis Find WHY the bug happens, not just WHERE. ### RCA Framework ``` STEP 1: Generate hypotheses (3-5) │ ▼ STEP 2: Gather evidence for/against each │ ▼ STEP 3: Eliminate hypotheses │ ▼ STEP 4: Confirm root cause ``` ### Bug Type → RCA Strategy | Bug Type | Strategy | Key Tools | | ------------------- | ------------------------- | ------------------------------- | | **Regression** | Find breaking change | `git bisect`, `git blame` | | **Edge case** | Analyze boundary inputs | Type inspection, boundary tests | | **Race condition** | Trace async flow | Timing logs, async analysis | | **Data corruption** | Trace state changes | Data flow analysis | | **External dep** | Check version/API changes | Changelogs, API docs | ### Oracle for RCA **Hypothesis Generation:** ``` oracle( task: "Generate root cause hypotheses", context: """ Symptom: Code path: Recent changes: Generate 3-5 hypotheses ranked by likelihood. For each, what evidence would support/refute it? """, files: [""] ) ``` **Hypothesis Validation:** ``` oracle( task: "Validate root cause hypothesis", context: """ Hypothesis: Evidence: 1. Does evidence support or refute? 2. Explain causal chain: cause → symptom 3. What would confirm this? """, files: [""] ) ``` ### Iteration: RCA → Reproduction Loop If hypothesis needs more evidence: ``` IN RCA: "Need timing logs to confirm race condition" │ ▼ BACK TO REPRO: • Add instrumentation • Run with specific conditions • Capture new evidence │ ▼ RETURN TO RCA with new evidence ``` ### RCA Report Template Save to `history/issues//rca.md`: ```markdown # Root Cause Analysis: ## Iteration: ## Hypotheses Considered ### Hypothesis A: - **Likelihood**: HIGH / MEDIUM / LOW - **Supporting evidence**: ... - **Refuting evidence**: ... - **Verdict**: ✓ CONFIRMED / ✗ ELIMINATED ### Hypothesis B: ... ## Root Cause (Confirmed) **Cause**: **Causal chain**: 1. leads to 2. leads to 3. ## Why This Happened ## Fix Approach **Immediate**: **Preventive**: ``` ## Phase 3: Impact Assessment Before fixing, understand blast radius. ### Impact Analysis ``` mcp__gkg__get_references → Who else calls this? Grep for related patterns → Similar code that might have same bug? Review test coverage → What tests cover this area? ``` ### Regression Risk | Factor | Risk Level | | ------------------- | ---------- | | High usage function | HIGH | | Shared utility | HIGH | | Public API change | HIGH | | Internal helper | LOW | | Isolated module | LOW | ### Spike for Complex Fixes If fix approach is uncertain: ```bash bd create "Spike: Validate fix approach for " -t task -p 0 ``` Execute via MULTI_AGENT_WORKFLOW, write to `.spikes//`. ### Impact Report Template Save to `history/issues//impact.md`: ```markdown # Impact Assessment: ## Blast Radius ### Direct Impact - ### Callers Affected - ### Related Code - ## Regression Risk **Level**: HIGH / MEDIUM / LOW **Reason**: ## Test Coverage - Existing tests: - Tests to add: ## Fix Validation ☐ Spike completed (if needed): `.spikes//` ☐ Fix approach validated ``` ## Phase 4: Fix Decomposition Break fix into beads. ### Simple Fix (Single Bead) ```bash bd create "Fix: " -t bug -p ``` Bead includes: - Root cause reference - Fix implementation - Test (failing → passing) - Docs update (if behavior change) ### Complex Fix (Multiple Beads) ```bash bd create "Epic: Fix " -t epic -p bd create "Add regression test for " -t task --blocks bd create "Fix " -t bug --blocks --deps bd create "Fix " -t bug --blocks --deps bd create "Update docs for " -t task --blocks --deps , ``` ### Fix Bead Template ```markdown # Fix: **Type**: bug **Priority**: <0-4> **Fixes**: ## Root Cause ## Fix Implementation ## Files to Modify - ``: ## Acceptance Criteria - [ ] Regression test passes - [ ] Original symptom no longer reproducible - [ ] No new test failures - [ ] `bun run check-types` passes - [ ] `bun run build` passes ``` ## Phase 5: Verification Prove fix works and nothing else broke. ### Verification Checklist ```bash # 1. Regression test passes bun test # 2. Original symptom gone # 3. No new failures bun run test # 4. Types and build bun run check-types bun run build ``` ### Iteration: Verify → RCA Loop If fix doesn't work: ``` Test still fails after fix │ ▼ Root cause was wrong or incomplete │ ▼ BACK TO RCA: • Eliminate current hypothesis • Generate new hypotheses • Update RCA Report with iteration ``` ### Verify → Impact Loop If fix causes regressions: ``` New test failures after fix │ ▼ Fix has unintended side effects │ ▼ BACK TO IMPACT: • Reassess blast radius • Consider alternative fix approach ``` ## Loop Limits Prevent infinite iteration: | Loop | Soft Limit | Hard Limit | At Hard Limit | | ------------ | ---------- | ---------- | --------------------------- | | RCA → Repro | 2 | 4 | Escalate / pair debug | | RCA → Triage | 1 | 2 | Re-evaluate original report | | Verify → RCA | 2 | 3 | Oracle deep review | ## Quick Reference ### Tool Selection | Need | Tool | | --------------------- | ------------------------------- | | Parse stack trace | Read + mcp**gkg**get_definition | | Find callers | mcp**gkg**get_references | | Recent changes | git log, git blame | | Binary search commits | git bisect | | Reasoning about cause | oracle | | Validate fix approach | Spike via MULTI_AGENT_WORKFLOW | ### Common Mistakes - **Fixing symptom, not cause** → Leads to recurrence - **Skipping reproduction** → Can't verify fix - **No regression test** → Bug returns later - **Ignoring impact** → Fix breaks other things - **Not iterating** → Wrong diagnosis persists