Skip to content

fix: add cycle detection to graph traversal functions#17

Merged
mark-pro merged 3 commits intooneirosoft:mainfrom
don-petry:fix/graph-cycle-detection
Apr 1, 2026
Merged

fix: add cycle detection to graph traversal functions#17
mark-pro merged 3 commits intooneirosoft:mainfrom
don-petry:fix/graph-cycle-detection

Conversation

@don-petry
Copy link
Copy Markdown
Contributor

@don-petry don-petry commented Mar 31, 2026

Summary

  • Add HashSet<Uuid> visited-set cycle detection to lineage(), branch_depth(), active_descendant_ids(), and subtree() in src/core/graph.rs
  • Prevents infinite loops when state.json contains corrupted circular parent references (e.g., A → B → A)
  • Adds three tests verifying termination on cyclic state for lineage, branch depth, and descendant traversal

Addresses #10 item 3 (cycle detection for graph traversal).

Test plan

  • cargo test --locked passes (new cycle detection tests + existing tests)
  • Manually verify with a corrupted state.json containing circular parent refs that dgr log and dgr status terminate

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings March 31, 2026 02:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 to lineage(), branch_depth(), and active_descendant_ids().
  • Refactor subtree() into subtree_inner() to track visited nodes and return an InvalidData error 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.

Comment thread src/core/graph.rs Outdated
Comment thread src/core/graph.rs
Comment thread src/core/graph.rs
DJ and others added 2 commits March 30, 2026 19:29
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>
@mark-pro mark-pro merged commit d1c6cdd into oneirosoft:main Apr 1, 2026
2 checks passed
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.

3 participants