オプション
家 Skill 開発者ツール systematic-debugging

systematic-debugging

obra/superpowers obra/superpowers

修正案を提案する前に、バグ、テストの失敗、または予期しない動作の根本原因を特定してください。

...すべて拡張します
21
更新された時間 2026年9月3日

体系的なデバッグ

概要

場当たり的な修正は時間を浪費し、新たなバグを生み出します。その場しのぎの修正は根本的な問題を覆い隠してしまいます。

基本原則:修正を試みる前に、必ず根本原因を突き止めること。症状だけの修正は失敗に終わる。

このプロセスの文字通りの規定に違反することは、デバッグの精神に反することである。

鉄則

根本原因の調査なしに修正を行ってはならない

フェーズ1を完了していない場合は、修正案を提案してはならない。

適用時期

あらゆる技術的な問題に適用します:

  • テストの失敗
  • 本番環境での不具合
  • 予期しない動作
  • パフォーマンスの問題
  • ビルドの失敗
  • 統合上の問題

特に次のような場合にこれを使用してください:

  • 時間的制約がある場合(緊急時には、当て推量をしがちになります)
  • 「ちょっとした手っ取り早い修正」が当然のように思える場合
  • すでに複数の修正を試みた場合
  • 前回の対処法が効果を示さなかった場合
  • 問題を完全に理解できていない場合

以下の場合はスキップしないでください:

  • 問題が単純に見える場合(単純なバグにも根本原因は存在する)
  • 急いでいる場合(急いで対応すると、必ず手直しが必要になります)
  • 上司が「今すぐ」修正を求めている場合(体系的な対応の方が、手探りでの対応より速い)

4つのフェーズ

各フェーズを必ず完了させてから、次のフェーズに進んでください。

フェーズ1:根本原因の調査

いかなる修正を試みる前に:

  1. エラーメッセージを注意深く読み取る

    • エラーや警告を無視しないでください
    • そこには多くの場合、正確な解決策が記載されています
    • スタックトレースを最後まで読みましょう
    • 行番号、ファイルパス、エラーコードをメモしてください
  2. 一貫して再現する

    • 確実に再現できますか?
    • 具体的な手順はどのようなものですか?
    • 毎回発生しますか?
    • 再現できない場合 → 推測せず、さらにデータを収集してください
  3. 最近の変更を確認する

    • 何が変更されて、この現象を引き起こした可能性があるか?
    • Git diff、最近のコミット
    • 新しい依存関係、設定の変更
    • 環境の違い
  4. マルチコンポーネントシステムにおける証拠の収集

    システムに複数のコンポーネントがある場合(CI → ビルド → 署名、API → サービス → データベース):

    修正案を提案する前に、診断用の計測機能を追加する:

    各コンポーネントの境界において:
      - コンポーネントに入力されるデータをログに記録する
      - コンポーネントから出力されるデータをログに記録する
      - 環境/設定の伝播を確認する
      - 各レイヤーの状態を確認する
    
    一度実行して、どこで障害が発生しているかを示す証拠を収集する
    その後、証拠を分析して障害を起こしているコンポーネントを特定する
    その後、その特定のコンポーネントを調査する
    

    例(多層システム):

    # レイヤー 1: ワークフロー
    echo "=== ワークフローで利用可能なシークレット: ==="
    echo "IDENTITY: ${IDENTITY:+SET}${IDENTITY:-UNSET}"
    
    # レイヤー2:ビルドスクリプト
    echo "=== ビルドスクリプト内の環境変数: ==="
    env | grep IDENTITY || echo "IDENTITYが環境変数に存在しない"
    
    # レイヤー 3: 署名スクリプト
    echo "=== キーチェーンの状態: ==="
    security list-keychains
    security find-identity -v
    
    # レイヤー 4: 実際の署名
    codesign --sign "$IDENTITY" --verbose=4 "$APP"
    

    これにより、どのレイヤーで失敗したかが明らかになります(シークレット → ワークフロー ✓、ワークフロー → ビルド ✗)

  5. データフローの追跡

    エラーがコールスタックの奥深くにある場合:

    完全な逆方向トレース手法については、このディレクトリ内のroot-cause-tracing.md を参照してください。

    簡易版:

    • 不正な値はどこから発生したのか?
    • どの関数がその不正な値でこの関数を呼び出したのか?
    • 原因が特定できるまで、呼び出し元をさかのぼり続けてください
    • 症状ではなく、原因の根本で修正する

フェーズ2:パターン分析

