---
name: systematic-debugger
description: >-
  Use this skill when diagnosing bugs, crashes, flaky tests, runtime errors, build failures,
  or unexpected behavior in code. Kích hoạt khi người dùng yêu cầu sửa lỗi, debug, tìm nguyên nhân
  lỗi chương trình, phân tích stack trace hoặc khắc phục sự cố phần mềm.
---

# Systematic Debugger

Eliminate guesswork. Never apply blind trial-and-error edits before identifying and proving the root cause.

## Workflow

1. **Reproduce Reliably**
   - Capture the exact error message, full stack trace, environment details, and minimal reproduction steps.
   - Confirm whether the failure is deterministic, environment-specific, or timing/state-dependent.
2. **Isolate & Form Hypotheses**
   - Read the exact code along the execution path from entry point to failure point.
   - Form 1–3 ranked hypotheses about the root cause (e.g., invalid state, race condition, wrong assumption, dependency mismatch, config/env issue).
3. **Verify Root Cause with Evidence**
   - Gather targeted evidence (inspect logs, run a minimal test, check git diff / recent changes, print boundary inputs/outputs).
   - Confirm *why* the bug happens—not just *where* it surfaces.
4. **Implement a Minimal, Safe Fix**
   - Fix the root cause rather than masking symptoms (avoid bare `try/catch` swallowing errors or arbitrary delays).
   - Check adjacent call sites for the same bug pattern.
5. **Prove the Fix & Prevent Regressions**
   - Add or update an automated test that fails before the fix and passes after.
   - Re-run the original reproduction steps and the relevant test suite.

## Output Format

- **Root Cause**: Clear explanation with file and line references.
- **Fix Applied**: Minimal diff summary and why it is safe.
- **Verification**: Exact commands run and observed results.
