debugging은(는) 무엇을 하나요?
A method for bugs that are not obvious at a glance. If the cause is plain from the error and one read, fix it and skip this. Otherwise follow the phases in order; skip one only with a stated reason.
Redact secrets in every command and output you show (<REDACTED>). Keep credentials in env vars,
not in the loop's text; quote only the lines of a captured artefact that carry the signal.
1. Build a feedback loop (most of the work)
You need one command that goes red on this bug. With it, bisection, hypotheses and logging are mechanical; without it, reading code is guessing. Ways to get one, roughly in this order:
- A failing test at the seam that reaches the bug (unit, integration, e2e).
- A curl/HTTP script against a running dev server (ask the user to start it in a second terminal).
- A CLI run on a fixture input, diffing stdout against a known-good snapshot.
- A headless browser script that asserts on DOM, console or network.
- A captured trace (request, payload, event log) saved to disk and replayed through the code path.
- A throwaway harness: the smallest slice of the system that runs the path in one call.
- A property/fuzz loop for "sometimes wrong": many random inputs, look for the failure.
- A bisection harness for "worked at X, broken at Y":
git bisect run <script>. - A differential loop: the same input through old vs new version (or two configs), diff the outputs.
- Last resort, a person in the loop: a script that tells them exactly what to do and captures what they report.
Then tighten it: faster (cache setup, narrow scope), sharper (assert the exact symptom, not "did
not crash"), deterministic (pin time, seed RNG, isolate the filesystem and network). Run it through
bash with timeoutMs; never wait with a bare sleep.
Flaky bugs: aim for a higher reproduction rate, not a clean repro: loop the trigger 100×, parallelise, add load, narrow timing windows. A 50% flake is debuggable; 1% is not yet.
Done when you can name one command you have already run (show it and its redacted output) that drives the real code path, asserts the user's exact symptom, gives the same verdict each run, and finishes in seconds. If you catch yourself building a theory before this command exists, stop.
No loop possible: say so, list what you tried, and ask for access to the environment that reproduces it, a captured artefact (log, HAR, core dump, timestamped recording), or permission for temporary instrumentation. Do not go on guessing.
2. Reproduce and minimise
- Confirm the loop shows the failure the user described, not a nearby one. Wrong bug, wrong fix.
- Record the exact symptom (message, wrong value, timing) so the fix can be checked against it.
- Cut inputs, callers, config, data and steps one at a time, re-running after each cut, until every remaining element is load-bearing (removing any one turns the loop green).
3. Gather evidence
- Read the whole error and stack trace: file, line, code.
- Check what changed:
git log -p,git diffagainst the last good state, dependency and config changes, environment differences. - Find similar code that works and list every difference, however small.
- Multi-component path (CI → build → sign, API → service → DB): log what enters and leaves each boundary and run once. The evidence names the failing layer; investigate only that one.
- Bad value deep in the stack: trace it backward (who passed it, who passed that) to where it was
first wrong. Fix there, not where it surfaced. Method and examples:
references/tracing.md.
4. Hypothesise, then instrument
- Write 3–5 ranked hypotheses before testing any. Each states a prediction: "if X is the cause, changing Y makes the bug vanish". No prediction, no hypothesis.
- Show the ranking to the user when one is present (they often re-rank it at once); do not block on it.
- Test one hypothesis at a time, changing one variable. A failed test means a new hypothesis, not a second fix stacked on the first.
- Prefer a debugger or REPL; otherwise targeted logs at the boundaries that separate hypotheses.
Never "log everything and grep". Tag every debug line with a unique prefix (
[DEBUG-a4f2]) so cleanup is one grep. - Performance: logs mislead. Measure a baseline (timer, profiler, query plan), change one thing, measure again; bisect if it regressed between two known states.
5. Fix with a regression test
- Turn the minimised repro into a failing test at a seam that exercises the real bug pattern. Watch it fail; if you forced red by editing code or a fixture, diff to prove the edit landed.
- Apply one fix at the root cause. No "while I'm here" changes.
- Watch the test pass, then re-run the original, un-minimised loop.
- If no seam can reproduce the real pattern, say so: that is a finding about the design.
Three failed fixes: stop. When each fix reveals a new problem somewhere else, the design is the problem, not the hypothesis. Report what you tried and what each attempt revealed, and discuss the structure with the user (or supervisor) before a fourth.
Truly environmental or external cause (timing, a third-party service): document what you checked, add the right handling (retry, timeout, clear error) and the logging that would catch it next time. Most "no root cause" verdicts are an unfinished investigation.
6. Clean up before claiming done
- The original loop no longer reproduces; the regression test passes (or the missing seam is stated).
grepthe debug prefix: every tagged line is gone. Throwaway harnesses deleted.- State the hypothesis that proved right in the commit message or report.