Skip to content

Prevent memoizer collisions between object hashes and IDs - #4901

Merged
behackl merged 1 commit into
ManimCommunity:mainfrom
pjfo:hashing_signature_kinds
Jul 29, 2026
Merged

Prevent memoizer collisions between object hashes and IDs#4901
behackl merged 1 commit into
ManimCommunity:mainfrom
pjfo:hashing_signature_kinds

Conversation

@pjfo

@pjfo pjfo commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Overview: What does this pull request change?

Tag each membership sign with its signature kind ("h" for hash, "i" for id) so the two kinds can never collide, and add a regression test covering both collision directions.

The test fails on the current main branch, but succeeds on this branch.

Motivation and Explanation: Why and how do your changes improve the library?

This is a separate bug to the one found in PR 4896: Hashing stability for transient objects in manim 0.20.1.

The _Memoizer class mixes two classes of ints when it is processing, hashes and id addresses. If a hash matches a recorded id or vice-versa then the current behaviour is to record a potentially never recorded object to the already processed placeholder, which changes the serialisation of the json and the play hash.

Because str hashes are randomised per process, whether such a coincidence occurs varies between otherwise identical runs, so a cached scene can silently re-render partial movie files.

Links to added or changed documentation pages

Further Information and Comments

Depending on which (if either) are merged first between this and PR 4896, a trivial rebase will be needed on the other, but even though the code is adjacent it does not conflict.

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

The _Memoizer records processed objects in a single set of raw ints that mixes hash() values with id() addresses. A hash() value that numerically equals a recorded id() address (or vice versa) collapses a never-processed object to the already-processed placeholder, changing the serialized JSON and thus the play hash. Because str hashes are randomized per process, whether such a coincidence occurs varies between otherwise identical runs, so a cached scene can silently re-render partial movie files.

Tag each membership sign with its signature kind ("h" for hash, "i" for id) so the two kinds can never collide, and add a regression test covering both collision directions.

@behackl behackl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks for the detailed report and comment in the changed code!

@behackl
behackl merged commit 6f20425 into ManimCommunity:main Jul 29, 2026
17 checks passed
@behackl behackl added the pr:bugfix Bug fix for use in PRs solving a specific issue:bug label Jul 29, 2026
@pjfo
pjfo deleted the hashing_signature_kinds branch July 31, 2026 00:00
@behackl behackl changed the title Fix to prevent hash()/id() collisions in the memoizer Prevent memoizer collisions between object hashes and IDs Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:bugfix Bug fix for use in PRs solving a specific issue:bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants