Skip to content

Fix circular reference handling in epoch table hash computation#46

Merged
stevevanhooser merged 2 commits into
mainfrom
claude/fix-epochtable-recursion-phWks
Mar 22, 2026
Merged

Fix circular reference handling in epoch table hash computation#46
stevevanhooser merged 2 commits into
mainfrom
claude/fix-epochtable-recursion-phWks

Conversation

@stevevanhooser
Copy link
Copy Markdown
Contributor

Summary

Fixed a potential infinite loop issue in the _compute_hash method of EpochSet that could occur when computing hashes of epoch tables containing circular references.

Key Changes

  • Improved object serialization strategy: Changed the hash computation to prefer to_dict() method when available (which already handles circular references) rather than blindly walking __dict__
  • Removed unsafe __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)
  • Extended tuple support: Updated the type check to handle both list and tuple types consistently in the make_hashable function
  • Enhanced documentation: Added clarifying comments explaining the rationale for the serialization approach

Implementation Details

The change prioritizes objects that implement to_dict() (like ndi_epoch_epoch) since they already exclude circular back-references by design. For other objects without to_dict(), the function now falls back to using repr() 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

claude added 2 commits March 22, 2026 18:05
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
@stevevanhooser stevevanhooser merged commit c725edf into main Mar 22, 2026
5 checks passed
@stevevanhooser stevevanhooser deleted the claude/fix-epochtable-recursion-phWks branch March 22, 2026 18:18
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.

2 participants