Skip to content
mentoor

Topic 5 of 5 · 4 min read

Taking back control from a stuck agent

Goal: Recognise a guess loop or symptom patch in an agent's debugging run and choose the reset that ends it.

When an agent has failed to fix a bug twice in a row, stop the loop yourself: go back to evidence, reset the session and give it a smaller task. More turns in the same context rarely help. The context fills with failed attempts, and the agent starts to repeat them.

Check yourself · 1 of 3

An agent has failed to fix the same bug three times and keeps proposing new edits. Best move?

Choose one answer

Signs that it is stuck

  • A guess loop. Each turn proposes a new edit, runs the test, and fails the same way.
  • A symptom patch. It hides the error instead of fixing the cause: a broad try/except, a default value, a retry, a sleep.
  • Weakened checks. It skips a test, loosens an assertion, or edits the expected value to match the wrong output.
  • Growing diff. Files that have nothing to do with the bug keep appearing.
  • Confident claims without runs. "This should fix it" with no command output.

Anthropic's best-practices page advises clearing the context when you have corrected the agent more than once on the same problem, and starting again with a better prompt.

How to reset

  1. Stop the run. Do not add one more instruction to a long failed thread.
  2. Revert the changes. Use git restore or git stash so the next attempt starts from clean code. Keep the failing reproduction.
  3. Write down what you learned: causes ruled out, evidence found, the exact failing check.
  4. Start a fresh session and give it only that, plus one narrow task: "Explain why this test fails. Do not change code."
  5. Or take over. Run the debugger yourself. A person with a breakpoint often finds in minutes what ten guesses missed.

Before and after

Stuck run:

-    assert total(items) == 100.00
+    assert total(items) == 99.99

The agent changed the expected value to match the bug. The test is green and the bug is still there.

Reset prompt:

Fresh start. Facts: total() returns 99.99 for 3 x 33.333. Not the cause:
the tax table, the currency code. Do not edit tests. Find where rounding
happens and show me the line, with no changes yet.

What goes wrong

  • Adding more instructions to a long, polluted thread.
  • Accepting a green test without reading the diff.
  • Resetting without keeping the facts, so the new session repeats the same dead ends.

Examples

A symptom patch

try:
    price = lookup(sku)
except Exception:
    price = 0

The crash is gone, and customers can now buy items for 0. A good fix finds why lookup fails for this SKU.

A narrow restart

Task: explain, with a log line only, why lookup('A-17') raises KeyError.
Do not change behaviour. Report the value of the key at the failure.

The task is small, the evidence is named, and the output is one fact.

Key points

  • Two failed fixes on the same bug is the signal to stop and reset.
  • Watch for broad try/except blocks, skipped tests and edited expectations as symptom patches.
  • Revert the failed changes but keep the reproduction.
  • Carry the facts you learned into a fresh session with a narrower task.
  • Taking over with a debugger yourself is a valid move, not a failure.

Common mistakes

  • Giving the same stuck agent a ninth instruction.
  • Allowing it to edit or skip the failing test.
  • Resetting the session without writing down what was learned.
  • Calling a green test a fix without reading what changed.

Check yourself · 2 of 3

Which change is a symptom patch?

Choose one answer

Check yourself · 3 of 3

An agent turns a failing test green by changing the expected value to match the wrong output. What does that show?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic