interplane.Get Omega
Read in your language

synapse

A component of the AienOS ecosystem.

Brought by drakestapleton

branch main Branches Tags History

synapse / docs / D1_MERGE_TIER_T1.md

98 lines · 7928 bytes Raw Blame History Source

D1: Merge tier T1 (region)

ADR 0003 section 9 step D1 (issue aien-dev/synapse#39), section 5.5 merge tiers: a T1 merge combines revisions that change different regions of the same file. Path-level merging (T0, B5) refuses them.

Code:

Tests:

Evidence: evidence/d1-merge-tier-t1/.

1. The merge rule

region_merge(base, versions) merges the versions of one file that several revisions wrote against the same base version. The result does not depend on which line diff is chosen.

  1. Forced lines. For one version, a base line is forced when every longest common subsequence of base and version matches it, and always to the same version line. It is computed from a prefix table and a suffix table of LCS lengths. Base line i is forced when:
    • no version position j gives prefix[i][j] + suffix[i+1][j] == total, so skipping the line always loses a match; and
    • exactly one j gives prefix[i][j] + 1 + suffix[i+1][j+1] == total.
  2. Anchors. The anchors are the base lines forced for every version.
  3. Segments. The anchors cut the base and every version into matching segments. In each segment at most one version may differ from the base, and the merged file takes that version's segment. If two versions change one segment, the merge is refused (RegionConflict::Overlap).

Why it agrees with Git:

The brute-force test d1_forced_matches_are_exactly_the_pairs_every_optimal_alignment_shares checks the forced-line computation against every optimal alignment on small inputs.

A first design used one Myers diff and then widened each change to cover the lines the diff could have slid. The differential test against git merge-file found merges Git refuses, because a different minimal diff can re-pair lines far from the change. The forced-anchor rule replaced it; d1_edits_that_some_minimal_diff_places_together_conflict holds the counterexample.

2. In the derivation rule

DerivationRule::Merge { tier: MergeTier::T1Region } is encoded with tier tag 1. The rule is the same B5 rule: the server derives it, the store recomputes it at admission (check_derivation), and replicas recompute it at verification. The attestation records the tier and the canonical merge order (strictly ascending ChangesetId), as for T0.

Per path, t1_mutations:

The merged blob is new content that no source carried. The API preloads the blobs the rule reads (each upsert blob, and the base file at each mutated path, for T1 only). admit_derived_revision takes merged blobs that are not yet visible from produced_blob, checks their digest, and writes them in the same WAL record as the derived revision. Replay and verification recompute the same bytes. A forged T1 output, with a blob other than the recomputed one, is refused (d1_api_forged_t1_merge_output_is_refused).

T0 and T1 merges of the same sources share one ChangeId (merge_change_id). They are revisions of the same change.

3. Acceptance

Acceptance (issue #39)Result
The 3 disjoint-hunk pairs of the Gate 4 conflict scenario, refused by T0, now merge3 of 3 merged (d1_gate4_conflict_scenario_t1_merges_match_git_on_all_253_pairs); with the T1 arm switched to T0 (mutation t1-is-t0) the test fails
Every merged tree equals Git's merge result245 merged pairs, 0 differ from git merge-tree --write-tree on any touched path (blob digest and mode)
No pair git merge-tree reports as conflicting is merged (all 253 pairs)0 merged Git conflicts, 0 merge-tree errors. Per class, as (pairs, Synapse merged, Git clean): distinct paths (240, 240, 240), disjoint hunks (3, 3, 3), identical change (2, 2, 2), hotspot rewrite (6, 0, 0), modify/delete (1, 0, 0), file/directory collision (1, 0, 0)
Each result records its tier and merge order in its DerivationAttestation0 attestations without tier T1 and the canonical order; the API test checks the attestation's rule and inputs, and verify_revision_log checks every signature and recomputes every T1 record, also after a reopen and after checkpoint plus compaction

Also covered:

Red before green: evidence/d1-merge-tier-t1/red-green/red.txt holds 10 mutations from run.sh, one per behaviour, and each turns its tests red. green.txt holds the passing runs. The behaviours:

4. Limits