mcpField

Reflexion Debug Loop

FeaturedOn demand
Code QualityUp to 8 rounds

About Reflexion Debug Loop

A manually triggered debugging loop built around a failing test or repro. Each round runs the targeted test, records a short reflection on why it failed, then edits the code and checks again. It runs for at most 8 rounds.

Key features

  1. 01Targets a single test through --testNamePattern
  2. 02Capped at 8 rounds to avoid endless retries
  3. 03A reflection note each round guides the next fix
  4. 04Supports Claude Code and Cursor

Use cases

  1. 01A test that started failing after a recent change
  2. 02A bug report turned into a repro test
  3. 03Narrowing down a regression with one reproducible test
Goal
The previously failing test or repro passes when run with npm test -- --testNamePattern=<failing-test>.
Exit when
Stop when the repro test exits 0, or after 8 rounds if it still fails.
Between iterations run
npm test -- --testNamePattern=<failing-test>

Launch prompt

Paste into Claude Code / Cursor. The agent repeats the steps below until the exit condition is met.

prompt.md
Start the "Reflexion Debug Loop" loop.
Goal: The previously failing test or repro passes when run with npm test -- --testNamePattern=<failing-test>.
Max iterations: 8.
Step 1: Reproduce the bug — Run the targeted test and read its output. If it exits 0 the loop is finished; otherwise note the failing assertion and error message. `npm test -- --testNamePattern=<failing-test>`
Step 2: Reflect on the cause — Using this round's output and the notes from earlier rounds, write down a hypothesis for the failure and rule out ideas already shown not to work.
Step 3: Change the code — Make the smallest edit that addresses the hypothesis, then move to the next round, where the re-run test shows whether the fix worked.
Between iterations run: `npm test -- --testNamePattern=<failing-test>`
Exit when: Stop when the repro test exits 0, or after 8 rounds if it still fails.

Steps

Each round runs in order; if the exit condition isn’t met, another round starts, up to 8.

01
Reproduce the bug

Run the targeted test and read its output. If it exits 0 the loop is finished; otherwise note the failing assertion and error message.

$npm test -- --testNamePattern=<failing-test>
02
Reflect on the cause

Using this round's output and the notes from earlier rounds, write down a hypothesis for the failure and rule out ideas already shown not to work.

03
Change the code

Make the smallest edit that addresses the hypothesis, then move to the next round, where the re-run test shows whether the fix worked.

Not met → next roundExits when met

Supported agents

Coding agents that can run this loop directly.

Claude Code
Cursor

Comments

Markdown supported