From 696a55d42b5d6a7b1fb53dfe6c888b41bc5cd421 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 17 Nov 2026 02:23:17 +0000 Subject: sync: ask for what changes waiting in screening lack Screening keeps a change whose dependencies haven't come from Automerge, waiting, so Automerge never learns what it lacks: our next message asks for the peer's heads alone, and the peer, forgetting having sent those, sends them again, and what they build on only as far as it still counts it as sent. So the session asks for what changes waiting build on and the document lacks too (`Waiting::lacking`, `SyncSession::lacks`), as Automerge asks for what the changes it holds back lack. --- src/access/screen.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/access') diff --git a/src/access/screen.rs b/src/access/screen.rs index b6fb8fd..e37f2b9 100644 --- a/src/access/screen.rs +++ b/src/access/screen.rs @@ -283,6 +283,21 @@ impl Waiting { self.0.len() } + /// What the changes waiting build on that `doc` lacks, but for those waiting + /// themselves: what to ask the peers for (`SyncSession::lacks`). + pub(crate) fn lacking(&self, doc: &Document) -> Vec { + let waiting: HashSet = self.0.iter().map(Change::hash).collect(); + let mut lacking: Vec = self + .0 + .iter() + .flat_map(|change| change.deps().iter().copied()) + .filter(|dep| !waiting.contains(dep) && !crate::document::changes::holds(doc, dep)) + .collect(); + lacking.sort_unstable(); + lacking.dedup(); + lacking + } + /// The changes waiting, oldest first. #[cfg(test)] pub(crate) fn changes(&self) -> &[Change] { @@ -1460,6 +1475,7 @@ mod tests { let screened = screen(&mut ours, last, &mut waiting); assert_eq!(screened.applied, 0); assert_eq!(waiting.len(), 1); + assert_eq!(waiting.lacking(&ours), middle, "what it lacks, to ask for"); // The rest: all in, the waiting one too. let screened = screen(&mut ours, received(&theirs, &[]), &mut waiting); assert_eq!(screened.applied, 4); -- cgit v1.3.1