Skip to content

Python: Add allowed_checkpoint_types support to CosmosCheckpointStorage for parity with FileCheckpointStorage#5202

Open
moonbox3 wants to merge 3 commits intomicrosoft:mainfrom
moonbox3:agent/fix-5200-1
Open

Python: Add allowed_checkpoint_types support to CosmosCheckpointStorage for parity with FileCheckpointStorage#5202
moonbox3 wants to merge 3 commits intomicrosoft:mainfrom
moonbox3:agent/fix-5200-1

Conversation

@moonbox3
Copy link
Copy Markdown
Contributor

Motivation and Context

CosmosCheckpointStorage called decode_checkpoint_value without an allowed_types argument, causing it to use unrestricted pickle.loads instead of the RestrictedUnpickler that FileCheckpointStorage always uses. This meant the two providers—which implement the same protocol and share the same encoding—silently took different deserialization paths, making them non-interchangeable and leaving the Cosmos path without the restricted-type safety floor.

Fixes #5200

Description

The fix adds an allowed_checkpoint_types: list[str] | None = None keyword argument to CosmosCheckpointStorage.__init__, stored as a frozenset identical to the FileCheckpointStorage pattern. _document_to_checkpoint is changed from a @staticmethod to an instance method so it can forward allowed_types=self._allowed_types into decode_checkpoint_value, ensuring all load paths (load, list_checkpoints, get_latest) use restricted deserialization. New tests cover built-in safe types loading without opt-in, application-defined types being blocked unless explicitly listed, and all three load paths. A changelog entry notes this as a breaking change for users who store custom types.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Note: PR autogenerated by moonbox3's agent

Copilot and others added 2 commits April 10, 2026 06:18
…ge (microsoft#5200)

Add allowed_checkpoint_types parameter to CosmosCheckpointStorage for
parity with FileCheckpointStorage. This ensures both providers use the
same restricted pickle deserialization by default.

Changes:
- Accept allowed_checkpoint_types kwarg in __init__, stored as frozenset
- Convert _document_to_checkpoint from @staticmethod to instance method
- Forward allowed_types to decode_checkpoint_value on all load paths
- Update class docstring to describe the new parameter
- Add tests covering built-in safe types, app type opt-in/blocking,
  and all load paths (load, list_checkpoints, get_latest)
- Add changelog entry noting the breaking behavior change

BREAKING CHANGE: CosmosCheckpointStorage now uses restricted pickle
deserialization by default. Checkpoints containing application-defined
types will require passing those types via allowed_checkpoint_types.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…orage` for parity with `FileCheckpointStorage`

Fixes microsoft#5200
Copilot AI review requested due to automatic review settings April 10, 2026 06:27
@moonbox3 moonbox3 self-assigned this Apr 10, 2026
@moonbox3 moonbox3 added documentation Improvements or additions to documentation python labels Apr 10, 2026
Copy link
Copy Markdown
Contributor Author

@moonbox3 moonbox3 left a comment

Choose a reason for hiding this comment

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

Automated Code Review

Reviewers: 4 | Confidence: 98% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Design Approach


Automated review by moonbox3's agents

@moonbox3
Copy link
Copy Markdown
Contributor Author

moonbox3 commented Apr 10, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/azure-cosmos/agent_framework_azure_cosmos
   _checkpoint_storage.py135199%427
TOTAL27200318488% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
5447 20 💤 0 ❌ 0 🔥 1m 26s ⏱️

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR brings CosmosCheckpointStorage deserialization behavior into parity with FileCheckpointStorage by always using restricted pickle loading (with optional opt-in for application-defined types), and adds tests plus a changelog entry to document the breaking behavior change.

Changes:

  • Add allowed_checkpoint_types to CosmosCheckpointStorage.__init__ and flow it into decode_checkpoint_value(...) for restricted deserialization on all load paths.
  • Add azure-cosmos unit tests covering built-in safe types, blocked custom types, and opt-in custom types across load, list_checkpoints, and get_latest.
  • Add a changelog entry noting the breaking deserialization behavior change for the azure-cosmos package.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
python/packages/azure-cosmos/agent_framework_azure_cosmos/_checkpoint_storage.py Adds allowed_checkpoint_types plumbing and updates class docstring to describe restricted deserialization behavior.
python/packages/azure-cosmos/tests/test_cosmos_checkpoint_storage.py Adds test coverage for restricted deserialization and opt-in application types across Cosmos load paths.
python/CHANGELOG.md Documents the breaking behavior change for CosmosCheckpointStorage.

…ples

- Reintroduce explicit security warning about pickle deserialization risks
- Convert Example:: block to .. code-block:: python with imports for
  consistency with other docstring examples
- Note: PR title should be updated to include [BREAKING] prefix per
  changelog convention (comment #3, requires GitHub UI change)

Fixes microsoft#5200

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

@moonbox3 moonbox3 left a comment

Choose a reason for hiding this comment

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

Automated Code Review

Reviewers: 4 | Confidence: 96% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Design Approach


Automated review by moonbox3's agents

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

Labels

documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Add allowed_checkpoint_types support to CosmosCheckpointStorage for parity with FileCheckpointStorage

3 participants