Fix circular reference handling in epoch table hash computation#46
Merged
Conversation
The make_hashable helper recursed into obj.__dict__ for arbitrary objects without tracking already-visited references. Objects with circular references (e.g. probe -> session -> probe) caused a RecursionError. Track seen object ids to break cycles. https://claude.ai/code/session_018x9bY9c9DVBpg4JoEDDheR
Instead of tracking visited objects with a seen set, remove the __dict__ fallback altogether. Objects like ndi_epoch_epoch already have to_dict() methods that exclude circular back-references (e.g. epochset_object), so we should prefer that path. For anything else, fall through to returning the object as-is (scalar) rather than blindly walking __dict__. https://claude.ai/code/session_018x9bY9c9DVBpg4JoEDDheR
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.
Summary
Fixed a potential infinite loop issue in the
_compute_hashmethod ofEpochSetthat could occur when computing hashes of epoch tables containing circular references.Key Changes
to_dict()method when available (which already handles circular references) rather than blindly walking__dict____dict__traversal: Eliminated the fallback that walked an object's__dict__directly, which could encounter circular references (e.g., epoch → epochset_object → epoch table → epoch)listandtupletypes consistently in themake_hashablefunctionImplementation Details
The change prioritizes objects that implement
to_dict()(likendi_epoch_epoch) since they already exclude circular back-references by design. For other objects withoutto_dict(), the function now falls back to usingrepr()implicitly rather than attempting to traverse__dict__, which is safer and avoids potential infinite loops in complex object graphs.https://claude.ai/code/session_018x9bY9c9DVBpg4JoEDDheR