Skip to content

Checking your reading list…

Retry verification

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

How to Resume Agent Tasks After Service Restart: Checkpoints, Idempotency, and the Gap Between Progress and Side Effects

How to Resume Agent Tasks After Service Restart: Checkpoints, Idempotency, and the Gap Between Progress and Side Effects

This article explains how to make long-running AI Agent tasks survive process restarts by using persistent checkpoints (LangGraph + SQLite), stable task identities, and idempotency keys for external side effects like ticket creation, demonstrating the critical gap between checkpoint persistence and external system writes.

An inspection Agent finishes querying metrics and generating a diagnosis, then prepares to create a ticket — but the service restarts. The new process must decide: can it reuse the diagnosis? Will re-running the ticket-creation step produce a duplicate? These questions mark the transition from demo-grade Agents to production-grade durable execution.

Distinguish What Must Be Saved

Chat history alone is insufficient. Continuing a conversation differs from continuing a task. A task requires three categories of information: (1) context and intermediate results (which metrics were seen, what conclusion was formed), (2) execution progress (which step is next, what tool is about to be called), and (3) external business facts (whether the ticket system actually accepted the creation request). Saving only the model's final suggestion leaves the new process guessing whether the action executed and how far it got. Re-prompting the model cannot reconstruct missing execution facts.

Therefore, each inspection run needs a stable identity — a task ID — so that metrics, diagnosis, and progress all attach to the same record. Any Worker picking up the task reads the same run log.

Checkpoints Capture Progress

A checkpoint is a committed progress record. After each relevant step completes (query metrics → save metrics; generate diagnosis → save diagnosis), the framework has a recoverable snapshot. LangGraph's checkpointer stores both graph state and scheduling information: the current result and the next node to execute (e.g., "diagnosis done, next create ticket").

Checkpoints do not serialize the entire Python process — call stacks, open connections, and instruction pointers are not transferred. The new Worker receives a recoverable task state and re-enters at the framework-scheduled position.

Storage matters: in-memory checkpointers vanish on exit. The article uses file-based SQLite for local verification; production chooses backends per multi-Worker access, concurrency, and ops requirements. Persistence timing affects recovery boundaries. LangGraph's synchronous durability mode waits for the checkpoint write before starting the next step, adding storage latency but guaranteeing the prior progress is committed when the next step begins. The author notes this observation applies to the simple serial graph tested; other frameworks, parallel graphs, or async modes may differ.

How a New Process Takes Over

Checkpoints record state but do not self-start Workers or discover interrupted tasks. After restart, a recovery job, scheduler, or explicit retry entry initiates continuation, supplying the original task identity so the framework locates the latest valid checkpoint.

In LangGraph, thread_id identifies the execution thread (not an OS thread). To resume an unfinished task, reuse the original thread_id and invoke with None as input — not the original input as a new task. The key calls:

config = {
  "configurable": {
    "thread_id": "inspection:INC-20261123-001"
  }
}
with SqliteSaver.from_conn_string("checkpoints.sqlite") as saver:
  graph = builder.compile(checkpointer=saver)
  result = graph.invoke(None, config, durability="sync")

No historical checkpoint_id needs to be specified; replaying from a past checkpoint is a separate operation, not failure continuation.

If the diagnosis node completed and its result was saved, the new process reuses that diagnosis and proceeds to ticket creation. However, any node still in progress may re-execute. If a node bundles model analysis, ticket creation, and notification but only returns at the end, the re-execution scope becomes large. Node or durable-task boundaries should align with individually recordable work units, not entire business flows stuffed into one function.

The Ticket May Already Exist

The critical failure window sits between the external system accepting the write and the checkpoint recording it. Sequence: Agent submits ticket request → ticket system creates ticket, returns ID → node prepares to write ID into state → framework submits checkpoint. If the process dies between the ticket creation and the checkpoint commit, the checkpoint still shows the ticket step as incomplete. On recovery, the node re-runs. If the ticket API treats every call as a new creation, a duplicate ticket appears.

This window cannot be closed by saving more chat logs. The two writes belong to different commit boundaries: one in the ticket system, one in the checkpoint store. The framework knows what it recorded; it cannot divine the external system's final outcome.

Network failures sharpen the problem: the request arrived, but the client never received a response. The result is unknown — cannot be assumed failed, cannot be blindly retried assuming single creation.

