fix(query): correct frontier eviction in shortest path priority queue#9678
Open
shaunpatterson wants to merge 1 commit intodgraph-io:mainfrom
Open
fix(query): correct frontier eviction in shortest path priority queue#9678shaunpatterson wants to merge 1 commit intodgraph-io:mainfrom
shaunpatterson wants to merge 1 commit intodgraph-io:mainfrom
Conversation
Three fixes to the MaxFrontierSize eviction logic in shortest path: 1. Replace pq.Pop() with removeMax() — the old code removed an arbitrary element (the last in the underlying slice) instead of the highest-cost node. removeMax() does a linear scan to find and remove the actual maximum via heap.Remove(), preserving the heap invariant. 2. Push before evict — the old code evicted before pushing the new node, so the new node was never considered for eviction. A high-cost new node would be admitted while a lower-cost existing node was evicted. Now we push first, then evict the max from the full set. 3. Guard MaxFrontierSize > 0 — skip eviction when the limit is disabled (zero value), matching the existing Params default. Tests: - 24 unit tests achieving 100% coverage on all priority queue and eviction functions (indexOf, Len, Less, Swap, Push, Pop, removeMax) - 10 integration tests exercising maxfrontiersize in DQL shortest path queries against a live cluster, covering: optimal path discovery, very small frontiers, large frontiers matching unconstrained results, k-shortest-path, linear chains, and the specific regression scenarios for all three bugs Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
pq.Pop()withremoveMax()— the old code removed the last element of the underlying slice (arbitrary in a min-heap) instead of the highest-cost node.removeMax()does a linear scan and usesheap.Remove()to properly evict the least promising candidate while maintaining the heap invariant.MaxFrontierSize > 0— skip eviction when the limit is disabled (zero value), preventing accidental eviction when no limit is configured.Builds on the fix in #9607 which identified the
pq.Pop()vsremoveMax()issue, and addresses two additional correctness problems (evict-before-push ordering and boundary condition) found during review.Test plan
indexOf,Len,Less,Swap,Push,Pop,removeMax)maxfrontiersizein DQL shortest path queries:maxfrontiersize=1doesn't crash (single-path and k-shortest)🤖 Generated with Claude Code