[Bug]: CheckpointStore silently loses checkpoint data when two checkpoints share an id (same-second collision)
Summary
CheckpointStore silently loses checkpoint data and permanently desynchronizes index.json when two checkpoints are created for the same node and type within the same wall-clock second.
Checkpoint.create() builds checkpoint_id from a whole-second timestamp:
core/framework/schemas/checkpoint.py:83—timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")core/framework/schemas/checkpoint.py:84—checkpoint_id = f"cp_{checkpoint_type}_{current_node}_{timestamp}"
The store writes one file per id and keys the index by that same id:
core/framework/storage/checkpoint_store.py:63—checkpoint_path = self.checkpoints_dir / f"{checkpoint.checkpoint_id}.json"core/framework/schemas/checkpoint.py:156—self.checkpoints.append(summary)
So when two ids collide, the second save_checkpoint() overwrites the first checkpoint file. The index then lists the same id twice, and total_checkpoints reports a count that does not match the files on disk.
Why this is reachable
node_start / node_complete for the same node can easily land in the same second: fast graphs, retry loops, and resumed runs. The store already takes an _index_lock for concurrent writers, so concurrent checkpointing is an expected scenario rather than a theoretical one.
Reproduction
Save as repro_checkpoint_collision.py and run from core/:
cd core && uv run python repro_checkpoint_collision.pyimport asyncio
import tempfile
from pathlib import Path
from framework.schemas.checkpoint import Checkpoint
from framework.storage.checkpoint_store import CheckpointStore
def make(step: int) -> Checkpoint:
return Checkpoint.create(
checkpoint_type="node_start",
session_id="sess_1",
run_id="run_1",
current_node="node_a",
execution_path=[],
data_buffer={"step": step},
)
async def main() -> None:
with tempfile.TemporaryDirectory() as d:
store = CheckpointStore(Path(d))
first, second = make(1), make(2)
print("first.checkpoint_id =", first.checkpoint_id)
print("second.checkpoint_id =", second.checkpoint_id)
print("ids equal =", first.checkpoint_id == second.checkpoint_id)
await store.save_checkpoint(first)
await store.save_checkpoint(second)
reloaded = await store.load_checkpoint(first.checkpoint_id)
index = await store.load_index()
files = sorted(p.name for p in store.checkpoints_dir.glob("cp_*.json"))
print("index.total_checkpoints =", index.total_checkpoints)
print("distinct ids in index =", len({s.checkpoint_id for s in index.checkpoints}))
print("cp_*.json files on disk =", len(files))
print("data stored for first =", reloaded.data_buffer, "(expected {'step': 1})")
asyncio.run(main())Actual output on main (6193aea)
first.checkpoint_id = cp_node_start_node_a_20260926_203502
second.checkpoint_id = cp_node_start_node_a_20260926_203502
ids equal = True
index.total_checkpoints = 2
distinct ids in index = 1
cp_*.json files on disk = 1
data stored for first = {'step': 2} (expected {'step': 1})Every number above is wrong in a way that matters:
| Reported | Actual |
|---|---|
total_checkpoints = 2 |
1 checkpoint file exists |
| 2 index entries | 1 distinct id |
load_checkpoint(first_id) → {'step': 2} |
checkpoint {'step': 1} is gone |
Impact
- Data loss. The first checkpoint's
data_bufferis unrecoverable — there is no second copy anywhere. - Index desync.
total_checkpointsover-reports permanently, anddelete_checkpoint()on the id removes both index entries while only one file existed, so the counts drift further. - Wrong resume.
load_checkpoint()with no argument resolves throughindex.latest_checkpoint_id(checkpoint_store.py:104-109). Because that id is ambiguous, a resumed run can come back from the wrong state — which is the opposite of what checkpointing is for. The resume path is live:orchestrator.py:538constructs the store andorchestrator.py:599-602loads from it.
Suggested fix
- Make ids collision-proof: sub-second precision plus a short random suffix. The repo already uses
%Y%m%d_%H%M%S_%ffor ids inframework/llm/litellm.py:1008andframework/agent_loop/internals/compaction.py:850, so this matches existing convention. Microseconds alone can still collide under coarse clock resolution, hence the suffix. - Make
CheckpointIndex.add_checkpoint()replace on a duplicate id instead of appending, so the index cannot describe a file that does not exist even when aCheckpointis built directly rather than viacreate().
Separately, and not a security issue: checkpoint_id embeds the graph node id, which comes from user-supplied agent config, and is interpolated straight into a path at checkpoint_store.py:63, :91, :175, :252. A node id containing .. builds a path outside checkpoints_dir. It is not currently escapable — the cp_<type>_ prefix means the traversal would have to pass through a directory literally named cp_node_start_.., which cannot exist, so the open fails with FileNotFoundError. That is incidental rather than guaranteed, so it would be worth asserting containment explicitly.
Test coverage
core/framework/storage/checkpoint_store.py (323 lines) currently has no tests — checkpoint_store does not appear anywhere under core/tests/. I'd like to add core/tests/test_checkpoint_store.py covering the save/load/list/delete/prune surface plus the index-matches-disk invariant.
Filed with AI assistance (OpenCode). The reproduction above was run against main and the output is copied verbatim; the fix and its tests are in the linked PR.
Source: aden-hive/hive