Phase gated debugging

From Fandry96/k3-agentic-skills · View interactive version

Phase gated debugging is an AI agent skill from the GitHub repository Fandry96/k3-agentic-skills. Use when debugging any bug. Enforces a 5-phase protocol where code edits are blocked until root cause is confirmed. Prevents premature fix attempts.

How to use this skill

Skill file

Phase-Gated Debugging

Overview

AI coding agents see an error and immediately edit code. They guess at fixes, get it wrong, and spiral. This skill enforces a strict 5-phase protocol where you CANNOT edit source code until the root cause is identified and confirmed.

Based on claude-debug (full plugin with PreToolUse hook enforcement).

When to Use

Use this skill when:

The Protocol

Phase 1: REPRODUCE

Run the failing command/test. Capture the exact error. Run 2-3 times for consistency.

Phase 2: ISOLATE

Read code. Add diagnostic logging marked // DEBUG. Re-run with diagnostics. Binary search to narrow down.

Phase 3: ROOT CAUSE

Analyze WHY at the isolated location. Use "5 Whys" technique. Remove debug logging.

State: "This is my root cause analysis: [explanation]. Do you agree, or should I investigate further?"

WAIT for user confirmation. Do NOT proceed without it.

Phase 4: FIX

Remove all // DEBUG lines. Apply minimal change addressing confirmed root cause.

Phase 5: VERIFY

Run original failing test — must pass. Run related tests. For intermittent bugs, run 5+ times.

If verification fails: root cause was wrong, go back to Phase 2.

Bug-Type Strategies

| Type | Technique |

|------|-----------|

| Crash/Panic | Stack trace backward — trace the bad value to its source |

| Wrong Output | Binary search — log midpoint, halve search space each iteration |

| Intermittent | Compare passing vs failing run logs — find ordering divergence |

| Regression | git bisect — find the offending commit |

| Performance | Timing at stage boundaries — find the bottleneck |

Key Rules

  1. NEVER edit source code in phases 1-3 (except // DEBUG in phase 2)
  2. NEVER proceed past phase 3 without user confirmation
  3. ALWAYS reproduce before investigating
  4. ALWAYS verify after fixing
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.