From d1248829c53385b698b3081b8db058854239cc0c Mon Sep 17 00:00:00 2001 From: clover caruso Date: Mon, 19 Oct 2026 12:31:04 -0700 Subject: [PATCH] fix(notebook): name each merge after the state it merged onto A merge named the revision it wrote after the merged version's revision alone. Two devices merging one version onto different states of a page wrote different contents under one revision identity, which MS-ONESTORE forbids, and a later merge of their results took the file as already holding the other's page and dropped a device's typing. The name now hashes the file revision the merge depends on as well; onto no revision, as in a space the merge creates, it stays the name older builds gave. Conflict page identities stay as older builds wrote them, and the names older builds gave merges still count as held, as devices run mixed builds. A seal refuses a name its space already stores, so a mix-up sets the version aside rather than writing a duplicate identity. In the cloud-drive sweep (release, seeds 200 to 799) the strings lost this way (seeds 342, 593 and 600) now arrive. Fourteen seeds still show a string twice, where both devices merged one version and a third merge replays it, and seed 728 loses one to a version retired as held by a device whose copy was stale. Assisted-by: claude-opus-5.5 --- arc/sync.md | 18 ++-- .../older-build-merges/clash-merged.one | Bin 0 -> 12520 bytes .../older-build-merges/clash-version.one | Bin 0 -> 9536 bytes .../older-build-merges/clean-merged.one | Bin 0 -> 11272 bytes .../older-build-merges/clean-version.one | Bin 0 -> 9544 bytes crates/notebook/README.md | 10 +- crates/notebook/src/resolve.rs | 62 +++++++---- crates/notebook/tests/cloud.rs | 99 ++++++++++++++++++ crates/onestore/src/section.rs | 25 +++-- 9 files changed, 171 insertions(+), 43 deletions(-) create mode 100644 corpus/icloud-merge/older-build-merges/clash-merged.one create mode 100644 corpus/icloud-merge/older-build-merges/clash-version.one create mode 100644 corpus/icloud-merge/older-build-merges/clean-merged.one create mode 100644 corpus/icloud-merge/older-build-merges/clean-version.one diff --git a/arc/sync.md b/arc/sync.md index 1d4f5c3b2ce3ede9e7c53f6959e06045e1c48799..341ae965dfaa74e0cd413473de6bdfa3cb976515 100644 --- a/arc/sync.md +++ b/arc/sync.md @@ -289,14 +289,16 @@ for each version V the remote lists (Remote::versions) revisions, publish on C's stamp; then retire V (resolved, removed) ``` -Merged page revisions and conflict page identities are named after the incoming version's -revision (a hash of it), so "holds merged" is a lookup by revision identity. A version merged -once, by this device or another, merges as nothing the next time. Two devices merging the same -version onto the same current page state name corresponding outcomes alike. This deduplicates -retries; it does not make integrations from opposite primary bases order-independent or -produce byte-identical files. Any device merges any version at once; nothing waits for the -device that wrote it. A version of another section, or one that cannot be read, is kept beside -the file as `Name (Device).one` instead. +A merged page revision is named after the incoming version's revision and the file's revision it +depends on (a one-way hash of both), and conflict page identities after the version's revision +alone, so "holds merged" is a lookup by revision identity; the names older builds gave merges +are recognised too, as devices run mixed builds. A version merged once, by this device or +another, merges as nothing the next time. Two devices merging the same version onto the same +current page state name corresponding outcomes alike; onto different states, differently, as +their contents differ. This deduplicates retries; it does not make integrations from opposite +primary bases order-independent or produce byte-identical files. Any device merges any version +at once; nothing waits for the device that wrote it. A version of another section, or one that +cannot be read, is kept beside the file as `Name (Device).one` instead. iCloud Drive can also lose an upload outright: another device's lands over it and no conflict version reaches this one. So on the Mac, the iPhone and Android each image a section publishes diff --git a/corpus/icloud-merge/older-build-merges/clash-merged.one b/corpus/icloud-merge/older-build-merges/clash-merged.one new file mode 100644 index 0000000000000000000000000000000000000000..e8745b382bd4abda4541bd6e81506011e1ae2a0c GIT binary patch literal 12520 zcmeHN4RBP|6}}-fSzrk(gdbs(ERjm6A;vLCRMaIT7=*xzKZA(480Al!rZ%*Z((;Vd z2BNZng&-DUEo;3Ke|!a z;JQOkxCSjdGj2m;|7E8dYMXundN``?tpL7vRSoi~+HK9D&z7>|IiU}{1QM(-HfGCr zztt4_dm=mZYQB_a9v8{4cfWqeQRlY5tbL$H$#7)ytob`~R~A0+kIUNLSbSmRsLroW z4g6nfz~~~f-NJp3TMTeP0ZGk&&be`9@uU^oohd6Wz2zI@1M^@=BVGIF{ zeNsnUy7|;6&3Q{N8!>31f94w*plv7h`ugfa}%~JAa**9EDJHI}%j{_?{{3Gkbhlh@L*C=z=47A3T;-UDv@SX_d z{_sh;xkApzCpGbUuYG%6gYZI-GFu;=e>*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001*m1nzrN0MGebrF6j&tg2`)s%DqFT;u;9DnstbMU`Pfj|!#T-%VH4eew z%J@Gm{GCkwX2##k)}p4m4oELI2Qg{3_?aj{b+mni;_lT9AM~7iS--Cva_evZ?cE2> zbHFf4RCOHgXgDX!ZpNY20?NrErPHhlcT|7>05xJKY-a&b)r$4pxhI77m3XV2^HR3X zdc5-0x_bQk(DO>E>yB-Lb{)MQ#653s4QTvc>hpuam_Wa<`8TZtcROa~FMoJ>@lzx3 zkMIlZW4B`!r-QsK0+=DRtIsz|VgN)2@m#tAYJkOi|4_UD7>e5k@g_+u1hHLx-owKK z&<62pN%W#aL;&NQO_Jybk*6~v!siY{3xIth>OhmzQ)k_g`q7DD{pR{F8vWCSOo{!n zvlpE^tOM1^&YY47*MC@_mx0c#&)fHf+9lA}&UVbK-ZFfzuVQEK3G*&X+Nfw&kG8*7 zJ7Zv-6qI!!okc|RwW>aEmnOUpWT!>efpq>^#V;9{g%fsa=R(<82bz6}wVr0VEFC|P zzC*mFWuM<2M9D2nTju#H`Q3uF1CMnbxBB5lZ@qiVr*kQ{in|oq9_7{fdM1-pO&%O0 z?$WRGM8(O|#&{iX{#LC1FN3oyY|9g5pf%-n+&v~Yv%Y@(`rETwU%p|bSwoB^ugWX! z`@?q1v+UH?#qLcl!G)Rrv+KPllhpbG!$AaO1C{@Xr)V+O2deQyiqC4lrMENnckJGR zr#2ia7{58I+m@^PEIP;~DgE(1nm$UiKm-JU+_#X+jG+%TKl5+uI@;OS<>Zvb%ClT@ zCk%Y+tTo!%SN|`uQ;x60c%AihG+xLIne*$k7i)a%JWuI|u9x~@ZFh=1S3Z2(ZI(LG H`Hz1C7h~=V literal 0 HcmV?d00001 diff --git a/corpus/icloud-merge/older-build-merges/clash-version.one b/corpus/icloud-merge/older-build-merges/clash-version.one new file mode 100644 index 0000000000000000000000000000000000000000..6e060a0c4855871d368eb1fc78177890e71acebf GIT binary patch literal 9536 zcmeHM4{(&l72iwJ%K=9?NJ1jqUCtP%!BRY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6X0xmtjCRMbs|^Oyp(!+T>`T;2neS7AQt z1jI%`9o6_$tc=gmwT&2S8DA_ue6hH&G~sM~v3D|wVFKa+42N>eGs@~FXV1wc(Xv{(GE)u^_t(AvXVY2N_imVflKTGBj$XTp=f_<*w<<7hc1?nJ0a6N ztw$UCuyHw&+<1RmK&6NYYw1>YANww=({E!ECxHi`F2c!EFJ9?*^JaI&&X>a0 zh%Sxi`MdW=t&OEC7wtQK;b?oV|1Ei*djTRu9%8haOWNu8EZi>wLRd@!C?31HEGcxa zxYPZ?$te@>ufC%6J8P5QFQ}!K{2kJavOqYa&DWED@?PrE|I>p?VCekc#l@`SoeH4l zrFySG|Ikj-rFgH9V|>2%3YyB#@ZNyFN1g{*DC1nYF3}2vb$RS-i`V_6|Lu9ZE?jH9 zYX6Q5)Hkk6^UTY2S?oa%j8?tkiXZYo#Dy1K@drJ+Ont@oUCxEdP%;%@QE zXc5+!Z}EID7_mXdH^z4&{0}kmJCU4U{!S$QD|V&s-yd7s+j?DF%Ug%KUe5mQg@w>4 znSbTGZbCe`f;u4b5hEsvJ#&aHuChz&g*XJ`BNm&%9UB@<#2c!=;D2QLc(l zQO@6OgTky%%B#>UQ7rmU-oxqo8$+SqmHrR5YSkrbKX=+vE85o!%QsUuDz7GLk9T9d RLzq1Z%MiWsH(izA{sWm2A$b4* literal 0 HcmV?d00001 diff --git a/corpus/icloud-merge/older-build-merges/clean-merged.one b/corpus/icloud-merge/older-build-merges/clean-merged.one new file mode 100644 index 0000000000000000000000000000000000000000..6a0d4b4e9c05eee63b3b85470c92379abea305e0 GIT binary patch literal 11272 zcmeHN4RlRc7CuQNc_HDcgpl`=D^dw1^Nftr(RvXgKQgkY5kJ*XmIRGdV?>y7t5Weh z57QP!P5slcf|LvzQ);4gtqEqZ2CYsE>OUbw%+&1f-gB;(oBLkUuCdnqWUqDJz31$6 z_St9ebN1eMpLc2SsF{n-Zcf>;b4YGkr}s|XFS_M_!MieX%{AYBkH&nkhUuWsg;nN| zrB#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ONR ztDa*a*ZiKPS8sctVK3}04fi_~)>X*0CpV^bL_d9qayNO2_KiXTC|^@0S>R>$$`S`gQAbR$|>o`wTPb~t~^XQ}3mnt{o`Cw8(9>bA;gkYg_2ng+1DB5A4(GI(1qJndVC-xnl&?owXZ+wMf z&cMAJzqHa5ULceT=!Een=EDw0zkIK+pO@%~>#p`xu$RKApnnG{Xh%qoI>up6jQehL zj}`Q2ghmN8N}z!faJD%O98!1k#n9Gaa#R(UZGbt&nw~`_&)&T+hYc5UOn5q4-@O-+Evy!u+!b4y|2tmUizo&_gYTvx(y_q z*XL>-COCTni3-N_Bkq)V5_!)kj*KD%7}vhsA1$;@`%7d%O}pX=yNh2LKF@u;E%-$o zfjRIE{b9R_ElbWd>%V&R;Jc$9v@S!tQN9!HYW!(#ue>TZ&qk-kRs7d4I?V_1XExUu z!WX06;A%YLM~qM9!YHKiM$&dQepZ{eypUVfYXB=l)TYL!8J+2sU>!A!b3j$yen_My zeB))(*~?&4Se9~YAml3%27vt@)^^L7cC-JHd|yx{Yjf9 ze)^-+n=E6nuc7ju&nhI8e5e{zQtE;ZBpVzaI^mVjOIJI!o|xVt_Vw9r_Br*Y`wrY! zi2DxMJ@^j&-G=%}LA)v7W9m7_cNp$-aHk~hr$UGp?v+G-(!-?zr<1;uVa zZAf&JlRjx`ec;Un_T`cB2frCn9jKS1o?jtHBRd2+7Iso;OY{IO%`Y`Tj_@;ZSMW1Q zCyuP2ey0B)dklJTBF%SeAJ8)LJ!n_`OgcX~4yqejQCD`pGP|NX{De7DA*HZwbgEsA tPpwG*9mW^%9RxpRv^!mm7k*0Ok^}!nyQseLWqds5H`1!R@$U01{{rG${@?%r literal 0 HcmV?d00001 diff --git a/corpus/icloud-merge/older-build-merges/clean-version.one b/corpus/icloud-merge/older-build-merges/clean-version.one new file mode 100644 index 0000000000000000000000000000000000000000..16efd99431d7af86a04bb56ddbb64bcf76cea742 GIT binary patch literal 9544 zcmeHN3s98T6~4>MMN!uX0c96{kQk%Jt|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5gebmNun7&ppaVw}g5 zY2vtV!GMAH>MWi^Jn2#}kul6Sy6s)fS7Nm3%uSWiZR=?MwVdWrSie@N5-KpVen<1u VnqBW9*Q)o(&TAVXy!I literal 0 HcmV?d00001 diff --git a/crates/notebook/README.md b/crates/notebook/README.md index f0c0ab0c7fa80cd305bc6950ce8598904b587e70..1ec9013b7161e1b699475e071ee9f4e9bd75754f 100644 --- a/crates/notebook/README.md +++ b/crates/notebook/README.md @@ -149,10 +149,12 @@ stops at a checkpoint) the newest of the file's the version holds; the section o revisions (`onestore::Section::open_at`) is the base the version's changes lower from (`lower_page`), and they replay on the file through the rebase rules above, conflict pages where they clash. A page whose two copies share no revision stays the file's, the version's kept -beside it as a conflict page (`corpus/icloud-merge/first-edit-checkpoints`). The revisions the merge writes are named after the version's it merged -(`Section::seal_as`), so a version merged once, here or on another device, merges as nothing -again. It is published on the file's stamp, then retired; one of another section, or one that -cannot be read, is retired with `keep` for the remote to keep beside the file. +beside it as a conflict page (`corpus/icloud-merge/first-edit-checkpoints`). The revisions the +merge writes are named after the version's it merged and the file's they depend on +(`Section::seal_as`), so a version merged once, here or on another device or by an older build, +merges as nothing again, and merges of one version onto different states never share a name. It +is published on the file's stamp, then retired; one of another section, or one that cannot be +read, is retired with `keep` for the remote to keep beside the file. A provider can also lose an upload outright, another device's landing over it with no version kept. A remote keeps what it publishes with `published::Published` (`keep` after each publication) and lists each image the file no longer stands as among its versions diff --git a/crates/notebook/src/resolve.rs b/crates/notebook/src/resolve.rs index 9de868cf0cb324a5de7bcbca0ad74d7e8de8f7b6..0e5677e25245d1e28fd97b5e995a451377813e63 100644 --- a/crates/notebook/src/resolve.rs +++ b/crates/notebook/src/resolve.rs @@ -4,11 +4,12 @@ //! (`merge.rs`), with conflict pages where they clash, as a queue replays on a changed //! remote. //! -//! Each revision the merge writes is named after the version's revision it merged -//! (`merged`). A space whose newest revision the file holds, or holds merged, needs nothing; -//! older ones are where the version and the file last agreed. So a version merged once, by -//! this device or another, merges as nothing the next time, and two devices merging it at -//! once write revisions of the same names, which the next merge of the two finds held. +//! Each revision the merge writes is named after the version's revision it merged and the +//! file's revision it merged onto (`merged`), and older builds' names (`named`) still count. +//! A space whose newest revision the file holds, or holds merged, needs nothing; older ones +//! are where the version and the file last agreed. So a version merged once, by this device or +//! another, merges as nothing the next time, and two devices merging it onto one state write +//! revisions of the same names, which the next merge of the two finds held. use crate::{PendingEdit, Result, merge}; use onestore::{ @@ -39,9 +40,9 @@ pub(crate) enum Merged { Foreign, } -/// The name of the revision a merge writes in a space for the version's revision `rid`, a -/// different one for each `kind` of space it writes. -fn merged(rid: ExGuid, kind: &str) -> ExGuid { +/// What older builds named a merge of the version's revision `rid`: the revisions it wrote +/// (`"page"`), and the conflict pages it made (`"conflict"`), which keep the name. +fn named(rid: ExGuid, kind: &str) -> ExGuid { let digest = Sha256::new() .chain_update(b"snowbound merge ") .chain_update(kind) @@ -53,6 +54,25 @@ fn merged(rid: ExGuid, kind: &str) -> ExGuid { ExGuid { guid, n: 1 } } +/// The name of the revision a merge writes for the version's revision `rid` onto the file's +/// revision `onto` of that space, which it depends on: two merges of one version onto +/// different states are different revisions. Onto no revision, as in a space the merge +/// creates, it is the name older builds gave. +fn merged(rid: ExGuid, onto: Option) -> ExGuid { + let mut digest = Sha256::new() + .chain_update(b"snowbound merge page") + .chain_update(rid.guid) + .chain_update(rid.n.to_le_bytes()); + if let Some(onto) = onto { + digest = digest + .chain_update(onto.guid) + .chain_update(onto.n.to_le_bytes()); + } + let mut guid = [0; 16]; + guid.copy_from_slice(&digest.finalize()[..16]); + ExGuid { guid, n: 1 } +} + /// Merges `version` into `current`, the file as it stands, `device` naming who saved the /// version. pub(crate) fn merge(current: &[u8], version: &[u8], device: &str) -> Result { @@ -79,18 +99,16 @@ pub(crate) fn merge(current: &[u8], version: &[u8], device: &str) -> Result Result = changed .iter() - .filter_map(|space| Some((*space, merged(head(space)?, "page")))) + .filter_map(|space| Some((*space, merged(head(space)?, onto(space))))) .collect(); for (space, objects) in &clashes { let Ok(page) = theirs.page(*space) else { @@ -264,7 +286,7 @@ pub(crate) fn merge(current: &[u8], version: &[u8], device: &str) -> Result Result Merged::Publish(Box::new(transaction)), diff --git a/crates/notebook/tests/cloud.rs b/crates/notebook/tests/cloud.rs index 44644a521cc46b685a3132bd459ea4363163e8cd..f27cdf31113c5c46202584a24426b7e92936f8f1 100644 --- a/crates/notebook/tests/cloud.rs +++ b/crates/notebook/tests/cloud.rs @@ -1206,3 +1206,102 @@ fn a_page_past_the_chain_cap_on_one_device_merges_as_edits() { ); } } + +/// Two devices merge one version onto different states of a page, then their results meet: +/// each merge is its own revision, so neither device's typing is taken as held by the other +/// (sweep seed 600). The version's own typing, merged on both sides, may show twice: the limit +/// on integrations from opposite bases in `arc/sync.md`. +#[test] +fn merges_of_one_version_onto_different_states_keep_both() { + let source = fixture(); + let arena = onestore::Arena::default(); + let mut section = Section::open(&arena, source.clone()).unwrap(); + let space = section.pages().unwrap()[0].0; + let (text, body) = bodies(§ion.page(space).unwrap())[0].clone(); + let end = body.encode_utf16().count() as u32; + let typed = |at: u32, with: &str| { + let arena = onestore::Arena::default(); + let mut section = Section::open(&arena, source.clone()).unwrap(); + let op = PageOp::Text { + text, + range: at..at, + with: with.into(), + }; + edit(&mut section, "Device", vec![Op::Page { space, op }]); + section.seal().unwrap(); + section.image() + }; + let (a, b, c) = (typed(0, "⟨A⟩"), typed(end, "⟨B⟩"), typed(4, "⟨C⟩")); + let onto_a = merged(&[a, c.clone()], 0); + let onto_b = merged(&[b, c], 0); + for winner in 0..2 { + let image = merged(&[onto_a.clone(), onto_b.clone()], winner); + let (listed, conflicts) = texts_of(&image); + for (token, shown) in [("⟨A⟩", 1..=1), ("⟨B⟩", 1..=1), ("⟨C⟩", 1..=2)] { + let count = listed.matches(token).count(); + assert!(shown.contains(&count), "{winner} {token}:\n{listed}"); + } + assert!(conflicts.is_empty(), "{winner}: {conflicts}"); + } +} + +/// A version an older build merged, under the names it gave merges, merges as nothing again: +/// neither its clean merge nor its conflict page comes back +/// (`corpus/icloud-merge/older-build-merges`). +#[test] +fn a_version_an_older_build_merged_merges_as_nothing() { + let row = format!( + "{}/../../corpus/icloud-merge/older-build-merges", + env!("CARGO_MANIFEST_DIR") + ); + for name in ["clean", "clash"] { + let read = |kind: &str| std::fs::read(format!("{row}/{name}-{kind}.one")).unwrap(); + let file = read("merged"); + assert!( + merged(&[file.clone(), read("version")], 0) == file, + "{name}" + ); + } +} + +/// A merge of a merge onto the same state is a revision of its own: Z's version merged into X's +/// file, that file merged into W's on X's state, and W's file merged back into Z's copy keeps +/// X's typing. Z's own, merged on both sides, may show twice, as in the sweep's duplicates. +#[test] +fn a_merge_merged_again_onto_the_same_state_is_its_own_revision() { + let source = fixture(); + let arena = onestore::Arena::default(); + let mut section = Section::open(&arena, source.clone()).unwrap(); + let pages = section.pages().unwrap(); + let space = pages[0].0; + let (text, words) = bodies(§ion.page(space).unwrap())[0].clone(); + let end = words.encode_utf16().count() as u32; + let typed = |image: Vec, space, text, at: u32, with: &str| { + let op = PageOp::Text { + text, + range: at..at, + with: with.into(), + }; + let arena = onestore::Arena::default(); + let mut section = Section::open(&arena, image).unwrap(); + edit(&mut section, "Device", vec![Op::Page { space, op }]); + section.seal().unwrap(); + section.image() + }; + let x = typed(source.clone(), space, text, end, "⟨X⟩"); + let z = typed(source.clone(), space, text, 0, "⟨Z⟩"); + let onto_x = merged(&[x.clone(), z.clone()], 0); + let other = pages[1].0; + let (text, _) = bodies(§ion.page(other).unwrap())[0].clone(); + let w = typed(x, other, text, 0, "⟨W⟩"); + let onto_w = merged(&[w, onto_x], 0); + let image = merged(&[z, onto_w], 0); + let (listed, conflicts) = texts_of(&image); + for (token, shown) in [("⟨X⟩", 1..=1), ("⟨W⟩", 1..=1), ("⟨Z⟩", 1..=2)] { + let count = listed.matches(token).count(); + assert!( + shown.contains(&count), + "{token}:\n{listed}\n--\n{conflicts}" + ); + } +} diff --git a/crates/onestore/src/section.rs b/crates/onestore/src/section.rs index c3168ddc4d7dd3f5818c7db06652ead131360a32..c90684622767dcfec1b0e5bdd9c55ff21d023d10 100644 --- a/crates/onestore/src/section.rs +++ b/crates/onestore/src/section.rs @@ -820,17 +820,20 @@ impl<'a> Section<'a> { /// merged, so that the next merge knows it holds that. pub fn seal_as(&mut self, names: &BTreeMap) -> Result> { self.usable()?; - if names.iter().any(|(space, name)| { - name.guid == [0; 16] - || self - .spaces - .get(space) - .is_some_and(|stored| stored.rid == Some(*name)) - }) { - return Err(Error { - offset: 0, - message: "Name each revision anew", - }); + if !names.is_empty() { + let image = self.image(); + let store = Store::parse(&image)?; + let index = RevisionIndex::parse(&store)?; + if names.iter().any(|(space, name)| { + name.guid == [0; 16] + || (index.spaces.get(space)) + .is_some_and(|stored| stored.revisions.contains_key(name)) + }) { + return Err(Error { + offset: 0, + message: "Name each revision anew", + }); + } } self.broken = true; let arena = &self.arena.0; -- 2.54.1