Python: fix(checkpoint): preserve dicts whose keys collide after str() - #8272
Open
LI (ktz03) wants to merge 1 commit into
Open
Python: fix(checkpoint): preserve dicts whose keys collide after str()#8272LI (ktz03) wants to merge 1 commit into
LI (ktz03) wants to merge 1 commit into
Conversation
When dict keys collide after str() (e.g. 1 and "1"), JSON encoding silently overwrote values. Pickle those mappings instead (microsoft#8256).
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused implementation resolves the reported data-loss case and includes appropriate regression coverage.
Pull request overview
Prevents checkpoint data loss when distinct dictionary keys stringify identically.
Changes:
- Pickles mappings with stringified-key collisions.
- Adds a restricted-decoding round-trip regression test.
File summaries
| File | Description |
|---|---|
python/packages/core/agent_framework/_workflows/_checkpoint_encoding.py |
Detects collisions before dictionary encoding. |
python/packages/core/tests/workflow/test_checkpoint_encode.py |
Verifies colliding keys retain both values. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Author
|
Fork CI for this PR may need a maintainer to Approve workflows before Python tests run (same as other community PRs). Happy to address review feedback once checks appear. |
Contributor
|
Nice narrow fix for the Should be ready for maintainer review on #8256. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #8256. Checkpoint encoding converts dict keys with
str(k). Distinct keys like1and"1"collapsed and silently lost a value.Narrow fix: if
len({str(k) for k in d}) != len(d), pickle the whole mapping (same path as reserved-marker keys). Non-colliding non-string keys still stringify.Validation
test_encode_dict_with_stringified_key_collision_uses_pickletest_encode_dict_with_non_string_keysstill passes