By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
The approval landed, the graph resumed, and the refund node called the payments vendor. The call timed out. A retry policy fired, the node ran again, and the vendor — which had already committed the first charge before its response was lost — received a second one. Nothing in the trace looks wrong: one node, one retry, two committed credits. This is the failure the applied module exists to prevent, because a refund graph moves money and money cannot be un-moved by editing state.
The same hazard arrives through every door a graph has. A retry re-runs a node. An interrupt() resume re-runs the interrupted node from its first statement. A time-travel replay re-runs every node after a fork. A queue can redeliver the same resume command. Two workers can pick up the same thread if the coordination is wrong. The runtime is deliberately at-least-once in execution; only the effect layer can turn that into at-most-once in the real world.
"Exactly-once effects" is not a runtime setting. It is a composition: the runtime may run the node again, and the node's write is keyed so the second run observes the first. That is why the design question is not "how do I stop the retry" — retries are correct and necessary — but "what makes this node safe to run twice". A node that only writes state is naturally safe. A node that calls a vendor is safe only if the vendor write carries an idempotency key or is recorded in a ledger the node reads first.
| Duplicate source | What the graph re-runs | Control |
|---|---|---|
| Retry after a timeout | The same node, after the vendor may have committed | Intent key plus ledger read-back |
| Interrupt resume | The interrupted node from its first statement | Record the intent before any effect |
| Queue redelivery | The same resume command a second time | Delivery id and command-key dedupe |
| Two approvals at once | Two workers on the same thread | A unique constraint or per-thread lease |
| Checkpoint replay or fork | Every node after the forked checkpoint | Recorded outcomes in the replay fixture |
An intent key names what the effect is for, using facts that do not change between attempts: the thread id, the action and the target. thread-c91:refund:A17 means one refund for one order on one conversation, no matter how many times the node runs. The attempt number, the wall-clock time and the current state version must stay out of the key — include any of them and the retry quietly becomes a new effect, which is the bug wearing a deduplication badge.
The ledger that stores the key is the source of truth for effects, and state is a cache of what the ledger accepted. Record the intent before the vendor call so a crash mid-call is discoverable; record the outcome after it so a later retry returns the same answer. A unique constraint enforces one record per key even when two workers race past the read, which application code alone cannot guarantee.
from typing import Any
# Stand-in for a unique-key table in the payments database.
LEDGER: dict[str, dict[str, Any]] = {}
def charge_once(
ledger: dict[str, dict[str, Any]], intent_key: str, amount_cents: int
) -> dict[str, Any]:
"""One charge per intent key; a replay returns the first outcome."""
recorded = ledger.get(intent_key)
if recorded is not None:
return {**recorded, "replayed": True}
outcome = {"intent_key": intent_key, "amount_cents": amount_cents, "charged": True}
ledger[intent_key] = outcome
return {**outcome, "replayed": False}
print(charge_once(LEDGER, "thread-c91:refund:A17", 8400))
print(charge_once(LEDGER, "thread-c91:refund:A17", 8400))
print(charge_once(LEDGER, "thread-c91:refund:A17", 9999))
print("ledger entries:", len(LEDGER))The third call is the interesting one. It asks to charge 9999 against a key that already recorded 8400, and it returns 8400 with replayed: True. That is the property a retry needs: the effect does not happen again, and the caller learns what actually happened instead of what it asked for. A node that returns this record can be retried, resumed and replayed indefinitely, and the ledger still holds one charge.
Two details keep this honest. First, the key is derived in one place — a helper the node and its tests share — so a refactor cannot change it in one path and not another. Second, the returned dictionary is the same shape on the first run and on every replay, because downstream nodes and the checkpointer both diff that shape. If the replayed result looked different, a later bug report would be about formatting rather than about money.
The failure to reproduce is a commit followed by a timeout, so the test fixture must commit and then raise. A fake ledger that writes the record and raises TimeoutError exercises the exact tear: the node thinks it failed, the external system thinks it succeeded. Assert three things — one ledger entry, a replayed outcome on the second attempt, and the same amount in both results. No vendor, model or key is involved, so the test runs in every CI job.
Key takeaways
LangGraph executes a node at least once and may execute it again on retry, resume or replay, so exactly-once effects are an effect-layer property rather than a runtime promise.
Derive the intent key from facts that do not change between attempts — thread, action, target — never from the attempt number, timestamp or current state version.
Record the intent before the effect and the outcome after it; a replay then reads the recorded result instead of performing the effect a second time.
Let a unique constraint enforce dedupe, because it also covers two concurrent workers that both pass the application-level read before either writes.
Test the torn write — commit then timeout — and assert one ledger entry, a replayed outcome and an amount that matches the first attempt.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.