--- name: "Fix Bug" description: "Reproduce a bug, patch the root cause, add regression coverage, and validate" --- # Skill: Fix Bug ## 1. Purpose To isolate the exact conditions causing a system failure, apply a permanent patch to the root cause, and write a regression test. ## 2. When to Use When a bug report is raised or test assertions fail in production/local environments. ## 3. Preconditions * Access to local logs showing error tracebacks. * Test environment configured to execute regression scripts. ## 4. Step-by-Step Checklist 1. Read error traceback logs to identify the module and file. 2. Write a minimal reproduction test case that successfully fails. 3. Debug the logic flow (e.g. check for null variables or missing try-except wrappers). 4. Apply the patch to the root cause (do not just patch the symptoms). 5. Execute the reproduction test case and ensure it now passes. ## 5. Validation Checklist * The reproduction test case executes and passes. * Entire existing test suite passes (zero regression breakages). * Logic changes do not introduce performance downgrades. ## 6. Examples ```python # Symptom patch (Bad): if x is None: return 0 # Root cause patch (Good): ensure database query defaults are instantiated during model creation. ``` ## 7. Failure Cases * Adding conditional checks that temporarily hide errors, leading to silent database state corruption. * Fixing code without writing a regression test, allowing the bug to return in future refactors.