Systematic debugging

From Undermybelt/hermes-skills · View interactive version

Systematic debugging is an AI agent skill from the GitHub repository Undermybelt/hermes-skills. Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes

How to use this skill

Skill file

Execute

→ Bug? Test failure? Unexpected behavior? → Find root cause first. No fixes without evidence.

1. Isolate: read error → reproduce → check git diff → drill upward through diagnostic layers:

L1 symptom → L2 logic → L3 system → L4 architecture →

L5 cross-system contract → L6 platform constraint → L7 spec gap.

Stop when no deeper "why" remains OR terminal unactionable (T1-T4).

2. Identify owner: compare with working code → locate canonical owner → flag duplicate owners as a finding

3. Before fixing, run Patch-Shape Triage and Ripple Signal Triage if the candidate fix touches shared/core/cross-module behavior, contract, source-of-truth, fallback, adapter, duplicate owner, producer+consumer, or consumer-side patching. Also run Pre-Edit Complexity Check when the candidate fix touches an overloaded owner or may worsen source complexity.

4. Prove: one hypothesis → minimal test → iterate. 3+ failed fixes = question architecture, do not attempt another code fix.

After fix, if any symptom persists → differential diagnosis (Phase 4 Step 4bis).

5. Fix: failing test → minimal code at canonical owner → verify → Reflection + architecture review → repair + retirement track

→ Done when: confidence ≥ B, both tracks explicit, DeeperCause answered "no" with evidence, no H-class hard signal still active.

Systematic Debugging

Overview

Random fixes waste time and create new bugs. Symptom fixes are failure.

This skill is the canonical debugging workflow. Use it to move from symptom to

root cause, then to the smallest sufficient stable repair and retirement plan.

Smallest repair means correct owner + bug class fixed + bounded entropy, not the smallest textual diff.

When to Use

Any technical issue: test failures, bugs, unexpected behavior, performance problems, build/integration failures.

Especially under time pressure, when "just one quick fix" seems obvious, after multiple failed fixes, or when duplicate owners / fallback chains may be involved.

Quick bug lane

For low-risk, single-owner bugs, keep the report compact: Symptom,

Reproduction, Root Cause, Fix Boundary, and Verification. Still collect

root-cause evidence before editing. If fallback, duplicate owner, consumer-side

patching, contract risk, shared logic, or cross-module behavior appears,

escalate to the full workflow.

The Four Phases

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
  1. Trace Data Flow (when error is deep in call stack)
  1. Drill Upward Through Diagnostic Layers

Start at L1. Exhaust all "why" questions at each layer before moving upward.

The chain is open-ended — architecture is not the endpoint.

```

L1 Symptom: what failed? where? exact reproduction?

L2 Logic: which branch, invariant, or state transition is wrong?

L3 System: which component boundary, dependency, or ownership seam?

L4 Architecture: what design choice, duplicated owner, or fallback chain?

L5 Cross-system: which API / SLA / timing contract between systems?

L6 Platform: what runtime / OS / framework constraint?

L7 Spec gap: who never defined correct behavior for this case?

```

Hard signal definitions (H/T/D) are in the Quality Gate — apply them there,

not during initial investigation.

When the stop layer is not obvious, the user asks where the diagnosis

stops, the issue crosses component/system boundaries, or a user-provided

fact falsifies the current layer, expose a compact Layer Stop Card before

fixing:

```text

Layer Stop Card:

```

The card is an advisory readback of the diagnostic stop point. It is not a

GateDecision, PolicySnapshot, or completion authority.

  1. Patch-Shape Triage Before Editing

Treat the first obvious fix as evidence, not clearance to edit. If the

candidate fix shape matches any item below, continue upward before changing

code unless you can prove the local layer is the canonical owner:

contract, or another source-of-truth already exists

the producer and source-of-truth owner

Required output before editing when this gate fires:

```text

PatchShape:

CanonicalOwner:

UpwardDrillSignal:

Decision: fix owner | continue investigation | escalate

```

If the tempting fix is "just add a small guard/fallback", also run:

```text

Minimality Check:

```

local patch is a mitigation, not a sufficient repair, unless it is the

canonical owner and includes a retention reason plus retirement trigger.

If the repair or retirement boundary depends on deleting old paths,

retaining compat for a proven external dependency, or stopping on

persistent-state risk, compose anti-entropy-governance before editing. It

decides the path; it does not grant destructive authority.

  1. Pre-Edit Complexity Check

After root cause and canonical owner are identified, check whether the fix

adds complexity to the wrong or overloaded place:

```text

Pre-Edit Complexity Check:

```

Use this for 800+ line files, 80+ line blocks, generic owners,

fallback/adapter/guard paths, or unclear root-cause ownership. Advisory only:

if the safer boundary changes the implementation shape, pause and update the

plan/spec.

Phase 2: Pattern Analysis

  1. Find working examples in the same codebase — what works that's similar?
  2. Compare against references — read completely, don't skim
  3. Identify differences between working and broken — list every difference
  4. Understand dependencies — config, environment, assumptions
  5. Locate the canonical owner — which file/module should own this? Multiple owners = a finding, not normality

