--- name: git-bisect-debugging description: Use when debugging regressions or identifying which commit introduced a bug - provides systematic workflow for git bisect with automated test scripts, manual verification, or hybrid approaches. Can be invoked from systematic-debugging as a debugging technique, or used standalone when you know the issue is historical. --- # Git Bisect Debugging ## Overview Systematically identify which commit introduced a bug or regression using git bisect. This skill provides a structured workflow for automated, manual, and hybrid bisect approaches. **Core principle:** Binary search through commit history to find the exact commit that introduced the issue. Main agent orchestrates, subagents execute verification at each step. **Announce at start:** "I'm using git-bisect-debugging to find which commit introduced this issue." ## Quick Reference | Phase | Key Activities | Output | |-------|---------------|--------| | **1. Setup & Verification** | Identify good/bad commits, verify clean state | Confirmed commit range | | **2. Strategy Selection** | Choose automated/manual/hybrid approach | Test script or verification steps | | **3. Execution** | Run bisect with subagents | First bad commit hash | | **4. Analysis & Handoff** | Show commit details, analyze root cause | Root cause understanding | ## MANDATORY Requirements These are **non-negotiable**. No exceptions for time pressure, production incidents, or "simple" cases: 1. **ANNOUNCE skill usage** at start: ``` "I'm using git-bisect-debugging to find which commit introduced this issue." ``` 2. **CREATE TodoWrite checklist** immediately (before Phase 1): - Copy the exact checklist from "The Process" section below - Update status as you progress through phases - Mark phases complete ONLY when finished 3. **VERIFY safety checks** (Phase 1 - no skipping): - Working directory MUST be clean (`git status`) - Good commit MUST be verified (actually good) - Bad commit MUST be verified (actually bad) - If ANY check fails -> abort and fix before proceeding 4. **USE AskUserQuestion** for strategy selection (Phase 2): - Present all 3 approaches (automated, manual, hybrid) - Don't default to automated without asking - User must explicitly choose 5. **LAUNCH subagents** for verification (Phase 3): - Main agent: orchestrates git bisect state - Subagents: execute verification at each commit (via Task tool) - NEVER run verification in main context - Each commit tested in isolated subagent 6. **HANDOFF to systematic-debugging** (Phase 4): - After finding bad commit, announce handoff - Use superpowers:systematic-debugging skill - Investigate root cause, not just WHAT changed ## Red Flags - STOP and Follow the Skill If you catch yourself thinking ANY of these, you're about to violate the skill: - "User is in a hurry, I'll skip safety checks" -> NO. Run all safety checks. - "This is simple, no need for TodoWrite" -> NO. Create the checklist. - "I'll just use automated approach" -> NO. Use AskUserQuestion. - "I'll run the test in my context" -> NO. Launch subagent. - "Found the commit, that's enough" -> NO. Handoff to systematic-debugging. - "Working directory looks clean" -> NO. Run `git status` to verify. - "I'll verify good/bad commits later" -> NO. Verify BEFORE starting bisect. **All of these mean: STOP. Follow the 4-phase workflow exactly.** ## The Process Copy this checklist to track progress: ``` Git Bisect Progress: - [ ] Phase 1: Setup & Verification (good/bad commits identified) - [ ] Phase 2: Strategy Selection (approach chosen, script ready) - [ ] Phase 3: Execution (first bad commit found) - [ ] Phase 4: Analysis & Handoff (root cause investigation complete) ``` ### Phase 1: Setup & Verification **Purpose:** Ensure git bisect is appropriate and safe to run. **Steps:** 1. **Verify prerequisites:** - Check we're in a git repository - Verify working directory is clean (`git status`) - If uncommitted changes exist, abort and ask user to commit or stash 2. **Identify commit range:** - Ask user for **good commit** (where it worked) - Suggestions: last release tag, last passing CI, commit from when it worked - Commands to help: `git log --oneline`, `git tag`, `git log --since="last week"` - Ask user for **bad commit** (where it's broken) - Usually: `HEAD` or a specific commit where issue confirmed - Calculate estimated steps: ~log2(commits between good and bad) 3. **Verify the range:** - Checkout bad commit and verify issue exists - Checkout good commit and verify issue doesn't exist - If reversed, offer to swap them - Return to original branch/commit 4. **Safety checks:** - Warn if range is >1000 commits (ask for confirmation) - Verify good commit is ancestor of bad commit - Note current branch/commit for cleanup later **Output:** Confirmed good commit hash, bad commit hash, estimated steps ### Phase 2: Strategy Selection **Purpose:** Choose the most efficient bisect approach. **Assessment:** Can we write an automated test script that deterministically identifies good vs bad? **MANDATORY: Use AskUserQuestion tool** to present these three approaches (do NOT default to automated): ```javascript AskUserQuestion({ questions: [{ question: "Which git bisect approach should we use?", header: "Strategy", multiSelect: false, options: [ { label: "Automated - test script runs automatically", description: "Fast, no manual intervention. Best for: test failures, crashes, deterministic behavior. Requires: working test script." }, { label: "Manual - you verify each commit", description: "Handles subjective issues. Best for: UI/UX changes, complex scenarios. Requires: you can manually check each commit." }, { label: "Hybrid - script + manual confirmation", description: "Efficient with reliability. Best for: mostly automated but needs judgment. Requires: script for most cases, manual for edge cases." } ] }] }) ``` **Three approaches to present:** **Approach 1: Automated Bisect** - **When to use:** Test failure, crash, deterministic behavior - **How it works:** Script returns exit 0 (good) or 1 (bad), fully automatic - **Benefits:** Fast, no manual intervention, reproducible - **Requirements:** Can write a script that runs the test/check **Approach 2: Manual Bisect** - **When to use:** UI/UX changes, subjective behavior, complex scenarios - **How it works:** User verifies at each commit, Claude guides - **Benefits:** Handles non-deterministic or subjective issues - **Requirements:** User can manually verify each commit **Approach 3: Hybrid Bisect** - **When to use:** Mostly automatable but needs human judgment - **How it works:** Script narrows range, manual verification for final confirmation - **Benefits:** Efficiency of automation with reliability of manual check - **Requirements:** Can automate most checks, manual for edge cases **If automated or hybrid selected:** Write test script following this template: ```bash #!/bin/bash # Exit codes: 0 = good, 1 = bad, 125 = skip (can't test) # Setup/build (required for each commit) npm install --silent 2>/dev/null || exit 125 # Run the actual test npm test -- path/to/specific-test.js exit $? ``` **Script guidelines:** - Make it **deterministic** (no random data, use fixed seeds) - Make it **fast** (runs ~log2(N) times) - **Exit codes:** 0 = good, 1 = bad, 125 = skip - Include build/setup (each commit might need different deps) - Test ONE specific thing, not entire suite - Make it **read-only** (no data modification) **If manual selected:** Write specific verification steps for subagent: **Good example:** ``` 1. Run `npm start` 2. Open browser to http://localhost:3000 3. Click the "Login" button 4. Check if it redirects to /dashboard 5. Respond 'good' if redirect happens, 'bad' if it doesn't ``` **Bad example:** ``` See if the login works ``` **Output:** Selected approach, test script (if automated/hybrid), or verification steps (if manual) ### Phase 3: Execution **Architecture:** Main agent orchestrates bisect, subagents verify each commit in isolated context. **Main agent responsibilities:** - Manage git bisect state (`start`, `good`, `bad`, `reset`) - Track progress and communicate remaining steps - Launch subagents for verification - Handle errors and cleanup **Subagent responsibilities:** - Execute verification in clean context (no bleeding between commits) - Report result: "good", "bad", or "skip" - Provide brief reasoning for result **Execution flow:** 1. **Main agent:** Run `git bisect start ` 2. **Loop until bisect completes:** a. Git checks out a commit to test b. **Main agent launches subagent** using Task tool: **For automated:** ``` Prompt: "Run this test script and report the result: