Skip to content

Undo under sync follows neither consistent approach, nor ADR 0011 #1337

Open

Description

@yuxi-liu-wired

Summary

When 2 people edit one graph, undo can mean 2 consistent things, and ADR 0011 picks one of them. The code does neither: depending on the case it overwrites the other person's change, undoes an older unrelated change, or empties the undo history. An interactive page walks through 12 journeys, measured on master 16c4ed1a0, with both consistent approaches next to what Logseq does:

https://logseq-undo-journeys.netlify.app

The problem has no free answer

For 1 user, undo takes back the last change. With 2 users the log reads Alice's change a1, Bob's change b1, then Alice's undo u. Undoing a1 while keeping b1 has a single meaning only when a1 and b1 commute.

  • Dolan, "The Only Undoable CRDTs are Counters" (PODC 2020, arXiv 2006.10494): if every pair of concurrent operations commutes and every operation can be undone back to the exact previous state, the data type is equivalent to a tuple of counters. Anything richer, such as an outline, must give up exact undo somewhere.
  • Stewen and Kleppmann, "Undo and Redo Support for Replicated Registers" (PaPoC 2024, arXiv 2404.11308) tested 6 mainstream apps. Google Sheets, Google Slides, Excel Online, PowerPoint Online and Figma undo the user's own last change, "thereby possibly also undoing the effects of operations by other users". Miro "blocks undo every time an operation by another user on the same register is received".

So there are 2 consistent approaches when a1 and b1 do not commute:

  1. The Google approach: restore the state before a1; b1's overlapping effect is lost.
  2. The Miro / ADR 0011 approach: refuse the undo. ADR 0011 line 300: "The design should allow semantic replay when the attrs commute and reject it when they do not." Line 297: "A remote title update on an unrelated block should not invalidate a local undo stack entry."

What the code does

  1. Undoes an older, unrelated change instead. When the undo of a1 fails, skip-op-and-recur (src/main/frontend/worker/undo_redo.cljs:231) pops it and undoes the entry before it in the same keypress. Journeys 1, 3, 5, 10 (confirmed): Alice's earlier edit on another page is reverted, and the history is emptied.
  2. Overwrites the other person's change. Journey 8 (confirmed): Alice renames a block, Bob renames it again, Alice's undo restores her old title over Bob's. That is the Google approach, against ADR 0011.
  3. Empties the whole undo history on every sync that lands while the user has unconfirmed changes: the finally of the rebase calls clear-history! (src/main/frontend/worker/sync/apply_txs.cljs:1767). Every unconfirmed journey shows it.

It also fails where nothing needs to commute. An undo that is still unconfirmed when the other change arrives sits right after its change in the server order, yet it is replayed from its recorded label and lands wrong or is dropped (#1313, logseq/logseq#1314, logseq/logseq#1315; journeys 1, 7, 8, 9 unconfirmed). Journeys 1 and 3 fail with Alice's change confirmed even though the 2 changes commute.

Counts

23 journey runs: 13 end the same as both approaches, 9 match neither, 1 matches the Google approach against ADR 0011. All 46 runs (both undo methods) ended with the client equal to the server.

Why

The unit of change is the operation label (#13464): from [:move-blocks ...] or [:delete-page ...] the code can compute neither the exact inverse of a change nor whether 2 changes commute, so ADR 0011's rule cannot be evaluated, and the behavior at the boundary is set by whichever path fails. #1339 proposes the database's own record for graphs without sync, where the inverse is exact by construction. For synced graphs, a rule that follows ADR 0011 could be: undo from the recorded facts of the change when no remote change since touched the same entities; otherwise refuse with a notice, leave the history intact, and never undo a different entry.

Reproducing

The page, its data and the test are in webdev-experiments/logseq-undo-journeys. The test (undo_sync_journey_test.cljs) runs Alice's worker with its undo history, Bob on a server copy, and moves changes through apply-remote-tx! and apply-tx-entry!.

Activity

  1. transferred this issue fromlogseq/logseqon Sep 27, 2026
  2. yuxi-liu-wired commented on Oct 27, 2026

    @yuxi-liu-wired
    Author

    Two open issues about undo made offline, checked against current master (d06ded9971), both from the op replay this issue describes:

    Thirteen more on graphs without sync, all from inverses rebuilt from the operation rather than from the transaction, are listed on #1339.

  3. TheSnakePolyglot commented on Oct 27, 2026

    @TheSnakePolyglot

    Interesting distributed systems issue you encountered

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions