agentleFS
dork-labsdork-labs/dorkos/.agents/skills/debugging-systematically/SKILL.md

debugging-systematically

Skill11 starsChanged 47 days agoMITView on GitHub

Guides systematic debugging methodology and troubleshooting approaches. Use when investigating bugs, tracing issues, or teaching debugging patterns.

7 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

35 rules. 0 are common, 34 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 7 edited versions we read keep these.

  • 34

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Never make changes to code you don't understand.

    line 26
  2. Distinctive:

    Test hypotheses in order of:

    line 65
  3. Distinctive:

    When you don't know where the bug is:

    line 75
  4. Distinctive:

    If midpoint is good, bug is in second half

    line 79
  5. Distinctive:

    If midpoint is bad, bug is in first half

    line 80
  6. Distinctive:

    When facing complex bugs:

    line 97
  7. Distinctive:

    Create automated reproduction if possible

    line 113
  8. Distinctive:

    Check component receives correct data

    line 128
  9. Distinctive:

    Check TanStack Query returns correct data

    line 129
  10. Distinctive:

    Check Hono route returns correct data

    line 130
  11. Distinctive:

    Check service returns correct data

    line 131
  12. Distinctive:

    Check data store has correct data

    line 132
  13. Distinctive:

    Verify data store has correct data (SQLite, JSONL transcripts, JSON state files)

    line 136
  14. Distinctive:

    Verify service reads/writes correctly

    line 137
  15. Distinctive:

    Verify Hono route transforms correctly

    line 138
  16. Distinctive:

    Verify TanStack Query caches correctly

    line 139
  17. Distinctive:

    Verify component renders correctly

    line 140
  18. Distinctive:

    When debugging data issues, verify the actual data using direct inspection:

    line 154
  19. Distinctive:

    If data exists in store but not in UI → Issue is in application layers

    line 175
  20. Distinctive:

    If data missing from store → Issue is in write operation

    line 176
  21. Distinctive:

    If data is wrong in store → Issue is in mutation logic

    line 177
  22. Very specific:

    Use /debug:data for detailed data inspection or /debug:logs for server log analysis.

    line 179
  23. Distinctive:

    Don't randomly change things

    line 269
  24. Distinctive:

    Test one hypothesis at a time

    line 270
  25. Distinctive:

    Document what you've tried

    line 271
  26. Distinctive:

    Verify assumptions with evidence

    line 275
  27. Distinctive:

    Check "impossible" scenarios anyway

    line 276
  28. Distinctive:

    Read the actual error message carefully

    line 277
  29. Distinctive:

    After 30+ minutes with no progress

    line 283
  30. Distinctive:

    When you need domain knowledge

    line 284
  31. Distinctive:

    When a fresh perspective would help

    line 285
  32. Distinctive:

    If you have attempted 3 or more fixes without success:

    line 300
  33. Distinctive:

    Check recent git changes

    line 336
  34. Distinctive:

    Search for similar issues

    line 337
  35. Distinctive:

    Ask for a second pair of eyes

    line 338

“Common” is measured: kept by at least 6 in 10 of the 7 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Debugging Systematically

This skill provides debugging methodology — systematic approaches to finding and fixing bugs. It covers the mental models and techniques for effective troubleshooting.

For specific debugging tools: See /debug:* commands.

Core Debugging Methodology

The Scientific Method for Bugs

  1. Observe — What is actually happening?
  2. Hypothesize — What could cause this?
  3. Test — Design an experiment to verify
  4. Analyze — Did the test confirm or refute?
  5. Iterate — Refine hypothesis and repeat

The Golden Rule

Understand before you fix.

Never make changes to code you don't understand. Reading and comprehending the code often reveals the bug.

Problem Articulation

Questions to Answer First

QuestionWhy It Matters
What should happen?Defines the expected behavior
What actually happens?Identifies the discrepancy
When did it start?Narrows the scope of changes
What changed recently?Identifies potential causes
Is it reproducible?Determines debugging approach

Rubber Duck Method

