fix(workflows): preserve intra-overlay order for multiple insert_after edits#3662
Open
jawwad-ali wants to merge 1 commit into
Open
fix(workflows): preserve intra-overlay order for multiple insert_after edits#3662jawwad-ali wants to merge 1 commit into
jawwad-ali wants to merge 1 commit into
Conversation
…r edits _traverse_and_apply's insert_after loop iterated reversed(edits) over the flat per-anchor edit list. The reversal is only meant to place a higher-priority OVERLAY closer to the anchor (mirroring insert_before's winner-closest behaviour), but reversing the flat list also flipped the declared order of multiple insert_after edits authored within a SINGLE overlay: [insert_after a->x, insert_after a->y] produced [a, y, x, b] instead of [a, x, y, b]. insert_before (a forward loop) already preserves order, so the two operations were asymmetric. Group contiguous same-layer edits and reverse the GROUP order only, keeping each overlay's own inserts in declared order. Cross-overlay priority is unchanged (higher-priority overlay still lands closest to the anchor). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.8 (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.
What
In
_traverse_and_apply(workflows/overlays/merge.py), theinsert_afterloop iteratedreversed(edits)over the flat per-anchor edit list. That reversal exists to place a higher-priority overlay closest to the anchor (mirroringinsert_before's winner-closest behaviour) — but reversing the flat list also flips the declared order of multipleinsert_afteredits authored within a single overlay.Concretely, one overlay with
[insert_after a→x, insert_after a→y]produced[a, y, x, b]instead of[a, x, y, b]. The siblinginsert_beforeloop directly above iterates forward and preserves order, so the two operations were asymmetric.Fix
Group contiguous same-layer edits and reverse the group order only, keeping each overlay's own inserts in declared order. Cross-overlay priority is unchanged — a higher-priority overlay's group still lands closest to the anchor.
Tests
tests/workflows/test_overlay_merge.py::TestMergeSteps::test_merge_steps_multiple_insert_after_same_overlay_preserves_order— one overlay, twoinsert_afteron the same anchor → asserts[a, x, y, b]. Fails before the fix ([a, y, x, b]); passes after. The existingtest_merge_steps_higher_priority_wins(cross-overlay ordering) still passes.ruffclean; all 43 overlay merge + composer tests pass.AI-assisted: authored with Claude Code. Verified the asymmetry against the forward
insert_beforeloop and confirmed cross-overlay priority is preserved.