root-cause-tracing

Systematically traces bugs backward through the call stack to identify where invalid data or incorrect behavior originates.

  • Purpose - Find the source of bugs that manifest deep in execution

  • Output - Trace chain from symptom to original trigger with fix recommendation

/kaizen:root-cause-tracing

Arguments

None. The command works with the current bug context from your conversation.

How It Works

  1. Observe Symptom: Identify where the error appears (e.g., wrong file created, incorrect output)

  2. Find Immediate Cause: Locate the code that directly causes the error

  3. Trace Upward: Ask "what called this?" and follow the chain

  4. Track Values: Note what values were passed at each level

  5. Find Origin: Continue until you find where invalid data originated

  6. Add Instrumentation: If manual tracing fails, add stack trace logging

  7. Fix at Source: Address the root trigger, not the symptom location

Key Principle

Never fix just where the error appears. Trace back to find the original trigger.

Usage Examples

Example Trace

Best practices

  • Use console.error in tests - Loggers may be suppressed in test environments

  • Log before dangerous operations - Capture state before failure, not after

  • Include full context - Directory, cwd, environment variables, timestamps

  • Add defense-in-depth - Fix at source AND add validation at each layer

  • Capture stack traces - Use new Error().stack for complete call chains

Last updated