By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
Harbor Supply, Tuesday morning. Finance opens a ticket: customer 8841 was refunded twice for order A17. The two refund records are three seconds apart, on the same thread, with the same arguments. No alert fired. Both API calls returned success to the graph, the traces are green, and the two confirmation emails went out within the same second. This is the hard class of agent incident — not a crash, a duplicate.
The on-call engineer has the thread id from the finance ticket (thread-c91) and four evidence sources: the LangSmith trace, the checkpoint store, the structured logs and the deployment record. The job is not to guess the bug from memory. It is to reconstruct what ran, prove where the duplicate came from, fix the graph, and leave a test that fails if the same class of bug returns. Replay is how this lesson turns a fixed outage into a fixed category of outage.
The three sources are not interchangeable, and reading only one of them is how investigations go sideways. The trace shows calls; the checkpoint shows what the runtime believed; the logs and the deployment record supply the context that makes either interpretable. Line them up before forming a hypothesis.
| Source | Question it answers | What this incident showed |
|---|---|---|
| LangSmith trace | Which nodes and tools ran, in what order, and how many attempts? | write_refund ran twice: attempts 1 and 2, both refund_order(order_id="A17") |
| Checkpoint history | What did the runtime believe at each superstep, and which task was pending? | The run paused at approve, resumed, then retried write_refund; no refund_id was ever merged |
| Structured logs | What failure class, timing and keys were recorded? | First attempt: ConnectionError: response lost after commit; no idempotency key on either call |
| Deployment record | Which graph version and retry configuration were live? | RetryPolicy(max_attempts=2) had been added to the write node during an unrelated latency fix |
The trace alone cannot tell you whether the first refund committed, because the timeout happened after the commit. The checkpoint alone cannot tell you what the tool wrote. The logs supply the bridge between the two. Together they tell a consistent story, and consistency is what you need before you change a line of graph code.
Start from the symptom and walk backwards. Two refund records mean two tool invocations, so the trace should show two spans with the same tool and the same arguments. Find them, note their parent node, attempt numbers and timestamps, then ask what caused the second one: a loop, a retry, a resume, or a second thread? That distinction decides where the fix goes.
# A recorded trace for thread-c91, trimmed to the spans that matter.
TRACE = [
{"node": "model", "kind": "llm"},
{"node": "approve", "kind": "interrupt"},
{"node": "write_refund", "kind": "tool", "tool": "refund_order",
"args": {"order_id": "A17"}, "attempt": 1, "error": "response lost"},
{"node": "write_refund", "kind": "tool", "tool": "refund_order",
"args": {"order_id": "A17"}, "attempt": 2, "error": None},
]
def refund_spans(trace):
return [
span
for span in trace
if span.get("kind") == "tool" and span.get("tool") == "refund_order"
]
spans = refund_spans(TRACE)
print("refund calls:", len(spans))
print("attempts:", [span["attempt"] for span in spans])
print("same arguments:", spans[0]["args"] == spans[1]["args"])
print("nodes:", [span["node"] for span in spans])On the real trace the parent node is write_refund, and the second span is a retry attempt of the same task, not a new node. That is the difference between a routing bug and a write bug. A loop would be repaired in the router or in the handoff budget; a retry is repaired in the node's write semantics and in the policy attached to it.
The trace says the call happened; the checkpoint says what the runtime believed. Walk the thread's history and read four things: the transition into approve, the resume, the write task's attempts, and the channel values after the failure. In this incident the post-failure state held the approval and the order id but no refund_id — the retried node raised before its update merged, so the graph had no record of the first refund.
| Question | Where to look | Incident answer |
|---|---|---|
| Was the thread paused or running? | The pending next node and tasks on the snapshot | Paused at approve, then resumed |
| How many attempts did the task make? | Task attempt metadata in the trace and snapshots | Two |
| What did the node see? | Channel values at the paused snapshot | approval="approved", order A17 |
| What did the failed attempt write? | Pending writes and the task error | Nothing merged; no refund_id |
| What was deployed? | Checkpoint metadata and the deployment record | v1.4.2 with retry on the write node |
Three decisions lined up: the write was non-idempotent, a retry policy treated a post-commit timeout as transient, and the failure happened after the commit, so the retry created a second refund. If any one of those had been different, the duplicate would not have happened. Fixing only the retry leaves the tool next retry from any source; fixing only the tool leaves a retry policy aimed at a write.
f"{thread_id}:refund:{order_id}" names the intent, not the attempt, so every retry and resume derives the same key.A fix without a failing test is a hope. The test recreates the exact failure mode without a live service: a fake refund store that commits and then raises a timeout after the commit. Run it against the old code first and watch it fail with two refunds; then add the key and watch one.
class RefundStore:
"""Stand-in for the refund service: commits, then loses the response."""
def __init__(self):
self.by_key = {}
self.refunds = []
self.fail_next_after_commit = False
def refund(self, order_id, idempotency_key):
if idempotency_key in self.by_key:
return self.by_key[idempotency_key]
refund_id = f"refund-{len(self.refunds) + 1}"
self.refunds.append(order_id)
self.by_key[idempotency_key] = refund_id
if self.fail_next_after_commit:
self.fail_next_after_commit = False
raise ConnectionError("response lost after commit")
return refund_id
def write_refund_with_retry(store, order_id, key, max_attempts=2):
"""Stand-in for a graph node the runtime retries in place."""
for attempt in range(1, max_attempts + 1):
try:
return attempt, store.refund(order_id, key)
except ConnectionError:
if attempt == max_attempts:
raise
raise AssertionError("unreachable")
store = RefundStore()
store.fail_next_after_commit = True
attempts, refund_id = write_refund_with_retry(
store, "A17", "thread-c91:refund:A17"
)
print("attempts:", attempts)
print("refunds:", store.refunds)
print("same refund id:", store.by_key["thread-c91:refund:A17"] == refund_id)Three assertions make it a regression test rather than a demo: the attempt count is two, so the retry actually happened; the refund list has one item, so the duplicate is gone; and both attempts returned the same refund id, so the retry is a read of the first write rather than a second write. Keep the fake's commit-then-timeout behaviour in the test suite — that is the regression.
Replay answers a different question: with the fixed code, would this thread have ended correctly? Do not run it on the production thread against the live refund service. Fork the thread from the checkpoint before the bad call, or copy the thread id into a sandbox, point it at a stub service seeded with the same pre-incident data, replay, and compare the new trace to the incident trace.
refund_id and a complete answer is evidence that the new logic handles the old state.RetryPolicy on every write node.Key takeaways
Reconstruct before you change code: trace, checkpoint history, logs and deployment record answer different questions and together locate the duplicate write.
A duplicated side effect usually has a chain of causes — a non-idempotent write, a retry that treats a post-commit timeout as transient, and a failure after the commit; fixing one link only hides the bug.
Fix the write path with an intent-derived idempotency key, a check-before-write and a deliberate retry decision, keeping the write behind the approval gate.
Prove the fix with a regression test that reproduces commit-then-timeout and asserts one refund, two attempts and one stable refund id.
Replay a forked sandbox thread from the checkpoint, never the production thread; the real effects need compensation, and the replay is evidence, not rollback.
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.