Fix bug

From hawkyre/hawk-skills · View interactive version

Fix bug is an AI agent skill from the GitHub repository hawkyre/hawk-skills. Find and fix the cause of a reported bug, crash, regression, or intermittent failure. Use when symptoms are vague or reproduction is difficult. Rank hypotheses before inspecting code. Require a failing reproduction and evidence that the fix passes. Route design-level changes through the planning ski

How to use this skill

Skill file

Fix a Bug

Process

Step 1 — Collect the symptom

Ensure you have:

Step 2 — Generate hypotheses BEFORE looking at code

Step 3 — Online research (always considered, applied when triggered)

At the hypothesis stage, always pause and ask whether online research applies to this bug. Apply it when any of these heuristics matches:

When triggered, use:

Fold findings back into the hypothesis list:

If none of the heuristics match, skip online research and go to Step 4. The skill always considers research; it does not always perform it.

Step 4 — Investigate top hypothesis

Read the relevant code. Compare evidence against the hypothesis. Three branches:

If still ambiguous within a hypothesis, add a targeted log/print or run a focused test before continuing. For large search spaces, dispatch an Explore subagent to keep main context focused on the fix.

Step 5 — Fix the bug class at its source

5a. Reproduction test first

Write a test that reproduces the bug. Run it and capture the failing run:

<test-cmd for the new test> > /tmp/hawk-fix-bug-repro-pre.log 2>&1

If the test doesn't fail pre-fix, you haven't actually reproduced the bug — return to Step 4 before proceeding. A "fix" without a failing reproduction is a guess.

5b. Heisenbugs — when reproduction is genuinely infeasible

If reproduction is genuinely infeasible after reasonable effort (race conditions, environmental dependencies, load-only failures), stop and surface this to the user before attempting a fix. A fix without a reproduction is shipping a guess; the user must consciously agree to that trade-off. The typical right next step is to add instrumentation/logging that will catch the bug in the wild on the next occurrence — not blind-fixing.

5c. Implement the fix — at the source, and not lazy

Think in systems. This bug is one member of a class. Before you write the fix, name the class and the source that lets it occur: a missing invariant, a weak type, an unchecked boundary, duplicated logic, or two sources of truth. Fix the source so that the whole class cannot occur, not only this instance. A fix at the symptom site works once; the next member of the class needs another patch, and patches pile up.

Work outside this bug class is a separate task. Do not fold it in.

Reject the lazy patch. A fix that silences the symptom without addressing the cause is worse than no fix — it makes the underlying issue invisible to the next developer. The following are lazy patches; if your candidate fix matches any of them, revert and treat the bug as design-level (5g):

If the fix is a one-liner at the symptom site, be suspicious. Check whether it closes the class or only this instance. If it closes only this instance, it is not the fix.

5d. Verify the test passes

Run the reproduction test again. It must now pass. Capture:

<test-cmd for the new test> > /tmp/hawk-fix-bug-repro-post.log 2>&1

Claiming "fixed" without the post-fix passing log on disk is not allowed. The two files (-pre.log failing, -post.log passing) are the evidence the fix did what it claims. Self-asserted "I verified it" is the canonical hallucination pattern; evidence on disk is not.

5e. Bugs travel in packs

Grep for the bug fingerprint across the repo:

rg -n '<fingerprint>' . > /tmp/hawk-fix-bug-pattern.log 2>&1
rg -n '<narrower pattern>' /tmp/hawk-fix-bug-pattern.log | head -50

Each sibling instance is a member of the class. The fix at the source must close all of them. If an instance stays open, the fix is at the wrong level: go back to 5c. When a sibling exists, add a test for it too. If the source fix spans modules or PRs, use 5g.

5f. Full check command — with the layered retry ladder

Run the project's full check command (full test suite, type-check, lint — not a partial scope). Regression-check is the whole suite; a bug fix that introduces a regression elsewhere is worse than the original bug.

<check-cmd> > /tmp/hawk-fix-bug-check.log 2>&1
rg -n 'error|warning|fail|FAIL' /tmp/hawk-fix-bug-check.log | head -50

If the check fails, escalate through the layered ladder (matches implement-plan substep 3.5 — the retry ladder — with one bug-fix-specific divergence at Stage 3, called out below):

5g. Design-level bugs — route through plan skills

If the investigation reveals that the bug's root cause is structural — the design is wrong, not a specific line — a fix inside this session is the wrong tool. The lazy-patch list above triggers this; so does a hypothesis revealing that the bug class will recur in different shapes until the underlying design changes.

Stop the in-session fix and route the work to a plan:

Surface the design concern to the user with a one-line summary. The default is the plan for the class. A patch for this instance first is valid only when the user asks for it, for example to stop a production incident. In that case, write the plan for the class too. Never ship a band-aid without the plan.

Step 6 — Update common-mistakes if applicable

If the bug pattern is novel for this codebase, add an entry to .agents/common-mistakes/ so the next implementer doesn't recreate it. Include the symptom, the cause, and the fix.

If online research was load-bearing for the fix, capture the URL + brief in the common-mistake entry. Future you will not remember which Stack Overflow answer it was.

Committing the fix

If a commit is being made, delegate to implement-plan contract CC-1 (Step 3.5 — Commit cadence) in full — stop-out edge cases (mid-rebase / mid-merge / unresolved conflicts), discovery-based staging, repo style mirroring via git log -10 --oneline, no --amend, no --no-verify, and no AI attribution ever (no Co-Authored-By: Claude, no 🤖, no "Generated with Claude" line).

The reproduction test goes in the same commit as the fix — they're one logical change, and you want future bisects to see the test arriving with the code it covers.

Rules — pointer index

Anchors back to Process. The canonical statement of each rule lives in the section it points to; this index exists so callers can cite "rule X" without re-stating it.

Two cross-cutting rules that don't have a single Process anchor:

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.