Avoid duplicate work after a retry

Keep action verbs and their objects together. · 213 words

Suppose an AI adds a travel weather alert, but the tool times out. Do not repeat the call yet. The first attempt may have succeeded. Assume the tool supports idempotency keys and can look up a request by its key. Prompt: 'Create one Rome museum-closure alert for May 3 with key travel-alert-rome-05-03. After a timeout, query status with that key. Never create a second alert.' The source says to deliver by email to a saved trip. A good result says 'completed' and shows one ID, AL-204. The check is one record for that key. The tool enforces uniqueness for this key even if an earlier request is still in progress. A status read by itself cannot prevent two concurrent writes.

A second example adds two blue notebooks to a shopping list. The tool says 'Saved, quantity 2,' but the network drops before the reply arrives. Say: 'Read the item by key notebook-blue-large. If it has quantity 2, report success and do not add it again.' The check is quantity 2, not 4, with one record. This prompt puts a status read before a write and supplies a stable key. For any paid or changed action, state the intended end state. After a timeout, check by key before retrying, then report the found ID.

Check your recall

After a tool times out while creating an alert, what should the AI do before retrying?

Check your answer

It should query the tool's status using the same idempotency key, compare the stored result with the intended end state, and retry only if no completed record exists. Reusing the same key helps ensure that one request cannot create duplicate alerts.

Sources and credits

Original KeyTouch lesson. Background reading · Microsoft · Generative AI for Beginners.