修正する前にパターンを見つけましょう:

  1. 正常に動作する例を見つける

    • 同じコードベース内で、同様の正常に動作するコードを探す
    • 不具合のあるコードと類似していて、正常に動作しているものは何か?
  2. リファレンスと比較する

    • パターンを実装する場合は、参照実装を「完全に」読み込む
    • 流し読みせず、一行一行しっかり読む
    • 適用する前に、そのパターンを完全に理解する
  3. 相違点を特定する

    • 正常に動作する場合と動作しない場合の違いは何か?
    • どんなに些細な違いでも、すべてリストアップしてください
    • 「そんなことは重要ではない」と決めつけないでください
  4. 依存関係を把握する

    • これには他にどのようなコンポーネントが必要か?
    • どのような設定、構成、環境が必要か?
    • どのような前提条件があるか?

フェーズ3:仮説と検証

科学的方法:

  1. 単一の仮説を立てる

    • 明確に述べる:「Yであるため、Xが根本原因だと考える」
    • 書き留める
    • 曖昧にせず、具体的に記述する
  2. 最小限の検証を行う

    • 仮説を検証するために、可能な限り最小限の変更を加える
    • 一度に一つの変数だけ
    • 一度に複数の点を修正しない
  3. 先に進む前に検証する

    • うまくいったか? はい → フェーズ4
    • うまくいかなかったか? 新しい仮説を立てる
    • その上にさらに修正を加えないでください
  4. 分からないときは

    • 「Xが分かりません」と言う
    • 知っているふりをしない
    • 助けを求めましょう
    • さらに調べてみる

フェーズ4:実行

症状ではなく根本原因を修正する:

  1. 失敗するテストケースを作成する

    • 可能な限り単純な再現手順
    • 可能であれば自動テスト
    • フレームワークがない場合は、単発のテストスクリプトを作成する
    • 修正前に必ず行うこと
    • 適切な失敗するテストを作成するには、「テスト駆動開発」という強力なスキルを活用する
  2. 単一の修正を実装する

    • 特定された根本原因に対処する
    • 一度に1つの変更のみ
    • 「ついでに」という改善はしない
    • リファクタリングをまとめて行わない
  3. 修正の検証

    • テストは通るようになったか?
    • 他のテストは失敗していないか?
    • 問題は実際に解決したか?
  4. 修正が機能しない場合

    • 中止
    • カウント:これまでいくつの修正を試しましたか?
    • 3未満の場合:フェーズ1に戻り、新しい情報をもとに再分析する
    • 3以上の場合:停止し、アーキテクチャを見直す(以下のステップ5を参照)
    • アーキテクチャに関する検討なしに、修正策 #4 を試行しないでください
  5. 3つ以上の修正が失敗した場合:アーキテクチャを見直す

    アーキテクチャ上の問題を示すパターン:

    • 修正を行うたびに、別の場所で新たな共有状態・結合・問題が明らかになる
    • 修正を実装するには「大規模なリファクタリング」が必要となる
    • 修正を行うたびに、別の場所で新たな症状が生じる

    一旦立ち止まり、基本を見直すべきです:

    • このパターンは根本的に妥当なのか?
    • 私たちは「単なる惰性でこれを使い続けている」だけではないだろうか?
    • アーキテクチャをリファクタリングすべきか、それとも症状の修正を続けるべきか?

    さらなる修正を試みる前に、人間であるパートナーと話し合おう

    これは「失敗した仮説」ではなく、間違ったアーキテクチャである。

危険信号――一旦停止し、プロセスに従う

もし次のような考えが頭をよぎったら:

  • 「とりあえず手っ取り早く直して、後で調査しよう」
  • 「とりあえずXを変えてみて、動くか試してみよう」
  • 「変更をいくつか加えて、テストを実行しよう」
  • 「テストは飛ばして、手動で確認しよう」
  • 「たぶんXが原因だろう、そこを直そう」
  • 「完全には理解できていないけど、これでうまくいくかもしれない」
  • 「パターンではXとされているが、私は別の方法で適応させる」
  • 「主な問題は以下の通りです:[調査せずに修正案を列挙する]」
  • データフローを追跡する前に解決策を提案する
  • 「もう1回修正を試みます」(すでに2回以上試した後に)
  • 修正を行うたびに、別の場所で新たな問題が発覚する

これらすべてが意味するのは、「停止」。フェーズ1に戻る。

3回以上の修正が失敗した場合:アーキテクチャを見直す(フェーズ4.5を参照)

人間のパートナーから「やり方が間違っている」というサイン

