Skip to content

fix(engine): prioritize direct parent match over ancestor fallback - #246

Merged
HarshK97 merged 1 commit into
mainfrom
fix/topdown-direct-parent-precedence
Oct 10, 2026
Merged

HarshK97 merged 1 commit into
mainfrom
fix/topdown-direct-parent-precedence

Conversation

@HarshK97

Copy link
Copy Markdown
Owner

Problem

  1. When TopDown ranks candidate matches, any candidate with zero direct parent similarity falls back to an outer construct like a loop or function and takes half of its score.
  2. If that outer loop is mostly unchanged, taking half its score easily beats a candidate whose direct parent actually matched, so the candidate with no parent match ends up stealing the node.

What Changed

  • Track isFallback on candidate pairs in internal/engine/top-down.go, and only set it when the fallback construct actually matches.
  • In slices.SortStableFunc, make sure a candidate with a real direct parent match (dice > 0) always beats a fallback candidate before comparing raw Dice scores.
  • Add TestTopDown_DirectParentPrecedenceOverFallback in internal/engine/topdown_test.go to test that direct parent matches win over high-scoring outer loops.

When two candidate pairs compete, a candidate with zero direct parent
similarity could fall back to an enclosing construct like an outer loop.
If that outer loop had high similarity, taking half of it could outscore
a candidate with genuine direct parent similarity, stealing the match.

- engine: track isFallback on scoredPair and rank direct parent matches
  ahead of ancestor fallbacks in slices.SortStableFunc
- tests: add TestTopDown_DirectParentPrecedenceOverFallback covering
  direct parent priority over outer construct fallbacks
@HarshK97
HarshK97 merged commit 1f6b667 into main Oct 10, 2026
17 checks passed
@HarshK97
HarshK97 deleted the fix/topdown-direct-parent-precedence branch October 10, 2026 12:04
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.

1 participant