Debugging
Reproduce a runtime failure, prove its cause with NDJSON runtime logs, patch only the proven cause, and rerun the failing check
$debugging-phase starts from runtime evidence, not from a code smell. It reproduces the visible
failure, runs $debug-agent to prove a cause with NDJSON runtime logs, patches only the proven
cause, and reruns the failing check. It runs standalone, or inside delivery when validation or review
finds a runtime failure.
- Use this when: runtime behavior is broken, flaky, slow, or inconsistent; a smoke, browser, or CLI check, a recording, or a log shows a failure; or a delivery run hits a runtime failure.
- It gives you: an evidence matrix with cited evidence per hypothesis, a confirmed root cause, a bounded patch, and before/after proof.
- It ends with: exactly one exit: fixed, blocked, or
human_steering_required. Inside AFKdelivery-phase,human_steering_requiredmeans missing access only; see Inside AFK Delivery. - Wrapped skills:
$verify-behavior(reproduce mode),$debug-agent,$show-me, optional readonly$parallel-research.
Do not use it for planning, requirements, or design work; for a failure that is already proven and only needs implementation inside an active spec plan; or for static review with no runtime symptom.
Entry
| Entry | Trigger | Input recorded |
|---|---|---|
| Standalone | The operator reports broken behavior or invokes $debugging-phase. | Broken behavior, artifact links, reproduction command or manual scenario, expected and observed behavior. |
| Delivery: verification | implement-spec gets a verify-behavior verify mismatch, or update-verification-skill returns product-failure. | The failing validation and the delivery scope it belongs to. |
| Delivery: review | A Pass Report finding has return_route: debugging. Delivery opens debug_active. | The review finding, its stable ID, and the delivery scope. |
Inside delivery, the debug gate of delivery-phase loads debugging-phase only after the router
selects that gate. Debugging is never a normal delivery-start dependency. The gate preserves the opening
pass_report and review_run_id through the repair.
Debugging Loop
Workflow
- Classify entry. Record the standalone inputs, or cite the delivery trigger and scope. Scan routed learning artifacts for prior bugs, edge cases, and prevention notes before forming hypotheses.
- Set bounds. Define owned files, systems, and scenarios. Delivery-internal patches stay inside
the active delivery scope. When the next action exceeds the bounds, a standalone run retains the
evidence and the required decision, returns
human_steering_required, and stops. Inside AFKdelivery-phase, the run takes an out-of-bounds Autonomous Decision and continues. - Reproduce. When the behavior is visibly exercisable, run
$verify-behaviorinreproducemode before any hypothesis or fix. The result isconfirmed,partially confirmed,not reproduced, orblocked. It seeds the evidence matrix. A blocked reproduction is evidence of the blocker, not proof that the failure occurred or disappeared. - Run
$debug-agent. This step is mandatory. It forms 3-5 hypotheses, adds runtime instrumentation, and marks each hypothesisconfirmed,rejected, orinconclusivewith cited log lines, recordings, commands, test output, or scenario evidence.$show-mepresents the evidence matrix before a cause or fix is chosen; cited evidence stays authoritative. - Optional readonly
$parallel-research. Use it for independent hypotheses, unfamiliar subsystems, logs, docs, or prior art. Synthesize the lanes into one matrix before any fix. - Fix only proven causes. Make the smallest patch that addresses confirmed evidence. Remove
speculative edits from rejected hypotheses. Keep the instrumentation until the
$debug-agentCleanup rule removes it. - Verify. Rerun the failing smoke check, focused test, browser path, CLI command, or manual
scenario, and compare before/after evidence. Record failures outside the reported behavior as
unrelated, with evidence; they need no baseline run. Then hand off review by entry mode:
- Delivery-internal: return the repair to
delivery-phasefor Focused Repair Validation. This phase opens no review pass. - Standalone: hand the human the
$review-phase <commit-or-range>command that names the commit orbase..headrange holding the fix.
- Delivery-internal: return the repair to
- Exit. Report one exit (see Exits).
debug-agent Instrumentation
$debug-agent edits source to add temporary logging. It never fixes from code alone.
- Session:
npx debug-agent --daemonstarts a background log server and printssessionId,port,endpoint, andlogPath. If the server does not start, debugging stops. The command is idempotent: when adebug-server.lockin the log directory names a reachable server, the command reuses that server. - Logs: 1-10 log points, usually 2-6. JavaScript and TypeScript send a POST to the endpoint.
Other languages append one NDJSON line to
logPath, for example/tmp/debug-agent/debug-<sessionId>.log. Logs never contain secrets. - Markers: every log point sits inside a
#region debug log/#endregionblock, so cleanup is deterministic. - Runs: a
DELETEto the endpoint clears the session log before each run. The agent reuses an existing failing test, a short reproduction script, or user steps; once a path is agreed, it reuses that path. Inside AFKdelivery-phase, the agent writes and runs the reproduction itself, through$verify-behaviorreproduceon the Owned Stack or an ad hoc script, reruns it to verify, and asks nothing. - Fix rule: fix only with log proof. A
sleepor timeout change is not a fix. - Failed fix: first revert rejected-hypothesis code, then form new hypotheses in other subsystems. The instrumentation stays in place.
- Cleanup: the debug-agent Cleanup section is the one rule for instrumentation removal. It
removes instrumentation when post-fix logs prove success, or earlier on explicit user request:
delete every
#region debug logblock, check that no marker remains, and inspectgit diff. - Server stop: on every exit, including a blocked one, the final step stops the log server that
this session started (
kill $(lsof -t -iTCP:PORT -sTCP:LISTEN)) and leaves a reused server running. It copies the cited log lines into the report, deletes the session log file and adebug-server.lockthat still names the stopped server, and checks thatcurl -s ENDPOINTcan no longer connect.
Evidence Matrix And Verification Tiers
The evidence matrix is the phase's main artifact. Each row is one hypothesis with its status and cited evidence. Worker findings merge into this one matrix before a patch decision.
Each hypothesis is tested at the cheapest tier that can decide it. implement-spec's
references/validation-scope.md owns these rules:
| Tier | Evidence | Use |
|---|---|---|
| 1 | Saved receipts and pure-helper checks | Correct a diagnosis cheaply. |
| 2 | Focused reproduction of one hypothesis on the Owned Stack | Decide one hypothesis at runtime. |
| 3 | Plan-scoped acceptance journey | Confirm after focused checks settle. |
The Owned Stack is the runtime this delivery started and owns, isolated from other runs. It is reused across steps and reset, not relaunched. Before another expensive run, the agent states its New Discriminator, the fact that earlier runs could not confirm or reject, and checks that the Observation Manifest covers it. When the same observation is missing again, the agent revises the plan instead of rerunning.
Parallel Rules
parallel: false: one thread owns hypotheses, instrumentation, fix, verification, and review handoff.parallel: true: only readonly research fans out, one lane per independent hypothesis.- Disjoint worker fixes are allowed only after the cause is proven and file ownership is explicit.
- Parallel workers never make speculative fixes against unproven hypotheses.
- Delivery-internal workers stay inside the delivery scope unless assigned readonly investigation.
Exits
| Exit | Report |
|---|---|
| Fixed | Cause, patch, verification, residual risk. |
| Blocked | The concrete blocker and the missing artifact, access, or action. Inside AFK delivery, a blocker other than access first takes an Autonomous Decision. |
human_steering_required | Standalone: the retained decision record; the run stops until the user decides. Inside AFK delivery: the missing-access record. |
There is no escalation to a spec, a debt item, or a docs update from inside this phase. In a
standalone run, out-of-bounds work becomes human_steering_required.
Inside AFK Delivery
Inside AFK delivery-phase, every pending question or human decision becomes an
Autonomous Decision, recorded in
the Phase Result's changed_facts. Each out-of-bounds decision is posted to the thread at once.
- Next action exceeds bounds: take an out-of-bounds Autonomous Decision and continue.
- Blocker other than access: take an Autonomous Decision per delivery's failure continuity: another approach, debt capture, or a narrower scope.
human_steering_required: return it only for missing access (credentials, permissions, or an unreachable provider), with the missing-access record.- Reproduction and verification:
$debug-agentwrites, runs, and reruns the reproduction itself and reads the logs after its own run.
The output report names the mode (standalone or delivery-internal, parallel: true|false), the
input artifacts, the evidence matrix, the root cause, the changes, the verification, and the exit.
Return To Delivery
Delivery-internal runs end in the debug gate of delivery-phase. The gate writes runtime evidence,
the root cause or narrowed hypothesis, the fix or blocker, rerun validation, and the preserved
pass_report and review_run_id. It emits the common Phase Result, then re-enters delivery-phase routing. Only Full
Delivery continues without a stop.
- After a completed review pass: an ordinary repair goes to
focused_validation. Delivery reruns focused checks and only the Verification scenarios the repair invalidated. A pass goes toclean_handoff; a failure returns todebug_active. - Risk trigger: when one Pass Report exists and the repair changes architecture, security or
authorization, a public contract, runtime or deployment topology, or accepted scope, delivery
returns to
review_duefor a second pass. - Bounds exceeded: debugging takes the out-of-bounds Autonomous Decision, records it in the Phase Result, and returns to the delivery router before any new goal opens.
Debugging never invokes $docs-ingest-phase. Docs follow-up comes from a review docs_ingest
route inside delivery, or from an operator choice after a standalone run.
Standalone Review
review-phase is explicit-only, so a standalone run does not start a review itself. Step 7 hands
the human the $review-phase command with the commit or range of the fix, and the human invokes
it. See Review.
Return To ClawPatch Resolution
A ClawPatch finding classified needs-runtime-debugging enters this phase from
$bug-resolution-phase. After the fix, the operator re-invokes $bug-resolution-phase with the
finding ID and the debugging result. That run revalidates the finding with
clawpatch revalidate --finding <id>.
Related Pages
- Massive Bug Hunt And Fix: ClawPatch findings
classified
needs-runtime-debuggingenter this phase. - Project Verification Flow
- Validation Gates
- External Tool Contract