次のような話題のそらしに注意してください:

  • 「それは起きていないの?」――確認せずに勝手に仮定してしまった
  • 「それで結果が出るの…?」 — 証拠収集の手順を追加すべきだった
  • 「推測はやめて」――理解せずに修正案を提案している
  • 「もっと深く考えて」―― 症状だけでなく、根本的な問題に目を向けてください
  • 「行き詰まっている?」(苛立ち) - あなたのアプローチが機能していない

こうした言葉を見かけたら:立ち止まってください。フェーズ1に戻ってください。

よくある自己正当化

言い訳 現実
「問題は単純だから、プロセスは必要ない」 単純な問題にも根本原因は存在する。単純なバグの場合、プロセスに従う方が早く解決できる。
「緊急事態だ。手順を踏んでいる暇はない」 体系的なデバッグは、当てずっぽうな試行錯誤よりも速い。
「まずはこれを試してみて、それから調査しよう」 最初の修正がパターンを決める。最初から正しく行おう。
「修正が機能することを確認してからテストを書く」 テストされていない修正は定着しない。テストを先に行うことで、その有効性が証明される。
「一度に複数の修正をすれば時間を節約できる」 何がうまくいったのか特定できなくなる。新たなバグの原因になる。
「リファレンスが長すぎるから、パターンをアレンジしよう」 部分的な理解ではバグが確実に出る。完全に読み通すこと。
「問題点はわかった、修正するよ」 症状が見えること ≠ 根本原因を理解していること。
「もう1回修正を試みる」(2回以上失敗した後) 3回以上の失敗=アーキテクチャ上の問題。修正パターンを見直し、再度修正しようとしないでください。

クイックリファレンス

フェーズ 主要な活動 成功基準
1. 根本原因 エラーを確認し、再現し、変更点を確認し、証拠を収集する 「何が」「なぜ」を理解する
2. パターン 正常に動作する例を見つけ、比較する 相違点を特定する
3. 仮説 理論を立て、最小限の検証を行う 仮説の検証または新たな仮説の提示
4. 実装 テストを作成し、修正し、検証する バグが解消され、テストに合格した

プロセスで「根本原因なし」と判明した場合

体系的な調査の結果、問題が真に環境要因、タイミングに依存する、または外部要因によるものであることが判明した場合:

  1. プロセスは完了した
  2. 調査内容を文書化する
  3. 適切な処理(再試行、タイムアウト、エラーメッセージ)を実装する
  4. 今後の調査のために監視・ログ記録を追加する

ただし:「根本原因不明」のケースの95%は、調査が不完全であることが原因です。

支援手法

これらの手法は体系的なデバッグの一部であり、以下のディレクトリで利用可能です:

  • root-cause-tracing.md- コールスタックを遡ってバグを追跡し、元の引き金を特定する
  • defense-in-depth.md- 根本原因を特定した後、複数のレイヤーで検証を追加する
  • condition-based-waiting.md- 任意のタイムアウトを条件に基づくポーリングに置き換える

関連スキル:

  • superpowers:test-driven-development- 失敗するテストケースを作成するため(フェーズ4、ステップ1)
  • superpowers:verification-before-completion- 修正が成功したと断定する前に、修正が機能したことを検証する

実世界への影響

デバッグセッションからの教訓:

  • 体系的なアプローチ:修正に15~30分
  • 手探りでの修正アプローチ:2~3時間の無駄な試行錯誤
  • 初回修正成功率:95% 対 40%
  • 新たなバグの発生:ほぼゼロ 対 頻繁
GitHubで見る
---
name: systematic-debugging
description: Find root causes of bugs, test failures, or unexpected behavior before proposing any fixes.
---

# Systematic Debugging

## Overview

Random fixes waste time and create new bugs. Quick patches mask underlying issues.

**Core principle:** ALWAYS find root cause before attempting fixes. Symptom fixes are failure.

**Violating the letter of this process is violating the spirit of debugging.**

## The Iron Law

```
NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST
```

If you haven't completed Phase 1, you cannot propose fixes.

## When to Use

Use for ANY technical issue:
- Test failures
- Bugs in production
- Unexpected behavior
- Performance problems
- Build failures
- Integration issues

**Use this ESPECIALLY when:**
- Under time pressure (emergencies make guessing tempting)
- "Just one quick fix" seems obvious
- You've already tried multiple fixes
- Previous fix didn't work
- You don't fully understand the issue

**Don't skip when:**
- Issue seems simple (simple bugs have root causes too)
- You're in a hurry (rushing guarantees rework)
- Manager wants it fixed NOW (systematic is faster than thrashing)

## The Four Phases

