Trace Bug
The first task is to reproduce what the user experiences, not to patch the first suspicious line.
Workflow
- Capture the report, environment, expected behavior, observed behavior, frequency, and impact.
- Reproduce the defect end to end as closely as possible to the user path. Preserve the command, inputs, logs, screenshot, or trace.
- If it does not reproduce, vary one dimension at a time: data, timing, permissions, platform, locale, network, cache, concurrency, or version.
- Build a hypothesis ledger before editing.
- Instrument or inspect the boundary that most efficiently separates competing hypotheses.
- Identify the first point where actual state diverges from expected state.
- Add a regression test that fails for the root cause, not just the visible symptom.
- Apply the smallest root-cause fix. Avoid unrelated refactors until green.
- Re-run the end-user reproduction, regression, relevant suites, and adjacent failure modes.
- Remove diagnostic code and review the final diff.
Boundary-fidelity gate
When the defect crosses a serialization, protocol, database, money, timestamp, identifier, or encoding boundary, preserve the external representation until its constraints have been validated.
- Identify the exact boundary representation, including lexical details that downstream types may erase.
- Parse into a lossless domain type before validation. For JSON money in Python, use
json.loads(payload, parse_float=Decimal) and explicitly reject non-finite constants. Do not parse through binary float and then call Decimal(str(value)).
- Validate the domain invariant in the lossless type. Whole-cent acceptance is a numeric invariant:
1.230 may equal 1.23, while 0.105 and 0.29000000000000001 are not whole-cent values.
- Inventory consumers of the boundary-facing functions, return types, and serialized fields before changing their representation. Preserve established contracts unless the task explicitly authorizes a migration.
- Convert once into the canonical internal representation, such as integer minor units, and keep calculations in that representation. Keep the conversion behind the existing API when callers still depend on the prior type or unit.
- Format display output from the canonical value. Do not reintroduce a lossy type merely for presentation.
If a public type or unit must change, treat it as a migration: update every known caller, add contract tests at the consumer boundary, and state the compatibility impact. A locally correct numeric fix that silently changes dollars to cents, seconds to milliseconds, or strings to identifiers is not complete.
Add an adversarial boundary regression that would pass after lossy conversion but must fail at the original boundary. Also cover accepted equivalent spellings, rejected excessive precision, non-finite values, booleans, zero floors, existing typical behavior, and the pre-existing consumer contract when relevant.
Hypothesis ledger
| Hypothesis | Prediction | Discriminating check | Result | Status |
| --- | --- | --- | --- | --- |
Statuses: untested, supported, rejected, root-cause, contributing.
Flake discipline
- Preserve seed, order, timing, machine, retries, and pass/fail history.
- A retry is diagnostic evidence, not a fix.
- Do not add sleeps when an observable condition can be awaited.
- Distinguish product nondeterminism, test pollution, environmental variance, and insufficient assertions.
Stop rules
- Do not change production code before a credible reproduction or a clearly documented substitute exists.
- Do not broaden the fix beyond the causal chain without new evidence.
- Do not silently change a public function's type, unit, schema, or error contract to make the local fix convenient.
- If evidence contradicts the original report, report the contradiction instead of forcing a diagnosis.
- Do not claim exact boundary validation when the parser has already discarded information required to enforce it.
Evidence packet
Return reproduction, root cause, rejected hypotheses, regression test, fix, verification commands and outcomes, adjacent risks, and any environment where the defect remains untested. For boundary defects, include the raw adversarial input and show where lossless validation occurs before canonical conversion.
1---2name: trace-bug3description: Diagnose and fix a reproducible defect by starting from the end-user failure, tracing evidence across boundaries, testing competing hypotheses, and adding a regression test. Use for bugs, flaky behavior, and unexplained test failures. Do not use for feature design.4license: Apache-2.05---67# Trace Bug89The first task is to reproduce what the user experiences, not to patch the first suspicious line.1011## Workflow12131. Capture the report, environment, expected behavior, observed behavior, frequency, and impact.142. Reproduce the defect end to end as closely as possible to the user path. Preserve the command, inputs, logs, screenshot, or trace.153. If it does not reproduce, vary one dimension at a time: data, timing, permissions, platform, locale, network, cache, concurrency, or version.164. Build a hypothesis ledger before editing.175. Instrument or inspect the boundary that most efficiently separates competing hypotheses.186. Identify the first point where actual state diverges from expected state.197. Add a regression test that fails for the root cause, not just the visible symptom.208. Apply the smallest root-cause fix. Avoid unrelated refactors until green.219. Re-run the end-user reproduction, regression, relevant suites, and adjacent failure modes.2210. Remove diagnostic code and review the final diff.2324## Boundary-fidelity gate2526When the defect crosses a serialization, protocol, database, money, timestamp, identifier, or encoding boundary, preserve the external representation until its constraints have been validated.27281. Identify the exact boundary representation, including lexical details that downstream types may erase.292. Parse into a lossless domain type before validation. For JSON money in Python, use `json.loads(payload, parse_float=Decimal)` and explicitly reject non-finite constants. Do not parse through binary `float` and then call `Decimal(str(value))`.303. Validate the domain invariant in the lossless type. Whole-cent acceptance is a numeric invariant: `1.230` may equal `1.23`, while `0.105` and `0.29000000000000001` are not whole-cent values.314. Inventory consumers of the boundary-facing functions, return types, and serialized fields before changing their representation. Preserve established contracts unless the task explicitly authorizes a migration.325. Convert once into the canonical internal representation, such as integer minor units, and keep calculations in that representation. Keep the conversion behind the existing API when callers still depend on the prior type or unit.336. Format display output from the canonical value. Do not reintroduce a lossy type merely for presentation.3435If a public type or unit must change, treat it as a migration: update every known caller, add contract tests at the consumer boundary, and state the compatibility impact. A locally correct numeric fix that silently changes dollars to cents, seconds to milliseconds, or strings to identifiers is not complete.3637Add an adversarial boundary regression that would pass after lossy conversion but must fail at the original boundary. Also cover accepted equivalent spellings, rejected excessive precision, non-finite values, booleans, zero floors, existing typical behavior, and the pre-existing consumer contract when relevant.3839## Hypothesis ledger4041```markdown42| Hypothesis | Prediction | Discriminating check | Result | Status |43| --- | --- | --- | --- | --- |44```4546Statuses: `untested`, `supported`, `rejected`, `root-cause`, `contributing`.4748## Flake discipline4950- Preserve seed, order, timing, machine, retries, and pass/fail history.51- A retry is diagnostic evidence, not a fix.52- Do not add sleeps when an observable condition can be awaited.53- Distinguish product nondeterminism, test pollution, environmental variance, and insufficient assertions.5455## Stop rules5657- Do not change production code before a credible reproduction or a clearly documented substitute exists.58- Do not broaden the fix beyond the causal chain without new evidence.59- Do not silently change a public function's type, unit, schema, or error contract to make the local fix convenient.60- If evidence contradicts the original report, report the contradiction instead of forcing a diagnosis.61- Do not claim exact boundary validation when the parser has already discarded information required to enforce it.6263## Evidence packet6465Return reproduction, root cause, rejected hypotheses, regression test, fix, verification commands and outcomes, adjacent risks, and any environment where the defect remains untested. For boundary defects, include the raw adversarial input and show where lossless validation occurs before canonical conversion.