Reflexion Debug Loop
FeaturedOn demandAbout 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
- 01Targets a single test through --testNamePattern
- 02Capped at 8 rounds to avoid endless retries
- 03A reflection note each round guides the next fix
- 04Supports Claude Code and Cursor
Use cases
- 01A test that started failing after a recent change
- 02A bug report turned into a repro test
- 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.
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.
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>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.
Make the smallest edit that addresses the hypothesis, then move to the next round, where the re-run test shows whether the fix worked.
Supported agents
Coding agents that can run this loop directly.