Repository navigation
Description
Proposal
On a graph that is not synced (:logseq.kv/graph-remote? unset), undo and redo could replay DataScript's own record of each change: the tx report's :tx-data, each datom flipped and in reverse order for undo, as recorded for redo, with the worker pipeline's extra derivation off. Nothing can happen between a change and its undo on such a graph, so this restores the exact previous state for every operation kind, with no per-operation inverse to maintain. Synced graphs keep the current path.
Why
Today undo builds an inverse operation per operation kind (build-inverse-* in construct.cljc), for the sake of rebase (ADR 0011). On a graph that never syncs, those inverses are the only source of undo bugs. A property-based test of random outliner operations with undo and redo found them, all single-user: the ones fixed in logseq/logseq#13444 and logseq/logseq#13458, and the ones reported as #1296 to logseq/logseq#1300, logseq/logseq#1302, logseq/logseq#1304 to logseq/logseq#1306 and logseq/logseq#1309. The test is logseq/logseq#13461.
The stored datoms of a change are not an exact record either. They mix levels: single facts next to :db/retractEntity of whole entities, which makes their replay depend on order. The same was true of undo before ADR 0011: get-reversed-datoms grouped the recorded datoms by entity (group-by :e) and emitted [:db/retractEntity e] for deleted entities next to the other entities' facts.
Example
Block "Buy milk" has the text property note "2 liters". Delete the property note. DataScript's record of the change is 14 datoms, all single facts:
[:db/retract "Buy milk" :user.property/note "2 liters"]
[:db/retract "note" :block/created-at ...]
[:db/retract "note" :block/name "note"]
;; ... every datom of the property entity ...
[:db/retract "note" :db/ident :user.property/note]
[:db/retract "2 liters" :logseq.property/created-from-property "note"]The client-op row stores:
[:db/retract "Buy milk" :user.property/note "2 liters"]
[:db/retractEntity "note"]The second record lists a whole (delete the property entity) next to one of its parts (remove its value from a block). The 2 steps do not commute, and the record's order is set by the rewriting (remove-conflict-datoms groups datoms with group-by; reorder-retract-entity moves entity retractions), not by DataScript. A prototype that replayed the stored rows on local graphs hit a wrong order on redo of a property delete, and needed 2 workarounds (pipeline derivation off, properties retracted last), each with a regression test that fails without it. The tx report's datoms are one level, in the order DataScript applied them, so their replay needs no reordering.
Evidence
- The prototype (stored rows, with the 2 workarounds) takes the property test from 16 kinds of undo/redo failure on master to 0 on a local graph, 300 sequences, with 3 rounds of undo-all and redo-all; the whole unit suite passed apart from 1 CPU-time bound in
search-testthat passed on rerun (#13446). A version that replays the tx report's datoms is not built yet; a PR follows. - The undo-stack cap bug found along the way is a separate PR.
Activity
yuxi-liu-wired commentedon Oct 27, 2026
An inventory of the open undo/redo issues on graphs without sync, checked against current master (d06ded9971). Each comes from the same place: the inverse is rebuilt from the operation (
deps/outliner/src/logseq/outliner/op/construct.cljc) instead of from the datoms the transaction changed, so whatever the operation did beyond its own entity is not undone. Replaying DataScript's record of each change, as proposed here, restores all of these at once.db-refs->page); the inverse restores the tag, not those titles or:block/refs[[Movie]]) instead of the stored[[uuid]]:logseq.property.view/group-by-propertyon views:logseq.property.class/properties)ns/childcreates two pages; the op finds neither by title, so redo makes new uuidsThe two offline-undo issues (#1314, #1315) belong to the synced case and are listed on #1337.
Every one of these is a fix to one inverse builder, and the next side effect added to an operation will need another. With the transaction's own datoms as the undo record, none of them needs its own fix. The no-sync implementation is in logseq/logseq#13786 (
frontend.worker.undo-redo).