Skip to content

Fix to prevent hash()/id() collisions in the memoizer - #4901

Open
pjfo wants to merge 1 commit into
ManimCommunity:mainfrom
pjfo:hashing_signature_kinds
Open

Fix to prevent hash()/id() collisions in the memoizer#4901
pjfo wants to merge 1 commit into
ManimCommunity:mainfrom
pjfo:hashing_signature_kinds

Conversation

@pjfo

@pjfo pjfo commented Jul 27, 2026

Copy link
Copy Markdown

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant