Skip to content

feat(flow): snapshots for resume, time-travel & replay (#281) - #355

Merged
Kaap10 merged 2 commits into
codeforstartups:developmentfrom
shivamm-gupta:issue-281-snapshots-replay
Nov 23, 2026
Merged

Kaap10 merged 2 commits into
codeforstartups:developmentfrom
shivamm-gupta:issue-281-snapshots-replay

Conversation

@shivamm-gupta

@shivamm-gupta shivamm-gupta commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Introduces snapshots for agent run state persistence, time-travel rewind, and replay with input overrides in dynaflow, addressing issue #281.

Related issue

Fixes #281

Changes

  • Defined immutable Snapshot data model in src/dynavec/checkpoint.py with unique identifier, step, state, inputs, parent pointer, timestamp, and metadata.
  • Extended BaseCheckpointer, MemoryCheckpointer, and DynamoDBCheckpointer with:
    • save_snapshot: Persists snapshot atomically with attribute_not_exists(pk) immutability protection.
    • get_snapshot: Loads specific snapshot by thread ID and snapshot ID.
    • list_snapshots: Lists snapshots chronologically with optional limit parameter.
    • fork_from_snapshot: Creates a forked thread with a distinct checkpoint ID pointing to source as parent, applies input overrides directly to state and goal, and records provenance metadata.
  • Integrated replay execution with ReActAgent, supporting rewind and resumed execution with edited inputs.
  • Added comprehensive unit tests in tests/test_snapshots.py covering in-memory and DynamoDB storage, immutability guarantees, limit filtering, and end-to-end agent replay.

Testing

  • Tests pass locally (pytest tests/test_snapshots.py tests/test_checkpointer.py -> 19 passed)
  • Ruff checks pass (ruff check src/dynavec/checkpoint.py tests/test_snapshots.py -> All checks passed)
  • Mypy checks pass (mypy src/dynavec/checkpoint.py -> Success: no issues found)
  • Documentation updated, if applicable

Checklist

  • My changes are focused and relevant to this pull request.
  • I have added or updated tests where appropriate.
  • I have reviewed my changes for unrelated modifications.
  • I have updated documentation where necessary.

@Kaap10

Kaap10 commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator

Thanks, could you write PR description in proper format?
same format issue in #355, #356 and #357

@Kaap10 Kaap10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! The snapshot data model, in-memory isolation, and tests are a great starting point.

However, there are a few important issues that need to be addressed before we can merge:

  1. Checkpoint ID self-loop in fork_from_snapshot: When forking, forked_cp_id reuses source.checkpoint_id, and parent_checkpoint_id is also set to source.checkpoint_id. This makes the checkpoint its own parent (checkpoint_id == parent_checkpoint_id). A new thread should generate its own unique checkpoint ID.
  2. override_inputs does not update Checkpoint state: override_inputs updates Snapshot.inputs, but Checkpoint.state is copied without changes. When an agent resumes on the new thread, it reads Checkpoint.state and still sees the old goal/messages.
  3. Incomplete Replay test: test_react_agent_snapshot_capture_and_replay only checks dictionary values after forking. It doesn't actually run the agent again to test replay with overridden inputs.
  4. DynamoDB redundant read: DynamoDBCheckpointer.save_snapshot calls get_item before put_item. The ConditionExpression="attribute_not_exists(pk)" in put_item already prevents overwrites atomically.
  5. PR description format: Please update the PR description to follow .github/pull_request_template.md and remove the escaped backslashes (\).

Please see the inline comments below for suggested fixes.

Comment thread src/dynavec/checkpoint.py Resolved
Comment thread src/dynavec/checkpoint.py Resolved
Comment thread src/dynavec/checkpoint.py Resolved
Comment thread src/dynavec/checkpoint.py Resolved
Comment thread src/dynavec/checkpoint.py Resolved
Comment thread tests/test_snapshots.py Resolved
@shivamm-gupta

Copy link
Copy Markdown
Collaborator Author

Thanks @Kaap10 for the thorough review! All requested changes have been addressed:

  1. Unique Checkpoint ID on fork: ork_from_snapshot now generates a fresh unique checkpoint_id (cp_...) on the forked thread and sets parent_checkpoint_id to source.checkpoint_id.
  2. State and Goal Update on override: ork_from_snapshot now applies override_inputs directly into Checkpoint.state, updating goal, the initial user message, and inputs so resuming agents immediately see overridden inputs.
  3. End-to-End Replay Test: Added an end-to-end replay verification in est_react_agent_snapshot_capture_and_replay asserting that �gent.run(..., thread_id=new_thread_id) resumes and completes with the new output.
  4. Redundant read removed: Removed the redundant get_item prior to put_item in DynamoDBCheckpointer.save_snapshot.
  5. Type annotation & Limit parameter: Replaced �uiltins.list with Sequence[Snapshot] to avoid shadowing the list() method while remaining compatible with mypy and ruff, and added an optional limit parameter to list_snapshots.
  6. PR Description: Updated according to .github/pull_request_template.md without escaped backslashes.

@shivamm-gupta shivamm-gupta self-assigned this Nov 22, 2026
@shivamm-gupta
shivamm-gupta requested a review from Kaap10 November 22, 2026 13:33

@Kaap10 Kaap10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for addressing all the feedback quickly. The unique checkpoint ID generation on fork, state updates for overridden inputs, and end-to-end replay test look great. Approved and ready to merge.

@Kaap10
Kaap10 merged commit 04190c3 into codeforstartups:development Nov 23, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Snapshots for resume, time-travel & replay

2 participants