Support cbor2 6.x deserialization changes#2379
Support cbor2 6.x deserialization changes#2379muratclk wants to merge 1 commit intonewton-physics:mainfrom
Conversation
|
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughReplaced runtime Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@pyproject.toml`:
- Line 82: Update the CHANGELOG.md [Unreleased] entry to reflect that the cbor2
version cap was removed (the PR allows cbor2 6.x) instead of saying it was
capped; locate the line that currently reads something like "Cap `cbor2`
dependency to `<6`" and change it to a concise note such as "Allow `cbor2` 6.x
by removing the `<6` version cap" in the appropriate category so it matches the
pyproject.toml change (the dependency line mentioning "cbor2>=5.7.0").
- Line 82: Update the cbor2 constraint in pyproject.toml by changing the
requirement string "cbor2>=5.7.0" to constrain the major version to <6 (e.g.,
"cbor2>=5.7.0,<6") to avoid pulling in the unreleased/breaking 6.x, and add a
brief entry under the CHANGELOG.md [Unreleased] section noting "Constrain cbor2
to <6 until 6.x breaking changes are validated" so the dependency change is
tracked; locate the dependency line referenced as "cbor2>=5.7.0" and the
CHANGELOG.md [Unreleased] heading to apply these edits.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 2055740a-0a94-43c4-ab26-a0ac9fb1f9fb
📒 Files selected for processing (2)
newton/_src/viewer/viewer_file.pypyproject.toml
| "imgui_bundle>=1.92.0", # for viewer GUI | ||
| "pyyaml>=6.0.2", | ||
| "cbor2>=5.7.0, <6", # for binary recording format (.bin files) - more efficient than JSON | ||
| "cbor2>=5.7.0", # for binary recording format (.bin files) - more efficient than JSON |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify changelog entry exists for cbor2 compatibility change.
fd -i '^CHANGELOG\.md$' | xargs -r rg -n -C2 '\[Unreleased\]|cbor2|binary recording|examples'Repository: newton-physics/newton
Length of output: 2617
Update the CHANGELOG.md entry to reflect removal of the cbor2 version cap.
The existing CHANGELOG entry at line 135 states "Cap cbor2 dependency to <6…", which describes the opposite of this PR's change. Since this PR removes the cap and enables cbor2 6.x support, update the [Unreleased] section to document this change (e.g., "Allow cbor2 6.x by removing the <6 version cap" or similar, in the appropriate category).
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@pyproject.toml` at line 82, Update the CHANGELOG.md [Unreleased] entry to
reflect that the cbor2 version cap was removed (the PR allows cbor2 6.x) instead
of saying it was capped; locate the line that currently reads something like
"Cap `cbor2` dependency to `<6`" and change it to a concise note such as "Allow
`cbor2` 6.x by removing the `<6` version cap" in the appropriate category so it
matches the pyproject.toml change (the dependency line mentioning
"cbor2>=5.7.0").
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check whether CI/tests explicitly exercise multiple cbor2 majors.
rg -n -C3 'cbor2|extras|examples|matrix|tox|pytest' .github pyproject.toml tox.ini noxfile.py 2>/dev/nullRepository: newton-physics/newton
Length of output: 5219
🏁 Script executed:
#!/bin/bash
# Check cbor2 specifics: releases, breaking changes, and version documentation
# First, find any version pinning or pinned versions in CI/config files
echo "=== Checking for explicit cbor2 version pinning or testing ==="
rg 'cbor2' .github pyproject.toml -n --type yaml --type toml
echo -e "\n=== Checking CHANGELOG.md for dependency-related entries ==="
if [ -f CHANGELOG.md ]; then
head -100 CHANGELOG.md | rg -i 'cbor2|dependency|version|constraint' -C2
else
echo "CHANGELOG.md not found at root"
fi
echo -e "\n=== Checking for any requirements files ==="
fd -e 'txt' -e 'lock' -e 'in' | head -20 | xargs -I {} sh -c 'echo "=== {} ===" && rg "cbor2" {} 2>/dev/null || true'Repository: newton-physics/newton
Length of output: 12590
🌐 Web query:
cbor2 Python package version releases and breaking changes between 5.x 6.x 7.x
💡 Result:
What versions exist (as of Apr 8, 2026)
- Latest stable on PyPI: 5.9.0 (uploaded Mar 22, 2026) [1]
- 6.x: only a pre-release is documented: 6.0.0rc1 (Mar 26, 2026) [2]
- 7.x: no 7.x release is listed in the upstream cbor2 version history / docs at this time [2].
Breaking / behavior-changing differences: 5.x → 6.x (6.0.0rc1)
6.0.0rc1 is a major rewrite (single Rust-based implementation replacing the prior Python + C implementations) [2].
Documented backward-incompatible changes in 6.0.0rc1 include [2]:
- Callback signature changes
tag_hooknow receives (CBORTag, immutable) instead of (CBORDecoder, CBORTag)object_hooknow receives (Mapping[Any, Any], bool) instead of (CBORDecoder, dict[Any, Any])
- Removals
- Removed
break_markersingleton - Removed
CBORDecodeValueError(nowValueError/TypeErrorare chained underCBORDecodeError) - Removed “individual decoding functions” from the public API (previously misused directly)
- Dropped deprecated
cbor2.encoder/cbor2.decodermodules (import fromcbor2directly)
- Removed
- Semantic / encoding changes
- Semantic tag 261 decoding may now yield
IPv4Interface/IPv6Interfacewhen host bits exist - IP address encoding switches to semantic tags 52/54 (instead of deprecated 260/261)
- Semantic tag 261 decoding may now yield
- Type rename / availability
cbor2.FrozenDictrenamed tofrozendict; and on Python 3.15 it defers to the built-infrozendict
- Python support
- Drops Python 3.9
Notable “upgrade friction” within 5.x (not a major-version break, but relevant)
From the 5.x changelog [2]:
- 5.5.0: deprecated
cbor2.encoder,cbor2.decoder,cbor2.typesmodules (intended removal “next major release”); dropped Python 3.7 [2] - 5.7.0: dropped Python 3.8 [2]
- 5.9.0: default
read_sizechanged from 4096 to 1 (to restore stream-position behavior); opt-in back to faster buffered reads withread_size=4096[2]
6.x → 7.x
- No 7.x releases are documented yet, so no confirmed breaking-change list is available upstream at this time [2].
Sources: PyPI project page (release info) [1]; cbor2 upstream “Version history” / changelog (details of 5.x + 6.0.0rc1 breaking changes) [2].
🏁 Script executed:
#!/bin/bash
# Verify if CHANGELOG.md exists and what format is used for dependency entries
echo "=== Checking for CHANGELOG.md ==="
find . -maxdepth 2 -iname '*change*' -o -iname '*release*' -o -iname '*history*' | head -10
echo -e "\n=== Checking pyproject.toml for exact current state ==="
sed -n '75,90p' pyproject.toml
echo -e "\n=== Checking if 6.x versions have actually shipped stable (not just rc) ==="
# From the lock file, check if any 6.x non-rc versions are referenced
grep -A5 -B5 'cbor2.*6\.' uv.lock || echo "No cbor2 6.x found in lock"Repository: newton-physics/newton
Length of output: 9280
🌐 Web query:
cbor2 6.0.0 release date stable version 2026
💡 Result:
As of April 8, 2026, cbor2 6.0.0 has not been released (no such release is listed on PyPI). The latest stable cbor2 release available on PyPI is 5.9.0, uploaded on March 22, 2026. [1]
Source: PyPI project page for cbor2. [1]
[1] (pypi.org)
Citations:
Constrain to <6 instead of <7; add CHANGELOG.md entry.
cbor2 6.0.0 has not yet released to stable—only 6.0.0rc1 exists—and it contains breaking changes (callback signatures, module removals, semantic tag shifts). Constraining to <6 aligns with validated 5.x support and matches the already-applied constraint in uv.lock. When 6.0 stabilizes, compatibility should be explicitly validated before loosening the bound.
Additionally, per coding guidelines, this dependency change requires a corresponding entry in CHANGELOG.md under [Unreleased] (e.g., "Constrain cbor2 to <6 until 6.x breaking changes are validated").
Proposed dependency guardrail
- "cbor2>=5.7.0", # for binary recording format (.bin files) - more efficient than JSON
+ "cbor2>=5.7.0,<6", # allow validated 5.x; avoid untested major version changes📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| "cbor2>=5.7.0", # for binary recording format (.bin files) - more efficient than JSON | |
| "cbor2>=5.7.0,<6", # allow validated 5.x; avoid untested major version changes |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@pyproject.toml` at line 82, Update the cbor2 constraint in pyproject.toml by
changing the requirement string "cbor2>=5.7.0" to constrain the major version to
<6 (e.g., "cbor2>=5.7.0,<6") to avoid pulling in the unreleased/breaking 6.x,
and add a brief entry under the CHANGELOG.md [Unreleased] section noting
"Constrain cbor2 to <6 until 6.x breaking changes are validated" so the
dependency change is tracked; locate the dependency line referenced as
"cbor2>=5.7.0" and the CHANGELOG.md [Unreleased] heading to apply these edits.
cbor2 6.0 returns `cbor2.frozendict` (not a `dict` subclass) for nested dicts and `tuple` instead of `list` for arrays. This caused `isinstance(data, dict)` checks in the deserialization path to silently skip processing, breaking recorder round-trip tests. Replace `isinstance(..., dict)` with `isinstance(..., Mapping)` in all deserialization functions (`deserialize`, `transfer_to_model`, `depointer_as_key`, `_resolve_cache_refs`) since `cbor2.frozendict` implements `collections.abc.Mapping`. The `Mapping` import was already present. Also remove the `cbor2<6` version cap from pyproject.toml. Fixes newton-physics#2375
cb06b52 to
22bde7c
Compare
|
Thanks for the fix. Let's wait a bit before merging until v6 is released. |
Summary
Fixes #2375
cbor26.0 introduces breaking deserialization changes:cbor2.frozendict(not adictsubclass)tupleinstead oflistThis caused
isinstance(data, dict)checks in the deserialization path to silently skip processing, breaking recorder round-trip tests.Changes
isinstance(..., dict)withisinstance(..., Mapping)in all deserialization functions (deserialize,transfer_to_model,depointer_as_key,_resolve_cache_refs).cbor2.frozendictimplementscollections.abc.Mapping, so this handles both old and new cbor2 versions.Mappingwas already imported fromcollections.abc— no new dependencies.cbor2<6version cap frompyproject.toml.Compatibility
dictis a subclass ofMapping, so all existing behavior is preserved.frozendictimplementsMapping, so deserialization now works correctly.deserialize_ndarraycallstuple(data["shape"])explicitly, andnp.array()accepts both list and tuple inputs.Test plan
Summary by CodeRabbit
cbor2version constraint for examples to allow newer patch/major releases.