Bug analyzer

From event4u-app/agent-config · View interactive version

Bug analyzer is an AI agent skill from the GitHub repository event4u-app/agent-config. Use when the user shares a Sentry error, Jira bug ticket, or error description and wants root cause analysis. Also for proactive bug hunting and code audits for hidden bugs.

How to use this skill

Skill file

bug-analyzer

When to use

Reactive mode: User reports a bug, shares a Sentry issue, or asks to investigate an error.

Proactive mode: User asks to audit code for hidden bugs, edge cases, or risky patterns.

Do NOT use when:

CODE0

route to CODE0

Input sources

Bugs can come from multiple sources — gather as many as available:

| Source | What it provides |

|---|---|

| Branch name | Auto-detected ticket ID (e.g., fix/DEV-1234/...) |

| Jira ticket | Description, acceptance criteria, comments, priority |

| Sentry issue URL | Stacktrace, affected users/environments, frequency, tags |

| Sentry event ID | Specific occurrence with full context |

| Error message | String to search in codebase |

| User description | Reproduction steps, expected vs. actual behavior |

Branch ticket detection

Always check the current branch for ticket IDs:

git branch --show-current

Pattern matching:

If found, auto-fetch the ticket and confirm with the user.

The Iron Law

NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST

If you haven't completed Phase 1, you cannot propose fixes. Random fixes waste time and

create new bugs. Quick patches mask underlying issues.

Red flags — STOP immediately

Procedure: Analyze a bug

  1. Inspect inputs and reproducers — Pull every source named in Input sources (branch, Jira, Sentry, error string, user description) before forming a hypothesis.
  2. Investigate root cause — Run Phase 1 below; gather evidence, walk the stacktrace, consult engineering memory.
  3. Find the pattern — Run Phase 2; check for similar bugs elsewhere in the codebase.
  4. Form and test a hypothesis — Run Phase 3; write a failing test that reproduces the bug.
  5. Fix and verify — Run Phase 4; apply the minimal change, re-run the failing test plus the wider suite.

Phase 1: Root Cause Investigation

Gather all available evidence before forming any hypothesis:

CODE0 call

`retrieve(types=["historical-patterns", "incident-learnings"],

keys=[<error class>, <affected file paths>], limit=3)`. A prior

matching pattern or incident is the single most reliable accelerator

for root-cause analysis. Cite id and path verbatim so the user

can verify the precedent.

Multi-component diagnostics

When the system has multiple layers (Controller → Service → Repository → DB, or multi-tenant

DB switching), add diagnostic instrumentation before proposing fixes:

For EACH component boundary:
  - Log what data enters the component
  - Log what data exits the component
  - Verify environment/config propagation (e.g. DB connection, tenant context)
  - Check state at each layer

Run once → gather evidence → identify WHICH layer breaks → investigate that layer.

This is especially important for:

Phase 2: Pattern Analysis

Phase 3: Hypothesis and Testing

Shift strategy (CODE0 ladder). Signs:

Phase 4: Implementation

variant analysis below before closing the bug.

Variant analysis — one bug found, find its siblings

Once the root cause is confirmed, sweep for variants before closing:

  1. Extract the signature — the minimal code shape that makes the bug

(e.g. "optional relation accessed without null check after first()").

  1. Sweep — grep/code-graph ask for the shape, not the symptom:

the same API misuse, the same copy-pasted block, the same missing guard.

  1. Verify each hit through the false-positive gate (§ 4 proactive mode)

— a matching shape whose inputs cannot reach the bad state is a rejected

candidate, not a variant.

  1. Report — confirmed variants join the fix (same commit if within

minimal-safe-diff's remediation carve-out) or land as a noted follow-up.

Worked example: root cause $order->customer->email crashes when the

customer was soft-deleted. Signature: ->customer-> after an unguarded

relation. Sweep finds 3 more sites; 2 are variants (same nullable relation),

1 is rejected (eager-loaded with whereHas, cannot be null there).

Proactive mode (bug hunting)

When asked to audit code for hidden bugs, use this workflow instead of the 4 phases above:

1. Execution tracing

Trace the actual code path step by step:

2. Edge case analysis

For each code path, test these scenarios mentally:

| Category | What to check |

|---|---|

| Null/empty | Null inputs, empty arrays, empty strings, missing keys |

| Boundaries | Zero, negative, max int, first/last element |

| Type coercion | String "0" vs int 0, loose comparison bugs |

| Timing | Race conditions, stale cache, concurrent writes |

| State | Uninitialized state, partial updates, rollback failures |

| External | Network timeout, API errors, malformed responses |

3. Known bug patterns

→ PHP/Laravel bug-pattern catalogue: see CODE0.

4. False-positive gate (proactive mode)

Before a candidate enters the report, restate it as one falsifiable sentence:

the concrete input or state that triggers it, and the observable wrong

behavior that follows. A candidate whose trigger you cannot name is **not a

finding** — trace further or drop it with a one-line reason.

Route verification by severity: a Low/Medium finding with a traced trigger

reports normally (Standard); a High/Critical finding gets a

devil's-advocate pass first (Deep) — actively try to refute it (guard

clause upstream? framework default? unreachable input?) and report only what

survives. List killed candidates one-line under Rejected candidates so the

triage is auditable.

5. Output format (proactive mode)

For each bug found: Bug → Location → Severity → Root Cause → Trigger → Fix → Confidence

Close with Rejected candidates — one line per looks-broken-but-benign

pattern the gate killed, with the traced reason.

Commands

| Command | Purpose |

|---|---|

| bug-investigate | Gather context from all sources, analyze, identify root cause |

| bug-fix | Plan the fix, implement, verify with tests and quality tools |

Project awareness

Read AGENTS.md and ./agents/ for project-specific architecture, business rules, and domain docs.

Detect the project from the repo name (see rules/architecture.md).

Check for existing contexts in agents/settings/contexts/ or module agents/settings/contexts/.

Adversarial review

Before implementing a fix, run the adversarial-review skill.

Focus on the "Bug fixes" attack questions: Is this the root cause or a symptom? Will the fix break something else?

Auto-trigger keywords

Rationalization prevention

| Excuse | Reality |

|---|---|

| "Should work now" | RUN the verification — confidence ≠ evidence |

| "It's probably X, let me fix that" | "Probably" = guessing. Complete Phase 1 first |

| "Quick fix for now" | Quick fixes mask root causes and create technical debt |

| "I'll investigate later" | Later never comes. Investigate now |

| "One more fix attempt" (after 2+) | 3 failures = wrong hypothesis. Shift strategy |

| "Issue is simple, don't need process" | Simple issues have root causes too. Process is fast for simple bugs |

| "Emergency, no time for process" | Systematic debugging is FASTER than guess-and-check thrashing |

| "It looks broken" | Pattern-recognition is not analysis — name the concrete trigger or drop it |

| "This is clearly critical" | Complete a devil's-advocate pass — models overrate severity |

| "Report it just in case" | Over-reporting erodes trust; an unverifiable finding is noise |

Output format

  1. Root cause analysis with evidence trail
  2. Fix implementation or fix plan with specific files and changes
  3. Regression test covering the failure scenario

Verification examples

Gotcha

Do NOT

References

Generate candidate answers, then verify each with follow-up

questions. This skill adapts CoVe by verifying stacktrace-derived

hypotheses against Sentry data and surrounding code before 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.