The act of explaining code line-by-line forces you to:

  • Think through logic sequentially
  • Surface implicit assumptions
  • Notice gaps in understanding
  • Catch inconsistencies

Often, the solution becomes obvious mid-explanation.

Hypothesis Formation

Common Bug Categories

CategorySymptomsCheck
DataWrong values, undefinedLog actual values
LogicWrong branch, off-by-oneTrace conditionals
TimingRace conditions, stale dataCheck async flow
StateInconsistent behaviorInspect state at each step
IntegrationAPI mismatchesVerify contracts

Ranking Hypotheses

Test hypotheses in order of:

  1. Likelihood — Most common causes first
  2. Ease of testing — Quick tests before complex ones
  3. Impact — High-impact issues take priority

Investigation Techniques

Binary Search Debugging

When you don't know where the bug is:

  1. Identify start point (known good) and end point (known bad)
  2. Check the midpoint
  3. If midpoint is good, bug is in second half
  4. If midpoint is bad, bug is in first half
  5. Repeat until isolated

Data Flow Tracing

For data issues, trace the complete path:

Input → Transform → Store → Retrieve → Transform → Output
  ↓         ↓          ↓         ↓          ↓         ↓
Verify   Verify     Verify   Verify     Verify    Verify

Log at each step to find where data diverges from expected.

Isolation Technique

When facing complex bugs:

  1. Remove variables — Simplify to minimal reproduction
  2. Mock dependencies — Eliminate external factors
  3. Hardcode values — Remove dynamic inputs
  4. Comment out code — Find which section causes issue

Reproducing First

Never try to fix a bug you can't reproduce.

Steps to reproduce:

  1. Document exact steps
  2. Note environment (browser, OS, data state)
  3. Identify minimum case
  4. Create automated reproduction if possible

Layer-by-Layer Debugging

Project Data Flow

Component → TanStack Query → Transport → Hono Route → Service → Data Store (SQLite/JSONL/JSON)

Debug from the outside in or inside out:

Outside-in (start at symptom):

  • User sees wrong data
  • Check component receives correct data
  • Check TanStack Query returns correct data
  • Check Hono route returns correct data
  • Check service returns correct data
  • Check data store has correct data

Inside-out (start at source):

  • Verify data store has correct data (SQLite, JSONL transcripts, JSON state files)
  • Verify service reads/writes correctly
  • Verify Hono route transforms correctly
  • Verify TanStack Query caches correctly
  • Verify component renders correctly

Layer-Specific Checks

LayerWhat to CheckTools
ComponentProps received, render conditions, stateBrowser DevTools
TanStack QueryCache key, staleTime, enabled, queryFnReact Query Devtools
Hono RouteZod validation, boundary check, feature flagNetwork tab, server logs
ServiceBusiness logic, error handlingServer logs (NDJSON)
Data StoreSQLite tables, JSONL files, JSON statesqlite3, /debug:data

Data Store Verification (Ground Truth)

When debugging data issues, verify the actual data using direct inspection:

DORK_HOME="apps/server/.temp/.dork"

# SQLite queries
sqlite3 -header -column "$DORK_HOME/dork.db" "SELECT * FROM [table] LIMIT 10;"

# Relay state files
cat "$DORK_HOME/relay/adapters.json" | python3 -m json.tool
cat "$DORK_HOME/relay/bindings.json" | python3 -m json.tool

# Server config
cat "$DORK_HOME/config.json" | python3 -m json.tool

# Server logs (NDJSON)
tail -20 "$DORK_HOME/logs/dorkos.log" | python3 -m json.tool

This establishes ground truth:

  • If data exists in store but not in UI → Issue is in application layers
  • If data missing from store → Issue is in write operation
  • If data is wrong in store → Issue is in mutation logic

Use /debug:data for detailed data inspection or /debug:logs for server log analysis.

Common Bug Patterns

JavaScript/TypeScript