You MUST complete each phase before proceeding to the next.

### Phase 1: Root Cause Investigation

**BEFORE attempting ANY fix:**

1. **Read Error Messages Carefully**
   - Don't skip past errors or warnings
   - They often contain the exact solution
   - Read stack traces completely
   - Note line numbers, file paths, error codes

2. **Reproduce Consistently**
   - Can you trigger it reliably?
   - What are the exact steps?
   - Does it happen every time?
   - If not reproducible → gather more data, don't guess

3. **Check Recent Changes**
   - What changed that could cause this?
   - Git diff, recent commits
   - New dependencies, config changes
   - Environmental differences

4. **Gather Evidence in Multi-Component Systems**

   **WHEN system has multiple components (CI → build → signing, API → service → database):**

   **BEFORE proposing fixes, add diagnostic instrumentation:**
   ```
   For EACH component boundary:
     - Log what data enters component
     - Log what data exits component
     - Verify environment/config propagation
     - Check state at each layer

   Run once to gather evidence showing WHERE it breaks
   THEN analyze evidence to identify failing component
   THEN investigate that specific component
   ```

   **Example (multi-layer system):**
   ```bash
   # Layer 1: Workflow
   echo "=== Secrets available in workflow: ==="
   echo "IDENTITY: ${IDENTITY:+SET}${IDENTITY:-UNSET}"

   # Layer 2: Build script
   echo "=== Env vars in build script: ==="
   env | grep IDENTITY || echo "IDENTITY not in environment"

   # Layer 3: Signing script
   echo "=== Keychain state: ==="
   security list-keychains
   security find-identity -v

   # Layer 4: Actual signing
   codesign --sign "$IDENTITY" --verbose=4 "$APP"
   ```

   **This reveals:** Which layer fails (secrets → workflow ✓, workflow → build ✗)

5. **Trace Data Flow**

   **WHEN error is deep in call stack:**

   See `root-cause-tracing.md` in this directory for the complete backward tracing technique.

   **Quick version:**
   - Where does bad value originate?
   - What called this with bad value?
   - Keep tracing up until you find the source
   - Fix at source, not at symptom

### Phase 2: Pattern Analysis

**Find the pattern before fixing:**

1. **Find Working Examples**
   - Locate similar working code in same codebase
   - What works that's similar to what's broken?

2. **Compare Against References**
   - If implementing pattern, read reference implementation COMPLETELY
   - Don't skim - read every line
   - Understand the pattern fully before applying

3. **Identify Differences**
   - What's different between working and broken?
   - List every difference, however small
   - Don't assume "that can't matter"

4. **Understand Dependencies**
   - What other components does this need?
   - What settings, config, environment?
   - What assumptions does it make?

### Phase 3: Hypothesis and Testing

**Scientific method:**

1. **Form Single Hypothesis**
   - State clearly: "I think X is the root cause because Y"
   - Write it down
   - Be specific, not vague

2. **Test Minimally**
   - Make the SMALLEST possible change to test hypothesis
   - One variable at a time
   - Don't fix multiple things at once

3. **Verify Before Continuing**
   - Did it work? Yes → Phase 4
   - Didn't work? Form NEW hypothesis
   - DON'T add more fixes on top

4. **When You Don't Know**
   - Say "I don't understand X"
   - Don't pretend to know
   - Ask for help
   - Research more

### Phase 4: Implementation

**Fix the root cause, not the symptom:**

1. **Create Failing Test Case**
   - Simplest possible reproduction
   - Automated test if possible
   - One-off test script if no framework
   - MUST have before fixing
   - Use the `superpowers:test-driven-development` skill for writing proper failing tests

2. **Implement Single Fix**
   - Address the root cause identified
   - ONE change at a time
   - No "while I'm here" improvements
   - No bundled refactoring

3. **Verify Fix**
   - Test passes now?
   - No other tests broken?
   - Issue actually resolved?

4. **If Fix Doesn't Work**
   - STOP
   - Count: How many fixes have you tried?
   - If < 3: Return to Phase 1, re-analyze with new information
   - **If ≥ 3: STOP and question the architecture (step 5 below)**
   - DON'T attempt Fix #4 without architectural discussion

5. **If 3+ Fixes Failed: Question Architecture**

   **Pattern indicating architectural problem:**
   - Each fix reveals new shared state/coupling/problem in different place
   - Fixes require "massive refactoring" to implement
   - Each fix creates new symptoms elsewhere

   **STOP and question fundamentals:**
   - Is this pattern fundamentally sound?
   - Are we "sticking with it through sheer inertia"?
   - Should we refactor architecture vs. continue fixing symptoms?

   **Discuss with your human partner before attempting more fixes**

   This is NOT a failed hypothesis - this is a wrong architecture.

