Skip to content

Python: fix(core): align in-memory checkpoint isolation - #7848

Closed
Patel Namraa (Namraa310806) wants to merge 1 commit into
microsoft:mainfrom
Namraa310806:fix/inmemory-checkpoint-deepcopy
Closed

Python: fix(core): align in-memory checkpoint isolation#7848
Patel Namraa (Namraa310806) wants to merge 1 commit into
microsoft:mainfrom
Namraa310806:fix/inmemory-checkpoint-deepcopy

Conversation

@Namraa310806

@Namraa310806 Patel Namraa (Namraa310806) commented Aug 24, 2026

Copy link
Copy Markdown

Motivation & Context

This PR fixes checkpoint state isolation issues tracked in #7683.

Checkpoint state could previously share mutable references with the live workflow
state or with the internal InMemoryCheckpointStorage representation. As a
result, mutating a restored or loaded checkpoint could silently modify the
original checkpoint snapshot.

This is especially problematic for nested mutable values such as lists and
dictionaries because the mutation happens without an exception and without
another save() operation.

Description & Review Guide

  • What are the major changes?

    • Isolate nested values when exporting and importing State using the existing
      checkpoint-value serialization mechanism.
    • Make InMemoryCheckpointStorage return caller-owned checkpoint copies using
      copy.deepcopy() for load(), list_checkpoints(), and get_latest().
    • Keep save() isolated so changes to the caller's checkpoint after saving
      cannot modify stored state.
    • Document the ownership contract on the CheckpointStorage protocol.
    • Add checkpoint-storage conformance tests covering both in-memory and file
      storage backends.
    • Add regression tests covering nested state and checkpoint data isolation.
  • What is the impact of these changes?

    • Checkpoints remain stable snapshots after they are exported, restored, loaded,
      or listed.
    • Mutating a returned in-memory checkpoint no longer mutates the stored
      checkpoint.
    • The direct State export/import path is also isolated, including nested
      mutable values.
    • This does not change the public checkpoint value contract or workflow
      behavior; it only prevents unintended reference sharing.
  • What do you want reviewers to focus on?

    • The ownership/isolation boundaries between State, WorkflowCheckpoint,
      and CheckpointStorage.
    • The use of the checkpoint-value isolation mechanism for State, while
      InMemoryCheckpointStorage uses copy.deepcopy() as requested for the
      in-memory backend.
    • The conformance tests verifying that both in-tree storage backends satisfy
      the checkpoint ownership contract.

Related Issue

Fixes #7683

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Aug 24, 2026
@github-actions github-actions Bot changed the title fix(core): align in-memory checkpoint isolation Python: fix(core): align in-memory checkpoint isolation Aug 24, 2026
@TaoChenOSU

Tao Chen (TaoChenOSU) commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Superseded by #7847

@Namraa310806

Copy link
Copy Markdown
Author

Tao Chen (@TaoChenOSU)
Before the PR was superseded, I updated my implementation to incorporate the
feedback and address both related isolation issues:

  • State.export_state() / import_state() retain checkpoint-value isolation
    so the original Python: [Bug]: Checkpoint state is not isolated from live workflow state across restoration and storage boundaries #7683 aliasing issue is fixed without unnecessarily changing
    the checkpoint value contract.
  • InMemoryCheckpointStorage uses copy.deepcopy() for caller/storage
    isolation, rather than pickle, following the feedback that pickle is not
    needed for the in-memory backend.
  • The CheckpointStorage ownership contract is documented explicitly.
  • The conformance tests cover both InMemoryCheckpointStorage and
    FileCheckpointStorage, including nested mutable checkpoint data.
  • Regression coverage was added for the State export/import isolation boundary.

Since this PR is now superseded by #7847, I won't duplicate the work. If any of
these implementation details or tests are useful for the consolidated PR,
please feel free to incorporate them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Checkpoint state is not isolated from live workflow state across restoration and storage boundaries

3 participants