PatternExampleFix
Implicit coercion"5" + 3 = "53"Explicit conversion
Async not awaitedMissing awaitAdd await, check Promise
Closure captureLoop variable capturedUse let, not var
Null/undefined accessobj.prop when obj is nullOptional chaining ?.
Reference vs valueObject mutationSpread or clone

React

PatternSymptomFix
Stale closureOld state in callbackUse callback form or ref
Missing dependencyEffect doesn't re-runAdd to dependency array
Infinite loopComponent re-renders foreverCheck useEffect deps
Key issuesList items behave wrongUse unique, stable keys
Server/client mismatchHydration errorsCheck where state initializes

Data Fetching

PatternSymptomFix
Stale cacheOld data after mutationInvalidate queries
Race conditionWrong data displayedCancel previous requests
N+1 queriesSlow loadingUse include/eager loading
Missing error handlingSilent failuresAdd try/catch, onError

Debugging Tools

Console Methods

console.log(); // Basic output
console.table(); // Tabular data
console.group(); // Grouped output
console.time(); // Performance timing
console.trace(); // Stack trace
console.assert(); // Conditional logging

Strategic Logging

// Tag logs for filtering
console.log('[AUTH]', user);
console.log('[DATA]', response);

// Log with context
console.log('[API] Request:', { endpoint, params, timestamp: Date.now() });

// Remove before commit (or use debug library)

Debugger Usage

// Break at specific point
debugger;

// Conditional break
if (someCondition) debugger;

Browser DevTools

TabUse For
ConsoleErrors, logs, REPL
NetworkAPI calls, timing, payloads
ElementsDOM inspection, styles
SourcesBreakpoints, stepping
ApplicationStorage, cookies, cache
PerformanceProfiling, bottlenecks

Debugging Mindset

Stay Calm

  • Bugs are normal, not personal failures
  • Take breaks when frustrated
  • Fresh eyes often spot issues immediately

Be Systematic

  • Don't randomly change things
  • Test one hypothesis at a time
  • Document what you've tried

Trust Nothing

  • Verify assumptions with evidence
  • Check "impossible" scenarios anyway
  • Read the actual error message carefully

Ask for Help

When to escalate:

  • After 30+ minutes with no progress
  • When you need domain knowledge
  • When a fresh perspective would help

Anti-Patterns

Don'tInstead
Change random thingsForm hypothesis, test systematically
Assume you know the causeVerify with evidence
Debug without reproducingCreate minimal reproduction first
Skip reading error messagesRead the complete error carefully
Add code without understandingUnderstand existing code first
Debug in productionReproduce locally first

The 3-Fix Rule

If you have attempted 3 or more fixes without success:

STOP. Question the architecture.

Pattern indicating an architectural problem:

  • Each fix reveals new shared state, coupling, or problems in a different place
  • Fixes require "massive refactoring" to implement
  • Each fix creates new symptoms elsewhere

This is NOT a failed hypothesis — this is a wrong architecture. Discuss with the user before attempting more fixes.

Supporting Techniques

  • condition-based-waiting.md — Replace arbitrary timeouts with condition polling
  • defense-in-depth.md — Add validation at multiple layers after finding root cause
  • root-cause-tracing.md — Trace bugs backward through call stack to find original trigger
  • find-polluter.sh — Bisection script to find which test creates unwanted state

Quick Reference

Debugging Checklist

  • Can I reproduce the bug?
  • What changed recently?
  • What does the error message say?
  • What do the logs show?
  • What layer is the bug in?
  • What assumption might be wrong?
  • Have I tested my hypothesis?

When Stuck

  1. Take a break (walk, coffee)
  2. Explain the problem out loud
  3. Re-read the error message
  4. Check recent git changes
  5. Search for similar issues
  6. Ask for a second pair of eyes

References

  • /debug:browser — Visual and interaction debugging
  • /debug:api — Data flow debugging (Component → Query → Route → Service → DB)
  • /debug:data — Direct database and state file inspection
  • /debug:test — Test failure debugging
  • /debug:logs — Server log analysis
  • /debug:types — TypeScript error debugging
  • /debug:performance — Performance debugging

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.