---
name: debug-root-cause
description: Systematically find and fix the root cause of bugs, errors, failing tests, and crashes in JavaScript/TypeScript and Python. Use whenever the user pastes an error or stack trace, says something is broken, "not working", "error", "kenapa gagal", "bug", a test fails, or behavior is unexpected — instead of guessing at a fix.
title: debug-root-cause
canonical_url: https://skilld.dev/gh/kiln-skills/kiln/debug-root-cause
last_updated: 2026-11-12T03:45:56.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install kiln-skills/kiln/debug-root-cause`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/debug-root-cause`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/kiln-skills/kiln/debug-root-cause) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/debug-root-cause`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/debug-root-cause --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/debug-root-cause --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Debug: Root Cause First

The most common debugging failure is patching the symptom. This skill forces a reproduce → hypothesize → prove → fix loop.

## 1. Reproduce

- Get the exact failing command (test, script, request). Run it yourself and capture the full output.
- If it doesn't reproduce, stop and gather info: environment, versions (`node -v`, `python --version`, lockfile), input data, env vars. Don't fix what you can't see.
- Make the reproduction as small and fast as possible (a single test, `pytest path::test_name -x`, `npx vitest run file -t "name"`).

## 2. Read the error properly

- Read the **whole** stack trace. The first frame in *the user's own code* (not `node_modules` / `site-packages`) is usually where to look.
- Read the actual code at those lines, plus callers.
- Common decoders:
  - `Cannot read properties of undefined (reading 'x')` / `AttributeError: 'NoneType'` → something upstream returned nothing; find where the value came from.
  - `ERR_MODULE_NOT_FOUND`, `ModuleNotFoundError` → path, ESM/CJS mismatch, virtualenv not active, missing dependency.
  - `UnhandledPromiseRejection`, `RuntimeWarning: coroutine was never awaited` → missing `await`.
  - Works locally, fails in CI → env vars, timezone, file ordering, node/python version, test isolation.
  - Flaky → shared state between tests, time, randomness, network, race conditions.

## 3. Hypothesize, then prove

Write down 1–3 hypotheses ranked by likelihood. For each, pick the cheapest experiment that would confirm or kill it:
- Add a targeted log/print of the suspicious value (remove it after).
- Write a failing test that pins the bug.
- `git bisect` if it "used to work": `git bisect start; git bisect bad; git bisect good <sha>` then run the repro at each step.
- Check what changed recently: `git log -p --since="3 days ago" -- <file>`.

Only move to a fix when one hypothesis is **proven**. If all are killed, go back to step 2 with the new evidence.

## 4. Fix at the root

- Fix where the bad value/state is *created*, not where it *explodes*.
- Avoid symptom patches: blanket `try/except`, `?.` everywhere, `# type: ignore`, raising timeouts, `retry` on deterministic failures. If a guard really is the right answer, explain why.
- Keep the fix minimal; refactors go in a separate step.

## 5. Prevent regression

- Add (or keep) the test that failed before the fix and passes after.
- Run the related test suite, not just the single test.
- Search for the same pattern elsewhere: `grep -rn "<pattern>" src/` — same bug often lives in sibling code.

## 6. Report

```
**Root cause:** <1–2 sentences, name file:line>
**Evidence:** <what proves it — output, a test>
**Fix:** <what changed and why there>
**Prevention:** <test added / similar patterns found>
```

Write the report in the user's language (for example, Indonesian if they wrote in Indonesian); translate the headings too.
