Checked other resources
Related Issues / PRs
None
Reproduction Steps / Example Code (Python)
import asyncio
from langchain_core.runnables import RunnableConfig
from langgraph.checkpoint.base import Checkpoint, CheckpointMetadata
from langgraph.checkpoint.sqlite.aio import AsyncSqliteSaver
async def simulate_concurrent_writes():
# Initialize the checkpointer in memory
async with AsyncSqliteSaver.from_conn_string(":memory:") as saver:
await saver.setup()
# Prepare mock checkpoint data
config: RunnableConfig = {"configurable": {"thread_id": "test_thread", "checkpoint_ns": ""}}
checkpoint: Checkpoint = {"v": 1, "id": "1", "ts": "2026-01-01T00:00:00Z", "channel_values": {}, "channel_versions": {}, "versions_seen": {}}
metadata: CheckpointMetadata = {"source": "input", "step": 1, "writes": {}}
new_versions = {}
# Worker simulating concurrent agent writes
async def worker(worker_id):
cfg = config.copy()
cfg["configurable"] = config["configurable"].copy()
cfg["configurable"]["checkpoint_id"] = f"check_{worker_id}"
await saver.aput(cfg, checkpoint, metadata, new_versions)
# Trigger 50 concurrent writes at the exact same time
# Without BEGIN IMMEDIATE, this highly concurrent scenario can expose
# the database to "sqlite3.OperationalError: database is locked"
tasks = [worker(i) for i in range(50)]
await asyncio.gather(*tasks)
if __name__ == "__main__":
asyncio.run(simulate_concurrent_writes())
Error Message and Stack Trace (if applicable)
Description
Description
In high-concurrency environments, when multiple async agents attempt to write checkpoints simultaneously using AsyncSqliteSaver.aput, SQLite can occasionally fail with a sqlite3.OperationalError: database is locked.
Proposed Fix
Enforcing a BEGIN IMMEDIATE transaction block within the async with self.lock section inside langgraph/checkpoint/sqlite/aio.py ensures that SQLite acquires a write lock before executing the statement, preventing concurrent write collisions.
System Info
System Information
OS: Windows
OS Version: 10.0.26200
Python Version: 3.11.9 (tags/v3.11.9:de54cf5, Apr 2 2024, 10:12:12) [MSC v.1938 64 bit (AMD64)]
Package Information
langchain_core: 1.4.7
langsmith: 0.8.16
langchain_protocol: 0.0.17
Optional packages not installed
deepagents
deepagents-cli
Other Dependencies
httpx: 0.28.1
jsonpatch: 1.33
orjson: 3.11.9
packaging: 26.2
pydantic: 2.13.4
pyyaml: 6.0.3
requests: 2.32.3
requests-toolbelt: 1.0.0
rich: 15.0.0
tenacity: 9.1.4
typing-extensions: 4.15.0
uuid-utils: 0.16.2
websockets: 15.0
wrapt: 2.2.1
xxhash: 3.7.0
zstandard: 0.25.0
Checked other resources
Related Issues / PRs
None
Reproduction Steps / Example Code (Python)
Error Message and Stack Trace (if applicable)
Description
Description
In high-concurrency environments, when multiple async agents attempt to write checkpoints simultaneously using
AsyncSqliteSaver.aput, SQLite can occasionally fail with asqlite3.OperationalError: database is locked.Proposed Fix
Enforcing a
BEGIN IMMEDIATEtransaction block within theasync with self.locksection insidelanggraph/checkpoint/sqlite/aio.pyensures that SQLite acquires a write lock before executing the statement, preventing concurrent write collisions.System Info
System Information
Package Information
Optional packages not installed
Other Dependencies