🤖 The Prompt That Checks Whether Retrying Is Actually Safe
A retry policy wrapped around a network call is a reasonable default for handling transient failures, but it silently assumes the operation being retried is idempotent – safe to run more than once with the same net effect as running it once. A payment charge, an email send, or an insert without a uniqueness constraint retried after a timeout (where the first attempt may well have actually succeeded server-side despite the client never seeing the response) can duplicate the exact side effect the retry was only ever meant to recover from, not repeat.
🔎 The Problem
I'm going to paste code that wraps a network call (or several calls) in retry logic - a retry library, a manual loop, or a framework's built-in resilience policy. Please go through it and specifically identify: 1. Whether the underlying operation being retried is genuinely safe to execute more than once with the same effective outcome (a pure read, or a write using a client-generated idempotency key / unique constraint the server enforces), versus one where a duplicate execution would create a real duplicate effect (a charge, an email, an insert with no uniqueness guard, a non-idempotent external API call). 2. Specifically whether the retry can be triggered by a TIMEOUT where the original request may have already succeeded server-side before the response was lost - this is the single most dangerous case, since the client has no actual confirmation the first attempt failed at all, only that it never heard back. 3. Whether an idempotency key, request ID, or equivalent deduplication mechanism is actually being sent to the server (and whether the server referenced in this code is even known to honor one), rather than assumed to exist without any concrete evidence in the code. 4. Whether retries are applied uniformly to every HTTP method and operation in this code, without distinguishing GET/PUT-style safe retries from POST-style ones that need the idempotency check from point 1 before they're retried at all. 5. For each risky retry found, state plainly what duplicate side effect the retry could realistically cause in production, and what idempotency mechanism would need to exist before it's safe to keep retrying that specific call. Code: [paste the retry logic and the calls it wraps here]
✅ Fix: Why This Prompt Works
- Separating ‘is this call idempotent’ from ‘does the retry logic work correctly’ catches the actual root risk – a perfectly well-implemented, bug-free retry loop is still dangerous if it’s wrapped around an operation that was never safe to repeat, and a surface read of the retry code alone has no way to know that without being asked specifically.
- Flagging the timeout case by name targets the single most common real-world trigger for this exact bug – a timeout is ambiguous by definition, since the client genuinely cannot tell whether the server received and processed the request before the response was lost, which is precisely the condition that makes an automatic retry risky rather than merely cautious.
- Requiring a concrete ‘what duplicate effect would this cause’ statement for every finding turns an abstract idempotency concern into something that’s immediately obvious why it matters – a double charge or a duplicate email are outcomes anyone reviewing the findings can recognize as worth fixing without needing a lecture on distributed systems theory first.
🚨 Worth Keeping in Mind
- This can only evaluate idempotency based on what the code itself reveals – if the server side actually does deduplicate using a header this client code never sends, the finding will still (correctly) flag the client as not proving safety, even if the full system happens to be safe for other reasons invisible to this review.
- Adding true idempotency (keys, unique constraints, dedup windows) is frequently a larger change than the retry logic itself and may need server-side coordination – treat findings here as a prioritized list of real risk, not something to patch by simply deleting the retry logic, which trades a duplicate-effect risk for a much more mundane availability one.
Retry logic doesn’t make a failure disappear – it makes the failure happen again, and if the operation wasn’t safe to run twice in the first place, a well-intentioned retry is just a second, automatic copy of the exact problem it was supposed to fix.
