microsoft / microsoft/agent-framework

Python: get_latest timestamp ties return a checkpoint chosen by save order, can restore stale state

Open
#8,513 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

python triage
Dominant language
Python
Stars
13.6k
Forks
2.3k
Avg merge
2d 45m
Merged PRs (30d)
358

Description

### Description

`InMemoryCheckpointStorage.get_latest` picks `max()` by timestamp alone. Checkpoints at the same superstep boundary legitimately carry identical timestamps (the `WorkflowCheckpoint` docstring on `iteration_count` says so explicitly), and `datetime.now()` resolution means even distinct boundaries can collide. When timestamps tie, `max()` returns whichever checkpoint the dict iterates first, so the result depends on save order:

```python
storage = InMemoryCheckpointStorage()
parent = WorkflowCheckpoint(workflow_name="w", graph_signature_hash="h", checkpoint_id="parent", timestamp=ts)
child = WorkflowCheckpoint(workflow_name="w", graph_signature_hash="h", checkpoint_id="child", timestamp=ts, previous_checkpoint_id="parent")
# save parent then child -> get_latest returns parent
# save child then parent -> get_latest returns child
```

A workflow resuming via `get_latest` can therefore restore the stale checkpoint, with no error anywhere.

`FileCheckpointStorage.get_latest` has the same timestamp-only `max()`; it happens to mask the issue via list ordering, but the same identical-timestamp input can pick the wrong one.

The checkpoint docstring itself says ordering is defined by the `previous_checkpoint_id` lineage chain, not timestamps alone.

### Expected behavior

Ties on timestamp resolve through the lineage chain: the checkpoint that no other checkpoint supersedes is the latest, regardless of save order.

### Environment

agent-framework python main (astryx-era clone from this week), Python 3.12

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating InMemoryCheckpointStorage.get_latest and FileCheckpointStorage.get_latest, then read the WorkflowCheckpoint docstring, especially iteration_count and previous_checkpoint_id. Verify behavior with identical timestamps saved in both orders; done means the checkpoint not superseded in the lineage chain is selected consistently, regardless of save order.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.