Install
openclaw skills install @afonsoft/diagnoseUse when the user reports a hard bug, unexpected failure, or performance regression that needs root-cause analysis.
openclaw skills install @afonsoft/diagnoseA discipline for hard bugs and regressions. Skip phases only when explicitly justified. All questions and findings reported to the user must be in Portuguese (pt-BR).
When exploring the codebase, use the project's domain glossary from .claude/CONTEXT.md (if it exists) to get a clear mental model of the relevant modules, and check docs/architecture/ for decisions and ADRs in the area you are touching.
Re-validation loop: after every hypothesis, fix, or change, re-run the reproduction and the regression checks before declaring the bug resolved.
Iron rule: NO FIXES WITHOUT A RED LOOP AND A CONFIRMED ROOT CAUSE. A change made before Phase 1 produced a red signal and Phase 4 confirmed a hypothesis is a guess — and guessing under pressure is how one bug becomes three. This holds ESPECIALLY under time pressure, when the bug "looks simple", and after a previous fix already failed: those are exactly the moments the process pays off. Violating the letter of this process is violating the spirit of debugging.
Phase 0 Frame the bug → symptom, expected vs actual, env, frequency, scope
Phase 1 Build a feedback loop → ONE tight, red-capable command (the core of this skill)
Phase 2 Reproduce + minimise → smallest scenario that still goes red
Phase 3 Hypothesise → 3–5 ranked, falsifiable predictions
Phase 4 Instrument → one probe per prediction, one variable at a time
Phase 5 Fix + regression test → test at a correct seam, watch red → green
Phase 6 Cleanup + re-validate → remove probes, re-run the original repro
↺ If the bug survives or mutates, return to Phase 3.
↺ If every hypothesis dies, see "Stuck — when hypotheses run out".
Entry points for non-code failures:
This skill has you show commands, outputs, and captured artifacts. Redact every secret first: write <REDACTED> in its place. Build loops against env vars so credentials stay in the environment, not in what you show. Captured artifacts carry auth headers — quote only the lines that carry the signal.
If the redacted output is not enough to diagnose the bug, say so and ask the user (in Portuguese).
When the target codebase matches one of these stacks, load the matching playbook from references/ before building the loop — they contain ready-made reproduction commands, debugger/profiler workflows, instrumentation snippets, and log-query cheat sheets:
references/dotnet-debugging.md — .NET / ASP.NET Core / EF Core (dotnet-counters, dotnet-stack, dotnet-dump, dotnet-trace, EF LogTo/TagWith, journalctl/jq queries)references/angular-debugging.md — Angular (Angular DevTools profiler, ng.* console APIs, RxJS tap, change-detection profiling)references/python-debugging.md — Python (breakpoint()/pdb, pytest --pdb, py-spy, faulthandler, tracemalloc, asyncio debug)references/react-debugging.md — React (React DevTools profiler, why-did-you-render, re-render/effect bug patterns)Before building anything, pin down what "broken" means. A fuzzy symptom produces a fuzzy loop, and a fuzzy loop wastes every phase after it.
Capture — from the user, the bug report, or the evidence:
If the report is thin, interview the reporter before touching code (in Portuguese):
Antes de investigar, preciso enquadrar o bug:
1. O que deveria acontecer vs o que aconteceu? (mensagem de erro exata, se houver)
2. Onde acontece — local, CI, staging, produção?
3. Desde quando? Relacionado a algum deploy ou mudança recente?
4. Com que frequência — sempre, às vezes (quantas?), ou uma vez só?
5. Atinge um caso específico ou tudo?
Output of Phase 0: a one-sentence bug statement — "In <env>, <input/action> produces <actual> instead of <expected>, since <when> (<frequency>)." If you cannot write that sentence, keep interviewing — do not start Phase 1.
This is the skill. Everything else is mechanical. If you have a tight pass/fail signal for the bug — one that goes red on this bug — you will find the cause; bisection, hypothesis-testing, and instrumentation all just consume that signal. If you don't have one, no amount of staring at code will save you.
Spend disproportionate effort here. Be aggressive. Be creative. Refuse to give up.
git bisect run it. For "which test creates this stray file/state?", scripts/find-polluter.sh runs test files one-by-one until the polluter appears.scripts/hitl-loop.template.sh so the loop is still structured; captured output feeds back to you.Build the right feedback loop, and the bug is 90% fixed.
Treat the loop as a product. Once you have a loop, tighten it:
A 30-second flaky loop is barely better than no loop; a 2-second deterministic one is a debugging superpower.
The goal is not a clean repro but a higher reproduction rate. Loop the trigger 100×, parallelise, add stress, narrow timing windows, inject sleeps. A 50%-flake bug is debuggable; 1% is not — keep raising the rate until it is debuggable.
If the flake lives in a test that guesses timing with sleep/setTimeout, the flaky wait may be the bug — replace guessed delays with condition polling (references/condition-based-waiting.md).
Stop and say so explicitly, in Portuguese. List what you tried. Ask for: (a) access to whatever environment reproduces it, (b) a redacted captured artifact (HAR file, log dump, core dump, screen recording with timestamps), or (c) permission to add temporary production instrumentation. Do not proceed to hypothesise without a loop.
Preciso de um exemplo mínimo que reproduza o erro. Você consegue me fornecer:
1. O comando ou ação que dispara o problema.
2. A saída ou mensagem de erro exata.
3. O ambiente (local, CI, staging, produção).
4. Se possível, um artefato capturado (HAR, dump de log, gravação de tela) com segredos redigidos.
➡️ Se não tiver, vou tentar construir um caso de reprodução sozinho.
Phase 1 is done when you can name one command (script path, test invocation, curl) that you have already run at least once — show the invocation and its output, redacted — and that is:
scripts/hitl-loop.template.sh.If you catch yourself reading code to build a theory before this command exists, stop — jumping straight to a hypothesis is the exact failure this skill prevents. No red-capable command, no Phase 2.
Run the loop. Watch it go red as the bug appears. Confirm:
Shrink the repro to the smallest scenario that still goes red. Cut one thing at a time, re-running the loop after each cut, and keep only what is load-bearing for the failure:
Why bother: a minimal repro shrinks the hypothesis space in Phase 3 (fewer moving parts to suspect) and becomes the clean regression test in Phase 5.
Done when every remaining element is load-bearing — removing any one of them makes the loop go green. Do not proceed until you have reproduced and minimised.
Generate 3–5 ranked hypotheses before testing any of them. Single-hypothesis generation anchors on the first plausible idea.
Each hypothesis must be falsifiable — state the prediction it makes:
"If <X> is the cause, then <changing Y> will make the bug disappear / <changing Z> will make it worse."
If you cannot state the prediction, the hypothesis is a vibe — discard or sharpen it.
Sources for hypotheses — cheap checks first:
git log -p --since="<first sighting>" on the touched area, plus dependency and config changes. Bugs correlate strongly with fresh changes; "it worked before" is a bisection waiting to happen.references/root-cause-tracing.md).Where the bug may live, in roughly this order:
Show the ranked list to the user before testing — domain knowledge re-ranks instantly ("we just deployed a change to #3", "#2 is already ruled out"). Cheap checkpoint, big time saver. Don't block on it: proceed with your ranking if the user is AFK.
Hipóteses ranqueadas:
1. [HIPOTESE_1] — previsão: [PREDICAO_1]
2. [HIPOTESE_2] — previsão: [PREDICAO_2]
3. [HIPOTESE_3] — previsão: [PREDICAO_3]
Vou validar a nº [N] com [ACAO_EXPERIMENTAL]. Se confirmar, o próximo passo é [PROXIMO_PASSO].
Concorda, ou quer que eu teste outra hipótese primeiro?
For anything non-trivial, keep a running journal — it prevents re-testing a rejected hypothesis and survives context drift/compaction:
## Diagnostic Journal — <one-sentence bug statement>
- Loop: `<the Phase 1 command>` → currently red
- Min repro: <smallest red scenario>
| Hypothesis | Prediction | Test run | Result |
|---|---|---|---|
| H1: ... | ... | ... | rejected / confirmed |
- Root cause: <filled at the end>
Each probe must map to a specific prediction from Phase 3. Change one variable at a time.
Tool preference:
Tag every debug log with a unique prefix, e.g. [DEBUG-a4f2] — cleanup at the end becomes a single grep. Untagged logs survive; tagged logs die.
Probe placement. Put probes at the boundaries that bisect the hypothesis space: function entry/exit, before and after each transformation, each external call (network, DB, filesystem), and every state transition. One probe that discriminates between H1 and H2 beats ten that don't.
Multi-component sweep. When the bug could sit anywhere in a pipeline (CI → build → deploy, API → service → DB, frontend → gateway → backend), do ONE evidence run before drilling in: log what enters and what exits each component boundary — data shape, env/config propagation, state — in a single pass. That run usually reveals which layer breaks; then concentrate probes on that layer instead of instrumenting the whole pipeline.
Correlation. Stamp a request/trace id as early as possible and log it at every probe — otherwise concurrent flows interleave and your evidence is ambiguous.
Perf branch. For performance regressions, logs are usually wrong. Establish a baseline measurement (timing harness, profiler, query plan), then bisect. Measure first, fix second.
Write the regression test before the fix, but only if there is a correct seam for it — a seam where the test exercises the real bug pattern as it occurs at the call site. If the only available seam is too shallow (a unit test that cannot replicate the chain that triggered the bug), a regression test there gives false confidence.
If no correct seam exists, that itself is a finding. The architecture is preventing the bug from being locked down — flag it for Phase 6 and for improve-codebase-architecture.
If a correct seam exists:
references/defense-in-depth.md).If the fix touches many files, present the plan to the user in Portuguese before editing:
Raiz do problema: [RAIZ].
Correção proposta: [DESCRICAO_DA_CORRECAO].
Arquivos afetados: [LISTA].
Posso aplicar a correção e depois rodar os testes?
Required before declaring done:
[DEBUG-...] instrumentation removed (grep the prefix).Report the result in Portuguese:
Correção aplicada em [ARQUIVOS].
- Reprodução original: [não reproduz mais / ainda falha]
- Teste de regressão: [PASS/FAIL]
- Testes afetados: [PASS/FAIL]
- Instrumentação removida: [SIM/NÃO]
O bug está resolvido. Quer que eu abra uma Issue para documentar a causa raiz com /create-issues?
Three-strike rule. Count applied fixes, not hypotheses: if 3 fixes failed and the bug survives or mutates — each fix revealing a new problem in a different place, or each fix needing a workaround to land — the pattern itself is suspect. STOP and question the architecture with the user (in Portuguese) before attempting fix #4: is this design fundamentally sound, or are we fixing symptoms of a wrong structure? That conversation is improve-codebase-architecture territory, not another patch.
If every hypothesis is rejected, the failure is upstream of your assumptions:
observability-and-instrumentation so the next occurrence brings evidence with it.If the bug is not in the codebase but in the agent session — repeated tool-call failures, loops, context drift, or mismatch between expected and actual filesystem state — apply the agent-introspection loop.
Before trying to recover, record:
## Failure Capture
- Session / task:
- Goal in progress:
- Error:
- Last successful step:
- Last failed tool / command:
- Repeated pattern seen:
- Environment assumptions to verify:
Match the failure to a known pattern:
| Pattern | Likely Cause | Check |
|---|---|---|
| Maximum tool calls / repeated same command | loop or no-exit observer path | inspect the last N tool calls for repetition |
| Context overflow / degraded reasoning | unbounded notes, repeated plans, oversized logs | inspect recent context for duplication and low-signal bulk |
ECONNREFUSED / timeout | service unavailable or wrong port | verify service health, URL, and port assumptions |
429 / quota exhaustion | retry storm or missing backoff | count repeated calls and inspect retry spacing |
| file missing after write / stale diff | race, wrong cwd, or branch drift | re-check path, cwd, git status, and actual file existence |
| tests still failing after "fix" | wrong hypothesis | isolate the exact failing test and re-derive the bug |
Diagnosis questions:
Prefer these interventions in order:
Bad pattern: retrying the same action three times with slightly different wording. Good pattern: capture failure → classify the pattern → run one direct check → change the plan only if the check supports it.
End with:
## Agent Self-Debug Report
- Session / task:
- Failure:
- Root cause:
- Recovery action:
- Result: success | partial | blocked
- Token / time burn risk:
- Follow-up needed:
- Preventive change to encode later:
When the misbehaving system is an agent or AI workflow (not a code path), audit it across 5 dimensions. Score each 1–5 and report specific findings in Portuguese.
Structure (role, context, instructions, output zones); explicit output schema; instruction clarity; edge-case handling; anti-patterns (wall of text, contradictions, implicit format).
Context budget allocation (planned vs. ad-hoc); attention gradient (critical info at start/end); context window utilisation; state management (explicit vs. implicit); memory strategy appropriate for conversation length.
Tool count (3–7 ideal, 13+ problematic); description quality; error handling; schema completeness (input/output/error); idempotency. Scope attribution: distinguish project-configured tools from agent-level/built-in tools — only flag overhead the project can actually control.
Topology appropriateness (single vs. multi-agent justified); agent boundaries (clear vs. overlapping); handoff protocols (structured vs. ad-hoc); observability; cost awareness.
Input validation; output filtering (PII, content policy — scope contextually: user's own frontend→backend is lower risk than external services); cost controls; error recovery; evaluation strategy (golden tests vs. "it seems to work").
╔══════════════════════════════════════╗
║ WORKFLOW DIAGNOSTIC ║
╠══════════════════════════════════════╣
║ Prompt Quality ████░ 4/5 ║
║ Context Efficiency ███░░ 3/5 ║
║ Tool Health ██░░░ 2/5 ║
║ Architecture ████░ 4/5 ║
║ Safety & Reliability ██░░░ 2/5 ║
╠══════════════════════════════════════╣
║ Overall Score: 15/25 ║
╚══════════════════════════════════════╝
ACHADOS CRÍTICOS:
1. [Problema mais severo — ação imediata]
2. [Segundo mais severo]
3. [Terceiro]
AÇÕES RECOMENDADAS:
1. [Correção específica para o achado nº 1]
2. [Correção específica para o achado nº 2]
3. [Correção específica para o achado nº 3]
| Score | Meaning | Recommended Action |
|---|---|---|
| 5 | Production-excellent | No action needed |
| 4 | Good with minor gaps | Polish prompt clarity or output schema |
| 3 | Functional but risky | Add error handling or reduce complexity |
| 2 | Significant issues | Immediate attention — add retries/guards |
| 1 | Broken or missing | Rebuild from scratch with clear structure |
When the code "works" but misbehaves quietly, hunt for silent failures before declaring the bug resolved.
catch {}, ignored exceptions, errors converted to null / empty arrays with no context..catch(() => []), graceful-looking paths that make downstream bugs harder to diagnose.For each finding:
Diagnosis is iterative. After every change, re-run the reproduction. If the bug moves or changes, go back to Phase 3. Do not declare the bug fixed until the reproduction passes and the regression suite is green.
If you catch yourself thinking any of these, you are off the process — return to the phase you skipped:
User redirections are the same signal from the outside: "is that really happening?", "did you verify?", "stop guessing", "we're going in circles". When you hear one, stop and return to the phase you skipped.
| Mistake | Fix |
|---|---|
| Investigating a vague symptom | Phase 0 first — one-sentence bug statement or keep interviewing. |
| Fixing without a reproduction first | Build a red-capable loop before changing code. |
| Hypothesising before a tight loop exists | Phase 1 completion criterion first — no red command, no theory. |
| Testing the first plausible hypothesis only | Generate 3–5 ranked, falsifiable hypotheses. |
| Skipping minimisation | Minimise first, or you fix symptoms, not the cause. |
| Asserting "didn't crash" instead of the symptom | Sharpen the signal — assert the exact user-reported failure. |
| Regression test at a seam too shallow | Use a correct seam, or document that none exists. |
| Removing instrumentation too early | Keep [DEBUG-...] logs until the fix is verified, then grep-clean. |
| Not adding a regression test | Every fixed bug deserves a test. |
| Re-testing a rejected hypothesis | Keep the diagnostic journal; record every result. |
| Assuming recent changes are innocent | Diff first — fresh code is the prime suspect. |
| Ambiguous evidence from concurrent flows | Stamp a correlation id and log it at every probe. |
| Debugging the wrong environment | Verify env matches the Phase 0 report before trusting results. |
| Declaring done without re-validation | Re-run the reproduction and the suite. |
| Fixing where the error is thrown | Trace the bad value back to its origin (references/root-cause-tracing.md). |
| Fixing only the immediate cause | Add validation at every layer the bad data crosses (references/defense-in-depth.md). |
Flaky test fixed by bumping a sleep | Wait on the actual condition, not guessed time (references/condition-based-waiting.md). |
| Instrumenting a whole pipeline at once | One sweep across all component boundaries first, then drill into the failing layer. |
scripts/hitl-loop.template.sh — human-in-the-loop reproduction driverscripts/find-polluter.sh — bisects test files to find which one creates stray files/statereferences/root-cause-tracing.md — trace a bad value backward through the call stack to its originreferences/defense-in-depth.md — validate at every layer so the bug class becomes impossiblereferences/condition-based-waiting.md — replace guessed sleeps with condition polling in flaky testsreferences/dotnet-debugging.md — .NET diagnostics tools and log queriesreferences/angular-debugging.md — Angular DevTools, change-detection and RxJS debuggingreferences/python-debugging.md — pdb/pytest/py-spy debugging and log queriesreferences/react-debugging.md — React DevTools and re-render debuggingqa-analyst — for test planning and bug reportingwrite-specs — for producing specs when the bug reveals missing requirementsimprove-codebase-architecture — when the diagnosis reveals missing seams or structural problemsobservability-and-instrumentation — when the fix needs durable logging/metrics/tracing, not throwaway probescreate-issues — to track the documented root causeagent-introspection-debugging — when the failure is the agent session itself (loops, context drift, repeated tool calls)silent-failure-hunter — when the code works but misbehaves quietly