{"data":{"slug":"discovered-8a8c71ff5f651b9db9de0a38a289ac020a9d6aeb98f16cc3","title":"Debugging","summary":"Identify the root cause of software issues, including bugs, failing tests, crashes, and system outages, by building a reproduction loop, analyzing evidence, and applying structured diagnostic techniques.","url":"https:\/\/skillshunter.net\/skills\/discovered-8a8c71ff5f651b9db9de0a38a289ac020a9d6aeb98f16cc3","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/discovered-8a8c71ff5f651b9db9de0a38a289ac020a9d6aeb98f16cc3","markdown_url":"https:\/\/skillshunter.net\/skills\/discovered-8a8c71ff5f651b9db9de0a38a289ac020a9d6aeb98f16cc3.md","download_url":"https:\/\/skillshunter.net\/skills\/discovered-8a8c71ff5f651b9db9de0a38a289ac020a9d6aeb98f16cc3\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Before debugging, ensure the system is in a stable state and any ongoing harm is contained. Prepare a reproduction loop that reliably shows the failure, and replace any sensitive information with `<REDACTED>`.","instructions":"---\nname: debugging\ndescription: >-\n  Finds the root cause of a problem, or the contributing causes when several\n  line up, in software and the systems around it (code, builds and CI,\n  infrastructure, data pipelines, integrations) by first building a fast\n  reproduction or an evidence timeline, minimizing it, ranking falsifiable\n  hypotheses, instrumenting, fixing the cause, and adding a control. Use when something behaves\n  wrongly and the cause is unknown: a bug, failing or flaky test, crash,\n  error message, stack trace, build or CI failure, outage, systems that\n  stopped syncing, data that no longer matches, numbers that look wrong,\n  jobs that get stuck, something that stopped working or got slow since a\n  change, and when asked what broke, why something fails, for a root cause\n  analysis, the 5 whys, or a postmortem, before proposing any fix, even when the code\n  or a diff is pasted inline, the fix looks obvious, or a retry is requested\n  to turn CI green. Not for a business process or team problem with no\n  software, infrastructure, or data system.\nlicense: MIT\nmetadata:\n  author: ongtungduong\n---\n\n# Debugging\n\nBuild a feedback loop that shows this exact failure, then use it to find and\nprove the root cause. With a fast loop, bisection and hypotheses become\nmechanical; without one, reading the system produces stories, and a fix for a\nsymptom is a guess that made the symptom go quiet. The method is the same for\ncode, builds, infrastructure, and data; only the loop changes.\n\n**The rule:** no fix until there is a loop that shows the failure and a\nconfirmed cause. Containment is not a fix: when harm is ongoing, contain it\nfirst (step 1), then find the cause.\n\n## Five whys and the lenses\n\nThe method that carries the lenses is **five whys**: from the observed\nsymptom, ask \"why?\" link by link, prove each answer with the lenses before\nthe next, and at the confirmed cause switch to \"why was this possible?\" until\nyou reach a cause the team controls. When the cause is not obvious at step 4,\nor at step 6, read [references\/five-whys.md](references\/five-whys.md) and run\nits procedure.\n\nThe chain is a **why tree**, not a line. A failure in a complex system (an\nincident, an outage, a pipeline that keeps failing) rarely has one root cause: latent\nconditions and a trigger line up, and each is a contributing cause with its\nown control. Keep every branch that has evidence; pruning the tree to one\n\"root cause\" for a tidier story leaves the other causes in place.\n\nTen lenses in four groups. Use each where it changes a hypothesis, a\nprobe, or the fix, and drop it where it does not; they are not headings in\nyour reply. When a lens needs depth, or the first hypotheses all fail, read\n[references\/lenses.md](references\/lenses.md) for its procedure.\n\n| Group | Lens | What it forces | Steps |\n|---|---|---|---|\n| Evidence | Facts vs. assumptions | Every inference anchors to something observed or measured; what \"should\" be true, or \"worked yesterday\", is checked before it carries weight | 2-4 |\n| Evidence | Falsification | The fastest check that would prove each hypothesis wrong, not one that agrees with it; each one ruled out is progress | 4-5 |\n| Evidence | Nothing is obviously fine | When the failure is strange, the simplest and most trusted things get checked too, including what people understood from each other | 4-5 |\n| Isolation | Bisection | For anything ordered (a path, a history, a timeline): check the midpoint; each check rules out half | 4-5 |\n| Isolation | Minimization | For an unordered set (inputs, settings, parts, participants): take one element away at a time while the problem stays, until only what it needs remains | 3 |\n| Isolation | One variable at a time | One change per try, so the result says which change mattered | 5, 7 |\n| Time and systems | Delta | Something new or different appeared before it started; walk the timeline back from the first sign | 2, 4 |\n| Time and systems | Bottom-up | Confirm the basic conditions before the complex ones; do not jump to the suspect | 5 |\n| Probability and containment | Common before rare | Simple, frequent causes are checked before complex, unlikely ones | 4 |\n| Probability and containment | Contain before fixing | While damage is spreading, stop it and preserve the scene first; find the cause after | 1 |\n\n## Workflow\n\n1. **Contain, preserve, redact.** If harm is ongoing, contain it first (pause,\n   roll back, switch to a fallback, cut off the affected part), say you are\n   in the containment phase, and get the user's go-ahead for anything hard\n   to undo. Before changing anything, record the current state: what it\n   shows, the time, the affected items, logs and settings as they are now;\n   a restart or cleanup can erase the evidence. Replace secrets in what you\n   show with `<REDACTED>`, and build loops that read credentials from the\n   environment.\n2. **Build the loop**: a command or check that shows this exact failure. Pin\n   down its scope first: always or intermittent, everywhere or in one place,\n   since when, and for whom; the answers shape the loop. For\n   code, default to a failing test at the seam that reaches the bug. For a\n   system you cannot re-run on demand (a live outage, a data mismatch, a\n   job that keeps stalling), the loop is a check that shows the symptom on\n   current data plus an **evidence timeline** of what changed around when it\n   started. When only a person can trigger the failure, the loop is a\n   numbered checklist of steps for the user plus the observations to report,\n   requested through the host's selection tool when available\n   (`AskUserQuestion` on Claude Code), or in text. Reuse the same\n   checklist to verify the fix.\n   Tighten it: faster (narrow scope), sharper (assert the user's exact symptom,\n   not \"it did not crash\"), deterministic (pin what varies: time, randomness,\n   environment, ordering).\n   **Exit when** the loop for your kind of system holds, already run and\n   shown with output:\n   - *Re-runnable* (code, a build, a reproducible setup): one command that\n     drives the real path, asserts the symptom, gives the same verdict every\n     run (for an intermittent bug, it repeats the trigger until one\n     invocation fails reliably), and finishes in seconds.\n   - *Evidence timeline* (live system, data, scheduled jobs): a symptom check on\n     current data that shows the symptom in numbers or records (a query, a\n     count, a diff of two copies), cheap enough to re-run after every probe\n     and after the fix, plus a timeline with the first sign, each change in\n     the window with its source, and the affected set.\n   - *Person-triggered*: the checklist gives the same observation each time\n     the user repeats it.\n\n   If you cannot build one, stop: list what you tried and ask for\n   environment access, a redacted artifact, or permission to add temporary\n   instrumentation.\n3. **Reproduce and minimize.** Confirm the loop shows the failure the *user*\n   described, not a nearby one, then minimize it. For an evidence timeline,\n   narrow the window and the affected set until the pattern is sharp.\n4. **Hypothesize.** Write ranked hypotheses before testing any (three to five\n   for a cause that is open; one when a stack trace, a bisect, or the repro\n   already names the line), each with a prediction (\"if X is the cause, changing Y makes it disappear\").\n   Rank common causes before rare ones, and by likelihood for the cost of\n   checking: a likely cause that a quick probe settles goes before a slightly\n   likelier one that needs a new environment.\n   Check what changed and a similar case that works. When a known-good\n   version or state exists, bisect between it and now first: the change it\n   names replaces most of the list, and the hypotheses then explain that one\n   change. Show the list to the user without blocking on them; they often\n   re-rank it instantly.\n5. **Instrument.** One probe per prediction. Prefer a direct look at the\n   live state (a debugger, a query, the item itself); otherwise observe the\n   boundaries that separate hypotheses. Across several components, record\n   what enters and leaves each boundary once to find *where* it breaks. For\n   performance, measure a baseline first.\n6. **Ask why it was possible.** Once a prediction holds, the confirmed cause\n   is where the failure happened. Continue the five-whys chain with \"why was\n   this possible?\", each answer backed by evidence, until every branch\n   reaches a cause the team controls: a missing check, guard, test, review,\n   alert, or procedure step. A person's mistake is never the last why.\n7. **Fix,** in this order:\n   1. Choose the recurrence control that would have caught this earliest,\n      aimed at the last why of each branch: a failing test at a seam that exercises the\n      real bug pattern for code; otherwise a check, monitor, alert,\n      validation, guard, or a documented step in the procedure. If none can\n      be placed, report that as a finding.\n   2. Apply one fix at the confirmed cause, watch the control go from red to\n      green, run the wider checks (the full suite, the full reconciliation),\n      and re-run the original unminimized loop. A fix to the last why beyond\n      the control (a process or design change) is a proposal for the user,\n      not part of this fix.\n8. **Clean up:**\n   - [ ] the original reproduction or symptom check no longer fails;\n   - [ ] each branch's recurrence control is in place, or its absence is\n         documented;\n   - [ ] all debug lines and temporary probes are removed;\n   - [ ] throwaway harnesses are deleted or clearly marked;\n   - [ ] the confirmed cause is recorded where the fix is (commit, PR,\n         ticket, or incident note).\n9. **Report** in the output format below, also when the session ends\n   before a fix (a \"why does this fail\" question, a read-only session).\n   For an incident (step 1 had to contain ongoing harm), offer a postmortem;\n   when the user asks for one, or for a written RCA, fill\n   [assets\/postmortem-template.md](assets\/postmortem-template.md) from what\n   the session established, mark what it did not, and save it where the\n   project keeps postmortems, or ask where.\n\n## Gotchas\n\n- \"Just try a quick fix\" (a retry, a sleep, a skip) is the first ask, not\n  insistence. Lead with the loop and the ranked hypotheses; if you also give\n  the stopgap, label it as hiding the cause. Ship the stopgap alone only if\n  the user insists after seeing that.\n- Three failed fixes, each revealing a new problem elsewhere, means the design\n  is the bug. Stop and discuss the architecture with the user before a fourth.\n- A failure that shows up 1% of the time is not debuggable. Repeat the\n  trigger, add stress, or narrow timing until it fails reliably.\n- For performance, logs mislead; a timing harness or profiler on a fixed\n  input, against a good baseline, is the loop.\n- A mismatch between two systems has three suspects: the source, the copy,\n  and the path between them. Check each boundary before blaming one.\n- Untagged debug logs survive cleanup. Prefix every one with a unique tag such\n  as `[DEBUG-a4f2]` so removal is a single grep.\n- A symptom that moves, recurs elsewhere, or grows under load is a feedback\n  loop, not a single fault: something amplifying its own load, serving stale\n  state, backing up, or two parts correcting each other. Trace the loop end\n  to end.\n- Captured artifacts (request dumps, exports, screenshots) carry credentials\n  or personal data; quote only the lines with the signal.\n- Without tools to run anything (a pasted diff, a description of the\n  problem, a read-only session), the loop still comes first in the reply: the\n  test or check that shows the symptom and what it will show, then the\n  ranked hypotheses, the cause, and the fix, marked unverified. Give it in the\n  output format below, labels and all.\n\n## Output format\n\nEvery reply carries all the labels below, in this order, including a read-only one\nwhere nothing could be run. Write `none` or `not applicable: <why>` for a line\nwith nothing to say, never drop it: a missing line reads as \"not checked\", and\na reader looking for the cause finds it in the same place each time. Put\nexplanation after the labelled lines, not in place of them. Read\n[assets\/example-reply.md](assets\/example-reply.md) for a filled-in reply when\nunsure how much detail each line needs.\n\n```\nLoop: `<command or check>` -> <output that shows the symptom> | not run: `<the check>` -> <what it will show>\nCause: <the confirmed cause, at file:line or the exact step, record, or change> | not confirmed: <leading hypothesis and the probe that would settle it>\nContributing: <each other cause on the why tree, with its evidence> | none\nWhy chain: <cause> <- <why it was possible> <- ... <- <the cause you control> (one line per branch)\nEvidence: <the prediction that held, and the probe output>\nFix: <the change> | not applied: <why>\nRecurrence control: <test, check, monitor, or procedure step> RED -> GREEN | none possible: <why>\nUnverified: <what could not be run or checked here, or \"none\">\n```\n","use_cases":["Investigate and resolve a failing test in a codebase","Diagnose the cause of a system outage or performance degradation","Analyze a crash or error message to find the root cause","Perform a postmortem analysis after an incident","Debug a data pipeline that is failing or producing incorrect results"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/ongtungduong\/legion\/blob\/690826292f7c7319cc0923672ed049707aa58aa1\/skills\/debugging\/SKILL.md","source_commit":"690826292f7c7319cc0923672ed049707aa58aa1","license":null,"version":null,"listing_approved_at":"2026-12-01","created_at":"2026-11-30T08:06:21.000000Z","updated_at":"2026-12-01T12:48:20.000000Z","seo_title":"Debugging: Root Cause Analysis for Software and System Issues","seo_description":"Discover how to identify and resolve software bugs, system outages, and other technical issues through structured debugging techniques and evidence-based analysis.","seo_keywords":["debugging","root cause analysis","software troubleshooting","system diagnostics","incident investigation","five whys","evidence timeline","debugging workflow"]}}