Systematic Debugging
Adapted from obra/superpowers (MIT). Trimmed for a
solo non-developer working on Google Apps Script + HTML/JS learning games: the author's own
eval fixtures were dropped, and the test/verification hooks point at this project's tooling
(Tests.gs, game-content-audit, ship-check) instead of a JS test runner.
Overview
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:
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 → gather more data, don't guess
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
WHEN system has multiple components (browser → Apps Script → Sheet, 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 (browser → Apps Script → Sheet):
// Layer 1: client, right before the call (js-*.html)
console.log('[L1] sending to server:', JSON.stringify(payload));
// Layer 2: server entry point (Main.gs / Sync.gs) — shows in Executions log
function saveProgress(payload) {
console.log('[L2] server received:', JSON.stringify(payload));
// Layer 3: just before touching the Sheet (Sheet.gs)
console.log('[L3] about to write row:', JSON.stringify(row), 'to', sheetName);
sheet.appendRow(row);
// Layer 4: read it back — proves the write actually landed
console.log('[L4] row now in sheet:', JSON.stringify(sheet.getRange(sheet.getLastRow(), 1, 1, row.length).getValues()));
}
This reveals: which boundary drops the data (client → server ✓, server → Sheet ✗).
Read the Executions log in the Apps Script editor, not just the browser console —
console.log on the server never reaches the browser.
Remove this instrumentation once the root cause is found. Leftover logging is a
ship-blocker (ship-check flags it).
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:
Find Working Examples
- Locate similar working code in same codebase
- What works that's similar to what's broken?
Compare Against References
- If implementing pattern, read reference implementation COMPLETELY
- Don't skim - read every line
- Understand the pattern fully before applying
Identify Differences
- What's different between working and broken?
- List every difference, however small
- Don't assume "that can't matter"
Understand Dependencies
- What other components does this need?
- What settings, config, environment?
- What assumptions does it make?
Phase 3: Hypothesis and Testing
Scientific method:
Form Single Hypothesis
- State clearly: "I think X is the root cause because Y"
- Write it down
- Be specific, not vague
Test Minimally
- Make the SMALLEST possible change to test hypothesis
- One variable at a time
- Don't fix multiple things at once
Verify Before Continuing
- Did it work? Yes → Phase 4
- Didn't work? Form NEW hypothesis
- DON'T add more fixes on top
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:
Create Failing Test Case
- Simplest possible reproduction
- MUST have before fixing
- Red-green is mandatory: run it BEFORE the fix and watch it FAIL. A test you never
saw fail proves nothing — it may be testing the wrong thing.
- Where to put it, in order of preference:
| Bug is in |
Write the test as |
Server logic (*.gs) |
a new testStageN()-style function in src/Tests.gs, run from the Apps Script editor |
| Question generation / answer correctness |
a fixture for game-content-audit (scripts/audit_game_content.py) |
| Browser behaviour / UI flow |
a playwright script driving the real page |
| Nothing above fits |
a throwaway stdlib-Python or .gs script — still run it and watch it fail first |
Implement Single Fix
- Address the root cause identified
- ONE change at a time
- No "while I'm here" improvements
- No bundled refactoring
Verify Fix
- Test passes now?
- No other tests broken?
- Issue actually resolved?
- Use the
verification-before-completion skill before claiming success
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
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:
- You've completed the process
- Document what you investigated
- Implement appropriate handling (retry, timeout, error message)
- 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
1---2name: systematic-debugging3description: Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes4license: MIT5---6<!-- SKILL-VERSION: 2026.08.02 | name: systematic-debugging | canonical: ~/.codex/skills/systematic-debugging | bump this date on every edit -->78# Systematic Debugging910Adapted from [obra/superpowers](https://github.com/obra/superpowers) (MIT). Trimmed for a11solo non-developer working on Google Apps Script + HTML/JS learning games: the author's own12eval fixtures were dropped, and the test/verification hooks point at this project's tooling13(`Tests.gs`, `game-content-audit`, `ship-check`) instead of a JS test runner.1415## Overview1617**Core principle:** ALWAYS find root cause before attempting fixes. Symptom fixes are failure.1819**Violating the letter of this process is violating the spirit of debugging.**2021## The Iron Law2223```24NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST25```2627If you haven't completed Phase 1, you cannot propose fixes.2829## When to Use3031Use for ANY technical issue:32- Test failures33- Bugs in production34- Unexpected behavior35- Performance problems36- Build failures37- Integration issues3839**Use this ESPECIALLY when:**40- Under time pressure (emergencies make guessing tempting)41- "Just one quick fix" seems obvious42- You've already tried multiple fixes43- Previous fix didn't work44- You don't fully understand the issue4546**Don't skip when:**47- Issue seems simple (simple bugs have root causes too)48- You're in a hurry (rushing guarantees rework)49- Manager wants it fixed NOW (systematic is faster than thrashing)5051## The Four Phases5253You MUST complete each phase before proceeding to the next.5455### Phase 1: Root Cause Investigation5657**BEFORE attempting ANY fix:**58591. **Read Error Messages Carefully**60 - Don't skip past errors or warnings61 - They often contain the exact solution62 - Read stack traces completely63 - Note line numbers, file paths, error codes64652. **Reproduce Consistently**66 - Can you trigger it reliably?67 - What are the exact steps?68 - Does it happen every time?69 - If not reproducible → gather more data, don't guess70713. **Check Recent Changes**72 - What changed that could cause this?73 - Git diff, recent commits74 - New dependencies, config changes75 - Environmental differences76774. **Gather Evidence in Multi-Component Systems**7879 **WHEN system has multiple components (browser → Apps Script → Sheet, API → service → database):**8081 **BEFORE proposing fixes, add diagnostic instrumentation:**82 ```83 For EACH component boundary:84 - Log what data enters component85 - Log what data exits component86 - Verify environment/config propagation87 - Check state at each layer8889 Run once to gather evidence showing WHERE it breaks90 THEN analyze evidence to identify failing component91 THEN investigate that specific component92 ```9394 **Example (browser → Apps Script → Sheet):**95 ```javascript96 // Layer 1: client, right before the call (js-*.html)97 console.log('[L1] sending to server:', JSON.stringify(payload));9899 // Layer 2: server entry point (Main.gs / Sync.gs) — shows in Executions log100 function saveProgress(payload) {101 console.log('[L2] server received:', JSON.stringify(payload));102103 // Layer 3: just before touching the Sheet (Sheet.gs)104 console.log('[L3] about to write row:', JSON.stringify(row), 'to', sheetName);105 sheet.appendRow(row);106107 // Layer 4: read it back — proves the write actually landed108 console.log('[L4] row now in sheet:', JSON.stringify(sheet.getRange(sheet.getLastRow(), 1, 1, row.length).getValues()));109 }110 ```111112 **This reveals:** which boundary drops the data (client → server ✓, server → Sheet ✗).113 Read the Executions log in the Apps Script editor, not just the browser console —114 `console.log` on the server never reaches the browser.115116 **Remove this instrumentation once the root cause is found.** Leftover logging is a117 ship-blocker (`ship-check` flags it).1181195. **Trace Data Flow**120121 **WHEN error is deep in call stack:**122123 See `root-cause-tracing.md` in this directory for the complete backward tracing technique.124125 **Quick version:**126 - Where does bad value originate?127 - What called this with bad value?128 - Keep tracing up until you find the source129 - Fix at source, not at symptom130131### Phase 2: Pattern Analysis132133**Find the pattern before fixing:**1341351. **Find Working Examples**136 - Locate similar working code in same codebase137 - What works that's similar to what's broken?1381392. **Compare Against References**140 - If implementing pattern, read reference implementation COMPLETELY141 - Don't skim - read every line142 - Understand the pattern fully before applying1431443. **Identify Differences**145 - What's different between working and broken?146 - List every difference, however small147 - Don't assume "that can't matter"1481494. **Understand Dependencies**150 - What other components does this need?151 - What settings, config, environment?152 - What assumptions does it make?153154### Phase 3: Hypothesis and Testing155156**Scientific method:**1571581. **Form Single Hypothesis**159 - State clearly: "I think X is the root cause because Y"160 - Write it down161 - Be specific, not vague1621632. **Test Minimally**164 - Make the SMALLEST possible change to test hypothesis165 - One variable at a time166 - Don't fix multiple things at once1671683. **Verify Before Continuing**169 - Did it work? Yes → Phase 4170 - Didn't work? Form NEW hypothesis171 - DON'T add more fixes on top1721734. **When You Don't Know**174 - Say "I don't understand X"175 - Don't pretend to know176 - Ask for help177 - Research more178179### Phase 4: Implementation180181**Fix the root cause, not the symptom:**1821831. **Create Failing Test Case**184 - Simplest possible reproduction185 - MUST have before fixing186 - **Red-green is mandatory:** run it BEFORE the fix and watch it FAIL. A test you never187 saw fail proves nothing — it may be testing the wrong thing.188 - Where to put it, in order of preference:189 | Bug is in | Write the test as |190 |---|---|191 | Server logic (`*.gs`) | a new `testStageN()`-style function in `src/Tests.gs`, run from the Apps Script editor |192 | Question generation / answer correctness | a fixture for `game-content-audit` (`scripts/audit_game_content.py`) |193 | Browser behaviour / UI flow | a `playwright` script driving the real page |194 | Nothing above fits | a throwaway stdlib-Python or `.gs` script — still run it and watch it fail first |1951962. **Implement Single Fix**197 - Address the root cause identified198 - ONE change at a time199 - No "while I'm here" improvements200 - No bundled refactoring2012023. **Verify Fix**203 - Test passes now?204 - No other tests broken?205 - Issue actually resolved?206 - Use the `verification-before-completion` skill before claiming success2072084. **If Fix Doesn't Work**209 - STOP210 - Count: How many fixes have you tried?211 - If < 3: Return to Phase 1, re-analyze with new information212 - **If ≥ 3: STOP and question the architecture (step 5 below)**213 - DON'T attempt Fix #4 without architectural discussion2142155. **If 3+ Fixes Failed: Question Architecture**216217 **Pattern indicating architectural problem:**218 - Each fix reveals new shared state/coupling/problem in different place219 - Fixes require "massive refactoring" to implement220 - Each fix creates new symptoms elsewhere221222 **STOP and question fundamentals:**223 - Is this pattern fundamentally sound?224 - Are we "sticking with it through sheer inertia"?225 - Should we refactor architecture vs. continue fixing symptoms?226227 **Discuss with your human partner before attempting more fixes**228229 This is NOT a failed hypothesis - this is a wrong architecture.230231## Red Flags - STOP and Follow Process232233If you catch yourself thinking:234- "Quick fix for now, investigate later"235- "Just try changing X and see if it works"236- "Add multiple changes, run tests"237- "Skip the test, I'll manually verify"238- "It's probably X, let me fix that"239- "I don't fully understand but this might work"240- "Pattern says X but I'll adapt it differently"241- "Here are the main problems: [lists fixes without investigation]"242- Proposing solutions before tracing data flow243- **"One more fix attempt" (when already tried 2+)**244- **Each fix reveals new problem in different place**245246**ALL of these mean: STOP. Return to Phase 1.**247248**If 3+ fixes failed:** Question the architecture (see Phase 4.5)249250## your human partner's Signals You're Doing It Wrong251252**Watch for these redirections:**253- "Is that not happening?" - You assumed without verifying254- "Will it show us...?" - You should have added evidence gathering255- "Stop guessing" - You're proposing fixes without understanding256- "Ultra-think this" - Question fundamentals, not just symptoms257- "We're stuck?" (frustrated) - Your approach isn't working258259**When you see these:** STOP. Return to Phase 1.260261## Common Rationalizations262263| Excuse | Reality |264|--------|---------|265| "Issue is simple, don't need process" | Simple issues have root causes too. Process is fast for simple bugs. |266| "Emergency, no time for process" | Systematic debugging is FASTER than guess-and-check thrashing. |267| "Just try this first, then investigate" | First fix sets the pattern. Do it right from the start. |268| "I'll write test after confirming fix works" | Untested fixes don't stick. Test first proves it. |269| "Multiple fixes at once saves time" | Can't isolate what worked. Causes new bugs. |270| "Reference too long, I'll adapt the pattern" | Partial understanding guarantees bugs. Read it completely. |271| "I see the problem, let me fix it" | Seeing symptoms ≠ understanding root cause. |272| "One more fix attempt" (after 2+ failures) | 3+ failures = architectural problem. Question pattern, don't fix again. |273274## Quick Reference275276| Phase | Key Activities | Success Criteria |277|-------|---------------|------------------|278| **1. Root Cause** | Read errors, reproduce, check changes, gather evidence | Understand WHAT and WHY |279| **2. Pattern** | Find working examples, compare | Identify differences |280| **3. Hypothesis** | Form theory, test minimally | Confirmed or new hypothesis |281| **4. Implementation** | Create test, fix, verify | Bug resolved, tests pass |282283## When Process Reveals "No Root Cause"284285If systematic investigation reveals issue is truly environmental, timing-dependent, or external:2862871. You've completed the process2882. Document what you investigated2893. Implement appropriate handling (retry, timeout, error message)2904. Add monitoring/logging for future investigation291292**But:** 95% of "no root cause" cases are incomplete investigation.293294## Supporting Techniques295296These techniques are part of systematic debugging and available in this directory:297298- **`root-cause-tracing.md`** - Trace bugs backward through call stack to find original trigger299- **`defense-in-depth.md`** - Add validation at multiple layers after finding root cause300- **`condition-based-waiting.md`** - Replace arbitrary timeouts with condition polling