AI chat drafts can be overwritten when a user switches between phone, web and desktop. HTTP conditional requests offer a simpler safety mechanism than broad database locks. This engineering runbook builds on the MDN guide to conditional requests and its 412 Precondition Failed reference. It covers editable unsent drafts, not sent-message ordering or transport stream recovery.
Model the editing conflict before choosing a transport
Consider an AI chat application where a user edits an unsent prompt on a laptop and later opens the same draft on a phone. The server may have version 17 while both clients hold version 16. If both upload an ordinary overwrite, the later request silently destroys the earlier edit. Streaming responses and network retries can make this harder to recognize because the application appears responsive. Define a canonical draft resource with a stable conversation ID, draft ID, revision and owner authorization. The draft is separate from already-sent messages and from the model’s long-term memory. The goal is not to prevent concurrent use; it is to prevent an unapproved last-writer-wins decision. Write a test fixture in which two clients read the same initial text, edit different lines, and submit changes in opposite orders. Record which request succeeds and whether either edit disappears.
Use strong validators for mutations
The MDN HTTP conditional-request guidance describes how an ETag and If-Match can implement optimistic locking. A GET response may include an ETag for a specific representation. When saving a draft, the client sends the validator it actually read in an If-Match header. The server accepts the update only if the current representation matches the supplied condition. A weak ETag is not appropriate for strong comparison in If-Match semantics; choose a stable strong validator derived from a revision token or the serialized representation under a documented scheme. Do not trust a validator supplied by a different user or tenant. The If-Match check and the write must be atomic with respect to the draft’s storage transaction. If a database update affects zero rows because the revision changed, return a conflict result instead of pretending the save succeeded. That invariant matters more than the choice of hash.
Distinguish 412 from transport failure
According to MDN’s reference, a failed If-Match precondition can produce HTTP 412 Precondition Failed. That is useful feedback, not a generic outage. Return a problem response with a machine-readable conflict type, current revision and a safe way to fetch the current draft; avoid leaking another account’s text in an error body. A 500 or network timeout is different: the client may not know whether its write committed. Give each logical save operation an idempotency key so a retry can consult the original outcome. Do not automatically overwrite the latest revision after receiving 412. Instead show a comparison or offer a separately named copy. A user may choose to merge the changes, but the server should then require the new current ETag. This yields a clear human recovery story, rather than a spinner that eventually erases work.
Exercise offline, reconnect and multi-tab sequences
Build a six-case test suite with a deterministic clock. Case one is a normal save. Case two uses two tabs with divergent edits. Case three retries the successful request after a timeout. Case four edits while offline, reconnects after another device has saved and checks preservation of both versions. Case five revokes the user’s session before replaying a queued mutation. Case six closes the conversation while an autosave is pending. Observe revision numbers, response codes, duplicate submissions and the exact text displayed on each client. Never use real private conversations in the test environment. The successful outcome is not merely that an HTTP request completes; the user must be able to identify which version is current, which text remains unsent, and whether the conflict was resolved intentionally.
Keep privacy and memory state outside the draft validator
AI chat clients can have text, voice transcripts, attachments and persona preferences. Treat them as different resources where their retention and synchronization semantics differ. A draft’s ETag must not become a permanent identifier for an individual’s private conversation content in analytics logs. Log a request ID, anonymized tenant key, revision transition, status and latency, but redact the draft body and secrets from tracing. An image attachment can use its own immutable object ID and separate upload integrity check. If the user deletes a draft, remove stale queued mutations on every authenticated device or reject them by comparing a tombstone revision. Do not let a previously cached voice transcript silently resurrect text that the user intentionally removed. Design authorization checks before version checks so a denied user learns nothing about another person’s latest revision.
Define acceptance criteria and operational metrics
A runbook needs pass/fail thresholds. Require zero silent lost updates across repeated concurrent-save tests, zero cross-tenant reads and a user-visible conflict recovery path. Measure save latency separately for normal writes, conditional failures and recovery fetches. An error-rate dashboard should distinguish expected 412 conflicts from 5xx server faults, and the team should track how many conflicts are successfully resolved instead of only counting retries. Check that caches forward the relevant ETag and If-Match headers, that gateways do not normalize them incorrectly, and that database revisions advance monotonically. During a staged rollout, sample high-concurrency conversations and verify the version ledger without storing the message content. A production incident checklist should include rollback of the sync feature, preservation of version history and communication that does not falsely claim lost drafts are recoverable.
The key product promise is modest: no client silently wins by overwriting text that another client changed. Sources (checked 13 November 2026): MDN Web Docs, HTTP conditional requests (living technical guide); MDN Web Docs, 412 Precondition Failed (living HTTP reference); IETF RFC 9110, HTTP Semantics (June 2022).