Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
AI

The AI Prompt That Audits Your Retry Logic for Requests That Aren’t Actually Idempotent

- 21.10.26 - ErcanOPAK

🤖 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.

— AI Power User

Related posts:

The AI Prompt That Reads a Year of Utility Bills and Flags Which Months Had an Unexplained Usage Spi...

The AI Prompt That Reads a Year of Utility Bills and Flags Which Months Had an Unexplained Usage Spi...

Turn Any Codebase Into a Performance Map

Turn Any Codebase Into a Performance Map

The AI Prompt That Turns a Failed CI Pipeline Log Into a Plain-English Explanation of What Actually ...

The AI Prompt That Turns a Failed CI Pipeline Log Into a Plain-English Explanation of What Actually ...

Views: 5

Post navigation

SQL Server: Fix a Columnstore Index Silently Falling Back to a Full Scan Because a Predicate Wraps the Column in a Function
Visual Studio: Fix the Diagnostic Tools Window Silently Showing Stale Memory Graphs Because the Debugger Never Switched Out of Managed-Only Mode

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (981)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (653)
  • Add Constraint to SQL Table to ensure email contains @ (609)
  • Average of all values in a column that are not zero in SQL (570)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (547)
  • Find numbers with more than two decimal places in SQL (475)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit
  • SQL Server: Fix ROW_NUMBER Ties Reordering Between Identical Runs
  • C#: Fix an Enum HasFlag Returning True for the Zero Value
  • WordPress: Fix Featured Images Vanishing After a CDN Migration
  • Photoshop: Fix Content-Aware Fill Smearing a Repeating Pattern
  • Asp.Net Core: Fix Antiforgery Tokens Rejected Behind a Reverse Proxy

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (981)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com