Operations that mutate external systems are side effects. Framework-provided durable tasks can record results individually, narrowing replay scope and reusing recorded results. Yet at the instant the external write completes but the call result is not yet persisted, the business system must still handle duplicate requests.

Thus, recoverable execution and business-action deduplication must be designed together. The former prevents progress loss; the latter prevents re-doing the same thing.

Retries Must Recognize the Same Operation

Assign a stable operation key to the ticket-creation action. The key can combine alert ID and action type, plus a fixed operation round if needed. As long as it's the same creation retry, the key stays constant. It must be saved before the side effect executes, or be stably reconstructible from persisted business identifiers.

Do not let the model generate a random key each time, nor generate a new UUID per retry. That makes the ticket system see distinct requests, defeating deduplication.

The stable key must take effect at the actual write point. The article's local ticket system stores operation key, request parameter digest, and ticket ID in the same database, performing check-and-create in a single transaction. A database unique constraint on the operation key blocks duplicate records.

First call creates ticket and returns ID; retry with same key and parameters finds the existing record and returns the original ID. The Agent writes that ID back into state and continues.

An overlooked detail: the same key must not sometimes mean "create database-alert ticket" and other times "create disk-alert ticket." Key parameters must be validated for consistency. Same key with different parameters should explicitly reject or enter conflict handling, not silently return the prior success.

The guarantee scope is clear: it covers this ticket system where deduplication records and business writes share a transaction. For third-party services, verify whether they support idempotency keys or reliable query-by-business-ID. Recording a "sent" flag locally still leaves a new window between local bookkeeping and remote execution.

If the external party supports neither deduplication nor reliable query, leave the result as "pending verification" and schedule reconciliation, audit, or manual handling. A reliable system can temporarily not know the result; it must not disguise unknown as failure and repeat the operation.

Run a Real Recovery Test

To verify these boundaries, the author built a local inspection flow with real LangGraph and SQLite. Diagnosis used a fixed value; ticket writes went to a separate local database; model capability was out of scope.

The test killed the Worker process after ticket write succeeded but before the node returned, then started a brand-new process with the original task identity. This mirrors the actual fault window more closely than catching an exception in-process — the dead process has no chance to run subsequent code.

Results table:

Normal completion: 1 query / 1 diagnosis, 1 ticket-node execution, 1 final ticket.

Exit after commit, no idempotency: 1/1, 2 executions, 2 tickets.

Same window, ticket service deduplicates: 1/1, 2 executions, 1 ticket.

Post-restart checkpoint still contained the diagnosis; next node was create_ticket with no ticket_id — exactly the window described. Recovery re-ran query and diagnosis zero times; ticket node executed once. Without idempotency, two tickets; with service-side deduplication, both calls returned the same ticket ID. Eight concurrent requests with the same operation key created only one ticket; same key with altered parameters returned conflict.

Environment: Python 3.12.16, LangGraph 1.2.24, SQLite checkpointer 3.1.3. These numbers reflect local fault reproduction, not production benchmarks.

Responsibilities of a Recoverable Inspection Agent

Task entry: locate original task, initiate recovery. Worker: run model and tools. Checkpoint backend: persist recoverable progress. Ticket service: detect duplicate actions within its own write boundary.

The local SQLite example demonstrates mechanism. Production adoption requires shared storage, task scheduling, and code-version compatibility — local restart success does not equal multi-machine high availability.

Summary

After a restart, task recovery must reconcile two records: runtime progress and business-system side effects. Agent long-tasks produce intermediate artifacts — model judgments, verified facts, chosen tool parameters. Regenerating them may alter subsequent behavior. Committing these results at appropriate boundaries gives the task a definite history.

As Agents perform more cross-system operations, execution-layer feedback becomes input for the model's next reasoning step. Treating unknown as success builds plans on unreliable data; treating unknown as failure risks duplicate writes. Making unknown state traceable and delegating it to explicit business rules for reconciliation should become an explicit architectural responsibility.

The model handles uncertain information and judgment; certain execution facts must be held by state, storage, and business rules. Getting this division right lets services deploy and processes restart normally, without tasks starting over.

About this article

For questions about attribution, corrections or content rights, please contactadmin@besthub.devand we will review it promptly.

Published

AI-assisted summary

Report an issue with this article
IdempotencySQLitecheckpointingLangGraphAgent orchestrationdurable executiontask recoveryside-effect deduplication

Reader feedback

Was this useful?

Useful0

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion