Python: fix(checkpoint): preserve dicts whose keys collide after str() - #8272
LI (ktz03) wants to merge 3 commits into
Conversation
When dict keys collide after str() (e.g. 1 and "1"), JSON encoding silently overwrote values. Pickle those mappings instead (microsoft#8256).
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.
|
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. |
|
Nice narrow fix for the Should be ready for maintainer review on #8256. |
Reuse one str(key) for reserved-key checks, collision detection, and the encoded mapping so stateful __str__ cannot disagree across passes.
Reuse one str(key) for reserved-key checks, collision detection, and the encoded mapping so stateful __str__ cannot disagree across passes.
|
Thanks for the update. Before this is ready, could you please:
Once those are addressed, please re-request review. Thanks! |
|
Eduard van Valkenburg (@eavanvalkenburg) Updated PR body to the repository template and addressed the latest review feedback on this head — please re-review when convenient. |
Motivation & Context
Checkpoint encoding stringifies dict keys for JSON. Distinct Python keys that collide after
str()(e.g.{1: "a", "1": "b"}) previously lost values in the encoded mapping. Stateful__str__implementations could also disagree across the reserved-key check, collision check, and final encode passes.Fixes #8200 (checkpoint dict key collision after str).
Description & Review Guide
__str__._encodedict path in_checkpoint_encoding.pyand the regression tests intest_checkpoint_encode.py.Related Issue
Fixes #8200
No other open PR targets this issue.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.