How to Resume a LangGraph Approval After a Worker Restart

AI Agents

If a worker restarts while a LangGraph workflow is waiting for human approval, resume the saved thread instead of starting a new run. This guide is for developers using LangGraph’s Python Graph API; it shows how to preserve the checkpoint, locate the pending approval, and continue with a reviewer’s decision. The examples follow the current LangGraph Python documentation.

Prerequisites

  • Software: A LangGraph Python application with an approval node that calls interrupt(), plus a persistent checkpointer such as PostgreSQL for production. The process-local InMemorySaver is suitable for examples, but its checkpoints disappear when the process stops.
  • Identifiers: The original, stable thread_id must be stored by your application alongside the approval request.
  • Time: About 20–40 minutes, depending on whether persistent checkpoint storage is already configured.
  • Difficulty: Intermediate.

A LangGraph checkpointer saves graph state as thread-scoped checkpoints. An interrupt pauses execution and surfaces its payload to the caller. The recovery key is the same thread_id, used with the same checkpoint store. A new ID points to a different thread and cannot recover the pending approval. See LangChain’s persistence guide and interrupt guide.

Step 1: Confirm the approval is backed by a persistent checkpointer

Compile the graph with a checkpointer and make sure production uses durable storage that survives worker replacement. For example, use LangGraph’s PostgreSQL checkpointer rather than an in-memory saver for a workflow expected to resume after a process restart. Configure the checkpointer once per application lifecycle and ensure restarted workers connect to the same database and checkpoint tables.

Keep the thread ID stable across the pause and recovery. Your application should persist it with the approval record, such as approval-7421. Do not generate a fresh thread ID in the worker startup or resume handler.

Step 2: Make approval-node work safe to repeat

When LangGraph resumes an interrupt, it restarts the node containing interrupt() from the beginning. Any code before that call runs again. Put the interrupt before side effects, such as sending a notification or executing a write tool, or make those operations idempotent so repeating them has no duplicate effect.

from langgraph.types import interrupt

def approval_node(state):
    decision = interrupt({
        "action": "Approve database update?",
        "request_id": state["request_id"],
    })
    return {"approval_decision": decision}

The interrupt payload must be JSON serializable. This example returns a small object the application can show to a reviewer; it does not execute the write before approval.

Step 3: Record the thread ID when the workflow pauses

Start the graph with a stable thread ID in the configurable section of the runtime config. When the graph returns an interrupt, save the ID and approval context in your durable application database. This lets a replacement worker associate the reviewer’s response with the correct graph thread.

config = {"configurable": {"thread_id": "approval-7421"}}
result = graph.invoke({"request_id": "req-7421"}, config)

pending = result.get("__interrupt__", ())
if pending:
    save_pending_approval(
        thread_id="approval-7421",
        request_id="req-7421",
        interrupt_value=pending[0].value,
    )

The invocation’s __interrupt__ field indicates that execution paused and includes the value passed to interrupt(). Store enough application data to route the decision, but do not treat an approval payload as proof that the requested operation already ran.

Step 4: After restart, restore the graph and find the pending thread

Start the replacement worker with the same graph definition and the same persistent checkpointer configuration. Load the pending approval record from your application database, then reuse its original thread ID. If needed, inspect the checkpoint state with the checkpointer’s supported state-reading API before continuing; this helps distinguish a pending interrupt from a thread that already completed.

Do not rebuild the graph with a new in-memory checkpointer and expect it to find old state. The checkpoint store must be the one that received the interrupt checkpoint. Do not invoke the original initial input again as if it were a new conversation; that can start new work instead of resolving the saved approval.

Step 5: Resume with the reviewer’s decision

Pass a Command(resume=...) to the graph using the same config and thread ID. The resume value becomes the return value of interrupt() inside the approval node. Validate the reviewer’s response in your application and, where appropriate, define a typed response schema for the interrupt.

from langgraph.types import Command

config = {"configurable": {"thread_id": "approval-7421"}}
result = graph.invoke(
    Command(resume={"approved": True, "reviewer": "user-18"}),
    config,
)

# Inspect result or subsequent state to confirm the graph progressed.

For a rejection, send an explicit negative decision and route it to a safe stop or review path in your graph. Treat the approval decision and execution of the protected action as separate events: make the action idempotent, and record its outcome so retries do not accidentally apply it twice.

Troubleshooting

The resumed run starts with empty state

Check that the replacement worker uses the same durable checkpointer database and that the config contains the exact original thread_id. A different ID selects a different thread. If the previous deployment used InMemorySaver or MemorySaver, its state was lost when that process ended; switch to a persistent checkpointer for future approvals.

The interrupt appears again instead of accepting the decision

Confirm that the input is Command(resume=decision), not a plain dictionary or Command(update=...), and that it is invoked with the same thread config. Also inspect the node: because it restarts from its beginning, earlier logic may reach the interrupt again. Keep that logic deterministic and avoid changing the interrupt ordering between deployments while approvals are pending.

A notification or tool action ran twice

Review code before interrupt() and make side effects idempotent. Use an application-level operation key, such as the request ID, and have the receiving system reject duplicate execution where possible. Persist the decision and action result so a retry can determine whether the protected operation already completed.

FAQ

Can I resume a LangGraph approval if the worker process has stopped?

Yes, if the interrupt checkpoint is in durable storage and the restarted worker uses that same checkpointer and thread ID. In-memory checkpoint data does not survive a process restart.

Does resuming continue at the exact line after interrupt()?

The resume value is returned by the interrupt call, but LangGraph reruns the containing node from its beginning. Code before the interrupt may run again, so keep it free of unsafe side effects or make those effects idempotent.

Should I use a new thread ID for a retry?

No, not when you mean to continue the same paused approval. Use the original thread ID to load its checkpoint. A new ID creates a separate thread with separate state.

Leave a Comment