Protect Human Edits: Conditional Saves for AI-Assisted Listing Drafts

Protect Human Edits: Conditional Saves for AI-Assisted Listing Drafts

●6 ●74 ●135
calendar_today • schedule5 min read

Original AI-generated concept illustration. Fictional interfaces and property details, not an actual product screenshot.

Imagine a fictional property-listing editor used by two colleagues. Mira and Dev open the same draft. Mira corrects “two bedrooms” to “three bedrooms” after checking the property details, advancing revision 7 to revision 8. Dev asks an AI assistant to improve the description, reviews its wording, and clicks Save.

Dev’s browser still holds the old bedroom count. If the server accepts the entire draft unconditionally, a polished description can quietly erase Mira’s correction.

The useful question at save time is: Is the version this draft was based on still current? A conditional save makes that question part of the server’s write operation, rather than a warning the interface hopes everyone notices.

Keep the baseline with the draft

When the editor loads a listing, retain three things together: the saved content, its ETag, and a separate working copy. Start AI generation from that captured baseline. Do not fetch a newer tag later and attach it to output generated from older content.

A server might return this illustrative header excerpt, not a complete HTTP message:

ETag: "listing-42-r7"

The corresponding save includes:

If-Match: "listing-42-r7"

If-Match uses strong comparison against the selected representation. If the condition is false, the server must not perform the requested change; the usual response is 412 Precondition Failed. RFC 9110, section 13.1.1

Clients should treat tags as opaque values, preserving their quotes. A weak tag such as W/"listing-42-r7" never satisfies this comparison. Removing W/ does not turn it into a trustworthy strong validator. Also, If-Match: * tests existence, not whether the editor has the latest revision. MDN’s If-Match reference

For this proposed design, use one stable JSON representation for editing. Issue a new revision whenever its saved representation changes, including changes made by imports or background jobs. If serialization or representation variants can change independently, account for them in validator generation too. A revision number is useful only when the server maintains that invariant.

Make comparison and writing one operation

A separate “check version” request cannot protect the later save. Another writer can commit in the gap. Even checking inside the save handler is insufficient if the database permits a competing update between comparison and persistence.

Here is untested, framework-neutral pseudocode, not a deployable handler. This endpoint’s contract requires an explicit revision-tag list rather than a wildcard; its parser enforces that contract and rejects malformed input. Weak tags remain weak and cannot match.

save_listing(request):
    authorize_and_validate_request(request)
    if request.IfMatch is missing:
        return 428 with retry_instructions, CacheControl="no-store"
    candidates = parse_revision_tag_list(request.IfMatch)

    begin_transaction()
    try:
        listing = select_listing_for_update(request.listing_id)
        if listing is absent:
            rollback()
            return 404

        current = strong_etag_for_edit_representation(listing)
        if not any_strong_match(candidates, current):
            rollback()
            return 412

        replace_saved_draft(listing, request.draft)
        advance_representation_revision(listing)
        persist(listing)
        saved = snapshot_edit_representation(listing)
        commit()
    catch error:
        rollback_if_active()
        raise error

    return 200 with body=saved  # no response validator shown

The lock must cover reading the current version, comparing it, and writing the replacement. PostgreSQL row locks normally remain held until transaction end, providing one possible building block. PostgreSQL row-level locking documentation

Every writer must preserve the same versioning rules. Keep model generation and human review outside the transaction; a database lock should not wait for someone to finish editing.

The 428 response is an optional API policy, not a universal requirement for every server. It means this server requires a conditional request. Explain how to fetch a baseline and resubmit; responses with this status must not be cached. RFC 6585, section 3

AI-generated concept illustration of a person using a laptop: a stale two-bedroom draft based on revision seven conflicts with the saved three-bedroom revision eight, alongside atomic version-check outcomes.

Original AI-generated concept illustration with fictional people, interface and property details. An atomic version check protects the newer edit; the article explains the already-applied exception for a lost response.

Make a conflict recoverable

When Dev receives 412, leave the working copy intact. Fetch the latest listing into a separate buffer and present a three-way comparison:

  • Base: the content Dev originally loaded.
  • Mine: Dev’s reviewed AI-assisted draft.
  • Current: the latest saved content, including Mira’s correction.

Compare each side against the base. Distinct field changes may be straightforward to combine, but rewritten paragraphs can overlap semantically even when their text differs. Highlight the bedroom discrepancy for review instead of asking another model to decide which factual claim wins.

After reconciliation, associate the reviewed result with the newly fetched baseline and its tag. Save conditionally again. If another edit arrives during review, repeat the comparison without discarding anyone’s work. Avoid an automatic “retry with latest tag” button: it would authorize the stale replacement without resolving the conflict.

AI-generated concept illustration of two collaborators reviewing three laptop panels: base revision seven and the AI draft show two bedrooms, while current revision eight shows three; the working draft is retained for explicit review.

Original AI-generated concept illustration. Fictional collaborators compare the base, working draft and current saved version; not an actual product screenshot.

Treat a missing response as uncertainty

Suppose Dev’s save commits, but its response disappears. Retrying with the original tag can produce 412 because the first save advanced the revision. That does not prove the first attempt failed.

HTTP permits a success response when the server can determine that the requested change was already applied. The simpler handler above deliberately does not implement that optional recovery path. RFC 9110, section 13.1.1

Retain the draft and fetch current state before deciding what happened. If duplicate-operation recognition is needed, design a durable operation record and its retention rules explicitly; do not guess from a timeout.

Six tests before shipping

  1. Ordinary save: a current tag succeeds, and a subsequent fetch reflects the saved draft and updated validator.
  2. Stale editor: Mira saves first; Dev’s stale request gets 412 without overwriting her correction.
  3. Concurrent saves: release two changed drafts together using the same tag; only one replacement commits.
  4. Validator contract: missing tags receive the documented 428; weak tags cannot match; wildcards cannot bypass revision protection.
  5. Conflict recovery: preserve the working copy, compare all three versions, and reject another stale reconciliation if a third change intervenes.
  6. Lost response: commit a save, drop its response, and retry. Verify that the client reconciles uncertainty rather than claiming the original save failed.

AI-assisted editing can make drafting faster. Conditional saves keep that speed from silently replacing a colleague’s more recent work.

Want more #ai & #software-engineering deep dives?

Join 6,095+ developers sharing real benchmarks, code breakdowns, and projects. Free forever.

Part 6 of 9 in Articles

More Posts

The Zero-Net-Loss Fleet & The Mercenary Squad: A Live AI Economy

DEVPlank - Aug 4

Local-First: The Browser as the Vault

Pocket Portfolio - Apr 20

Merancang Backend Bisnis ISP: API Pelanggan, Paket Internet, Invoice, dan Tiket Support

Masbadar - Mar 13

Should an AI Listing Draft Be Allowed to Overwrite Newer Agent Edits?

WAQAS AHMAD - Oct 20

The Esoteric Realms of Code

nevmenandr - Nov 14
chevron_left
5.2k Points • 215 Badges
Faisal Town Lahore B Block • dotera.co
60Posts
136Comments
42Connections
Waqas Ahmad is a Content Creator and Software Engineer passionate about building brands through cont... Show more

Related Jobs

Commenters (This Week)

40 comments
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!