/debug
Find root cause. Fix it. Prove it works.
Routing
| Intent |
Sub-capability |
| Debug a bug, test failure, unexpected behavior |
This file (below) |
| Flaky test investigation |
references/flaky-test-investigation.md |
| Incident lifecycle: triage, investigate, postmortem |
references/triage.md |
| Domain audit: "audit stripe", "audit quality" |
references/audit.md |
| Audit then fix highest priority issue |
references/fix.md |
| Create GitHub issues from audit findings |
references/log-issues.md |
If first argument matches a domain name (stripe, quality, etc.), route to references/audit.md.
If "triage", "incident", "postmortem", "production down" → references/triage.md.
If "flaky", "flake", "intermittent", "nondeterministic test" → references/flaky-test-investigation.md.
If "fix" → references/fix.md. If "log issues" → references/log-issues.md.
Otherwise, this is a debugging session — continue below.
The user's symptoms: $ARGUMENTS
The Iron Law
NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST
If you haven't completed Phase 1, you cannot propose fixes.
Rule #1: Config Before Code
External service issues are usually config, not code. Check in order:
- Env vars present?
npx convex env list --prod | grep <SERVICE> or vercel env ls
- Env vars valid? No trailing whitespace, correct format
- Endpoints reachable?
curl -I -X POST <webhook_url>
- Then examine code
Sub-Agent Patterns
Quick investigation (default)
For straightforward bugs, spawn a single sub-agent to gather evidence. Tell it
to investigate the symptoms, reproduce the issue, trace data flow, and report
back with root cause + evidence + proposed fix. It should NOT implement the fix —
just report. You review, decide if root cause is proven, then fix or dig deeper.
Multi-Hypothesis Mode
When >2 plausible root causes and a single investigation would anchor on one:
spawn parallel sub-agents, one per hypothesis. Each gets one hypothesis to
prove or disprove by tracing a specific subsystem. They report back with
confirmed/disproved + evidence. You synthesize into a consensus root cause.
Use when: ambiguous stack trace, multiple services, flaky failures.
Don't use when: obvious single cause, config issue, simple regression.
What you keep vs what you delegate
| You (lead) |
Sub-agents (investigators) |
| Ranking hypotheses |
Tracing one subsystem |
| Declaring root cause proven |
Comparing working vs broken |
| Choosing the fix |
Gathering logs and reproductions |
| Deciding when evidence is sufficient |
Running targeted test cases |
Instrumented Reproduction Loop
When you can't reproduce the bug yourself (auth-gated, mobile, timing-dependent,
hardware-specific, user-flow-dependent):
INSTRUMENT → USER REPRODUCES → READ LOGS → REFINE → REPEAT
- Hypothesize -- form 2-3 candidate root causes from symptoms
- Instrument -- add targeted logging that discriminates between hypotheses.
Write to a log file the user can share back:
LOG_FILE="${HOME}/Desktop/debug-$(date +%s).log"
Log at decision points: function entry/exit, branch taken, values at boundaries.
Tag each log line with the hypothesis it tests: [H1] auth token expired: ${token.exp}
- Hand off -- tell user: "Reproduce the bug, then say done." Give exact steps if known.
- Read & analyze -- when user signals done, read the log file. For each hypothesis:
- Supported? Design next experiment to narrow further.
- Disproved? Eliminate, remove its instrumentation, add new hypothesis.
- Insufficient data? Add more targeted logging at the next layer.
- Iterate -- repeat until one hypothesis survives all evidence. Max 3 rounds —
if still ambiguous after 3, escalate to Multi-Hypothesis Mode (agent teams).
- Clean up -- remove all instrumentation before fixing. Instrumentation is diagnostic,
not the fix.
Use when: flaky tests, user-reported bugs you can't trigger, environment-specific issues.
Don't use when: bug reproduces in your environment (just use Phase 1-4 directly).
The Four Phases
Phase 1: Root Cause Investigation
BEFORE attempting ANY fix:
- Read error messages carefully -- full stack traces, line numbers, error codes
- Reproduce consistently -- exact steps. If not reproducible, gather more data
- Check recent changes --
git diff, git log --oneline -10, new deps, config
- Gather evidence in multi-component systems -- log at each component boundary, run once, identify failing layer
- Trace data flow -- where does the bad value originate? Trace backward to source
Phase 2: Pattern Analysis
- Find working examples -- similar working code in same codebase
- Compare completely -- read reference implementations fully, don't skim
- Identify all differences -- however small
- Understand dependencies -- settings, config, environment, assumptions
Phase 3: Hypothesis and Testing
Scientific method. One experiment at a time. No stacking.
- Form single hypothesis -- "I think X causes Y because Z" (write it down explicitly)
- Design experiment -- What will prove or disprove this? Justify: why this experiment,
what will it tell us? Smallest possible change, one variable only.
- Run experiment -- observe result
- Evaluate:
- Disproved → eliminate this cause, form NEW hypothesis. This step matters —
ruling things out is progress, not failure.
- Supported → design next experiment to increase confidence. Not proven until
you can explain the full causal chain.
- Ambiguous → experiment was too broad. Narrow scope and rerun.
- Repeat until root cause is proven or confidence is high enough to act
Never skip justification. "Just try X" is a red flag — if you can't explain what
you'll learn from an experiment, you don't understand the problem yet.
Phase 4: Implementation
- Write failing test first -- reproduce the bug in a test before any fix
- Verify test fails for the right reason -- not syntax/import errors
- Implement single fix -- address root cause. ONE change at a time.
- Verify -- test passes, no other tests broken, issue resolved.
- If 3+ fixes failed -- STOP. Question the architecture. See
references/systematic-debugging.md.
Root Cause Discipline
For each hypothesis, categorize:
- ROOT: Fixing this removes the fundamental cause
- SYMPTOM: Fixing this masks an underlying issue
Post-fix question: "If we revert in 6 months, does the problem return?"
Demand Observable Proof
Before declaring "fixed", show:
- Log entry proving the fix worked
- Metric that changed
- Database state confirming resolution
Mark as UNVERIFIED until observables confirm.
Classification
| Type |
Signals |
Approach |
| Test failure |
Assertion error |
Read test, trace expectation |
| Runtime error |
Exception, crash |
Stack trace -> source -> state |
| Type error |
TS complaint |
Read error, check types |
| Build failure |
Bundler error |
Check deps, config |
| Behavior mismatch |
"Does Y, should do X" |
Trace code path |
| Performance |
Slow, timeout |
Add timing instrumentation |
| Production incident |
Sentry, alerts |
Create INCIDENT.md, timeline |
Investigation Work Log (Production Issues)
For non-trivial production issues, create INCIDENT-{timestamp}.md:
- Timeline: What happened when (UTC)
- Evidence: Logs, metrics, configs checked
- Hypotheses: Ranked by likelihood
- Actions: What tried, what learned
- Root cause: When found
- Fix: What resolved it
Bounded Shell Output (MANDATORY)
- Size first:
wc -l <file> or du -h
- Read windows:
sed -n '1,120p'; jump with rg -n
- Cap logs:
head -n 200, tail -n 200
- Abort after 20s without signal; narrow scope, rerun
Red Flags -- STOP and Return to Phase 1
- "Quick fix for now, investigate later"
- "Just try changing X and see"
- Multiple simultaneous changes
- Proposing solutions before tracing data flow
- "One more fix attempt" (when 2+ already tried)
- Each fix reveals new problem in different place
Toolkit
- Sentry MCP:
get_issue_details, analyze_issue_with_seer, get_trace_details, search_events
- Git: bisect, blame, recent deploys
- Observability: platform logs, sentry-cli, monitoring dashboards
- Sub-agents: Parallel hypothesis investigation (see above)
- /research thinktank: Multi-model hypothesis validation
Output
- Root cause: What's actually wrong
- Fix: How it was resolved
- Verification: Observable proof it works
Gotchas
- Fixing before investigating: The #1 failure mode. If you haven't traced data flow, you don't know the root cause.
- Stacking changes: One variable per experiment. Multiple simultaneous changes make results uninterpretable.
- Confusing symptom for root cause: "The test fails" is a symptom. "The auth token expires before the refresh interval" is a root cause.
- Skipping reproduction: If you can't reproduce it, you can't verify the fix. Gather more data first.
- Config is almost always the answer: Env vars, endpoints, credentials. Check config before reading code.
1---2name: debug3description: Investigate, audit, triage, and fix. Systematic debugging, incident lifecycle, domain auditing, and issue logging. Four-phase protocol: root cause → pattern analysis → hypothesis test → fix. Use for: any bug, test failure, production incident, error spikes, audit, triage, postmortem, "investigate", "why is this broken", "debug this", "production down", "is production ok", "audit stripe", "log issues".4---56# /debug78Find root cause. Fix it. Prove it works.910## Routing1112| Intent | Sub-capability |13|--------|---------------|14| Debug a bug, test failure, unexpected behavior | This file (below) |15| Flaky test investigation | `references/flaky-test-investigation.md` |16| Incident lifecycle: triage, investigate, postmortem | `references/triage.md` |17| Domain audit: "audit stripe", "audit quality" | `references/audit.md` |18| Audit then fix highest priority issue | `references/fix.md` |19| Create GitHub issues from audit findings | `references/log-issues.md` |2021If first argument matches a domain name (stripe, quality, etc.), route to `references/audit.md`.22If "triage", "incident", "postmortem", "production down" → `references/triage.md`.23If "flaky", "flake", "intermittent", "nondeterministic test" → `references/flaky-test-investigation.md`.24If "fix" → `references/fix.md`. If "log issues" → `references/log-issues.md`.25Otherwise, this is a debugging session — continue below.2627**The user's symptoms:** $ARGUMENTS2829## The Iron Law3031```32NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST33```3435If you haven't completed Phase 1, you cannot propose fixes.3637## Rule #1: Config Before Code3839External service issues are usually config, not code. Check in order:40411. **Env vars present?** `npx convex env list --prod | grep <SERVICE>` or `vercel env ls`422. **Env vars valid?** No trailing whitespace, correct format433. **Endpoints reachable?** `curl -I -X POST <webhook_url>`444. **Then** examine code4546## Sub-Agent Patterns4748### Quick investigation (default)4950For straightforward bugs, spawn a single sub-agent to gather evidence. Tell it51to investigate the symptoms, reproduce the issue, trace data flow, and report52back with root cause + evidence + proposed fix. It should NOT implement the fix —53just report. You review, decide if root cause is proven, then fix or dig deeper.5455### Multi-Hypothesis Mode5657When >2 plausible root causes and a single investigation would anchor on one:58spawn parallel sub-agents, one per hypothesis. Each gets one hypothesis to59prove or disprove by tracing a specific subsystem. They report back with60confirmed/disproved + evidence. You synthesize into a consensus root cause.6162Use when: ambiguous stack trace, multiple services, flaky failures.63Don't use when: obvious single cause, config issue, simple regression.6465### What you keep vs what you delegate6667| You (lead) | Sub-agents (investigators) |68|------------|---------------------------|69| Ranking hypotheses | Tracing one subsystem |70| Declaring root cause proven | Comparing working vs broken |71| Choosing the fix | Gathering logs and reproductions |72| Deciding when evidence is sufficient | Running targeted test cases |7374## Instrumented Reproduction Loop7576When you can't reproduce the bug yourself (auth-gated, mobile, timing-dependent,77hardware-specific, user-flow-dependent):7879```80INSTRUMENT → USER REPRODUCES → READ LOGS → REFINE → REPEAT81```82831. **Hypothesize** -- form 2-3 candidate root causes from symptoms842. **Instrument** -- add targeted logging that discriminates between hypotheses.85 Write to a log file the user can share back:86 ```bash87 LOG_FILE="${HOME}/Desktop/debug-$(date +%s).log"88 ```89 Log at decision points: function entry/exit, branch taken, values at boundaries.90 Tag each log line with the hypothesis it tests: `[H1] auth token expired: ${token.exp}`913. **Hand off** -- tell user: "Reproduce the bug, then say done." Give exact steps if known.924. **Read & analyze** -- when user signals done, read the log file. For each hypothesis:93 - Supported? Design next experiment to narrow further.94 - Disproved? Eliminate, remove its instrumentation, add new hypothesis.95 - Insufficient data? Add more targeted logging at the next layer.965. **Iterate** -- repeat until one hypothesis survives all evidence. Max 3 rounds —97 if still ambiguous after 3, escalate to Multi-Hypothesis Mode (agent teams).986. **Clean up** -- remove all instrumentation before fixing. Instrumentation is diagnostic,99 not the fix.100101Use when: flaky tests, user-reported bugs you can't trigger, environment-specific issues.102Don't use when: bug reproduces in your environment (just use Phase 1-4 directly).103104## The Four Phases105106### Phase 1: Root Cause Investigation107108BEFORE attempting ANY fix:1091101. **Read error messages carefully** -- full stack traces, line numbers, error codes1112. **Reproduce consistently** -- exact steps. If not reproducible, gather more data1123. **Check recent changes** -- `git diff`, `git log --oneline -10`, new deps, config1134. **Gather evidence in multi-component systems** -- log at each component boundary, run once, identify failing layer1145. **Trace data flow** -- where does the bad value originate? Trace backward to source115116### Phase 2: Pattern Analysis1171181. **Find working examples** -- similar working code in same codebase1192. **Compare completely** -- read reference implementations fully, don't skim1203. **Identify all differences** -- however small1214. **Understand dependencies** -- settings, config, environment, assumptions122123### Phase 3: Hypothesis and Testing124125Scientific method. One experiment at a time. No stacking.1261271. **Form single hypothesis** -- "I think X causes Y because Z" (write it down explicitly)1282. **Design experiment** -- What will prove or disprove this? Justify: why this experiment,129 what will it tell us? Smallest possible change, one variable only.1303. **Run experiment** -- observe result1314. **Evaluate**:132 - **Disproved** → eliminate this cause, form NEW hypothesis. This step matters —133 ruling things out is progress, not failure.134 - **Supported** → design next experiment to increase confidence. Not proven until135 you can explain the full causal chain.136 - **Ambiguous** → experiment was too broad. Narrow scope and rerun.1375. **Repeat** until root cause is proven or confidence is high enough to act138139Never skip justification. "Just try X" is a red flag — if you can't explain what140you'll learn from an experiment, you don't understand the problem yet.141142### Phase 4: Implementation1431441. **Write failing test first** -- reproduce the bug in a test before any fix1452. **Verify test fails for the right reason** -- not syntax/import errors1463. **Implement single fix** -- address root cause. ONE change at a time.1474. **Verify** -- test passes, no other tests broken, issue resolved.1485. **If 3+ fixes failed** -- STOP. Question the architecture. See `references/systematic-debugging.md`.149150## Root Cause Discipline151152For each hypothesis, categorize:153- **ROOT**: Fixing this removes the fundamental cause154- **SYMPTOM**: Fixing this masks an underlying issue155156Post-fix question: "If we revert in 6 months, does the problem return?"157158## Demand Observable Proof159160Before declaring "fixed", show:161- Log entry proving the fix worked162- Metric that changed163- Database state confirming resolution164165Mark as **UNVERIFIED** until observables confirm.166167## Classification168169| Type | Signals | Approach |170|------|---------|----------|171| Test failure | Assertion error | Read test, trace expectation |172| Runtime error | Exception, crash | Stack trace -> source -> state |173| Type error | TS complaint | Read error, check types |174| Build failure | Bundler error | Check deps, config |175| Behavior mismatch | "Does Y, should do X" | Trace code path |176| Performance | Slow, timeout | Add timing instrumentation |177| Production incident | Sentry, alerts | Create INCIDENT.md, timeline |178179## Investigation Work Log (Production Issues)180181For non-trivial production issues, create `INCIDENT-{timestamp}.md`:182- **Timeline**: What happened when (UTC)183- **Evidence**: Logs, metrics, configs checked184- **Hypotheses**: Ranked by likelihood185- **Actions**: What tried, what learned186- **Root cause**: When found187- **Fix**: What resolved it188189## Bounded Shell Output (MANDATORY)190191- Size first: `wc -l <file>` or `du -h`192- Read windows: `sed -n '1,120p'`; jump with `rg -n`193- Cap logs: `head -n 200`, `tail -n 200`194- Abort after 20s without signal; narrow scope, rerun195196## Red Flags -- STOP and Return to Phase 1197198- "Quick fix for now, investigate later"199- "Just try changing X and see"200- Multiple simultaneous changes201- Proposing solutions before tracing data flow202- "One more fix attempt" (when 2+ already tried)203- Each fix reveals new problem in different place204205## Toolkit206207- **Sentry MCP**: `get_issue_details`, `analyze_issue_with_seer`, `get_trace_details`, `search_events`208- **Git**: bisect, blame, recent deploys209- **Observability**: platform logs, sentry-cli, monitoring dashboards210- **Sub-agents**: Parallel hypothesis investigation (see above)211- **/research thinktank**: Multi-model hypothesis validation212213## Output214215- **Root cause**: What's actually wrong216- **Fix**: How it was resolved217- **Verification**: Observable proof it works218219## Gotchas220221- **Fixing before investigating:** The #1 failure mode. If you haven't traced data flow, you don't know the root cause.222- **Stacking changes:** One variable per experiment. Multiple simultaneous changes make results uninterpretable.223- **Confusing symptom for root cause:** "The test fails" is a symptom. "The auth token expires before the refresh interval" is a root cause.224- **Skipping reproduction:** If you can't reproduce it, you can't verify the fix. Gather more data first.225- **Config is almost always the answer:** Env vars, endpoints, credentials. Check config before reading code.