Skip to content

fix(engine): prevent large-distance line jumps in LineDiff DP backtrack - #92

Merged
HarshK97 merged 1 commit into
mainfrom
feat/line-distance-local-window
Aug 14, 2026
Merged

fix(engine): prevent large-distance line jumps in LineDiff DP backtrack#92
HarshK97 merged 1 commit into
mainfrom
feat/line-distance-local-window

Conversation

@HarshK97

Copy link
Copy Markdown
Owner

Problem

  1. In large JSON schema files like json_schemastore_workflow_step_reorder, identical lines like "$comment" or "type": "string" appear inside multiple definition blocks 50 to 200 lines apart.
  2. During DP backtrack, LineDiff greedily picked matching lines regardless of line distance. So line partitioning jumped across distant schema blocks, locking candidate AST matches across unrelated definitions and producing 42 actions (31 of them spurious moves) for a simple definition reorder.

What Changed

  • Updated DP backtrack in internal/engine/linediff.go to inspect line distance offsets.
  • When the default backtrack target j is more than 20 lines away (i-j > 20 or j-i > 20), LineDiff looks for an alternative optimal DP line k within a 20-line local window.
  • This keeps contiguous sequence alignment intact for local code blocks while stopping line partitions from jumping across distant blocks in large schema configs.
  • Updated tests/testdata/json_schemastore_workflow_step_reorder/expected.json

Visual Comparison

  • Example : tests/testdata/json_schemastore_workflow_step_reorder/

Before

  • Spacious moves are generated
image

After

  • No spacious moves are generated, and diff is clean.
image

@HarshK97
HarshK97 merged commit 0d1c6c7 into main Aug 14, 2026
13 checks passed
@HarshK97
HarshK97 deleted the feat/line-distance-local-window branch August 14, 2026 13:38
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