fix: add cycle detection to graph traversal functions#17
Merged
mark-pro merged 3 commits intooneirosoft:mainfrom Apr 1, 2026
Merged
fix: add cycle detection to graph traversal functions#17mark-pro merged 3 commits intooneirosoft:mainfrom
mark-pro merged 3 commits intooneirosoft:mainfrom
Conversation
Prevent infinite loops from corrupted state.json with circular parent references by adding HashSet-based visited tracking to lineage(), branch_depth(), active_descendant_ids(), and subtree(). Addresses oneirosoft#10 item 3. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR hardens BranchGraph traversal utilities against corrupted state.json graphs that contain parent-reference cycles, preventing infinite loops during lineage, depth, descendant, and subtree walks.
Changes:
- Add
HashSet<Uuid>visited-set cycle detection tolineage(),branch_depth(), andactive_descendant_ids(). - Refactor
subtree()intosubtree_inner()to track visited nodes and return anInvalidDataerror on detected cycles. - Add unit tests intended to verify traversal termination on cyclic graphs.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Include node_id and branch name in subtree cycle error messages, strengthen cycle test assertions to check exact values, and add dedicated test for subtree error on cycle. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
3 tasks
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
HashSet<Uuid>visited-set cycle detection tolineage(),branch_depth(),active_descendant_ids(), andsubtree()insrc/core/graph.rsstate.jsoncontains corrupted circular parent references (e.g., A → B → A)Addresses #10 item 3 (cycle detection for graph traversal).
Test plan
cargo test --lockedpasses (new cycle detection tests + existing tests)state.jsoncontaining circular parent refs thatdgr loganddgr statusterminate🤖 Generated with Claude Code