Skip to content

Debugging Workflows

Your API endpoint returns a 500 error, but only for certain users. You paste the error into Cursor Agent mode and say “fix this.” It changes three files, the error goes away for your test case, but now a different set of users gets a 403 error. You tell Agent to fix that too. Two more file changes. Now the original 500 is back. You have been going back and forth for 20 minutes and you are further from a fix than when you started.

The problem is not Cursor. The problem is treating debugging as “tell the AI to fix it and hope.” Effective AI-assisted debugging is a structured process: investigate first, understand the root cause, then apply a targeted fix.

  • A systematic debugging workflow using Ask, Debug, and Agent modes in sequence
  • Copy-paste prompts for each stage of the debugging process
  • Techniques for using logs, error traces, and runtime data with AI
  • Patterns for preventing the “fix-break-fix” loop

Before touching any code, understand what is happening:

This gives you a mental model of the problem before you start changing things.

Phase 2: Gather Evidence (Debug Mode or Manual Logging)

Section titled “Phase 2: Gather Evidence (Debug Mode or Manual Logging)”

Once you have hypotheses, gather runtime evidence to confirm or rule them out.

Option A: Use Debug Mode

Switch to Debug mode and describe the bug. The agent will:

  1. Generate hypotheses about root causes
  2. Add strategic log statements to the code
  3. Ask you to reproduce the bug
  4. Analyze the captured logs
  5. Identify the root cause based on evidence

Option B: Manual Log-and-Analyze

If Debug mode is not available or you prefer manual control:

After reproducing the bug, paste the logs back into Cursor:

Only after you understand the root cause, switch to Agent mode for the fix:

After every fix, verify it actually works by adding a test that would have caught the bug:

Add a regression test for the bug we just fixed.
The test should:
1. Set up the exact conditions that caused the failure (user with [specific condition])
2. Call the endpoint with the same request that was failing
3. Assert that it succeeds with the correct response
4. Also test the edge case where [related condition]
Put the test in @src/routes/__tests__/orders.test.ts following existing patterns.
Run the test to confirm it passes.

If the test fails, you know the fix was incomplete. If it passes, you have a regression test that prevents this bug from returning.

TypeScript reports this error at build time:
[PASTE TSC ERROR]
Trace the types involved. Show me:
1. Where the type is defined
2. How it flows through the code to this point
3. Why the types are incompatible
4. The minimal fix that maintains type safety
Do not use `any` or type assertions to fix this. Find the real type issue.
This code has a race condition -- when two requests arrive simultaneously
for the same user, the second request overwrites the first one's data.
Relevant code: @src/services/user-service.ts
Analyze the concurrent execution paths and identify:
1. Which operation is not atomic
2. Where the race window exists
3. The best fix (optimistic locking, database transaction, or mutex)
Show me the fix with before/after code comparison.

When you have many build errors, do not fix them one by one:

This is the TDD-style workflow that Steve Sewell at Builder.io popularized: let the agent run the build, see errors, fix them, and iterate until everything passes — all automatically when auto-run is enabled.

The “fix-break-fix” loop. You are skipping Phase 1 (investigation). Go back to Ask mode, understand the system, then make one targeted change.

Agent “fixes” the test instead of the code. Explicitly say: “The test is correct. The implementation is wrong. Fix the implementation to make the test pass.”

Debug mode logs do not capture the issue. The bug may be in a different part of the call chain than expected. Ask the agent to add logging more broadly, or reproduce the bug multiple times to capture intermittent behavior.

Too many errors to fix at once. Triage: fix compile errors first (they block everything else), then runtime errors, then logic errors. Use the build error cascade pattern above.