Debug and Prove
$fw:debug is the Flywheel bug-investigation path.
Use it for failures, regressions, stack traces, broken behavior, nondeterministic
failures, and performance regressions where the first job is diagnosis. If the
work is live operational response and rollback versus patch is still undecided,
start with $fw:incident. If the goal is general latency, throughput, memory,
query, build, or cost improvement rather than a regression, use $fw:optimize.
The goal is not to guess a fix. The goal is to build the fastest faithful
feedback loop, prove the causal chain, fix through a red signal when a local fix
is responsible, and route deeper design or architecture problems before they
become the next bug.
When directly invoked, always debug. Do not skip to code changes just
because the failure looks obvious.
Input
#$ARGUMENTS
Interpret the input as:
- a failing test or error message
- a bug report or issue reference
- a stack trace, crash, flaky failure, or performance regression
- a reproduction sequence
- unexpected behavior the user wants explained or fixed
Interaction Method
Follow ../references/host-interaction-contract.md.
Call the exact host question tool named in
../references/host-interaction-contract.md when that tool is available. Do
not ask for raw 1/2/3 replies when the host already offers a choice surface.
When the debug pass spans multiple material steps, use the host task-tracking
tool named in ../references/host-interaction-contract.md to create and
maintain a short task list.
Reference Loading Map
Do not preload every support file. Load only what the current investigation
needs:
- Load
../tdd/SKILL.md before implementing a local bug fix unless the red
signal is a non-test executable proof such as a CLI command, replay, or
manual fixture.
- Load
$fw:incident when a live or recently live issue still needs blast
radius, mitigation, rollback, or patch framing.
- Load
$fw:observability when the investigation exposes missing telemetry,
trace, dashboard, metric, or supportability signals.
- Load
$fw:logging when the main gap is log-event shape, field stability, or
correlation.
- Load
$fw:architecture-strategy, $fw:maintainability,
$fw:pattern-recognition, or $fw:simplify when the proven root cause is a
boundary, ownership, pattern, coupling, or accidental-complexity problem.
- Load
$fw:decision when the fix contradicts a durable product, workflow,
architecture, terminology, or compatibility decision.
- Load
$fw:verify discipline before claiming the bug is fixed.
Core Principles
- Feedback loop before cleverness - a fast, faithful pass/fail loop turns
debugging into evidence work. Without one, code reading easily becomes
guessing.
- Match the user's symptom - prove the loop reproduces the reported bug,
not a nearby failure that happens to be easier to trigger.
- Evidence outranks ideas - logs, traces, reproductions, tests, profiles,
data state, and code paths beat intuition.
- Minimize without changing the bug - shrink the reproduction until it is
cheap to run, but keep the same failure mode and causal path.
- Rank falsifiable hypotheses - generate several plausible causes, attach
predictions, then test one variable at a time.
- A local bug fix needs a red signal - when the bug is local enough to fix
now, prove it with a failing test or equivalent failing reproducer before
implementation.
- Architecture gaps are findings - no correct test seam, hidden coupling,
unclear ownership, or tangled boundaries are part of the root cause, not
cleanup trivia.
- No completion claims without fresh verification - rerun the original
feedback loop and the regression proof before saying the bug is fixed.
- Clean up the investigation - remove tagged debug instrumentation,
temporary harnesses, throwaway fixtures, and local-only probes unless they
become intentional repo artifacts.
- Preserve reusable lessons - when the investigation teaches a
non-obvious prevention pattern, offer
$fw:spin after the fix is verified.
Workflow
Phase 0: Intake And Route
If the input includes an issue reference, fetch it before investigating.
GitHub forms to recognize:
#123
owner/repo#123
https://github.com/<owner>/<repo>/issues/<number>
When GitHub CLI is available, use gh issue view with structured output and
extract:
- reported symptoms
- expected behavior
- reproduction steps
- environment notes
- labels, severity, or affected version hints
- prior discussion and already-failed fixes
If the input points at another tracker URL or identifier, use whatever local
tooling or available app surfaces can fetch it. If the issue cannot be fetched,
ask the user to paste the relevant content rather than pretending the report was
read.
Capture the bug frame before touching code:
- actual symptom and expected behavior
- environment, version, branch, config, dataset, tenant, browser, device, or
runtime details when relevant
- recent change window: commits, deploys, dependency updates, migrations,
config flips, data imports, or feature flags that may bound the regression
- attempts already tried and what they ruled out
Read .flywheel/config.local.yaml when present and carry forward local debug
gates such as debug.require_reproducer_before_fix.
If the issue is live, the blast radius is not bounded, or rollback versus patch
is still a decision, route to $fw:incident before local bug-fix work.
Phase 1: Build The Feedback Loop
This is the center of the skill. Spend disproportionate effort here.
Search the active repo's docs/solutions/ before deep investigation when it
exists:
- prefer frontmatter-first lookup by
files_touched, module, tags,
problem_type, component, and title
- prefer
doc_status: active
- if a strong hit has
superseded_by, follow that path first
- read only the strongest hits and use them to avoid repeating known dead ends
or outdated fixes
Construct the fastest faithful loop that reproduces the user-visible failure.
Try these in roughly this order:
- Failing test at the seam that reaches the bug: unit, integration, or
end-to-end.
- HTTP script against a running dev server, with stable request fixtures.
- CLI invocation with fixture input, diffing stdout or artifacts against a
known-good expectation.
- Headless browser script with Playwright or Puppeteer, asserting on DOM,
console, network, screenshots, or traces.
- Captured trace replay from a real network request, payload, event log,
queue message, or serialized state.
- Throwaway harness that boots the smallest subset of the system and calls
the bug path directly.
- Property or fuzz loop when the symptom is intermittent wrong output over
broad input space.
- Bisection harness when the bug appeared between two known states; make
the check suitable for
git bisect run when practical.
- Differential loop that runs the same input through old versus new code,
two configs, or two data snapshots and diffs the output.
- Structured human-in-the-loop script as a last resort when a human must
click or operate external state; capture timestamps, commands, and observed
output so the loop still feeds evidence back into the investigation.
Treat the loop itself as a product:
- make it faster by caching setup, narrowing scope, and skipping unrelated init
- make it sharper by asserting the specific symptom instead of "did not crash"
- make it more deterministic by pinning time, seeding randomness, isolating the
filesystem, and freezing network or service dependencies
A 30-second flaky loop is weak. A two-second deterministic loop is leverage.
For nondeterministic bugs, the immediate goal is a higher reproduction rate.
Loop the trigger, parallelize when safe, add stress, narrow timing windows,
seed randomness, inject sleeps, or isolate scheduler and IO boundaries. A bug
that reproduces 50% of the time can be debugged; a 1% failure needs a stronger
loop before root-cause work starts.
For performance regressions, create a baseline measurement before changing code:
timing harness, profiler, query plan, flamegraph, allocation profile, browser
trace, or benchmark. Measure first, fix second.
If no credible loop can be built, stop and say so explicitly. List what was
tried and ask for the missing access or artifact: a reproducing environment,
HAR file, log dump, trace, core dump, database snapshot, screen recording with
timestamps, or permission to add temporary instrumentation. Do not proceed to
hypothesize a fix without a loop or a clearly bounded no-loop diagnostic.
Phase 2: Reproduce And Minimize
Run the loop and watch the bug appear.
Confirm:
- the loop produces the failure mode the user described
- the failure is reproducible across multiple runs, or reproducible at a high
enough rate to debug for nondeterministic bugs
- the exact symptom is captured: error text, wrong output, state transition,
slow timing, profile shape, UI artifact, or runtime side effect
- the failure can be minimized without changing its nature
Read the relevant code path in both directions:
- from trigger to symptom
- from symptom back upstream to the first wrong assumption, state, boundary, or
contract
For data or state bugs, preserve a redacted fixture or state summary that lets
the failure be replayed. Do not mutate production state to make diagnosis
easier.
Phase 3: Rank Hypotheses
Generate 3-5 ranked hypotheses before testing any of them. Single
hypotheses anchor too early on the first plausible idea.
Each hypothesis must be falsifiable:
If <cause> is responsible, then <probe or change> will produce <specific result>.
Reject or sharpen any hypothesis that cannot state a prediction.
When interaction is useful, show the ranked list before testing so the user can
add domain facts, recent deploy knowledge, or already-ruled-out attempts. Do
not block indefinitely; proceed with the best ranking if the user is
unavailable.
Phase 4: Probe And Instrument
Each probe must map to one prediction from Phase 3. Change one variable at a
time.
Prefer tools in this order:
- debugger, REPL, trace viewer, profiler, or query analyzer when the
environment supports it
- targeted logs or counters at the boundaries that distinguish hypotheses
- temporary assertions or invariant checks near the first suspected wrong
state
Never "log everything and grep."
Tag every temporary debug log or probe with a unique prefix such as
[DEBUG-a4f2]. Cleanup must be a single search.
For distributed, async, queue, retry, cache, or concurrency bugs, probe
boundaries explicitly: correlation IDs, ordering, idempotency keys, lock state,
retry attempts, queue offsets, cache keys, clock assumptions, and timeout paths.
If the investigation turns into telemetry or instrumentation design, load
$fw:observability or $fw:logging instead of inventing a support strategy
from memory.
Phase 5: State The Causal Chain
Before editing production code, state:
- root-cause hypothesis
- responsible file, module, component, or boundary
- trigger -> path -> symptom chain
- evidence that supports the chain
- hypotheses rejected and what falsified them
- red signal that should fail before the fix and pass after it
- whether a prior
docs/solutions/ entry was confirmed, rejected, or only
partially applicable
If that chain cannot be stated yet, keep investigating.
Phase 6: Fix Or Route
Route A: Local Bug Fix
Use this route when the bug is local enough to fix responsibly now.
If local policy requires a reproducer before implementation and no red failing
test or equivalent reproducer exists, do not implement. Keep investigating
until the red signal exists or route the work upstream.
Use this sequence:
- Load
../tdd/SKILL.md unless the reproducer is a non-test executable proof
such as a CLI command, replay, or manual fixture.
- Turn the minimized reproduction into a red failing test or stable executable
reproducer at the correct seam.
- Confirm the red signal fails for the reason the causal chain predicts.
- Implement the minimal fix.
- Rerun the red signal until it turns green.
- Rerun the original feedback loop against the unminimized scenario.
- Refactor only after green when cleanup is useful, then rerun the target
proof.
- Run broader relevant checks and apply
$fw:verify discipline before
claiming the bug is fixed.
A correct regression seam exercises the real bug pattern as it occurs at the
call site. If the only available seam is too shallow, over-mocked, or unable to
replicate the chain that triggered the bug, do not lock in false confidence.
Document that as an architecture finding.
Route B: Design, Architecture, Or Requirements Problem
Use this route when:
- the code is behaving as currently designed but the design is wrong
- the clean fix requires changing responsibilities, boundaries, interfaces, or
ownership first
- no correct test seam exists because callers, state, or dependencies are too
tangled
- every plausible code change looks like a workaround
In that case:
- summarize the root cause and why it is not a safe local bug fix
- preserve the failing loop or reproducer as the truth surface for later work
- route to
$fw:architecture-strategy for boundary or service-shape issues
- route to
$fw:maintainability for unclear ownership, cohesion, naming, or
future edit cost
- route to
$fw:simplify when accidental abstraction or orchestration is the
core problem
- route to
$fw:brainstorm when the desired behavior or scope is still unclear
- route to
$fw:plan when the behavior is clear but execution needs redesign
- route to
$fw:decision when a durable decision must be reopened
Do not paper over the bug with a local workaround when the causal proof says the
architecture is the problem.
Phase 7: Cleanup And Prevention
Required before declaring done:
- rerun the original Phase 1 feedback loop and confirm the original symptom no
longer reproduces
- rerun the regression test or executable red signal
- run the broader relevant checks for the changed surface
- remove all
[DEBUG-...] instrumentation and search for the prefix
- delete throwaway harnesses and prototypes, or move them into a clearly marked
debug or regression-test location
- state the correct hypothesis and the rejected alternatives in the final
report, commit message, or PR body when applicable
- answer: what would have prevented this bug?
If the answer is durable and repo-specific, offer $fw:spin after verification
so the next debugging session can find the lesson in docs/solutions/.
Output Contract
Return:
- Problem - what is failing
- Feedback loop - the command, script, trace, fixture, or manual loop used
- Evidence - reproduction, measurements, logs, traces, profiles, or code
evidence
- Hypotheses - ranked causes, including what was falsified
- Causal chain - trigger -> path -> symptom
- Red signal - the failing test or reproducer that proves the hypothesis
- Fix or route - local fix, or handoff to the right Flywheel stage
- Prevention - architecture, maintainability, test-seam, observability, or
process change that would prevent recurrence
- Verification - fresh proof used before claiming success, or the exact
gap that blocks that claim
If no credible feedback loop exists yet, return the attempted loops, the reason
each failed, and the specific artifact or access needed next.
1---2name: debug3description: Investigate hard bugs, regressions, stack traces, or broken behavior with evidence, a repro loop, causal proof, and a fix path.4---56# Debug and Prove78`$fw:debug` is the Flywheel bug-investigation path.910Use it for failures, regressions, stack traces, broken behavior, nondeterministic11failures, and performance regressions where the first job is diagnosis. If the12work is live operational response and rollback versus patch is still undecided,13start with `$fw:incident`. If the goal is general latency, throughput, memory,14query, build, or cost improvement rather than a regression, use `$fw:optimize`.1516The goal is not to guess a fix. The goal is to build the fastest faithful17feedback loop, prove the causal chain, fix through a red signal when a local fix18is responsible, and route deeper design or architecture problems before they19become the next bug.2021**When directly invoked, always debug.** Do not skip to code changes just22because the failure looks obvious.2324## Input2526<bug_input> #$ARGUMENTS </bug_input>2728Interpret the input as:2930- a failing test or error message31- a bug report or issue reference32- a stack trace, crash, flaky failure, or performance regression33- a reproduction sequence34- unexpected behavior the user wants explained or fixed3536## Interaction Method3738Follow `../references/host-interaction-contract.md`.3940Call the exact host question tool named in41`../references/host-interaction-contract.md` when that tool is available. Do42not ask for raw `1/2/3` replies when the host already offers a choice surface.4344When the debug pass spans multiple material steps, use the host task-tracking45tool named in `../references/host-interaction-contract.md` to create and46maintain a short task list.4748## Reference Loading Map4950Do not preload every support file. Load only what the current investigation51needs:5253- Load `../tdd/SKILL.md` before implementing a local bug fix unless the red54 signal is a non-test executable proof such as a CLI command, replay, or55 manual fixture.56- Load `$fw:incident` when a live or recently live issue still needs blast57 radius, mitigation, rollback, or patch framing.58- Load `$fw:observability` when the investigation exposes missing telemetry,59 trace, dashboard, metric, or supportability signals.60- Load `$fw:logging` when the main gap is log-event shape, field stability, or61 correlation.62- Load `$fw:architecture-strategy`, `$fw:maintainability`,63 `$fw:pattern-recognition`, or `$fw:simplify` when the proven root cause is a64 boundary, ownership, pattern, coupling, or accidental-complexity problem.65- Load `$fw:decision` when the fix contradicts a durable product, workflow,66 architecture, terminology, or compatibility decision.67- Load `$fw:verify` discipline before claiming the bug is fixed.6869## Core Principles70711. **Feedback loop before cleverness** - a fast, faithful pass/fail loop turns72 debugging into evidence work. Without one, code reading easily becomes73 guessing.742. **Match the user's symptom** - prove the loop reproduces the reported bug,75 not a nearby failure that happens to be easier to trigger.763. **Evidence outranks ideas** - logs, traces, reproductions, tests, profiles,77 data state, and code paths beat intuition.784. **Minimize without changing the bug** - shrink the reproduction until it is79 cheap to run, but keep the same failure mode and causal path.805. **Rank falsifiable hypotheses** - generate several plausible causes, attach81 predictions, then test one variable at a time.826. **A local bug fix needs a red signal** - when the bug is local enough to fix83 now, prove it with a failing test or equivalent failing reproducer before84 implementation.857. **Architecture gaps are findings** - no correct test seam, hidden coupling,86 unclear ownership, or tangled boundaries are part of the root cause, not87 cleanup trivia.888. **No completion claims without fresh verification** - rerun the original89 feedback loop and the regression proof before saying the bug is fixed.909. **Clean up the investigation** - remove tagged debug instrumentation,91 temporary harnesses, throwaway fixtures, and local-only probes unless they92 become intentional repo artifacts.9310. **Preserve reusable lessons** - when the investigation teaches a94 non-obvious prevention pattern, offer `$fw:spin` after the fix is verified.9596## Workflow9798### Phase 0: Intake And Route99100If the input includes an issue reference, fetch it before investigating.101102GitHub forms to recognize:103104- `#123`105- `owner/repo#123`106- `https://github.com/<owner>/<repo>/issues/<number>`107108When GitHub CLI is available, use `gh issue view` with structured output and109extract:110111- reported symptoms112- expected behavior113- reproduction steps114- environment notes115- labels, severity, or affected version hints116- prior discussion and already-failed fixes117118If the input points at another tracker URL or identifier, use whatever local119tooling or available app surfaces can fetch it. If the issue cannot be fetched,120ask the user to paste the relevant content rather than pretending the report was121read.122123Capture the bug frame before touching code:124125- actual symptom and expected behavior126- environment, version, branch, config, dataset, tenant, browser, device, or127 runtime details when relevant128- recent change window: commits, deploys, dependency updates, migrations,129 config flips, data imports, or feature flags that may bound the regression130- attempts already tried and what they ruled out131132Read `.flywheel/config.local.yaml` when present and carry forward local debug133gates such as `debug.require_reproducer_before_fix`.134135If the issue is live, the blast radius is not bounded, or rollback versus patch136is still a decision, route to `$fw:incident` before local bug-fix work.137138### Phase 1: Build The Feedback Loop139140This is the center of the skill. Spend disproportionate effort here.141142Search the active repo's `docs/solutions/` before deep investigation when it143exists:144145- prefer frontmatter-first lookup by `files_touched`, `module`, `tags`,146 `problem_type`, `component`, and title147- prefer `doc_status: active`148- if a strong hit has `superseded_by`, follow that path first149- read only the strongest hits and use them to avoid repeating known dead ends150 or outdated fixes151152Construct the fastest faithful loop that reproduces the user-visible failure.153Try these in roughly this order:1541551. **Failing test** at the seam that reaches the bug: unit, integration, or156 end-to-end.1572. **HTTP script** against a running dev server, with stable request fixtures.1583. **CLI invocation** with fixture input, diffing stdout or artifacts against a159 known-good expectation.1604. **Headless browser script** with Playwright or Puppeteer, asserting on DOM,161 console, network, screenshots, or traces.1625. **Captured trace replay** from a real network request, payload, event log,163 queue message, or serialized state.1646. **Throwaway harness** that boots the smallest subset of the system and calls165 the bug path directly.1667. **Property or fuzz loop** when the symptom is intermittent wrong output over167 broad input space.1688. **Bisection harness** when the bug appeared between two known states; make169 the check suitable for `git bisect run` when practical.1709. **Differential loop** that runs the same input through old versus new code,171 two configs, or two data snapshots and diffs the output.17210. **Structured human-in-the-loop script** as a last resort when a human must173 click or operate external state; capture timestamps, commands, and observed174 output so the loop still feeds evidence back into the investigation.175176Treat the loop itself as a product:177178- make it faster by caching setup, narrowing scope, and skipping unrelated init179- make it sharper by asserting the specific symptom instead of "did not crash"180- make it more deterministic by pinning time, seeding randomness, isolating the181 filesystem, and freezing network or service dependencies182183A 30-second flaky loop is weak. A two-second deterministic loop is leverage.184185For nondeterministic bugs, the immediate goal is a higher reproduction rate.186Loop the trigger, parallelize when safe, add stress, narrow timing windows,187seed randomness, inject sleeps, or isolate scheduler and IO boundaries. A bug188that reproduces 50% of the time can be debugged; a 1% failure needs a stronger189loop before root-cause work starts.190191For performance regressions, create a baseline measurement before changing code:192timing harness, profiler, query plan, flamegraph, allocation profile, browser193trace, or benchmark. Measure first, fix second.194195If no credible loop can be built, stop and say so explicitly. List what was196tried and ask for the missing access or artifact: a reproducing environment,197HAR file, log dump, trace, core dump, database snapshot, screen recording with198timestamps, or permission to add temporary instrumentation. Do not proceed to199hypothesize a fix without a loop or a clearly bounded no-loop diagnostic.200201### Phase 2: Reproduce And Minimize202203Run the loop and watch the bug appear.204205Confirm:206207- the loop produces the failure mode the user described208- the failure is reproducible across multiple runs, or reproducible at a high209 enough rate to debug for nondeterministic bugs210- the exact symptom is captured: error text, wrong output, state transition,211 slow timing, profile shape, UI artifact, or runtime side effect212- the failure can be minimized without changing its nature213214Read the relevant code path in both directions:215216- from trigger to symptom217- from symptom back upstream to the first wrong assumption, state, boundary, or218 contract219220For data or state bugs, preserve a redacted fixture or state summary that lets221the failure be replayed. Do not mutate production state to make diagnosis222easier.223224### Phase 3: Rank Hypotheses225226Generate **3-5 ranked hypotheses** before testing any of them. Single227hypotheses anchor too early on the first plausible idea.228229Each hypothesis must be falsifiable:230231```text232If <cause> is responsible, then <probe or change> will produce <specific result>.233```234235Reject or sharpen any hypothesis that cannot state a prediction.236237When interaction is useful, show the ranked list before testing so the user can238add domain facts, recent deploy knowledge, or already-ruled-out attempts. Do239not block indefinitely; proceed with the best ranking if the user is240unavailable.241242### Phase 4: Probe And Instrument243244Each probe must map to one prediction from Phase 3. Change one variable at a245time.246247Prefer tools in this order:2482491. debugger, REPL, trace viewer, profiler, or query analyzer when the250 environment supports it2512. targeted logs or counters at the boundaries that distinguish hypotheses2523. temporary assertions or invariant checks near the first suspected wrong253 state254255Never "log everything and grep."256257Tag every temporary debug log or probe with a unique prefix such as258`[DEBUG-a4f2]`. Cleanup must be a single search.259260For distributed, async, queue, retry, cache, or concurrency bugs, probe261boundaries explicitly: correlation IDs, ordering, idempotency keys, lock state,262retry attempts, queue offsets, cache keys, clock assumptions, and timeout paths.263264If the investigation turns into telemetry or instrumentation design, load265`$fw:observability` or `$fw:logging` instead of inventing a support strategy266from memory.267268### Phase 5: State The Causal Chain269270Before editing production code, state:271272- root-cause hypothesis273- responsible file, module, component, or boundary274- trigger -> path -> symptom chain275- evidence that supports the chain276- hypotheses rejected and what falsified them277- red signal that should fail before the fix and pass after it278- whether a prior `docs/solutions/` entry was confirmed, rejected, or only279 partially applicable280281If that chain cannot be stated yet, keep investigating.282283### Phase 6: Fix Or Route284285#### Route A: Local Bug Fix286287Use this route when the bug is local enough to fix responsibly now.288289If local policy requires a reproducer before implementation and no red failing290test or equivalent reproducer exists, do not implement. Keep investigating291until the red signal exists or route the work upstream.292293Use this sequence:2942951. Load `../tdd/SKILL.md` unless the reproducer is a non-test executable proof296 such as a CLI command, replay, or manual fixture.2972. Turn the minimized reproduction into a red failing test or stable executable298 reproducer at the correct seam.2993. Confirm the red signal fails for the reason the causal chain predicts.3004. Implement the minimal fix.3015. Rerun the red signal until it turns green.3026. Rerun the original feedback loop against the unminimized scenario.3037. Refactor only after green when cleanup is useful, then rerun the target304 proof.3058. Run broader relevant checks and apply `$fw:verify` discipline before306 claiming the bug is fixed.307308A correct regression seam exercises the real bug pattern as it occurs at the309call site. If the only available seam is too shallow, over-mocked, or unable to310replicate the chain that triggered the bug, do not lock in false confidence.311Document that as an architecture finding.312313#### Route B: Design, Architecture, Or Requirements Problem314315Use this route when:316317- the code is behaving as currently designed but the design is wrong318- the clean fix requires changing responsibilities, boundaries, interfaces, or319 ownership first320- no correct test seam exists because callers, state, or dependencies are too321 tangled322- every plausible code change looks like a workaround323324In that case:325326- summarize the root cause and why it is not a safe local bug fix327- preserve the failing loop or reproducer as the truth surface for later work328- route to `$fw:architecture-strategy` for boundary or service-shape issues329- route to `$fw:maintainability` for unclear ownership, cohesion, naming, or330 future edit cost331- route to `$fw:simplify` when accidental abstraction or orchestration is the332 core problem333- route to `$fw:brainstorm` when the desired behavior or scope is still unclear334- route to `$fw:plan` when the behavior is clear but execution needs redesign335- route to `$fw:decision` when a durable decision must be reopened336337Do not paper over the bug with a local workaround when the causal proof says the338architecture is the problem.339340### Phase 7: Cleanup And Prevention341342Required before declaring done:343344- rerun the original Phase 1 feedback loop and confirm the original symptom no345 longer reproduces346- rerun the regression test or executable red signal347- run the broader relevant checks for the changed surface348- remove all `[DEBUG-...]` instrumentation and search for the prefix349- delete throwaway harnesses and prototypes, or move them into a clearly marked350 debug or regression-test location351- state the correct hypothesis and the rejected alternatives in the final352 report, commit message, or PR body when applicable353- answer: what would have prevented this bug?354355If the answer is durable and repo-specific, offer `$fw:spin` after verification356so the next debugging session can find the lesson in `docs/solutions/`.357358## Output Contract359360Return:3613621. **Problem** - what is failing3632. **Feedback loop** - the command, script, trace, fixture, or manual loop used3643. **Evidence** - reproduction, measurements, logs, traces, profiles, or code365 evidence3664. **Hypotheses** - ranked causes, including what was falsified3675. **Causal chain** - trigger -> path -> symptom3686. **Red signal** - the failing test or reproducer that proves the hypothesis3697. **Fix or route** - local fix, or handoff to the right Flywheel stage3708. **Prevention** - architecture, maintainability, test-seam, observability, or371 process change that would prevent recurrence3729. **Verification** - fresh proof used before claiming success, or the exact373 gap that blocks that claim374375If no credible feedback loop exists yet, return the attempted loops, the reason376each failed, and the specific artifact or access needed next.