🤖 The AI Prompt That Finds the Retry Loop That Never Actually Gives Up
Retry logic with backoff is meant to handle transient failures gracefully – but a subtle bug (a missing maximum attempt count, a backoff calculation that never actually increases, an exception type check that accidentally catches and retries something that will NEVER succeed) can turn well-intentioned retry logic into a silent, resource-consuming infinite loop. This prompt asks an AI assistant to review retry code specifically for that failure mode.
📋 The Prompt
Review this retry/backoff logic specifically for ways it could loop indefinitely or effectively forever, rather than general code quality. Check specifically for: 1. Is there a hard maximum number of attempts, and is it actually enforced correctly (off-by-one errors in the loop condition count)? 2. Does the backoff delay actually increase between attempts, or could a bug make it stay constant or even reset? 3. Is the retry condition (which exceptions/error codes trigger a retry) broad enough to accidentally include a PERMANENT failure (like an authentication error) that will never succeed no matter how many times it'"'"'s retried? 4. If this runs inside a loop or a scheduled/recurring job, could a single call'"'"'s retries interact badly with the OUTER loop also retrying, multiplying the effective number of attempts far beyond what'"'"'s obvious from reading this code in isolation? For each issue found, describe the specific scenario that would trigger it and roughly how long/how many attempts it would take before someone would actually notice something was wrong. [PASTE THE RETRY/BACKOFF CODE HERE]
✅ Why This Prompt Works
- Explicitly asking about permanent-vs-transient failure classification catches one of the most common real-world causes of this bug: retry logic that correctly retries a temporary network blip but ALSO retries a permanent 401 Unauthorized or 403 Forbidden that will identically fail on every single attempt, forever.
- Asking specifically about nested/outer-loop interaction catches a subtler compounding case that’s easy to miss when reviewing retry logic in isolation – a function with its own internal retry, called from within an outer loop that also retries on failure, can produce a MUCH larger effective attempt count than either piece of code suggests on its own.
- Asking for a rough estimate of how long it would take before someone notices frames the finding in terms of actual operational impact, which helps prioritize whether a given issue is a one-line fix worth doing today or a more involved rework worth scheduling deliberately.
⚠️ Where to Draw the Line
- This review is about the LOGIC’s structural soundness, not about picking specific retry counts or delay values for a particular system – those numbers depend on context (how expensive is a retry, how long can a caller reasonably wait) that only someone with full operational knowledge of the system can decide.
- A finding here is worth verifying with an actual test that intentionally triggers the failure condition described, rather than trusting the review’s reasoning alone – retry logic bugs are exactly the kind of thing that benefit from being reproduced concretely before considering them confirmed.
Retry logic is supposed to be the safety net under a flaky system – the version worth worrying about is the one that quietly becomes the thing generating the load, not catching it.
