Fix remove_cycles_dfs missing cycles due to wrong back-edge parent#111
Merged
HyperCodec merged 5 commits intodevfrom Feb 23, 2026
Merged
Fix remove_cycles_dfs missing cycles due to wrong back-edge parent#111HyperCodec merged 5 commits intodevfrom
HyperCodec merged 5 commits intodevfrom
Conversation
Co-authored-by: HyperCodec <72839119+HyperCodec@users.noreply.github.com>
Co-authored-by: HyperCodec <72839119+HyperCodec@users.noreply.github.com>
The original remove_cycles_dfs used a `prev: Option<NeuronLocation>` parameter to identify the back-edge when a cycle was detected. Due to HashMap iteration non-determinism, `prev` could hold the wrong value (an ancestor instead of the immediate parent), causing `self[prev].outputs.contains_key(¤t)` to fail silently and leaving cycles in the network. Fix: replace `prev` with an explicit `path: &mut Vec<NeuronLocation>` stack. `path.last()` is always the correct immediate predecessor of `current` in the DFS call stack, regardless of HashMap iteration order. Also remove all temporary debug assertions added during investigation. Co-authored-by: HyperCodec <72839119+HyperCodec@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Update to 1.0.0 with massive rewrite changes
Fix remove_cycles_dfs missing cycles due to wrong back-edge parent
Feb 23, 2026
HyperCodec
approved these changes
Feb 23, 2026
Owner
HyperCodec
left a comment
There was a problem hiding this comment.
LGTM. idk if I really care about having all these extra debug test cases, but it's probably better to have them than not.
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.
remove_cycleswould silently leave cycles intact after crossover. The colored DFS usedprev: Option<NeuronLocation>to identify the back-edge, but HashMap's non-deterministic iteration order could causeprevto hold a grandparent (or earlier ancestor) rather than the true immediate parent. The guardself[prev].outputs.contains_key(¤t)would then returnfalse, and the cycle edge was never added toedges_to_remove.Changes
remove_cycles_dfs: Replaceprev: Option<NeuronLocation>parameter with an explicitpath: &mut Vec<NeuronLocation>DFS stack.path.last()is guaranteed to be the immediate predecessor ofcurrentat the point a back-edge is detected, regardless of HashMap iteration order.split_connection,add_connection, andcrossover.🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.