Cm debugging

From tody-agent/codymaster · View interactive version

Cm debugging is an AI agent skill from the GitHub repository tody-agent/codymaster. Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes

How to use this skill

Skill file

Systematic Debugging

TL;DR

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:

Use this ESPECIALLY when:

Don't skip when:

The Four Phases

You MUST complete each phase before proceeding to the next.

Phase 0.5: Memory Integrity Check (BEFORE blaming code)

BEFORE blaming code, ASK: "Could memory be causing this bug?"

  1. SUSPECT — Identify relevant memories:
  1. INVESTIGATE — Did AI follow a memory when writing buggy code?
  1. VERIFY — Is the suspect memory still correct?
  1. HEAL (only if memory confirmed as cause):
IF memory caused the bug:
  → HEAL memory FIRST
  → THEN proceed to Phase 1 to fix code
  → The code fix will be correct because memory is now correct

IF memory did NOT cause the bug:
  → Proceed to Phase 1 normally

WHY PHASE 0.5? Fix memory first → code fix will be correct.

Without fixing memory → bug will return next session (bug loop).

Phase 1: Root Cause Investigation

BEFORE attempting ANY fix:

  1. Read Error Messages Carefully
  1. Reproduce Consistently
  1. Check Recent Changes
  1. 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:

Run once to gather evidence showing WHERE it breaks

THEN analyze evidence to identify failing component

THEN investigate that specific component

```

  1. Trace Data Flow

WHEN error is deep in call stack:

Phase 2: Pattern Analysis

Find the pattern before fixing:

  1. Find Working Examples
  1. Compare Against References
  1. Identify Differences
  1. Understand Dependencies

Phase 3: Hypothesis and Testing

Scientific method:

  1. Form Single Hypothesis
  1. Test Minimally
  1. Verify Before Continuing
  1. When You Don't Know

Phase 4: Implementation

Fix the root cause, not the symptom:

  1. Create Failing Test Case
  1. Implement Single Fix
  1. Verify Fix
  1. If Fix Doesn't Work
  1. If 3+ Fixes Failed: Question Architecture

Pattern indicating architectural problem:

Discuss with your human partner before attempting more fixes

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

Step 5: Record Learning (MANDATORY)

After fixing any bug, ALWAYS write to .cm/CONTINUITY.md → "Mistakes & Learnings":

- What Failed:      [exact error message or behavior]
- Why It Failed:    [root cause from Phase 1]
- How to Prevent:   [concrete pattern to avoid]
- Scope:            [global | module:{name} | file:{path}]

Scope rules: Choose the SMALLEST scope that applies.

Anti-duplicate: If a similar learning already exists in .cm/learnings.json,

reinforce it (reinforceCount++) instead of creating a new entry.

Token savings: Next time same error pattern appears, AI reads the learning

(~50 tokens) instead of repeating full 4-phase debug cycle (~3,000 tokens).

This is the #1 token saver in the entire kit.


Red Flags - STOP and Follow Process

If you catch yourself thinking:

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

When you see these user signals: 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. |

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.

Integration

Related skills:

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.