TL;DR: Run checks in order of cost after each edit, condense their output, and give the loop memory: a normalised signature for each failure (check, file, error type, message without volatile parts). Stop and re-plan when the same signature survives two fix attempts, when the number of failures stops falling for several iterations, or when edits spread into files unrelated to the task. Separate failures the change caused from ones already present on the base branch. Cap attempts per failing check and report clearly when the cap is hit.
How to approach it
Describe the loop, then what a spiral looks like in data, then the detectors and the responses.
A strong answer
The loop. Edit; format; type check or compile the touched files; run the tests nearest to the change; condense output into a few lines per failure; give that to the model; repeat. Full suite once at the end.
What a spiral looks like.
- The same error returns after each "fix" (the model's understanding is wrong).
- Errors move around without decreasing (whack-a-mole).
- Edits spread to unrelated files to silence errors.
- Failures appear that also fail on the base branch (not this change's problem).
Detectors.
import re
def signature(failure):
msg = re.sub(r"\d+", "N", failure["message"]) # drop line numbers, values
return (failure["check"], failure["file"], failure["type"], msg)
def loop_state(history, max_same=2, stall=3):
sigs = [frozenset(signature(f) for f in it["failures"]) for it in history]
counts = [len(s) for s in sigs]
repeat = [s for s in sigs[-1] if sum(s in prev for prev in sigs[:-1]) >= max_same]
if repeat:
return "re-plan: same failure after repeated fixes"
if len(counts) > stall and min(counts[-stall:]) >= counts[-stall - 1]:
return "re-plan: failures not decreasing"
return "continue"
f = {"check": "pytest", "file": "tests/test_dates.py", "type": "AssertionError",
"message": "assert 2026-03-01 == 2026-01-03 at line 41"}
history = [{"failures": [f]}, {"failures": [f]}, {"failures": [f]}]
print(loop_state(history)) # => re-plan: same failure after repeated fixes
The signature ignores line numbers and changing values, so "the same failure" is recognised even when the message shifts slightly.
Responses, escalating.
- Re-plan: tell the model what has been tried and that it did not work; ask it to gather more information (read the function's callers, run the test with more output) before editing again.
- Baseline check: run the failing test on the base branch; if it fails there too, report it as pre-existing.
- Scope guard: refuse edits to files outside the task's scope without a stated reason.
- Stop: after the attempt cap, end the step with the failure, what was tried and a suggestion for a person.
What interviewers probe next
"Why not just let the model keep trying with a bigger budget?" Repeated identical failures rarely resolve with more of the same; they burn budget and tend to end in test weakening.
"How many attempts?" Two or three per failure signature is a common starting point; tune on traces of runs that succeeded after several attempts versus ones that never did.
"Flaky tests?" Rerun once in isolation; if the outcome changes, mark it flaky and exclude it from the loop's signal.
How it's scored
Weak: Retries until tests pass or the budget runs out.
Hire: Orders checks by cost, condenses output and caps attempts.
Strong Hire: Defines normalised failure signatures, detects repeats, stalls and scope creep, checks failures against the base branch, escalates through re-plan, baseline check, scope guard and stop, handles flakes, and tunes caps from traces.
Common mistakes
- No memory of previous failures, so the loop cannot tell it is repeating.
- Fixing failures that pre-date the change.
- Letting edits spread across the codebase to silence errors.
- Ending at the cap without reporting what was tried.