Skip to content

Fix merges that lose an added object matching a later base object - #10629

Merged
skshetry merged 2 commits into
masterfrom
saugat/fix/merge-added-key-matches-later-base
Nov 30, 2026
Merged

skshetry merged 2 commits into
masterfrom
saugat/fix/merge-added-key-matches-later-base

Conversation

@skshetry

@skshetry skshetry commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Closes #10559
Closes #10627

Problem

A merge can silently lose data when a newly added object has the same content as the next object, in path order, of the merge base. Empty marker files such as _SUCCESS hit it most easily.

Both branches add the same path with different content. The merge succeeds and keeps one side instead of reporting a conflict:

  M      # merge feat into main: no conflict, a/x = v2
  |\
  C F    # main adds a/x = v2, feat adds a/x = v1
  |/
  B      # b/x = v1

One branch adds an object and the other deletes the next base object. The merge drops the added object:

  M      # merge feat into main: logs/0/_SUCCESS is gone
  |\
  D F    # main deletes logs/_SUCCESS, feat adds an empty logs/0/_SUCCESS
  |/
  B      # data/a = v1, empty logs/_SUCCESS

To find the base version of a path, the merge takes the first base entry at or after that path. In two places it compared only the content of that entry, not its path.

Solution

A base entry counts as the base version only when its path equals the path being merged. Otherwise the path is new.

Merges of the first shape used to succeed. They now fail with Conflict found, unless a merge strategy settles them. Revert and cherry-pick use the same merge, so they change the same way.

Testing

New unit tests cover both shapes, with source and destination swapped and under each merge strategy. They fail without the fix.

I also ran the reproductions against live servers built from master and from this branch:

Reproduction Expected master This branch
#10627 script: merge dev into main ["a"] [] ["a"]
#10627: cherry-pick add a onto dev ["a"] [] ["a"]
#10627: revert add b ["a"] [] ["a"]
#10559 Python SDK script conflict merged without conflict, prefix/A = b'D' conflict

🤖 Generated with Claude Code

@github-actions github-actions Bot added area/cataloger Improvements or additions to the cataloger area/testing Improvements or additions to tests labels Nov 30, 2026
@skshetry
skshetry force-pushed the saugat/fix/merge-added-key-matches-later-base branch from 0e65b14 to 1991f76 Compare November 30, 2026 14:39
#10629)

* graveler: test adding a key that matches a later base key

One side adds key k2 with the identity of base key k3, and the other
side deletes k3. The merge must keep k2 under every strategy, whichever
side added it.

The cases fail until the merge compares the base key with the key being
merged.

* graveler: keep an added key that matches a later base key

Once one side of a merge has no records left, the merge walks the rest
of the other side. It skipped a record whose identity matched the first
base record at or after its key, taking it as unchanged on this side and
deleted on the other. That base record can belong to a later key, so a
newly added key was dropped without a conflict.

A record is now skipped only when the base record has the same key.

Fixes: #10627
@skshetry
skshetry force-pushed the saugat/fix/merge-added-key-matches-later-base branch from 1991f76 to 0de0d0f Compare November 30, 2026 14:40
* graveler: test merges where both sides add the same key

Source and dest each add key a with a different identity, and base holds
only a later key b whose identity equals one side's a. A merge with no
strategy must report a conflict, and a merge with a strategy must write
the side that strategy favours.

The cases fail until the merge compares the base key with the key being
merged.

* graveler: report a conflict when both sides add a key

A merge looks up the first base record at or after the key it is
merging, so the record can belong to a later key. When both sides added
the same key with different identities, and that later base record had
the identity of one side, the merge took the key as changed by the other
side only. It wrote that side's value and reported no conflict, without
consulting conflict resolvers or the merge strategy.

The base record now counts as the base version only when its key equals
the key being merged. Otherwise the key is new on both sides and goes to
conflict handling.

Merges of this shape that used to succeed now fail with "Conflict found"
unless a strategy or resolver settles them.

Fixes: #10559
@skshetry
skshetry force-pushed the saugat/fix/merge-added-key-matches-later-base branch 4 times, most recently from 4fe9daf to 73054fd Compare November 30, 2026 14:44
@skshetry skshetry added the include-changelog PR description should be included in next release changelog label Nov 30, 2026
@skshetry skshetry self-assigned this Nov 30, 2026
@skshetry skshetry changed the title graveler: fix merges that misread a later base object as the base version Fix merges that lose an added object matching a later base object Nov 30, 2026

@AliRamberg AliRamberg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The merge.go and merge_test.go changes match lakeFS-Enterprise #4614 and #4613 line for line, and go test -race ./pkg/graveler/committed/ passes.

@skshetry
skshetry merged commit 1c9aae2 into master Nov 30, 2026
64 of 65 checks passed
@skshetry
skshetry deleted the saugat/fix/merge-added-key-matches-later-base branch November 30, 2026 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cataloger Improvements or additions to the cataloger area/testing Improvements or additions to tests include-changelog PR description should be included in next release changelog

Projects

None yet

2 participants