Phase 3: Hypothesis and Testing

  1. Form single hypothesis: "I think X is the root cause because Y" — be specific
  2. Test minimally: smallest possible change, one variable at a time. Prefer instrumentation over code edits while still proving the cause.
  3. Verify: worked? → Phase 4. Didn't? → Form NEW hypothesis. Don't stack fixes.
  4. When you don't know: say "I don't understand X", don't pretend
  5. Run Reflection at the end of each loop:

Phase 4: Implementation

Fix the root cause, not the symptom:

  1. Create Failing Test Case
  1. Implement Single Fix

fired, carry its owner, downstream, contract, source-of-truth, fallback,

retirement, edit-boundary, and verification findings into the fix

boundary before editing code.

  1. Verify Fix
  1. If Fix Doesn't Work

4bis. Post-Fix Differential Diagnosis

After applying a fix, if ANY symptom persists:

STOP. Do NOT attempt another fix without diagnosis.

1. Isolate the residual symptom precisely — what exactly remains?

2. Trace its causal chain independently (fresh Phase 1 run).

3. Compare with the causal chain of the fixed symptom:

| Residual pattern | Diagnosis | Action |

| --- | --- | --- |

| Same reproduction conditions as fixed symptom | Fix is incomplete | Continue upward drilling from same source |

| Different reproduction conditions, chains converge to same source | Fix was at wrong depth | Drill upward again from the shared source |

| Different reproduction conditions, chains diverge | Compound root cause (≥2 independent roots) | Each root needs its own fix |

| Same symptom, reduced but not eliminated | Fix was a downstream patch | Drill upward again from source |

4. If uncertain whether convergent or divergent: escalate. Do not guess.

Compound root cause forms:

  1. If 3+ Fixes Failed: Question Architecture

Pattern indicating architectural problem:

STOP and question fundamentals. Discuss with your human partner before attempting more fixes.

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

  1. Deliver Dual-Track Closure

For bug fixes, refactors, contract changes, or governance cleanup, always produce:

Repair track — root cause, canonical owner, smallest necessary change, compatibility boundary, verification method.

Retirement track — old owner / fallback / patch, whether it is still active on the main path, the only reason to keep it (if any), trigger for deletion, verification needed before removal.

Never add a new owner, fallback, prompt branch, or adapter path without stating what happens to the old one.

Quality Gate

Before you claim debugging is complete:

  1. Workspace record for non-trivial debugging — if this is medium+ complexity

or it writes docs/aegis/ records, initialize/check through configured

Aegis workspace support when available:

```bash

python <aegis-workspace-helper> init --root <target-project-root>

python <aegis-workspace-helper> new-work --root <target-project-root> ...

python <aegis-workspace-helper> add-evidence --root <target-project-root> --work <YYYY-MM-DD-slug> ...

python <aegis-workspace-helper> check --root <target-project-root>

```

Fast bug fix or quick bug fix pressure does not skip this: if Ripple Signal

Triage fires, do the triage before editing and expand verification to the

canonical owner plus affected downstream path.

These records are method-pack evidence trails only. They do not grant

authoritative completion.

  1. Stop-when review — re-read the diagnostic layer where you stopped. Did you reach "no deeper why remains" or a T-class terminal boundary? If the chain ended at L1-L2 and the evidence is conclusive, that is a valid endpoint. If there are still unexplained "why" questions, continue upward drilling before claiming done.

contract owner, spec/product decision, or user correction path. Keep

simple fast-path explanations cheap; do not emit the card for ordinary

factual Q&A about the skill itself.

  1. Hard signal check — apply these countable facts, not judgments:

Must continue upward drilling (H-class — ANY hit = NOT done):

Terminal unactionable (T-class — any hit = stop drilling, switch to mitigation):

→ On T-class: record root cause + system boundary + architecture review: what boundary vulnerability did this expose? can the system be made more resilient to this class of external failure?

Depth sufficient (D-class — ALL must pass before claiming done):

patch is explicitly bounded with retention reason and retirement trigger

  1. Reflection — re-run Goal / DeeperCause / Evidence / Risk/Unknown / Decision
  2. Confirm the fix addressed the source, not just the sample
  3. Retirement surface — did it shrink, stay, or grow?
  4. Confidence:

If confidence is not at least B, do not speak as if the issue is fully closed.

Red Flags - STOP and Follow Process

If you catch yourself thinking:

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

If 3+ fixes failed: Question the architecture (see Phase 4 Step 5)

If symptoms persist after fix: Run differential diagnosis (see Phase 4 Step 4bis)

Human Partner Signals

If you hear "Is that not happening?", "Will it show us...?", "Stop guessing", "Ultrathink this" → STOP. Return to Phase 1.

When Process Reveals "No Root Cause"

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

document what you investigated, implement appropriate handling (retry, timeout, error message),

add monitoring.

Supporting Techniques

See root-cause-tracing.md, defense-in-depth.md, condition-based-waiting.md, feedback-loop-construction.md in this directory for deeper guidance on specific diagnostic scenarios.

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.