Skip to content

Conversation

@christian-byrne
Copy link
Contributor

Summary

  • Creates reusable cycle detection utilities in src/subgraph/utils/cycleDetection.ts
  • Integrates cycle detection into LGraph.convertToSubgraph() to prevent creating subgraphs that would cause infinite recursion
  • Adds comprehensive test coverage for both the utility functions and integration points

Implementation Details

  • validateNoSubgraphCycles() - Checks if nodes contain circular references before subgraph creation
  • validateSubgraphAddition() - Validates nodes being added to existing subgraphs
  • containsSubgraph() - Helper function to recursively check subgraph containment
  • Integration point in LGraph.convertToSubgraph() at line 1417

Test Coverage

  • Unit tests for cycle detection utilities (test/subgraph/utils/cycleDetection.test.ts)
  • Integration tests for LGraph.convertToSubgraph() (test/LGraph.convertToSubgraph.test.ts)
  • Tests cover direct cycles, indirect cycles, mixed node types, and error messaging

This improvement prevents users from accidentally creating subgraphs that would cause infinite loops during execution by detecting cycles at creation time rather than runtime.

- Create src/subgraph/utils/cycleDetection.ts with validation functions
- Add validateNoSubgraphCycles and validateSubgraphAddition utilities
- Integrate cycle detection into LGraph.convertToSubgraph()
- Add comprehensive tests for cycle detection functionality
- Prevent creating subgraphs that would cause infinite recursion
@christian-byrne christian-byrne changed the title [subgraph] Extract cycle detection to shared utility [subgraph] Extract cycle detection to shared utility and validate on subgraph creation Jul 25, 2025
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