Sync: a local-win snapshot read before the batch reverts incoming edits the time fold hoists ahead of it

Author: johannesjoCreated Oct 1, 2026Updated Oct 1, 2026

Follow-up to #10415 (residual 2) and #10393. Related: #10379, #10398 (where the fold-and-hoist was added), #10381.

Problem

A local win against a remote LWW row is resolved with a whole-entity 'replace' snapshot. That snapshot is read from the store before the batch is applied (_createLocalWinUpdateOp → getCurrentEntityState, conflict-resolution.service.ts).

buildTimeAwareResolutionBatches (fold-sync-time-spent.util.ts) then does two things:

  • It folds incoming time ops into that snapshot.
  • It hoists the incoming prefix up to the last folded op ahead of the snapshot (precedingOps = nonConflictingOps.slice(0, lastFoldedIndex + 1)).

Incoming plain field edits are overlaid onto the snapshot. An incoming op that touches the task but is not a plain edit, such as a doneTask toggle, makes foldFieldOps give up (if (!changes) return op;). The stale snapshot is kept, now ordered after that toggle:

  • Live state keeps the toggle.
  • Status-blind replay and the other devices apply the snapshot last and revert it.

Since #10415, a local syncTimeSpent delta that sits beside a field patch stays pending and uploads on its own. So a third device's local-win fold reaches this shape more often.

Reproduction

This is a pinned failing fuzz trace in sync-fuzz-pinned-traces.json: "a done toggle hoisted ahead of a stale local-win snapshot changes on restart".

json
[{"d":"A","a":["editTaskNotes","t1","A14"]},{"d":"C","a":["editTaskNotes","t1","C17"]},{"d":"A","a":["track","t1",2000]},{"d":"C","a":["doneTask","t1",true],"s":1},{"d":"B","a":["track","t1",3000]}]

Signatures:

  • primary: restart-changed:.task.entities.*.isDone
  • also: divergence of isDone, doneOn and notes; field-reverted:task.isDone; field-unwritten:task.notes; restart-changed of doneOn and notes.

The hoisted edits are incoming ops (C's doneTask), not the resolving device's own. On master (3d4c941) the shrunk seed tasks:20725005 loses the toggle on every device and also loses time. With #10415 the time survives, but the toggle diverges and a restart changes it.

Proposed direction (not decided)

  1. Time-only local side: in this trace the local side is only a delta. Extend #10415's time rule to resolution rows. A winning local syncTimeSpent stays pending and is rebased past the row, with no snapshot, so nothing is folded or hoisted.
  2. Local side with absolute fields: emit a field patch built from post-batch state instead of a pre-batch replace snapshot. This is also what would let #10415's remote-win patch carry the loser's own timestamp (see the follow-up on per-field winners).

Risks to cover:

  • Ordering: the batch is appended atomically. Post-batch state means projecting the prefix, not applying it live.
  • Replay determinism: doneOn must travel beside isDone.
  • Server acceptance: the patch's clock must dominate the row, without merging the clocks of edits laid over it (see the #10398 caveat in foldFieldOps).
  • Released clients: v18.15.0 and v19.1.0 apply 'patch' via updateOne. v18.15–v18.21 ignore clearedFields.
  • v19.1.0 resolvers: they still emit replace rows. A patch that loses to one no longer overwrites that row's stale fields.

Needs an E2E reproduction first (rule: reproduce first), covering both directions.

Source: super-productivity/super-productivity