Root cause first

From cohen-liel/agent-skills · View interactive version

Root cause first is an AI agent skill from the GitHub repository cohen-liel/agent-skills. Root-cause-first debugging and repair workflow. Use when asked to fix a bug, runtime error, failing test, broken tool/agent behavior, unexpected logs, regression, flaky behavior, architecture issue, or any request that says "fix", "debug", "solve from the root", "no band-aids", "no fallback", or "un

How to use this skill

Skill file

Root Cause First

Use this skill to prevent premature patches. The goal is to make the smallest correct change only after the failure mechanism is understood.

Red Flags — Stop If You Catch Yourself Thinking

These thoughts mean you are about to ship a band-aid. Stop and find the mechanism first.

| Thought | Reality |

|---|---|

| "I'll add a ?. or null-check so it stops crashing" | You are hiding the signal. Ask why it is null and fix that. |

| "Wrapping it in try/catch makes the error go away" | Catch-and-continue turns a loud bug into a silent one. |

| "The test is flaky, let me add a retry or a longer timeout" | Flaky means a real race or order dependency. Retry hides it. |

| "I'll widen the parser to accept the weird input too" | The weird input is the clue. Find who produced it. |

| "I'll return a default on error so the flow continues" | Synthetic success masks the failure from everyone downstream. |

| "It works now, I am not sure why" | Then it is not fixed. You moved the bug. |

Relationship To SSOT Enforcer

If the root cause is duplicated constants, scattered policy, parallel calculations, copied parsing, or multiple modules answering the same question, switch to ssot-enforcer for the consolidation step. After consolidation, return here to verify the fix against the original failure.

When Not To Use

Do not use this skill for:

Required Workflow

  1. State the observed failure in concrete terms.
  1. Reconstruct the intended contract.
  1. Trace the real path before editing.
  1. Name the root cause.
  1. Reject band-aids explicitly.
  1. Implement the root fix.
  1. Verify against the original failure.

Worked Example

Symptom. TypeError: cannot read 'email' of undefined thrown in renderProfile() for ~2% of users.

Band-aid (what to avoid).

// Crash disappears, but those users now silently render a blank email.
const email = user.profile?.email ?? "";

The optional chain suppresses the only signal that something upstream is wrong.

Root-cause trace. Follow where user is built. loadUser() returns the record before profile is hydrated for accounts created before the profile backfill. The invariant "every user has a profile" is violated at the data layer, not in the view.

Root fix. Enforce the invariant at the source so every consumer can trust it:

// loadUser() now owns the invariant: it always returns a non-null profile.
function loadUser(id) {
  const row = db.fetchUser(id);
  return { ...row, profile: row.profile ?? defaultProfile(row.id) };
}

Now renderProfile() can trust its input and the ?. is unnecessary. (The invariant has exactly one owner — see ssot-enforcer.)

Verification. Add a regression test: loadUser() for a pre-backfill account returns a non-null profile; renderProfile() renders without optional chaining and the old input reproduces the original crash on the unpatched code.

Stop Conditions

Stop and ask or report a blocker when:

Final Answer Shape

Keep the close-out short:

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.