Skip to content

Merges between sibling branches can pick a common ancestor on the wrong clock #1912

Closed

Description

@zonotope

Summary

Every branch numbers its commits from its fork point, so two branches forked from the same parent share a numeric range of t without sharing a clock. Merge finds the common ancestor by a BFS over all parent edges and then uses ancestor.t as the cutoff for collecting the source's commits and for conflict detection. When the ancestor was reached through a merge edge, its t is on the other branch's clock and may exceed the t of the source's own commits, which are then silently excluded from the merge.

The fast-forward path has the mirror problem: adopting the other branch's head can move a branch's t backwards.

Pre-existing on main. Raised during the review of the #1783 fix; the pre-fix DAG walk applied the same t cutoff with continue, so the outcome is unchanged by that branch. Not yet reproduced end to end because the verifier that was running the probe was cut off; the scenario below is constructed from the code.

Scenario

Merging into a non-parent branch is allowed (merge_into_non_parent_allowed in fluree-db-api/tests/it_merge.rs), so sibling merges are reachable.

  1. main at t1. fluree branch create dev; fluree branch create feature.
  2. dev commits D2, D3. feature commits F2..F5.
  3. Merge feature into dev → M4 on dev with parents [D3, F5].
  4. dev commits D5. Merge dev into feature.

find_common_ancestor(dev head = D5, feature head = F5) finds F5 itself (F5 is a parent of M4). ancestor.t = 5 on feature's clock. The source collection collect_first_parent_cids(D5, stop_at_t = 5) sees D5 with t = 5 <= 5 and returns nothing. Conflict detection over the same cutoff sees nothing either. The merge commit carries none of D2, D3, D5, and no conflict is reported.

If instead step 4 is fast-forwardable (F5 is an ancestor of dev's head), feature adopts dev's chain and its head t drops from 5 to 4.

Where

  • fluree-db-core/src/commit.rs:811 find_common_ancestor: dual-frontier BFS over all parents; returns the first CID seen from both sides, with the t from that commit's own envelope.
  • fluree-db-api/src/merge.rs:248-259: ancestor drives the fast-forward decision; :483, :494, :526, :561 use ancestor.t as the cutoff for source delta, target delta, source collection, and commit copying.
  • fluree-db-core/src/commit.rs:633 (walk_first_parent) and :597 (walk_dag): both stop on t <= stop_at_t.

Decision needed

The cutoff is only sound when ancestor.t is on the source's own clock, which holds for child-into-parent merges and fails for sibling merges and back-merges. Options:

  • Refuse merges whose common ancestor is not on the source's first-parent lineage (reject with a clear error). Smallest change; sibling merges keep working only in the fast-forward case, which needs the t regression check below.
  • Cut the source walk by CID rather than by t: walk the source's first-parent lineage until the ancestor CID is met, and detect conflicts the same way. This makes sibling merges correct but needs the ancestor to lie on the source's lineage, so it still needs the refusal for the case where it does not.
  • Make fast-forward refuse any head change that lowers the target's t.

Related

Status

Confirmed end to end while fixing it. The reachable form is a repeated merge of the same branch: merge x into dev, let both sides change the same fact, merge x again. The base is the x commit the first merge took, whose t is above every commit dev has made since, so dev's side of the comparison comes out empty and no conflict is reported. abort then goes through and take-branch leaves both values in place.

PR #1905 replaces the t cutoff with diff_branches, which compares the two branches by commit identity. It takes the second option above and also covers the fast-forward regression, since fast-forward is now true only when the target's head is on the source's line.

Activity

  1. added
    bug
    P1
    area:transact
    on Sep 23, 2026
  2. changed the title [-]Merges between sibling branches can pick a common ancestor on the wrong clock and drop the source's commits[/-] [+]Merges between sibling branches can pick a common ancestor on the wrong clock[/+] on Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1area:transactbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions