Why a completed answer may already be stale

Fictional example: a workshop operator asks AI to draft confirmation of an order to reupholster four chairs. During generation, the customer increases the quantity to six. The operator updates the record and starts another attempt. The second answer arrives first, then the first replaces it with confirmation of four chairs.

Both answers may accurately reflect their respective inputs. The error occurs when applying the result: the application accepts the last message received, although the user is now working with different data. Checking facts within the answer will miss the problem if the reviewer accidentally uses the old order record.

For an editor with one AI draft field, we propose this policy: only the active attempt associated with the current source revision may update it. Any relevant edit immediately removes that permission from the previous attempt, even before the user requests another generation.

What to associate with each attempt

Before sending a request, create an internal attempt record. Store the order identifier, source revision, unique attempt identifier, and revision of the draft intended for replacement. The application maintains these values: asking the model to return the correct administrative values is insufficient for this check.

Advance the source revision whenever quantities, deadlines, conditions, or other information affecting the answer changes. Changing six chairs back to four also creates a new revision. Matching an earlier text state does not restore an old attempt’s permission to write its result.

A separate attempt identifier also matters when the source stays unchanged: the operator may request different wording. Under the proposed policy, that makes the previous attempt inactive. The destination draft revision protects manual editing: if someone changes the text while waiting, automatic replacement must be rejected.

Where to check permission to apply a result

Before displaying a result, compare its internal record with the current order, source revision, and active attempt. Also check the draft revision before replacing text. Disable automatic application while source edits remain unsaved: the server may not yet know about the operator’s local changes.

Saving on the server requires the same check against its current data. Microsoft recommends performing the version comparison and write as one atomic operation in the data store. Otherwise, another process can change the document between a separate check and save, allowing a stale write through.

If your document API supports conditional updates, ETag and If-Match are an option. MDN describes rejection with response 412 when the condition does not match. This is an application mechanism you must implement and test; adding the header to an arbitrary AI API does not establish protection.

How to handle cancellation, errors, and partial answers

MDN states that AbortController can interrupt fetch, response body consumption, and streams. Use cancellation when a result is no longer needed. Keep the freshness check as well: cancellation cannot restore text already replaced and does not itself confirm that computation on the server has stopped.

Apply the same policy to error messages and loading indicators. For example, the new attempt for six chairs is still running when the old attempt fails. That failure must not dismiss the new attempt’s loading indicator or replace its state with a general failure message.

If an answer arrives in parts, associate each part with its attempt and check eligibility before adding it to the screen. Stop extending the old draft after the source changes. If the new attempt fails, show that explicitly, without automatically restoring an answer based on previous data.

How to test protection without generating answers

Prepare two explicitly fictional answers: confirmation of four chairs and confirmation of six. In a test environment, replace the model connection with a controllable source of these prepared responses. It should let you deliver success, failure, and partial answers separately in your chosen order. No paid model calls are required.

First deliver the new answer, followed by the old one. Next test a source edit without another request, two attempts using identical data, and changes from four chairs to six and back again. Separately, edit the draft manually while waiting and switch to another order.

For each scenario, record the expected text, status, and stored revision in advance. Compare these with the actual screen and storage state. Add a late failure from the old attempt and its completion after cancellation. Record rejection reasons to distinguish intentional protection from an accidentally lost answer.

How to accept the result and define its limits

For this example, the acceptance criterion is that no tested event order makes the old four-chair answer current after the order changes to six. Manual edits remain intact, and old failures or completion events do not alter the new attempt’s state. Check both the screen and the reopened saved document.

The active-attempt policy suits one replaceable draft. If users intentionally request several alternatives, give each its own destination and identifier. Results for independent orders must not cancel one another either. The product workflow determines eligibility, so document beforehand which changes make an answer stale.

This protocol checks whether a result belongs to the application’s current state. Wording quality and factual accuracy require separate checks. The practical deliverables are an attempt record, a conditional application policy, and a scenario log. Passing selected scenarios establishes only those tested cases; repeat relevant checks after changing storage, queues, or the editor.

Sources