AI-Assisted Bug Fix
Isolate verified root causes, write reproducing regression tests, and fix defects systematically without guesswork.
The Problem
When facing bugs, AI agents frequently guess symptom patches (adding optional chaining `?.`, suppressive try-catch blocks) rather than diagnosing root causes, introducing silent technical debt.
Who It Is For
Developers debugging user-reported bugs, Sentry exceptions, or failing CI pipelines.
Prerequisites & Tools
- Reproducible bug report or failing test scenario
- Target repository with test suite configured
| Tool / Command | Type | Role in Tutorial |
|---|---|---|
| start_task | mcp | Register bugfix contract with reproduction steps |
| mark_bug_fixed | mcp | Record root cause analysis and evidence before code changes |
| run_tests | mcp | Verify regression test failure, then verify green |
Example Task Contract
Exact start_task payload representing this workflow in DevWorkflow local-first governance.
{
"description": "Prevent session crash and redirect to login when JWT expires during checkout",
"type": "bugfix",
"plan": [
"Add unit test in tests/authInterceptor.test.js",
"Update handleExpiredSession to emit reauth event and save cart draft",
"Verify all authentication tests pass"
],
"definitionOfDone": [
"Reproduction test verified failing before implementation",
"Failing test passes cleanly after fix",
"No unhandled Promise rejections on expired tokens"
]
}Step-by-Step Tutorial Workflow
Follow these sequential actions with validated copyable commands and expected outputs.
Register Bugfix Task
Pass `type: 'bugfix'` with reproduction steps, expected behavior, and observed failure.
{
"description": "Fix null pointer crash when user session expires during checkout",
"type": "bugfix",
"plan": [
"Write reproducing test simulating expired auth token on checkout API",
"Identify root cause in token refresh interceptor",
"Implement graceful redirect to login with cart preservation",
"Run paratest / jest suite to confirm regression is fixed"
],
"definitionOfDone": [
"Reproduction test fails before fix and passes after fix",
"Cart state remains preserved in storage on 401 response",
"All tests pass with zero regressions"
]
}Reproduce with a Failing Test First
Never touch production code before reproducing the defect with a failing automated test.
npm test -- -t 'handles expired session'FAIL tests/checkout.test.js
✕ handles expired session (TypeError: Cannot read properties of null)Apply Minimal Root-Cause Fix
Fix the underlying bug at the source. Re-run tests to confirm green status.
npm test -- -t 'handles expired session'PASS tests/checkout.test.js
✓ handles expired session (12.4ms)Verification Steps
Verify that your work genuinely satisfies the task contract before closing.