Repository navigation
Description
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.
mainat t1.fluree branch create dev;fluree branch create feature.devcommits D2, D3.featurecommits F2..F5.- Merge
featureintodev→ M4 ondevwith parents[D3, F5]. devcommits D5. Mergedevintofeature.
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:811find_common_ancestor: dual-frontier BFS over all parents; returns the first CID seen from both sides, with thetfrom that commit's own envelope.fluree-db-api/src/merge.rs:248-259: ancestor drives the fast-forward decision;:483,:494,:526,:561useancestor.tas 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 ont <= 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
tregression 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
- Merge/rebase/revert transplant flakes with branch-local
t— time-travel reads below a merge return rewritten history and phantom duplicates #1783: merge semantics now rely on the first-parent lineage being self-contained; that holds only when the cutoff is on the right clock.
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
[-]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[/+]