agent_signal

Guide

LangGraph tool retry runs twice: why a failed tool repeats a charge, and how to stop it

By Agent Signal · Published 2026-10-28 · Updated 2026-11-28

Short answer

A LangGraph node that raises has no saved result, so when RetryPolicy retries it or you resume with invoke(None, config), the whole node runs again from the top. If a tool in that node already charged a card before it failed, for example the payment went through but the reply timed out, the charge runs again. Every version we tested does this, and maintainers say it is how resume works. Fix it by sending an idempotency key built from thread_id plus the tool call id with every side effect, and by running one tool call per task so a failing sibling can't re-run a tool that already worked.

Your payment API timed out. LangGraph retried the tool, or you resumed the thread, and the customer was charged twice. This guide shows the three ways that happens and a fix you can paste in, so one tool call means one charge, however many times the node runs. Everything below was run on langgraph 1.2.15, 1.2.16 and 1.2.18 with langchain 1.4.7 (Python 3.13.5), Oct 28, 2026.

Why the tool runs twice

LangGraph saves a node's result only when the node finishes. A node that raises has nothing saved, so the next attempt starts it again from the top. That is fine for pure code. It is not fine for a tool that already moved money before it failed.

  1. You resume after a failure. The docs say that if a node fails you can "restart your graph from the last successful step" with graph.invoke(None, config) (LangGraph checkpointers). The failed node runs again. If the payment API charged the card and then the reply timed out, the tool raised, but the money had already moved. The resume charges again. A maintainer closed issue #9185 on Oct 16, 2026 with: "this is how resume works: a node that raised has no saved result, so it runs again, and side effects need an idempotency key (the tool call id works well)."
  2. RetryPolicy retries the node. A retry_policy on the tools node re-runs the whole node inside the same run (LangGraph fault tolerance). No error reaches you, and the card is charged twice. The default retry_on retries httpx timeouts and Python's ConnectionError. It does not retry Python's TimeoutError or requests timeouts, so whether you see this depends on which HTTP client your tool uses.
  3. A sibling tool fails in the same node. When one model turn asks for two tools, say charge the card and email the receipt, a hand-built StateGraph with ToolNode runs both calls inside one node. If the email fails, resume re-runs the node, and the charge runs again even though it worked. create_agent from LangChain sends each tool call as its own task. LangGraph saves the writes of tasks that finished in a step that failed elsewhere and doesn't re-run them on resume (pending writes), so there the charge ran once.

Reproduce it, then fix it

