Repository navigation
fix(model): preserve shortest breadth-first distances - #5106
Open
cangen185-sudo wants to merge 2 commits into
Open
cangen185-sudo wants to merge 2 commits into
cangen185-sudo wants to merge 2 commits into
Conversation
Co-authored-by: 福晋 <liufu.lf@antgroup.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5106 +/- ##
=======================================
Coverage 83.78% 83.78%
=======================================
Files 338 338
Lines 39416 39418 +2
Branches 8164 8168 +4
=======================================
+ Hits 33023 33027 +4
+ Misses 6369 6367 -2
Partials 24 24
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
📝 Description
Preserve the first-discovered distance in
Model.breadthFirstSearchand enqueue each discovered node once. In a graph witha → b,a → c, andb → c, the callback currently receives distance 2 forc, even thoughcis a direct neighbor ofa. This also makesgetSuccessors(a, { breadthFirst: true, distance: 1 })omitcandisSuccessorreturn false for that distance.Only assign a neighbor's distance and enqueue it when it has not already been discovered. FIFO discovery then keeps minimum hop counts through converging paths and cycles.
🖼️ Screenshot
Real-model regressions check callback order and distances, plus the public distance-filtered successor APIs.
💡 Motivation and Context
The previous traversal marked nodes visited when dequeuing but unconditionally rewrote every neighbor's distance while enqueuing. Another node on the same frontier could overwrite a shorter pending distance before its callback ran. The existing test asserted callback count only.
The change is confined to breadth-first discovery. Regressions also exercise incoming traversal, pruning, isolated nodes, and the depth-first
searchentry point.🧩 Types of changes
🔍 Self Check before Merge
Validation on Windows, against
masterat306eddb03fd5313d75d9a3ce084722f44475da01:tsc --noEmit, Biome on the new test file, andgit diff --checkpassed.src/model/model.tsreports the same 2 existing errors (import organization and formatting) and 7 warnings on both the exact upstream baseline and patched source. No unrelated formatting changes are included.AI assistance: implementation and test drafting assisted by OpenAI Codex; the patch was reviewed and locally tested.