Execute
→ Bug? Test failure? Unexpected behavior? → Find root cause first. No fixes without evidence.
- 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).
- Identify owner: compare with working code → locate canonical owner → flag duplicate owners as a finding
- 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. Run Minimality Check when the candidate fix adds a new branch, fallback, owner, adapter, or compatibility path. Also run Pre-Edit Complexity Check when the candidate fix touches an overloaded owner or may worsen source complexity.
- 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).
- 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:
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
Reproduce Consistently
- Can you trigger it reliably? What are the exact steps? Does it happen every time?
- If not reproducible → consult
feedback-loop-construction.md to build an automated reproduction loop; don't guess
- Record baseline: inputs, environment, version, logs, success/failure criteria
Check Recent Changes
- What changed that could cause this? Git diff, recent commits, new dependencies, config changes, environmental differences
Gather Evidence in Multi-Component Systems
- Instrument each component boundary: log what enters and exits
- Run once to see where data breaks, then focus investigation there
Trace Data Flow (when error is deep in call stack)
- 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.
- For the complete backward tracing technique, see
root-cause-tracing.md.
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:
Layer Stop Card:
- Current Stop Layer: L1 Symptom | L2 Logic | L3 System | L4 Architecture | L5 Cross-system Contract | L6 Platform | L7 Spec Gap | T-class boundary
- Checked Path:
- Evidence For Stop:
- Excluded Layers:
- Falsifier:
- User Intervention Point:
- Next Action:
The card is an advisory readback of the diagnostic stop point. It is not a
GateDecision, PolicySnapshot, or completion authority.
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:
- keyword, phrase, regex, negation-word list, or sample-text exception
- local guard, extra conditional,
try/catch, early return, or one-off branch
- fallback, adapter, compatibility branch, prompt branch, or legacy path expansion
- consumer/caller/readiness/presentation-layer patch
- downstream re-parsing of raw text when typed intent, normalized state,
contract, or another source-of-truth already exists
- artifact/download/export/readback/cache patch that does not first locate
the producer and source-of-truth owner
- duplicate parsing, duplicate owner, or "keep both for now" reasoning
- fix that only names the observed sample instead of the bug class
Required output before editing when this gate fires:
PatchShape:
CanonicalOwner:
UpwardDrillSignal:
Decision: fix owner | continue investigation | escalate
If the tempting fix is "just add a small guard/fallback", also run:
Minimality Check:
- Smallest textual diff:
- Existing owner / reuse path:
- Correct owner:
- Bug class fixed:
- New branch/fallback added:
- Existence proof for new path:
- Old path retired or scheduled:
- Verdict: sufficient repair | local patch | needs first-principles review
local patch is a mitigation, not a sufficient repair, unless it is the
canonical owner and includes a retention reason plus retirement trigger.
For candidate additions that are not ordinary repair code, use
docs/current/AEGIS_MINIMALITY_REFERENCE.md to check whether the new surface
needs to exist before editing.
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.
Pre-Edit Complexity Check
After root cause and canonical owner are identified, check whether the fix
adds complexity to the wrong or overloaded place:
Use using-aegis/references/complexity-governance.md for shared pressure
signals and the meaning of over-budget.
Pre-Edit Complexity Check:
- Target edit file:
- Existing pressure signal:
- Owner fit:
- Safer edit boundary:
- Decision: edit-in-place | extract helper | add owner file | split task | pause for plan update
If the safer boundary changes the implementation shape, pause and update the
plan/spec.
If the likely repair would grow an already oversized maintained artifact and
the slice cannot govern that growth immediately, do not present the repair as
a completed fix boundary. Escalate with a plan update or a visible follow-up
requirement.
Phase 2: Pattern Analysis
- Find working examples in the same codebase — what works that's similar?
- Compare against references — read completely, don't skim
- Identify differences between working and broken — list every difference
- Understand dependencies — config, environment, assumptions
- Locate the canonical owner — which file/module should own this? Multiple owners = a finding, not normality
Phase 3: Hypothesis and Testing
- Form single hypothesis: "I think X is the root cause because Y" — be specific
- Test minimally: smallest possible change, one variable at a time. Prefer instrumentation over code edits while still proving the cause.
- Verify: worked? → Phase 4. Didn't? → Form NEW hypothesis. Don't stack fixes.
- When you don't know: say "I don't understand X", don't pretend
- Run Reflection at the end of each loop:
- Goal | DeeperCause (yes/no/uncertain) | Evidence | Risk/Unknown | Decision (exit/iterate/escalate)
- If DeeperCause = uncertain → continue or escalate. Only exit when root cause is deep enough and evidence is sufficient.
Phase 3.5: Pre-Claim Gate
Before claiming a root cause and entering Phase 4, check whether the
Pre-Claim Gate applies. It applies whenever any Patch-Shape Triage signal is
active (candidate fix is a guard, fallback, consumer/caller patch,
artifact/cache patch, or sample-only naming — i.e. H1 / H3 / H8 / H10 / H11 /
H13), or whenever the diagnosis crosses a component or system boundary, or a
previous fix left a residual symptom.
When it applies, do not state a root cause or edit code until the five
mechanical checks below pass. See root-cause-claim-contract.md for the full
rationale, the six-topology table, and a worked example.
- Causal Closure — every causal edge from symptom to claimed root has an
evidence anchor (file:line, test, log, reproduction). One "probably" edge
leaves the chain open.
- Falsifier Checked — state "if X were not the root cause, observable F
would appear," and confirm F was checked and absent.
- Adversarial Self-Refutation — generate the strongest single argument
that this root cause is wrong, and show why it does not hold.
- Causal Topology Gate — classify the topology explicitly; do not default
to single-root. Topology and the anti-disguise check are in Phase 4 Step
4bis and in
root-cause-claim-contract.md.
- Layer Ceiling Proof — if the claim stops at L?, show why L?+1 is
unreachable by concrete constraint, not by omission.
Required output before entering Phase 4 when the gate fires:
Pre-Claim Gate Pass:
Topology: single-root | single-root-multi-symptom | chain | independent-compound | conjunctive-cluster | disjunctive-or
CausalClosure: closed | open-edge: <edge>
Falsifier: <if not-X then F; F checked: yes/no>
SelfRefutation: <strongest objection> -> <why it does not hold>
LayerCeiling: <L?> -> <why L?+1 unreachable>
Verdict: pass | fail-<which-gate>
This gate is advisory method-pack discipline. It is not a GateDecision,
PolicySnapshot, evidence sufficiency authority, or completion authority. It
turns a self-judged stop ("I think this is deep enough") into a checkable,
falsifiable claim ("here is the evidence chain, the falsifier I checked, the
objection I survived, and the ceiling I reached"). The quick bug lane is
exempt when no Patch-Shape signal fires and the bug is single-owner at the
canonical owner.
Phase 4: Implementation
Fix the root cause, not the symptom:
Create Failing Test Case
- Simplest possible reproduction. One-off test script if no framework.
- MUST have before fixing.
Implement Single Fix
- Address the root cause identified. ONE change at a time.
- No "while I'm here" improvements. No bundled refactoring.
- Prefer changing the canonical owner instead of stacking more logic into a fallback path.
- If Patch-Shape Triage, Ripple Signal Triage, or Pre-Edit Complexity Check
fired, carry its owner, downstream, contract, source-of-truth, fallback,
retirement, edit-boundary, and verification findings into the fix
boundary before editing code.
Verify Fix
- Test passes now? No other tests broken? Issue actually resolved?
- Verify the intended compatibility boundary still holds.
- Verify you did not silently move authority to the wrong layer.
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 6 below). DON'T attempt Fix #4 without architectural discussion.
4bis. Post-Fix Differential Diagnosis
After applying a fix, if ANY symptom persists:
STOP. Do NOT attempt another fix without diagnosis.
- Isolate the residual symptom precisely — what exactly remains?
- Trace its causal chain independently (fresh Phase 1 run).
- 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 |
- If uncertain whether convergent or divergent: escalate. Do not guess.
Compound root cause forms (legacy shorthand):
- True compound — ≥2 independent bugs surfaced together
- Single-root multi-symptom — 1 root, ≥2 symptom paths → fix root, all resolve
- Chain causal — A causes B causes C → fix A, B and C auto-resolve
Causal Topology Gate (full form, used by the Pre-Claim Gate): the three
legacy forms above are a shorthand. Before claiming any root — single or
compound — classify the topology explicitly. The default is unknown; you
must actively exclude the multi-root topologies before collapsing to a
single-root claim. See root-cause-claim-contract.md for the full table,
member necessity/sufficiency tests, and the anti-disguise check.
| Topology |
Structure |
Stop condition |
Repair shape |
single-root |
A → symptom |
Layer Ceiling Proof at A |
fix A |
single-root-multi-symptom |
A → B, C, D |
Layer Ceiling Proof at A |
fix A; symptoms self-resolve |
chain |
A → B → C → symptom |
Layer Ceiling Proof at A |
drill to A, fix A |
independent-compound |
A → symptom, Y → symptom, A ⊥ Y |
each root passes Gate 1/2/5; no shared upstream |
fix A and Y; missing one leaves symptom |
conjunctive-cluster |
A ∧ B ∧ C → symptom (each necessary, none sufficient) |
enumerate members, necessity test each, sufficiency test the set, anti-disguise check |
fix all members; missing one leaves symptom |
disjunctive-or |
A ∨ B → symptom (any one suffices) |
enumerate all disjuncts |
fix one to stop symptom; enumerate rest for defense-in-depth |
Member proof (cluster / compound): each claimed member must pass a
necessity test ("if this member alone were removed, would the symptom still
occur?" — if yes, it is not a member). The set must pass a sufficiency test
(together the members explain every observed manifestation). Necessity
tests here are conceptual proofs, not empirical runs — a method-pack
ceiling; state this honestly when the cluster has many members.
Anti-disguise check (most often skipped): before accepting
conjunctive-cluster, ask whether members X and Y share a deeper common
cause Z, such that X and Y are merely two manifestations of Z. If yes, the
topology collapses to single-root-multi-symptom or chain rooted at Z —
drill to Z. The reverse check protects independent-compound: if two
divergent chains share upstream Z, they are not independent and Z is the
root.
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. Discuss with your human partner before attempting more fixes.
This is NOT a failed hypothesis — this is a wrong architecture.
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:
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:
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.
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.
- Use a
Layer Stop Card when the stop point affects the fix boundary,
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.
Hard signal check — apply these countable facts, not judgments:
Must continue upward drilling (H-class — ANY hit = NOT done):
- H1 — fix added a conditional branch (
if / switch / catch / try)
- H2 — fix touched multiple sites but only 1 covered by failing test
- H3 — fix is at consumer/caller, not canonical owner
- H4 — same bug pattern exists elsewhere in repo (grep for it)
- H5 — original reproduction still produces any anomaly
- H6 —
git log --grep shows this symptom was "fixed" before → Read that commit's diff. Understand why it failed. Do not repeat the same patch pattern.
- H7 — candidate fix adds keyword, phrase, regex, negation-word list, or sample-text exception
- H8 — candidate fix adds a local guard, one-off branch, early return, fallback, adapter, compatibility branch, prompt branch, or legacy path expansion
- H9 — candidate fix patches a consumer/caller/readiness/presentation layer while an upstream owner could own correctness
- H10 — downstream logic re-parses raw text or re-infers action/state while typed intent, normalized state, contract, or another source-of-truth exists
- H11 — candidate fix patches artifact/download/export/readback/cache symptoms without proving the producer and source-of-truth owner
- H12 — candidate fix keeps duplicate owners active, moves authority silently, or says "keep both for now" without a retirement trigger
- H13 — candidate fix names only the observed sample wording/input instead of proving the bug class
- H14 — topology is
conjunctive-cluster or independent-compound but the member set is not enumerated, or a member was not necessity-tested
- H15 — topology was declared
conjunctive-cluster or independent-compound without running the anti-disguise check (a shared upstream Z may collapse the cluster/compound to a single root)
Terminal unactionable (T-class — any hit = stop drilling, switch to mitigation):
- T1 — required change is outside this repo's boundary
- T2 — would break published API contract with no migration path
- T3 — root is undefined spec behavior (nobody defined correctness)
- T4 — required permission or information is unavailable
→ 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):
- D0 — fix eliminated ≥1 code path (paths after ≤ paths before)
- D1 — fix eliminated ≥1 conditional branch (not added a fallback)
- D2 — fix is at canonical owner
- D3 — original reproduction steps no longer trigger any anomaly
- D4 — no same-pattern occurrences remain unaddressed in repo
- D5 — Minimality Check verdict is
sufficient repair, or the local
patch is explicitly bounded with retention reason and retirement trigger
- D6 — Causal topology is explicitly classified (not defaulted to
single-root); if
conjunctive-cluster or independent-compound, every
member is enumerated and necessity-tested, and the set is sufficiency-tested
- D7 — anti-disguise check has been run for any
conjunctive-cluster
or independent-compound classification (a shared upstream Z was sought)
Reflection — re-run Goal / DeeperCause / Evidence / Risk/Unknown / Decision
Confirm the fix addressed the source, not just the sample
Retirement surface — did it shrink, stay, or grow?
Confidence:
A = direct evidence and regression coverage support the root-cause conclusion
B = strong evidence, limited coverage or some bounded unknowns remain
C = partial evidence only; do not present as fully resolved
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:
- "Quick fix for now, investigate later"
- "Let me just try changing X and see if it works" (ignoring evidence, error messages, or hard signals)
- "Add multiple changes, run tests"
- "Skip the test, I'll manually verify"
- "I don't fully understand but this might work"
- Diagnosing by intuition — "It's probably X", listing fixes without investigation, proposing solutions before tracing data flow
- "One more fix attempt" (when already tried 2+)
- "Let's just add another fallback" instead of finding root cause
- "We can keep both owners for now" without a retirement condition
- Accepting a partial fix without differential diagnosis
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, and root-cause-claim-contract.md in this directory for deeper guidance on specific diagnostic scenarios.
1---2name: systematic-debugging-23description: Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes4---5
6# Execute
7
8→ Bug? Test failure? Unexpected behavior? → **Find root cause first. No fixes without evidence.**
9 1. Isolate: read error → reproduce → check git diff → drill upward through diagnostic layers:
10 L1 symptom → L2 logic → L3 system → L4 architecture →
11 L5 cross-system contract → L6 platform constraint → L7 spec gap.
12 Stop when no deeper "why" remains OR terminal unactionable (T1-T4).
13 2. Identify owner: compare with working code → locate canonical owner → flag duplicate owners as a finding
14 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. Run Minimality Check when the candidate fix adds a new branch, fallback, owner, adapter, or compatibility path. Also run Pre-Edit Complexity Check when the candidate fix touches an overloaded owner or may worsen source complexity.
15 4. Prove: one hypothesis → minimal test → iterate. 3+ failed fixes = question architecture, do not attempt another code fix.
16 After fix, if any symptom persists → differential diagnosis (Phase 4 Step 4bis).
17 5. Fix: failing test → minimal code at canonical owner → verify → Reflection + architecture review → repair + retirement track
18→ Done when: confidence ≥ B, both tracks explicit, DeeperCause answered "no" with evidence, no H-class hard signal still active.
19
20# Systematic Debugging
21
22## Overview
23
24Random fixes waste time and create new bugs. Symptom fixes are failure.
25
26This skill is the canonical debugging workflow. Use it to move from symptom to
27root cause, then to the smallest sufficient stable repair and retirement plan.
28Smallest repair means correct owner + bug class fixed + bounded entropy, not the smallest textual diff.
29
30## When to Use
31
32Any technical issue: test failures, bugs, unexpected behavior, performance problems, build/integration failures.
33
34Especially under time pressure, when "just one quick fix" seems obvious, after multiple failed fixes, or when duplicate owners / fallback chains may be involved.
35
36## Quick bug lane
37
38For low-risk, single-owner bugs, keep the report compact: `Symptom`,
39`Reproduction`, `Root Cause`, `Fix Boundary`, and `Verification`. Still collect
40root-cause evidence before editing. If fallback, duplicate owner, consumer-side
41patching, contract risk, shared logic, or cross-module behavior appears,
42escalate to the full workflow.
43
44## The Four Phases
45
46### Phase 1: Root Cause Investigation
47
48**BEFORE attempting ANY fix:**
49
501. **Read Error Messages Carefully**
51 - Don't skip past errors or warnings — they often contain the exact solution
52 - Read stack traces completely; note line numbers, file paths, error codes
53
542. **Reproduce Consistently**
55 - Can you trigger it reliably? What are the exact steps? Does it happen every time?
56 - If not reproducible → consult `feedback-loop-construction.md` to build an automated reproduction loop; don't guess
57 - Record baseline: inputs, environment, version, logs, success/failure criteria
58
593. **Check Recent Changes**
60 - What changed that could cause this? Git diff, recent commits, new dependencies, config changes, environmental differences
61
624. **Gather Evidence in Multi-Component Systems**
63 - Instrument each component boundary: log what enters and exits
64 - Run once to see where data breaks, then focus investigation there
65
665. **Trace Data Flow** (when error is deep in call stack)
67 - Where does bad value originate? What called this with bad value?
68 - Keep tracing up until you find the source. Fix at source, not at symptom.
69 - For the complete backward tracing technique, see `root-cause-tracing.md`.
70
716. **Drill Upward Through Diagnostic Layers**
72
73 Start at L1. Exhaust all "why" questions at each layer before moving upward.
74 The chain is open-ended — architecture is not the endpoint.
75
76 ```
77 L1 Symptom: what failed? where? exact reproduction?
78 L2 Logic: which branch, invariant, or state transition is wrong?
79 L3 System: which component boundary, dependency, or ownership seam?
80 L4 Architecture: what design choice, duplicated owner, or fallback chain?
81 L5 Cross-system: which API / SLA / timing contract between systems?
82 L6 Platform: what runtime / OS / framework constraint?
83 L7 Spec gap: who never defined correct behavior for this case?
84 ```
85
86 Hard signal definitions (H/T/D) are in the Quality Gate — apply them there,
87 not during initial investigation.
88
89 When the stop layer is not obvious, the user asks where the diagnosis
90 stops, the issue crosses component/system boundaries, or a user-provided
91 fact falsifies the current layer, expose a compact `Layer Stop Card` before
92 fixing:
93
94 ```text
95 Layer Stop Card:
96 - Current Stop Layer: L1 Symptom | L2 Logic | L3 System | L4 Architecture | L5 Cross-system Contract | L6 Platform | L7 Spec Gap | T-class boundary
97 - Checked Path:
98 - Evidence For Stop:
99 - Excluded Layers:
100 - Falsifier:
101 - User Intervention Point:
102 - Next Action:
103 ```
104
105 The card is an advisory readback of the diagnostic stop point. It is not a
106 `GateDecision`, `PolicySnapshot`, or completion authority.
107
1087. **Patch-Shape Triage Before Editing**
109
110 Treat the first obvious fix as evidence, not clearance to edit. If the
111 candidate fix shape matches any item below, continue upward before changing
112 code unless you can prove the local layer is the canonical owner:
113
114 - keyword, phrase, regex, negation-word list, or sample-text exception
115 - local guard, extra conditional, `try`/`catch`, early return, or one-off branch
116 - fallback, adapter, compatibility branch, prompt branch, or legacy path expansion
117 - consumer/caller/readiness/presentation-layer patch
118 - downstream re-parsing of raw text when typed intent, normalized state,
119 contract, or another source-of-truth already exists
120 - artifact/download/export/readback/cache patch that does not first locate
121 the producer and source-of-truth owner
122 - duplicate parsing, duplicate owner, or "keep both for now" reasoning
123 - fix that only names the observed sample instead of the bug class
124
125 Required output before editing when this gate fires:
126
127 ```text
128 PatchShape:
129 CanonicalOwner:
130 UpwardDrillSignal:
131 Decision: fix owner | continue investigation | escalate
132 ```
133
134 If the tempting fix is "just add a small guard/fallback", also run:
135
136 ```text
137 Minimality Check:
138 - Smallest textual diff:
139 - Existing owner / reuse path:
140 - Correct owner:
141 - Bug class fixed:
142 - New branch/fallback added:
143 - Existence proof for new path:
144 - Old path retired or scheduled:
145 - Verdict: sufficient repair | local patch | needs first-principles review
146 ```
147
148 `local patch` is a mitigation, not a sufficient repair, unless it is the
149 canonical owner and includes a retention reason plus retirement trigger.
150 For candidate additions that are not ordinary repair code, use
151 `docs/current/AEGIS_MINIMALITY_REFERENCE.md` to check whether the new surface
152 needs to exist before editing.
153
154 If the repair or retirement boundary depends on deleting old paths,
155 retaining compat for a proven external dependency, or stopping on
156 persistent-state risk, compose `anti-entropy-governance` before editing. It
157 decides the path; it does not grant destructive authority.
158
1598. **Pre-Edit Complexity Check**
160
161 After root cause and canonical owner are identified, check whether the fix
162 adds complexity to the wrong or overloaded place:
163
164 Use `using-aegis/references/complexity-governance.md` for shared pressure
165 signals and the meaning of `over-budget`.
166
167 ```text
168 Pre-Edit Complexity Check:
169 - Target edit file:
170 - Existing pressure signal:
171 - Owner fit:
172 - Safer edit boundary:
173 - Decision: edit-in-place | extract helper | add owner file | split task | pause for plan update
174 ```
175
176 If the safer boundary changes the implementation shape, pause and update the
177 plan/spec.
178
179 If the likely repair would grow an already oversized maintained artifact and
180 the slice cannot govern that growth immediately, do not present the repair as
181 a completed fix boundary. Escalate with a plan update or a visible follow-up
182 requirement.
183
184### Phase 2: Pattern Analysis
185
1861. **Find working examples** in the same codebase — what works that's similar?
1872. **Compare against references** — read completely, don't skim
1883. **Identify differences** between working and broken — list every difference
1894. **Understand dependencies** — config, environment, assumptions
1905. **Locate the canonical owner** — which file/module should own this? Multiple owners = a finding, not normality
191
192### Phase 3: Hypothesis and Testing
193
1941. **Form single hypothesis**: "I think X is the root cause because Y" — be specific
1952. **Test minimally**: smallest possible change, one variable at a time. Prefer instrumentation over code edits while still proving the cause.
1963. **Verify**: worked? → Phase 4. Didn't? → Form NEW hypothesis. Don't stack fixes.
1974. **When you don't know**: say "I don't understand X", don't pretend
1985. **Run Reflection** at the end of each loop:
199 - **Goal** | **DeeperCause** (yes/no/uncertain) | **Evidence** | **Risk/Unknown** | **Decision** (exit/iterate/escalate)
200 - If DeeperCause = uncertain → continue or escalate. Only exit when root cause is deep enough and evidence is sufficient.
201
202### Phase 3.5: Pre-Claim Gate
203
204Before claiming a root cause and entering Phase 4, check whether the
205Pre-Claim Gate applies. It applies whenever any Patch-Shape Triage signal is
206active (candidate fix is a guard, fallback, consumer/caller patch,
207artifact/cache patch, or sample-only naming — i.e. H1 / H3 / H8 / H10 / H11 /
208H13), or whenever the diagnosis crosses a component or system boundary, or a
209previous fix left a residual symptom.
210
211When it applies, do not state a root cause or edit code until the five
212mechanical checks below pass. See `root-cause-claim-contract.md` for the full
213rationale, the six-topology table, and a worked example.
214
2151. **Causal Closure** — every causal edge from symptom to claimed root has an
216 evidence anchor (file:line, test, log, reproduction). One "probably" edge
217 leaves the chain open.
2182. **Falsifier Checked** — state "if X were not the root cause, observable F
219 would appear," and confirm F was checked and absent.
2203. **Adversarial Self-Refutation** — generate the strongest single argument
221 that this root cause is wrong, and show why it does not hold.
2224. **Causal Topology Gate** — classify the topology explicitly; do not default
223 to single-root. Topology and the anti-disguise check are in Phase 4 Step
224 4bis and in `root-cause-claim-contract.md`.
2255. **Layer Ceiling Proof** — if the claim stops at L?, show why L?+1 is
226 unreachable by concrete constraint, not by omission.
227
228Required output before entering Phase 4 when the gate fires:
229
230```text
231Pre-Claim Gate Pass:
232Topology: single-root | single-root-multi-symptom | chain | independent-compound | conjunctive-cluster | disjunctive-or
233CausalClosure: closed | open-edge: <edge>
234Falsifier: <if not-X then F; F checked: yes/no>
235SelfRefutation: <strongest objection> -> <why it does not hold>
236LayerCeiling: <L?> -> <why L?+1 unreachable>
237Verdict: pass | fail-<which-gate>
238```
239
240This gate is advisory method-pack discipline. It is not a `GateDecision`,
241`PolicySnapshot`, evidence sufficiency authority, or completion authority. It
242turns a self-judged stop ("I think this is deep enough") into a checkable,
243falsifiable claim ("here is the evidence chain, the falsifier I checked, the
244objection I survived, and the ceiling I reached"). The quick bug lane is
245exempt when no Patch-Shape signal fires and the bug is single-owner at the
246canonical owner.
247
248### Phase 4: Implementation
249
250**Fix the root cause, not the symptom:**
251
2521. **Create Failing Test Case**
253 - Simplest possible reproduction. One-off test script if no framework.
254 - MUST have before fixing.
255
2562. **Implement Single Fix**
257 - Address the root cause identified. ONE change at a time.
258 - No "while I'm here" improvements. No bundled refactoring.
259 - Prefer changing the canonical owner instead of stacking more logic into a fallback path.
260 - If Patch-Shape Triage, Ripple Signal Triage, or Pre-Edit Complexity Check
261 fired, carry its owner, downstream, contract, source-of-truth, fallback,
262 retirement, edit-boundary, and verification findings into the fix
263 boundary before editing code.
264
2653. **Verify Fix**
266 - Test passes now? No other tests broken? Issue actually resolved?
267 - Verify the intended compatibility boundary still holds.
268 - Verify you did not silently move authority to the wrong layer.
269
2704. **If Fix Doesn't Work**
271 - STOP. Count: How many fixes have you tried?
272 - If < 3: Return to Phase 1, re-analyze with new information.
273 - **If ≥ 3: STOP and question the architecture (step 6 below)**. DON'T attempt Fix #4 without architectural discussion.
274
2754bis. **Post-Fix Differential Diagnosis**
276
277 After applying a fix, if ANY symptom persists:
278
279 **STOP. Do NOT attempt another fix without diagnosis.**
280
281 1. Isolate the residual symptom precisely — what exactly remains?
282 2. Trace its causal chain independently (fresh Phase 1 run).
283 3. Compare with the causal chain of the fixed symptom:
284
285 | Residual pattern | Diagnosis | Action |
286 | --- | --- | --- |
287 | Same reproduction conditions as fixed symptom | Fix is incomplete | Continue upward drilling from same source |
288 | Different reproduction conditions, chains converge to same source | Fix was at wrong depth | Drill upward again from the shared source |
289 | Different reproduction conditions, chains diverge | Compound root cause (≥2 independent roots) | Each root needs its own fix |
290 | Same symptom, reduced but not eliminated | Fix was a downstream patch | Drill upward again from source |
291
292 4. If uncertain whether convergent or divergent: **escalate. Do not guess.**
293
294 **Compound root cause forms (legacy shorthand):**
295 - True compound — ≥2 independent bugs surfaced together
296 - Single-root multi-symptom — 1 root, ≥2 symptom paths → fix root, all resolve
297 - Chain causal — A causes B causes C → fix A, B and C auto-resolve
298
299 **Causal Topology Gate (full form, used by the Pre-Claim Gate):** the three
300 legacy forms above are a shorthand. Before claiming any root — single or
301 compound — classify the topology explicitly. The default is `unknown`; you
302 must actively exclude the multi-root topologies before collapsing to a
303 single-root claim. See `root-cause-claim-contract.md` for the full table,
304 member necessity/sufficiency tests, and the anti-disguise check.
305
306 | Topology | Structure | Stop condition | Repair shape |
307 | --- | --- | --- | --- |
308 | `single-root` | A → symptom | Layer Ceiling Proof at A | fix A |
309 | `single-root-multi-symptom` | A → B, C, D | Layer Ceiling Proof at A | fix A; symptoms self-resolve |
310 | `chain` | A → B → C → symptom | Layer Ceiling Proof at A | drill to A, fix A |
311 | `independent-compound` | A → symptom, Y → symptom, A ⊥ Y | each root passes Gate 1/2/5; no shared upstream | fix A **and** Y; missing one leaves symptom |
312 | `conjunctive-cluster` | A ∧ B ∧ C → symptom (each necessary, none sufficient) | enumerate members, necessity test each, sufficiency test the set, anti-disguise check | fix **all** members; missing one leaves symptom |
313 | `disjunctive-or` | A ∨ B → symptom (any one suffices) | enumerate all disjuncts | fix one to stop symptom; enumerate rest for defense-in-depth |
314
315 **Member proof (cluster / compound):** each claimed member must pass a
316 necessity test ("if this member alone were removed, would the symptom still
317 occur?" — if yes, it is not a member). The set must pass a sufficiency test
318 (together the members explain every observed manifestation). Necessity
319 tests here are conceptual proofs, not empirical runs — a method-pack
320 ceiling; state this honestly when the cluster has many members.
321
322 **Anti-disguise check (most often skipped):** before accepting
323 `conjunctive-cluster`, ask whether members X and Y share a deeper common
324 cause Z, such that X and Y are merely two manifestations of Z. If yes, the
325 topology collapses to `single-root-multi-symptom` or `chain` rooted at Z —
326 drill to Z. The reverse check protects `independent-compound`: if two
327 divergent chains share upstream Z, they are not independent and Z is the
328 root.
329
3305. **If 3+ Fixes Failed: Question Architecture**
331
332 **Pattern indicating architectural problem:**
333 - Each fix reveals new shared state/coupling/problem in different place
334 - Fixes require "massive refactoring" to implement
335 - Each fix creates new symptoms elsewhere
336
337 **STOP and question fundamentals.** Discuss with your human partner before attempting more fixes.
338 This is NOT a failed hypothesis — this is a wrong architecture.
339
3406. **Deliver Dual-Track Closure**
341
342 For bug fixes, refactors, contract changes, or governance cleanup, always produce:
343
344 **Repair track** — root cause, canonical owner, smallest necessary change, compatibility boundary, verification method.
345
346 **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.
347
348 Never add a new owner, fallback, prompt branch, or adapter path without stating what happens to the old one.
349
350## Quality Gate
351
352Before you claim debugging is complete:
353
3540. **Workspace record for non-trivial debugging** — if this is medium+ complexity
355 or it writes `docs/aegis/` records, initialize/check through configured
356 Aegis workspace support when available:
357
358 ```bash
359 python <aegis-workspace-helper> init --root <target-project-root>
360 python <aegis-workspace-helper> new-work --root <target-project-root> ...
361 python <aegis-workspace-helper> add-evidence --root <target-project-root> --work <YYYY-MM-DD-slug> ...
362 python <aegis-workspace-helper> check --root <target-project-root>
363 ```
364
365 Fast bug fix or quick bug fix pressure does not skip this: if Ripple Signal
366 Triage fires, do the triage before editing and expand verification to the
367 canonical owner plus affected downstream path.
368
369 These records are method-pack evidence trails only. They do not grant
370 authoritative completion.
371
3721. **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.
373 - Use a `Layer Stop Card` when the stop point affects the fix boundary,
374 contract owner, spec/product decision, or user correction path. Keep
375 simple fast-path explanations cheap; do not emit the card for ordinary
376 factual Q&A about the skill itself.
3772. **Hard signal check** — apply these countable facts, not judgments:
378
379 Must continue upward drilling (H-class — ANY hit = NOT done):
380 - **H1** — fix added a conditional branch (`if` / `switch` / `catch` / `try`)
381 - **H2** — fix touched multiple sites but only 1 covered by failing test
382 - **H3** — fix is at consumer/caller, not canonical owner
383 - **H4** — same bug pattern exists elsewhere in repo (grep for it)
384 - **H5** — original reproduction still produces any anomaly
385 - **H6** — `git log --grep` shows this symptom was "fixed" before → Read that commit's diff. Understand why it failed. Do not repeat the same patch pattern.
386 - **H7** — candidate fix adds keyword, phrase, regex, negation-word list, or sample-text exception
387 - **H8** — candidate fix adds a local guard, one-off branch, early return, fallback, adapter, compatibility branch, prompt branch, or legacy path expansion
388 - **H9** — candidate fix patches a consumer/caller/readiness/presentation layer while an upstream owner could own correctness
389 - **H10** — downstream logic re-parses raw text or re-infers action/state while typed intent, normalized state, contract, or another source-of-truth exists
390 - **H11** — candidate fix patches artifact/download/export/readback/cache symptoms without proving the producer and source-of-truth owner
391 - **H12** — candidate fix keeps duplicate owners active, moves authority silently, or says "keep both for now" without a retirement trigger
392 - **H13** — candidate fix names only the observed sample wording/input instead of proving the bug class
393 - **H14** — topology is `conjunctive-cluster` or `independent-compound` but the member set is not enumerated, or a member was not necessity-tested
394 - **H15** — topology was declared `conjunctive-cluster` or `independent-compound` without running the anti-disguise check (a shared upstream Z may collapse the cluster/compound to a single root)
395
396 Terminal unactionable (T-class — any hit = stop drilling, switch to mitigation):
397 - **T1** — required change is outside this repo's boundary
398 - **T2** — would break published API contract with no migration path
399 - **T3** — root is undefined spec behavior (nobody defined correctness)
400 - **T4** — required permission or information is unavailable
401 → 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?
402
403 Depth sufficient (D-class — ALL must pass before claiming done):
404 - **D0** — fix eliminated ≥1 code path (paths after ≤ paths before)
405 - **D1** — fix eliminated ≥1 conditional branch (not added a fallback)
406 - **D2** — fix is at canonical owner
407 - **D3** — original reproduction steps no longer trigger any anomaly
408 - **D4** — no same-pattern occurrences remain unaddressed in repo
409 - **D5** — Minimality Check verdict is `sufficient repair`, or the local
410 patch is explicitly bounded with retention reason and retirement trigger
411 - **D6** — Causal topology is explicitly classified (not defaulted to
412 single-root); if `conjunctive-cluster` or `independent-compound`, every
413 member is enumerated and necessity-tested, and the set is sufficiency-tested
414 - **D7** — anti-disguise check has been run for any `conjunctive-cluster`
415 or `independent-compound` classification (a shared upstream Z was sought)
416
4173. **Reflection** — re-run Goal / DeeperCause / Evidence / Risk/Unknown / Decision
4184. **Confirm** the fix addressed the source, not just the sample
4195. **Retirement surface** — did it shrink, stay, or grow?
4206. **Confidence**:
421 - `A` = direct evidence and regression coverage support the root-cause conclusion
422 - `B` = strong evidence, limited coverage or some bounded unknowns remain
423 - `C` = partial evidence only; do not present as fully resolved
424
425If confidence is not at least `B`, do not speak as if the issue is fully closed.
426
427## Red Flags - STOP and Follow Process
428
429If you catch yourself thinking:
430
431- "Quick fix for now, investigate later"
432- "Let me just try changing X and see if it works" (ignoring evidence, error messages, or hard signals)
433- "Add multiple changes, run tests"
434- "Skip the test, I'll manually verify"
435- "I don't fully understand but this might work"
436- Diagnosing by intuition — "It's probably X", listing fixes without investigation, proposing solutions before tracing data flow
437- "One more fix attempt" (when already tried 2+)
438- "Let's just add another fallback" instead of finding root cause
439- "We can keep both owners for now" without a retirement condition
440- Accepting a partial fix without differential diagnosis
441
442**ALL of these mean: STOP. Return to Phase 1.**
443
444**If 3+ fixes failed:** Question the architecture (see Phase 4 Step 5)
445**If symptoms persist after fix:** Run differential diagnosis (see Phase 4 Step 4bis)
446
447## Human Partner Signals
448
449If you hear "Is that not happening?", "Will it show us...?", "Stop guessing", "Ultrathink this" → STOP. Return to Phase 1.
450
451## When Process Reveals "No Root Cause"
452
453If investigation reveals the issue is truly environmental, timing-dependent, or external:
454document what you investigated, implement appropriate handling (retry, timeout, error message),
455add monitoring.
456
457## Supporting Techniques
458
459See `root-cause-tracing.md`, `defense-in-depth.md`, `condition-based-waiting.md`, `feedback-loop-construction.md`, and `root-cause-claim-contract.md` in this directory for deeper guidance on specific diagnostic scenarios.