How to Prevent Stale AI Agent Writes
Permission answers the wrong question.
An AI agent may be fully authorized to update a ticket, patch a file, change a deployment record, or revise a customer profile. That does not mean the update is still correct when it reaches the system. Between observation and execution, another user, service, or agent may have changed the same state.
I treat every consequential agent write as a conditional operation: apply this mutation only if the world still matches the assumptions under which it was proposed.
Authorization and validity are different contracts
Authorization says who may act and within which scope. A precondition says when this particular action remains valid.
Consider an agent that reads incident INC-42 with status investigating, prepares a resolution summary, and then closes it. While the model is drafting, an engineer changes the status to escalated and adds evidence that contradicts the summary. The agent still has permission to close incidents. Its action is authorized—and stale.
A plain tool call hides that distinction:
{
"tool": "update_incident",
"incident_id": "INC-42",
"status": "closed",
"summary": "Transient network failure"
}
A preconditioned write makes it explicit:
{
"target": "incident/INC-42",
"mutation": {
"status": "closed",
"summary": "Transient network failure"
},
"preconditions": {
"version": "v184",
"status": "investigating",
"evidence_set_hash": "sha256:7f2…"
},
"on_conflict": "stop_and_replan"
}
The second envelope does not make the model smarter. It prevents an old decision from silently winning over newer reality.
The write needs four fields
I use a small mutation contract rather than another generic confidence score.
| Field | Question it answers |
|---|---|
observed_version |
Which state did the agent actually read? |
predicate |
Which facts must remain true for the mutation to make sense? |
write_scope |
Which fields or resources may change? |
conflict_policy |
What happens when any precondition fails? |
The version catches any intervening update. The predicate can be narrower when unrelated updates should not block useful work. The write scope prevents a convenient full-object replacement from erasing fields the agent never intended to touch. The conflict policy keeps the retry loop from converting a semantic conflict into persistence.
That last point matters. A 412 Precondition Failed or storage-level compare-and-swap failure is not a transient transport error. Retrying the same payload against the new version merely teaches the runtime to force stale intent through.
Compare-and-swap is the execution boundary
This pattern is old distributed-systems engineering, which is exactly why I trust it more than an agent-specific workaround.
HTTP exposes conditional requests through validators such as ETag and If-Match. A server can reject a mutation when the selected representation no longer matches. Kubernetes uses resourceVersion for concurrency control and documents 409 Conflict when an update is based on an outdated version. Databases expose equivalent ideas through optimistic locking or compare-and-swap.
The agent runtime should compile its mutation envelope into whichever primitive the target supports:
observe state + version
↓
propose bounded mutation
↓
authorize exact scope
↓
compare-and-swap(version, predicate, patch)
├── committed → record receipt
└── conflict → invalidate plan, re-observe, replan
If the target has no native conditional-write primitive, the tool adapter must not pretend the guarantee exists. It can serialize access, place the mutation behind a transactional service, or mark the operation as conflict-unsafe. That limitation belongs in the tool contract before execution.
Do not hash the whole world
A global version is safe but often too coarse. An agent changing a ticket label should not necessarily fail because an unrelated view counter changed.
The better boundary is the smallest set of facts that makes the decision true. For a label update, that may be the current label set and policy version. For a deployment, it may be the artifact digest, environment generation, and approval receipt. For a document patch, it may be a base commit plus hashes of the edited regions.
This is where preconditions differ from the freshness contract. Freshness limits how old an observation may be. Preconditions prove that the relevant state has not changed before commit. A recent observation can still become stale one millisecond later.
The same distinction separates this mechanism from stable effect identity. Effect IDs prevent one intent from executing twice. Preconditions prevent one intent from executing against the wrong state. Reliable agents need both.
Conflict is a normal result
I want tool outcomes to distinguish at least four cases:
committed: all preconditions held and the mutation was applied;conflict: the target changed and no mutation was applied;rejected: policy or validation denied the proposed write;unknown: the caller cannot yet prove whether the effect committed.
Only conflict authorizes re-observation and replanning. unknown requires reconciliation before another write, as described in the unknown outcome state. Collapsing them into failed is how runtimes create duplicate or stale effects while believing they are recovering.
A useful commit receipt records the observed version, predicates evaluated, committed version, changed fields, and target-native transaction or revision identifier. The receipt is evidence of what happened; it is not a claim that the new state is globally correct.
Boundaries
Preconditioned writes do not solve bad observations, incorrect policies, malicious tools, or two resources that must change atomically across systems. They also cannot recover semantics that the target API does not expose. If an API accepts only blind replacement, the adapter must add a guarded boundary or admit that lost updates remain possible.
Nor should every operation carry an elaborate predicate language. Low-consequence append-only notes may need only an idempotency key. The contract should grow with the cost of overwriting newer state.
But for consequential mutation, permission alone is not enough. I do not want an agent to ask only, “May I write?” I want the runtime to prove, at the commit boundary, “Is this still the state I was authorized to change?”
That is the difference between granting access and preserving reality.