## Red Flags - STOP and Follow Process

If you catch yourself thinking:
- "Quick fix for now, investigate later"
- "Just try changing X and see if it works"
- "Add multiple changes, run tests"
- "Skip the test, I'll manually verify"
- "It's probably X, let me fix that"
- "I don't fully understand but this might work"
- "Pattern says X but I'll adapt it differently"
- "Here are the main problems: [lists fixes without investigation]"
- Proposing solutions before tracing data flow
- **"One more fix attempt" (when already tried 2+)**
- **Each fix reveals new problem in different place**

**ALL of these mean: STOP. Return to Phase 1.**

**If 3+ fixes failed:** Question the architecture (see Phase 4.5)

## your human partner's Signals You're Doing It Wrong

**Watch for these redirections:**
- "Is that not happening?" - You assumed without verifying
- "Will it show us...?" - You should have added evidence gathering
- "Stop guessing" - You're proposing fixes without understanding
- "Ultra-think this" - Question fundamentals, not just symptoms
- "We're stuck?" (frustrated) - Your approach isn't working

**When you see these:** STOP. Return to Phase 1.

## Common Rationalizations

| Excuse | Reality |
|--------|---------|
| "Issue is simple, don't need process" | Simple issues have root causes too. Process is fast for simple bugs. |
| "Emergency, no time for process" | Systematic debugging is FASTER than guess-and-check thrashing. |
| "Just try this first, then investigate" | First fix sets the pattern. Do it right from the start. |
| "I'll write test after confirming fix works" | Untested fixes don't stick. Test first proves it. |
| "Multiple fixes at once saves time" | Can't isolate what worked. Causes new bugs. |
| "Reference too long, I'll adapt the pattern" | Partial understanding guarantees bugs. Read it completely. |
| "I see the problem, let me fix it" | Seeing symptoms ≠ understanding root cause. |
| "One more fix attempt" (after 2+ failures) | 3+ failures = architectural problem. Question pattern, don't fix again. |

## Quick Reference

| Phase | Key Activities | Success Criteria |
|-------|---------------|------------------|
| **1. Root Cause** | Read errors, reproduce, check changes, gather evidence | Understand WHAT and WHY |
| **2. Pattern** | Find working examples, compare | Identify differences |
| **3. Hypothesis** | Form theory, test minimally | Confirmed or new hypothesis |
| **4. Implementation** | Create test, fix, verify | Bug resolved, tests pass |

## When Process Reveals "No Root Cause"

If systematic investigation reveals issue is truly environmental, timing-dependent, or external:

1. You've completed the process
2. Document what you investigated
3. Implement appropriate handling (retry, timeout, error message)
4. Add monitoring/logging for future investigation

**But:** 95% of "no root cause" cases are incomplete investigation.

## Supporting Techniques

These techniques are part of systematic debugging and available in this directory:

- **`root-cause-tracing.md`** - Trace bugs backward through call stack to find original trigger
- **`defense-in-depth.md`** - Add validation at multiple layers after finding root cause
- **`condition-based-waiting.md`** - Replace arbitrary timeouts with condition polling

**Related skills:**
- **superpowers:test-driven-development** - For creating failing test case (Phase 4, Step 1)
- **superpowers:verification-before-completion** - Verify fix worked before claiming success

## Real-World Impact

From debugging sessions:
- Systematic approach: 15-30 minutes to fix
- Random fixes approach: 2-3 hours of thrashing
- First-time fix rate: 95% vs 40%
- New bugs introduced: Near zero vs common

すべてのファイル

0件のファイル

systematic-debuggingをインストール

スキルファイルをダウンロードし、.claude/skills/ ディレクトリに解凍してください。

ZIPをダウンロード

リポジトリをクローンし、スキルファイルをプロジェクトにコピーしてください。

git clone https://github.com/obra/superpowers/tree/main/skills/systematic-debugging # Copy SKILL.md to your .claude/skills/ directory

コピー コピー
クイックセットアップ: スキルフォルダを .claude/skills/ にコピーしてください。 Claude が自動的にそのスキルを検出して使用します。
リポジトリ obra/superpowers

関連スキル

algorithmic-art
更新された時間 2026年8月27日
receiving-code-review
更新された時間 2026年9月3日
tech-debt-tracker
更新された時間 2026年8月29日
deprecation-and-migration
更新された時間 2026年9月3日
OR