fix(dependency_graph): remove orphaned children in remove_dependency#1106
fix(dependency_graph): remove orphaned children in remove_dependency#1106
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe change updates DependencyGraph.remove_dependency() to delete the target node and then iteratively remove any descendant nodes that become orphaned (have no remaining parents). It snapshots direct children, removes the deleted node from each child’s parents and from each parent’s children, deletes the node from self.nodes, and enqueues children that now have no parents (excluding ROOT) for further removal. Tests were added with a local build_graph() helper and multiple test_remove_dependency* cases covering leaf removal, cascading orphan removal, shared-child preservation, diamond topologies, mid-graph removals, and removing nonexistent nodes. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@mergify rebase |
✅ Branch has been successfully rebased |
When a node is removed, child nodes that have no remaining parents are now recursively removed as well, preventing orphaned nodes from lingering in the graph. Closes: #1041 Signed-off-by: Josef Skladanka <jskladan@redhat.com> Co-Authored-By: Claude <claude@anthropic.com>
a04a1d6 to
1f8c31c
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/fromager/dependency_graph.py`:
- Around line 389-392: The recursive call in remove_dependency (the loop over
children checking child.key != ROOT and child.key in self.nodes and not
child.parents) causes repeated global child-edge cleanup and O(n²) behavior
during cascades; fix by avoiding re-entering remove_dependency for each orphan —
instead, when you detect an orphan node (use children, ROOT, self.nodes,
child.parents, child.canonicalized_name, child.version to locate it), remove it
from its direct parents' children lists and add it to a local queue of nodes to
delete, then process that queue iteratively (or mark nodes for bulk deletion) so
global child-edge cleanup runs once per node rather than once per orphan
recursion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: dc241074-4cae-4bfb-b1ea-5676ca7ac3e5
📒 Files selected for processing (2)
src/fromager/dependency_graph.pytests/test_dependency_graph.py
…h scans - Replace recursive orphan removal with iterative BFS - Use direct parent/child references instead of scanning all nodes - Add tests for diamond cascade and cross-subtree survival Signed-off-by: Josef Skladanka <jskladan@redhat.com> Co-Authored-By: Claude Code <noreply@anthropic.com>
f827fd2
|
@coderabbitai please re-review this |
|
Tip For best results, initiate chat on the files or code changes.
[full_review] |
|
@rd4398 / @LalatenduMohanty - if you could have a look, I addressed the feedback from the Coderabbit, it IMO made sense to make this into a pretty straightforward stack-driven BFS instead of the recursion (funny enough, I've seen the coderabbit implementation after I've made the changes 🥲 didn't know it proposes detailed solutions, but it is virtually the same, only I decided to use dequeue instead of plain list) |
|
@jskladan The BFS approach is the better choice here since it avoids stack depth issues on deep dependency chains and makes the traversal order explicit . You can squash the commits. I can approve the PR after that |
When a node is removed, child nodes that have no remaining parents are now recursively removed as well, preventing orphaned nodes from lingering in the graph.
Closes: #1041
[X] PR follows CONTRIBUTING.md guidelines