root-cause-tracing

Trace bugs backward through the call stack to identify the original trigger.

270k|24.1k|Updated Oct 9, 2025
One-click install
npx skills add https://github.com/obra/superpowers --skill root-cause-tracing-obra
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: root-cause-tracing
Source: https://github.com/obra/superpowers/tree/main/skills/root-cause-tracing
Command: npx skills add https://github.com/obra/superpowers --skill root-cause-tracing-obra

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solves? This Skill prevents fixing symptoms by guiding a systematic backward trace through the call stack. It helps identify the original trigger of invalid data or incorrect behavior, ensuring fixes are applied at the source, not just where the error manifests.

Core Features & Use Cases

  • Backward Tracing Process: Systematically traces errors up the call chain, from symptom to immediate cause to the original trigger, ensuring a thorough investigation.
  • Instrumentation for Evidence: Provides guidance on adding diagnostic logging and stack traces to gather crucial context when manual tracing is difficult.
  • Polluter Identification: Recommends a bisection script (find-polluter.sh) to pinpoint which specific test or code introduces unwanted state or pollution during test runs.
  • Use Case: When a git init command fails in an unexpected directory, this skill helps you trace back through WorktreeManager, Session.create(), and test setup to find that an empty string was passed as projectDir at the very beginning, allowing you to fix the true source.

Quick Start

Example: Tracing an error deep in the stack

You: I'm using the root-cause-tracing skill to find the source of this error.

1. Observe the Symptom

Error: git init failed in /Users/jesse/project/packages/core

2. Find Immediate Cause

- Identify the code directly causing the error (e.g., execFileAsync('git', ['init'], { cwd: projectDir }))

3. Ask: What Called This?

- Trace up the call stack (e.g., WorktreeManager.createSessionWorktree -> Session.initializeWorkspace -> Session.create -> test)

4. Keep Tracing Up

- Identify the problematic value (e.g., projectDir = '' (empty string!))

5. Find Original Trigger

- Locate where the bad value originated (e.g., context.tempDir accessed before beforeEach)

Adding Stack Traces (if manual tracing is hard)

async function gitInit(directory: string) { const stack = new Error().stack; console.error('DEBUG git init:', { directory, cwd: process.cwd(), stack }); await execFileAsync('git', ['init'], { cwd: directory }); }

Finding Which Test Causes Pollution (using find-polluter.sh script)

./find-polluter.sh '.git' 'src/**/*.test.ts'

Frequently Asked Questions about root-cause-tracing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I trace a bug back through the call stack to find where it really started?

Root-cause tracing systematically traces errors backward from where they manifest to their original trigger. Start by observing the symptom, identify the immediate code causing it, then ask what called that code repeatedly until you find the problematic value's origin. This prevents fixing symptoms by addressing the true source.

Why does my test keep failing and how do I find which test is causing the pollution?

Test pollution occurs when one test modifies shared state affecting others. Root-cause tracing uses a bisection script to pinpoint exactly which test introduces unwanted state, then traces back to identify the setup or teardown issue at the source rather than masking the failure.

What's the best way to add instrumentation to trace bugs when I can't manually follow the call stack?

Add diagnostic logging and stack traces at key execution points to gather context. Root-cause tracing guides you to instrument functions with console output, stack capture, and variable inspection, creating a trail that shows exactly what values flow through the call chain.

Can I use root-cause tracing with deep execution chains and unclear data origins?

Yes. Root-cause tracing is designed for errors deep in execution with long call chains and unclear data sources. It provides step-by-step backward tracing and layered validations to identify where invalid data entered the system, ensuring fixes enforce correctness at the origin.

How do I know if I'm fixing a symptom instead of the real problem?

Fixing at the symptom point—where the error manifests—leaves the root cause to resurface elsewhere. Root-cause tracing enforces fixing at the origin by requiring you to trace backward to the original trigger, ensuring the problematic value or behavior is corrected where it begins.