Darkmind / Issue 022

Make the Write Prove What You Read

Carry a record’s version from an agent’s read into its write, so the system refuses to overwrite work that changed while it was deciding.

Oct 29, 20264 min readAgent reliability

An AI agent can make a correct decision from a record that is no longer current. It reads a support ticket, decides to change the priority, perhaps pauses for an approval, and then sends an update. In the gap, a teammate may have reassigned the ticket, added an important note, or closed it. If the update blindly overwrites the record, the agent has not merely made a stale recommendation—it has erased a newer state.

The practical move is to make every consequential write carry a version witness from the read that justified it. Read the target and capture its server-issued version, revision, or ETag. Bind that exact value to the proposal. At write time, require the service to apply the change only if the target still has that version. If it changed, stop, re-read, and make a new proposal rather than trying to merge the old decision into an unknown current state.

HTTP defines this pattern with the If-Match header. The header makes a state-changing request conditional on the server having a current entity tag that matches the one the client supplied; the specification calls out preventing accidental overwrites and the lost-update problem.[1] Azure Storage documents the same operational flow: retrieve an object and its ETag, send that ETag on an If-Match write, and treat a mismatched current ETag as HTTP 412, Precondition Failed.[2] The useful AI-system rule is broader than either API: an action based on a read must prove that the read is still the one it is acting on.

Keep the decision attached to its state

An operation ID protects a retry from producing a duplicate effect. A version witness protects a valid-looking write from applying to the wrong revision. Use both when an agent makes a consequential change.

Store the witness in the proposed-action record beside the target ID and exact patch. Use a value the destination service can check—an HTTP ETag, row version, revision number, or another opaque concurrency token. The agent may carry it forward, but should never guess, edit, or synthesize it. This matters whenever approval, queueing, or another tool call creates a gap between read and write.

Copy this read-to-write contract

Put this contract at the boundary between a retrieval or read tool and any tool that can update, send, publish, or change a record.

1. READ THE TARGET
   target_id: [stable record ID]
   state_version: [ETag | revision | row_version]
   observed_at: [UTC timestamp]
   allowed_fields: [fields the workflow may change]
   evidence: [bounded facts that justify the proposed change]

2. CREATE A PROPOSAL
   proposal_id: [stable ID]
   target_id: [same stable record ID]
   expected_state_version: [exact value from the read]
   patch: [field-by-field intended changes]
   basis: [why this patch follows from the observed record]
   status: pending_approval | approved | rejected | stale

3. EXECUTE ONLY THE APPROVED PROPOSAL
   - Revalidate target ID, field allowlist, and patch shape.
   - Send expected_state_version in the provider's conditional-write field.
   - Reuse the original operation_id only for a retry of this exact write.

4. HANDLE THE RESULT
   - success: store the returned new version and result receipt.
   - precondition_failed / conflict: mark proposal stale; do not overwrite.
   - timeout: look up the operation outcome before retrying.
   - unsupported conditional write: stop or use a service-owned compare-and-swap
     endpoint; do not silently fall back to last-writer-wins.

5. ON A STALE PROPOSAL
   - Re-read the named target.
   - Show the relevant change or conflict to a reviewer when needed.
   - Create a new proposal with a new expected_state_version.

The expected_state_version is a guardrail, not a field the model may negotiate. If a target changes before execution, return a bounded conflict receipt and require a fresh read.

Let the service reject the stale write

Do not implement this only as an instruction that says, “check whether anything changed.” A second read followed by an unconditional write leaves a race between the check and the update. The check must happen at the same boundary as the write, where the service owns the current state.

With HTTP, send an ETag in If-Match; the origin server evaluates that precondition before performing the method.[1] Azure’s example makes the outcome concrete: when the stored ETag differs from the ETag supplied in If-Match, the service returns 412 and the client fetches the updated content and properties again.[2] Other systems may call the primitive compare-and-swap, a row-version condition, or an update_if_revision method. The names differ; the requirement does not.

Keep the conflict result small and actionable. Return the target ID, the submitted expected version, the current version or a safe reference if permitted, and next_safe_action: reread_and_repropose. Do not let the model resolve a conflict by replaying its old rationale over the new record, especially for permissions, billing, publication, assignments, or customer-facing messages.

Failure mode: treating a version match as approval

A matching version says only that the object did not change by the service’s token. It does not prove the agent chose the right target, had enough evidence, or is authorized. Some providers expose no conditional-write primitive at all.

Use version witnesses alongside target validation, field allowlists, approval, and idempotent execution. Make conflicts visible; do not add a “force update” escape hatch.

The habit to keep

when an agent changes the world because of what it read, make the write carry the proof of that read. If the state has moved on, let the system refuse the stale action and start the decision again from current evidence.

Sources

  1. IETF, “HTTP Semantics”
  2. Microsoft Learn, “Manage concurrency in Blob Storage”