No model and no network. The model node plays the LLM, and FakePayments stands in for a payment API that commits the charge and then, once, loses the reply. Its by_key dict behaves like a provider idempotency key (Stripe's Idempotency-Key, for example).

# retry_twice.py  (pip install langgraph==1.2.18 langchain==1.4.7 httpx)
import httpx
from langchain.tools import tool, ToolRuntime
from langchain_core.messages import AIMessage, HumanMessage, ToolMessage
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.graph import StateGraph, MessagesState, START
from langgraph.prebuilt import ToolNode, tools_condition
from langgraph.types import RetryPolicy


class FakePayments:
    """Stands in for Stripe & co. It commits the charge, then (once) the reply is lost."""
    def __init__(self):
        self.charges, self.by_key, self.lose_next_reply = [], {}, True

    def charge(self, amount, idempotency_key=None):
        if idempotency_key in self.by_key:          # same key again: return the first result
            return self.by_key[idempotency_key]
        self.charges.append(amount)                 # the money moves here
        result = f"ch_{len(self.charges)}"
        if idempotency_key:
            self.by_key[idempotency_key] = result
        if self.lose_next_reply:
            self.lose_next_reply = False
            raise httpx.ReadTimeout("reply lost after the charge went through")
        return result


def build(safe, retry=None):
    api = FakePayments()

    if safe:
        @tool
        def charge_card(amount: int, runtime: ToolRuntime) -> str:
            """Charge the customer's card."""
            thread = runtime.config["configurable"]["thread_id"]
            key = f"{thread}:{runtime.tool_call_id}"       # same on every retry and resume
            return api.charge(amount, idempotency_key=key)
    else:
        @tool
        def charge_card(amount: int) -> str:
            """Charge the customer's card."""
            return api.charge(amount)

    def model(state: MessagesState):                       # plays the LLM, deterministically
        if isinstance(state["messages"][-1], ToolMessage):
            return {"messages": [AIMessage("Charged.")]}
        return {"messages": [AIMessage("", tool_calls=[
            {"name": "charge_card", "args": {"amount": 79}, "id": "call_1"}])]}

    g = StateGraph(MessagesState)
    g.add_node("model", model)
    g.add_node("tools", ToolNode([charge_card]), retry_policy=retry)
    g.add_edge(START, "model")
    g.add_conditional_edges("model", tools_condition)
    g.add_edge("tools", "model")
    return g.compile(checkpointer=InMemorySaver()), api


def run(label, safe, retry=None):
    graph, api = build(safe, retry)
    config = {"configurable": {"thread_id": "order-42"}}
    try:
        graph.invoke({"messages": [HumanMessage("charge $79")]}, config)
    except httpx.ReadTimeout:
        graph.invoke(None, config)                         # the documented way to resume
    print(f"{label:<44} charges: {api.charges}")


retry = RetryPolicy(max_attempts=3, initial_interval=0.01, jitter=False)
run("A  reply lost, then invoke(None, config)", safe=False)
run("B  reply lost, RetryPolicy on the tools node", safe=False, retry=retry)
run("C  A with an idempotency key", safe=True)
run("D  B with an idempotency key", safe=True, retry=retry)

Output, identical on 1.2.15, 1.2.16 and 1.2.18 (20 runs each):

A  reply lost, then invoke(None, config)     charges: [79, 79]
B  reply lost, RetryPolicy on the tools node charges: [79, 79]
C  A with an idempotency key                 charges: [79]
D  B with an idempotency key                 charges: [79]

The sibling case, where the charge works and the receipt email fails once:

# siblings.py  (pip install langgraph==1.2.18 langchain==1.4.7)
from langchain.agents import create_agent
from langchain.tools import tool
from langchain_core.language_models.fake_chat_models import GenericFakeChatModel
from langchain_core.messages import AIMessage, HumanMessage, ToolMessage
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.graph import StateGraph, MessagesState, START
from langgraph.prebuilt import ToolNode, tools_condition

charges, email_down = [], [True]

@tool
def charge_card(amount: int) -> str:
    """Charge the customer's card."""
    charges.append(amount)
    return f"ch_{len(charges)}"

@tool
def send_receipt(to: str) -> str:
    """Email the receipt."""
    if email_down[0]:
        email_down[0] = False
        raise ConnectionError("SMTP server unreachable")
    return "sent"

CALLS = [{"name": "charge_card", "args": {"amount": 79}, "id": "call_1"},
         {"name": "send_receipt", "args": {"to": "a@b.co"}, "id": "call_2"}]

def hand_rolled():
    def model(state: MessagesState):
        if isinstance(state["messages"][-1], ToolMessage):
            return {"messages": [AIMessage("Done.")]}
        return {"messages": [AIMessage("", tool_calls=CALLS)]}
    g = StateGraph(MessagesState)
    g.add_node("model", model)
    g.add_node("tools", ToolNode([charge_card, send_receipt]))
    g.add_edge(START, "model")
    g.add_conditional_edges("model", tools_condition)
    g.add_edge("tools", "model")
    return g.compile(checkpointer=InMemorySaver())

class FakeModel(GenericFakeChatModel):
    def bind_tools(self, tools, **kwargs):
        return self

def with_create_agent():
    model = FakeModel(messages=iter([AIMessage("", tool_calls=CALLS), AIMessage("Done.")]))
    return create_agent(model, [charge_card, send_receipt], checkpointer=InMemorySaver())

for label, make in [("StateGraph + ToolNode (one task)", hand_rolled),
                    ("create_agent (one task per tool call)", with_create_agent)]:
    charges.clear(); email_down[0] = True
    graph, config = make(), {"configurable": {"thread_id": "order-42"}}
    try:
        graph.invoke({"messages": [HumanMessage("charge $79 and email the receipt")]}, config)
    except ConnectionError:
        graph.invoke(None, config)
    print(f"{label:<40} charges: {charges}")

Output on all three versions:

StateGraph + ToolNode (one task)         charges: [79, 79]
create_agent (one task per tool call)    charges: [79]

create_agent only helps with the sibling case. When the charge tool itself is the one that fails, we saw two charges under create_agent too, and one with the idempotency key.

The fix in 3 steps

  1. Give every side effect a key that survives retries. Build it from thread_id plus the tool call id. ToolRuntime gives a tool both (runtime.tool_call_id, runtime.config). The tool call id lives in the AI message, which was saved before the tools ran, so every retry and resume of that call sees the same id. Send the key as your provider's idempotency key. Stripe keys can be up to 255 characters. On Stripe's v1 API a key may be pruned once it is 24 hours old, and the same key then creates a new request (Stripe idempotent requests). So for anything that can resume a day later, also keep your own record.
  2. Keep your own record when the provider has no keys. Insert the key into a table with a UNIQUE constraint before you act, and mark it done after. A timeout means "unknown", not "failed": if a row exists but isn't done, look the result up at the provider before you charge again. Our free side-effect ledger is that table, tested on Postgres.
  3. Run one tool call per task. Use create_agent, or route each tool call with Send, so a failing sibling can't re-run a tool that already worked. If you write nodes by hand, put each side effect in its own node, and keep RetryPolicy off nodes that move money unless the call carries a key.

FAQ

Does upgrading LangGraph fix it? No. All three causes behaved the same on 1.2.15, 1.2.16 and 1.2.18, and the maintainers closed #9185 as "how resume works". The open issue #9240 asks the docs to say plainly that durability modes don't give exactly-once side effects.

Should I turn off RetryPolicy? Not everywhere. Retries are useful for model calls and reads. For a tool that charges, emails or writes to another system, retry only if the call carries an idempotency key.

Is the tool call id the same after a resume? Yes, as long as the model node already finished, because the id is in the saved AI message. In our runs the key was order-42:call_1 on the first try and again on the retry or the resume. If the model node itself runs again, it can produce new ids, so key on the tool call that was saved, not on a fresh model answer.

Does this happen on LangGraph Cloud too? We only ran local graphs. The open issue #7417 (88 comments as of Oct 28, 2026) reports long tool calls being run again from the checkpoint on LangGraph Cloud. We cover that case, with a tested fix, in LangGraph long-running tool runs twice. The same key is what makes a second run harmless.

What we did not test

No real model, payment API, email server or production database. We used InMemorySaver in one process, not Postgres, a server deployment or a resume in a fresh process. We did not test async nodes, per-node timeout=, error_handler=, or LangGraph.js.

Get the template

Check your own agent in 2 minutes

Want to see a repeated side effect happen, then stop? Run the free 2-minute crash test. It kills a LangGraph agent right after an approved charge, resumes it, and counts how many times the charge runs, so you can check your fix before your customers do.

Free starter pack

The approval-flow starter pack

Tested human-in-the-loop approval starters for LangGraph, OpenAI Agents SDK, Vercel AI SDK and Google ADK, plus the Agent Signal newsletter. Free.

Get the Agent Signal newsletter