Durable and Asynchronous Agent Work › Duplicate delivery and fencing
Language AI HandbookAll chapters Worker A stalls past its lease. Worker B acquires a new generation. In this fixture A fails its renewal before it can invoke a new step. The state store also checks ownership at commit, since renewal alone cannot protect against an old worker that remains active.
PythonIn [26]Expand
EXECUTED.clear()
tid2 = submit("draft_report", {"topic": "split brain"})
t1 = claim_task("A")
t2 = None
# Simulate: A holds the lease, but stalls so long that B can claim.
time.sleep(LEASE_SECONDS + 0.5)
# B claims because A's lease has expired
t2 = claim_task("B")
# Now both A and B "run". A is stale: its renew_lease will fail.
a_result = run_task("A", t1)
b_result = run_task("B", t2)ConsoleOut [27]Expand
A: lost_lease B: completed real tool calls: 3 ['search', 'summarize', 'send_email']
Worker A stops when it tries to renew the old claim. Worker B can complete under the newer generation. Rejecting a stale write does not prevent an earlier external operation from taking effect.
The generation check rejects a stale writer even if the worker had earlier passed renewal. The sequence constraint protects event ordering. An external effect requires its own protection at the downstream service.
The local cache can admit a duplicate when both callers miss before either records a result, or when a crash interrupts the operation after an effect but before insertion. A remote service that enforces the logical key can narrow this window under its own contract.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!