Skip to content

fix(db): sync checksum and local graphs, page and tag names, orphaned pages, tag deletion, recycled values, and unreachable code - #13786

Open
yuxi-liu-wired wants to merge 41 commits into
logseq:masterfrom
yuxi-liu-wired:fix/db-page-delete-combined
Open

yuxi-liu-wired wants to merge 41 commits into
logseq:masterfrom
yuxi-liu-wired:fix/db-page-delete-combined

Conversation

@yuxi-liu-wired

@yuxi-liu-wired yuxi-liu-wired commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

This PR combines #13545, #13620, #13626, #13675, #13686, #13728, #13739, which change the same files, into one branch on current master so they no longer conflict with each other. Each part is unchanged except where two of them touched the same lines.


#13545: perf(sync): cheaper checksum; undo and no sync rows on local graphs

This brings #13469, #13470, #13466 and #13478 into 1 pull request, so they merge once. They share test files (db_sync_test.cljs, db_sync_sim_test.cljs, undo_redo_test.cljs) and the undo and pipeline code, so each merge made the others conflict. The branch is on current master. Each part keeps its own commits, changed only where a test conflict had to be resolved, so the review can go commit by commit. The old pull requests are closed with a link here; their review threads stay there.

Commits, in order:

  1. test(sync): pin recompute-checksum to a reference (perf(sync): recompute the checksum in 1 walk of :eavt #13469)
  2. test(sync): give the uuid churn test a real tx id (perf(sync): recompute the checksum in 1 walk of :eavt #13469)
  3. perf(sync): read each entity's datoms once (perf(sync): recompute the checksum in 1 walk of :eavt #13469)
  4. perf(sync): read parent and page uuids from a map (perf(sync): recompute the checksum in 1 walk of :eavt #13469)
  5. perf(sync): walk :eavt once for the full recompute (perf(sync): recompute the checksum in 1 walk of :eavt #13469)
  6. perf(sync): write the checksum in 1 transaction (perf(sync): write the checksum in 1 transaction #13470)
  7. fix(undo): replay the tx datoms on local graphs (fix(undo): replay the tx datoms on local graphs #13466)
  8. perf(sync): keep no sync record on local graphs (perf(sync): keep no sync record on local graphs #13478)
  9. test(sync): fit the checksum tests to local graphs, new: with perf(sync): keep no sync record on local graphs #13478 every graph of the sync tests is marked synced unless it asks to stay local, so the checksum tests of graphs that do not sync (from perf(sync): keep checksum only on remote graphs #13476) ask for a local graph, and the reopen test of fix(db): restore :max-tx of pipeline transactions #13468 opens its reopened graph as a local one, since it is marked synced already through its storage.
  10. test(undo): run the cardinality undo tests synced, new: the 2 tests of fix(outliner): do not revert many to one on undo #13526 check the inverse op of a one-to-many property change, which after fix(undo): replay the tx datoms on local graphs #13466 runs only on a synced graph.

Undo of a one-to-many change on a local graph

This is a behavior difference to decide on. #13526 keeps :db.cardinality/many when a one-to-many change is undone, so that the inverse op does not throw or clear the history. With #13466, undo on a graph that does not sync replays the change's recorded datoms instead of an inverse op: the undo gives the property :db.cardinality/one back, and the block its single value as it was, and redo makes it :many again with the value in a set. Nothing throws and the history stays. On a synced graph the undo goes through the inverse op of #13526 and keeps :many. In the run of #13526's 2 tests on a local graph with this branch, the failing assertions were exactly these, in each test: no inverse op, :one after undo, a single value after undo. In the first test the value's title was still "text 1" and the redo assertions passed; the second test has no redo. If :many should survive undo on local graphs as well, the replay would need an exception for this change.

Tests

The whole unit suite on commits 1 to 9 (master 68a68263b plus these commits), with the db-worker-node target compiled: at TZ=Etc/GMT+12 2585 tests, 12924 assertions; at TZ=Pacific/Kiritimati, the date-dependent namespaces, 1537 tests, 9433 assertions. The only failures were the 2 tests of #13526 described above (3 assertions each, in both zones). With commit 10, frontend.worker.undo-redo-test (62 tests), frontend.worker.db-sync-test (242) and frontend.worker.db-sync-sim-test (21) have 0 failures in both zones.

The descriptions of the parts follow, as each pull request had them.

#13469: perf(sync): recompute the checksum in 1 walk of :eavt

What changes

recompute-checksum (deps/db-sync/src/logseq/db_sync/checksum.cljs) computes the whole-graph sync checksum from scratch. The worker runs it when it opens a graph whose stored checksum does not cover the graph's :max-tx (#13415), before a snapshot upload, and for the checksum diagnostics; update-checksum runs it when the e2ee flag changes or the stored checksum is not valid. On a graph of 157,614 checksum-eligible entities (1,326,567 :eavt datoms, imported from a file graph), the release build took 3.39 s with the graph in memory and 5.83 s with its index nodes still in sqlite. This branch takes that to 0.25 s and 2.81 s, and the recompute returns the same value.

On master, for each entity in the :block/uuid index, the recompute ran 5 d/datoms lookups for the eligibility check, 2 more for the entity's uuid and datoms, and 1 per parent and page tuple for their uuids. It then built a set of [uuid attr value] tuples and a [fnv djb] vector per tuple and per digest step. A CPU profile of the in-memory recompute on master (release build, 1 run, 1 ms sampling, 3,509 ms window) has 1,633 ms in index seeks (-slice and its comparators), 419 ms in hashing and 381 ms in garbage collection.

The commits:

  1. test(sync): pin recompute-checksum to a reference: a reference recompute written from the definition in the test file, compared with recompute-checksum on 37 graphs (listed under Tests), and the value on 1 fixed graph pinned to the one master gives.
  2. test(sync): give the uuid churn test a real tx id: incremental-checksum-matches-recompute-with-duplicate-block-uuid-tx-churn-test gave its datoms tx 200, below datascript's tx0 (536870912). Such a datom is missed by (d/datoms db :eavt 3) and d/entity and returned by a walk of the whole :eavt index, so the test's outcome depended on which read each checksum path used. It now uses the next tx id, and passes on master.
  3. perf(sync): read each entity's datoms once: 1 :eavt read per entity answers the eligibility check and gives the tuples. The eligibility check of update-checksum reads the same way.
  4. perf(sync): read parent and page uuids from a map, filled by 1 walk of the :block/uuid index.
  5. perf(sync): walk :eavt once for the full recompute: an entity's datoms are adjacent in :eavt, so 1 walk of the whole index reads each entity's eligibility and checksum datoms as it passes them, and folds each tuple's digest into 2 running sums, with the entity's uuid prefix folded once per entity. An entity still counts once per :block/uuid datom, as when the recompute walked that index. An entity with a repeated attribute goes through the tuple set as before, since 2 of its datoms can give the same tuple (2 parents with equal uuids).

Recompute time on that graph, standalone db worker, median (range) of 3 runs per build. Cold is the first recompute after the start, with every index node loaded from sqlite. Warm is the later recomputes of the same runs that loaded no index node, 4 to 6 values per build. Each build is the source tree of the commit named.

  • master (16c4ed1a0): release cold 5.83 s (5.42 - 6.59), warm 3.39 s (2.45 - 3.48); dev cold 6.70 s (6.56 - 7.66), warm 4.16 s (4.15 - 4.23).
  • commit 3: release cold 5.07 s (5.06 - 5.20), warm 2.66 s (2.19 - 3.16); dev cold 5.77 s (5.58 - 6.49), warm 2.65 s (2.58 - 4.24).
  • commit 4: release cold 4.56 s (4.56 - 5.09), warm 2.10 s (1.88 - 2.79); dev cold 4.98 s (4.39 - 5.29), warm 3.00 s (2.12 - 3.15).
  • the walk of commit 5 without the digest folding, an intermediate build that is not a commit here: release cold 3.50 s (3.00 - 4.16), warm 1.75 s (1.34 - 2.28); dev cold 3.97 s (3.74 - 4.21), warm 1.88 s (1.49 - 2.41).
  • commit 5, the head: release cold 2.81 s (1.91 - 3.02), warm 0.25 s (0.23 - 0.37); dev cold 2.83 s (1.96 - 2.94), warm 0.50 s (0.26 - 0.67).

Worker start on the graph as imported, which recomputes the checksum at start (fix/restore-max-tx removes that recompute), from the worker's first log line to its ready line, 3 runs per build: master release 5.75 s (5.61 - 7.22) and dev 7.90 s (7.00 - 8.24); this branch release 2.71 s (2.41 - 2.98) and dev 3.10 s (2.02 - 3.27). The cold recompute still loads the graph's 70,194 index nodes from sqlite, which this branch does not change.

Per transaction, update-checksum takes about the same time as on master (release build, median (range) of 3 runs): 0.12 ms (0.12 - 0.13) against 0.14 ms (0.11 - 0.14) on master for a 1-block save, 11.0 ms (10.9 - 11.2) against 10.9 ms (10.5 - 11.0) for a 200-block insert.

The value, on the same graph: every recompute of every build above gave 9b54a1fd6dc28b43, the value master gives. On the head's build that is 24 recomputes in 12 runs, dev and release. After 6 edits on that graph (save, insert, move and delete of 1 block, insert and delete of 200 blocks), the checksum the listener kept incrementally equals a full recompute in all 6 runs on the head's build.

Tests

  • logseq.db-sync.checksum-test, run from deps/db-sync since it reads its fixtures from there: 29 tests, 116 assertions, 0 failures on master's checksum.cljs with this branch's tests, and on commits 3, 4 and 5.
  • The reference test compares on 37 graphs: edge cases (tag-only pages, built-in true and false, a parent or page without a uuid, an entity with a uuid and nothing else), a graph whose datoms bypass cardinality and uniqueness (2 titles, 2 uuids, 2 parents with equal uuids, a shared uuid), the sample graph, the 2 fixture payloads before and after, and 29 generated graphs, e2ee on and off. With the tuple-set path of commit 5 turned off, it fails on the repeated-attribute graph and on 1 fixture graph, and incremental-checksum-matches-recompute-on-rebased-retract-entity-log-repro-test fails as well (3 failures).
  • The churn test with its old tx 200 fails on this branch (1 failure: full bb99d466953b7166 against incremental d74eeb69c5a85c5b). With the next tx id it passes on master and on this branch.
  • frontend.worker.db-sync-test 233 tests, 2222 assertions; frontend.worker.sync.client-op-test 6 tests, 22 assertions: 0 failures.
  • The whole unit suite at TZ=Etc/GMT+12 (2502 tests, 12497 assertions) and its time-zone-dependent namespaces at TZ=Pacific/Kiritimati (1469 tests, 9056 assertions): 0 failures, 0 errors. Its runner leaves out logseq.db-sync.*, hence the separate run above.
  • clj-kondo on the 2 changed files, run from deps/db-sync: 0 errors, 0 warnings.

#13470: perf(sync): write the checksum in 1 transaction

What changes

After every transaction, the db listener stores the new sync checksum and the tx it covers in the graph's client-ops database (update-local-checksum, src/main/frontend/worker/sync/client_op.cljs). The 2 keys went in 2 upserts, each its own sqlite autocommit. That database runs in WAL mode with synchronous FULL (read with PRAGMA synchronous on a graph's client-ops file), so each autocommit is a synced write. The 2 upserts now run in 1 transaction through sqlite-with-tx!, which the file already has, so each transaction pays 1 synced commit, and the 2 keys change together.

;; before
(sqlite-set-meta! store :db-sync/checksum checksum)
(sqlite-set-meta! store :db-sync/checksum-covered-tx covered-tx)
;; after
(sqlite-with-tx!
 store
 (fn [tx]
   (sqlite-set-meta! tx :db-sync/checksum checksum)
   (sqlite-set-meta! tx :db-sync/checksum-covered-tx covered-tx)))

In the node worker, sqlite-with-tx! calls the connection wrapper's transaction (wrap-node-sqlite-db in src/main/frontend/worker/platform/node.cljs), which runs the function between BEGIN and COMMIT.

Timings on a graph of 157,614 checksum-eligible entities (imported from a file graph), standalone db worker, median (range) of 3 runs per build:

  • The checksum write alone, 20 writes of changing values per run: master release 16.7 ms (14.0 - 17.0), dev 16.5 ms (15.5 - 17.2); with this change release 8.9 ms (8.8 - 10.5), dev 8.9 ms (8.5 - 11.2).
  • The listener's checksum stage per transaction (update-checksum plus the write), which the dev build logs, master against this change: 1-block insert 17.5 ms (17.0 - 17.8) against 10.0 ms (9.4 - 10.0), 1-block move 17.2 ms (16.4 - 25.0) against 9.2 ms (8.5 - 10.0), 1-block delete 17.2 ms (16.4 - 19.9) against 9.6 ms (9.2 - 10.3), 200-block insert 34.8 ms (33.7 - 36.6) against 28.2 ms (26.1 - 29.3), 200-block delete 33.1 ms (32.7 - 36.2) against 25.0 ms (24.6 - 27.4). The first transaction after the start, a 1-block save, takes 18.0 ms (17.2 - 24.0) on master and 17.7 ms (17.0 - 18.7) with this change.

The builds with this change also carried the commits of perf/checksum-one-walk and fix/restore-max-tx and 1 change to the sqlite read path. A build with the recompute changes and without this commit wrote in 16.8 ms (16.2 - 17.1) release and 17.2 ms (16.6 - 17.6) dev, 3 runs each, the same as master.

Tests

  • New checksum-and-covered-tx-written-in-1-transaction-test in frontend.worker.sync.client-op-test: counts the calls of the database's transaction during update-local-checksum and reads both keys back. On master it fails (1 failure: 0 calls). With this change it passes. The test's database is better-sqlite3 in memory, as in the rest of that namespace.
  • frontend.worker.sync.client-op-test 7 tests, 25 assertions; frontend.worker.db-sync-test 233 tests, 2222 assertions; logseq.db-sync.checksum-test (run from deps/db-sync) 28 tests, 78 assertions: 0 failures.
  • The whole unit suite at TZ=Etc/GMT+12 (2503 tests, 12500 assertions) and its time-zone-dependent namespaces at TZ=Pacific/Kiritimati (1469 tests, 9056 assertions): 0 failures, 0 errors.
  • clj-kondo on the 2 changed files: 0 errors, 0 warnings.

#13466: fix(undo): replay the tx datoms on local graphs

What changes

On a graph without sync, undo and redo now replay DataScript's own record of each change, as logseq/db-test#1339 proposes: the tx report's datoms, each flipped and last first for undo, as recorded for redo. Synced graphs keep the semantic inverse ops.

Today undo replays an inverse op built from the change's label (build-inverse-* in construct.cljc). Where an operation does more than its label says, undo loses the difference (#13464). Deleting a property or a tag is the clearest case. On a graph without sync (:logseq.kv/graph-remote? not set), nothing can land between a change and its undo, so the exact undo is the change's own datoms, reversed, whatever the operation.

It fixes, on graphs without sync:

Each has a regression test in frontend.worker.undo-redo-test that fails on master. It also fixes the 2 undo bugs the property test of #13461 found once it saw links:

How

  • gen-undo-ops! keeps, on a graph without sync, the tx report's datoms as [e a v added], entity ids unchanged, in DataScript's order (:tx-datoms of the entry). The report is the one ldb/transact! hands to its listeners, which already holds what the worker pipeline added in the same transaction (tag templates, refs, revision stamps). The datoms stay in memory with their entry, like the rest of the undo stack.
  • Undo transacts them flipped, last first; redo transacts them as recorded. The transaction carries the tx meta that apply-history-action! gives a history action, so the undo is recorded as a client-op row as before, plus :undo-redo/replay-tx-datoms?.
  • For that key, transact-pipeline derives nothing: the datoms already hold what it derived for the change. Without this, each redo of a block tagged with a class that has a template inserted the template again. ldb/transact! also skips expand-delete-blocks-tx and update-refs-history for it: the datoms are the whole change, and distinct in expand-delete-blocks-tx dropped a retraction that repeats after its opposite, which left a revision stamp on a deleted block.
  • The pipeline still stamps :block/tx-id on what an undo or redo changes, so the renderer refreshes those blocks. The entry pushed on the opposite stack therefore holds the undo's or redo's own datoms, stamps included, and the next undo or redo is again the exact inverse of the last transaction.
  • A retraction of :block/tx-id retracts the stamp whatever its value: the undo of a later change can restamp an entity of an earlier one (the pages tagged with a tag whose parent changed).
  • A replay that throws has changed nothing. The undo or redo is refused and the history is kept, instead of trying the entry below or clearing the history (ADR 0011: invalidate the whole action, not a part of it).
  • The graph flag is read when the user undoes, so a graph uploaded mid-session takes the semantic ops for its older entries.

Builds on #13462

The first commit of this branch is #13462's. Without it a full undo stack (250 entries) drops its newest half, so the datoms of the entries below the hole no longer match the graph, and a replay that yields an invalid entity is refused. all-core-outliner-ops-local-undo-redo-random-sim-test (1000 operations on a graph without sync) then fails with "undo-all exceeded max steps".

Tests

#13478: perf(sync): keep no sync record on local graphs

What changes

This builds on #13466 and is stacked on its branch.

After every local transaction, the db listener stores the change as a client-op row: its normalized and reversed datoms, its forward and inverse outliner ops, pending (persist-local-tx! in src/main/frontend/worker/sync/apply_txs.cljs). That is 1 synced sqlite commit per edit, on every graph. With #13466, undo and redo on a graph without sync (:logseq.kv/graph-remote? not true) replay the tx datoms the undo entry keeps, and on such a graph nothing reads the row any more. Every reader of these rows:

  • The undo entry reads its own row back for the semantic ops (gen-undo-ops!, through history-action-ops-by-tx-id), and apply-history-action! reads a row by tx id for the semantic undo and redo. On a graph without sync, fix(undo): replay the tx datoms on local graphs #13466's undo and redo replay the entry's datoms and use neither.
  • The upload of pending rows (flush-pending!), the rebase of pending rows under remote txs (apply-remote-txs!), the rollback after a reject (rollback-and-mark-failed-txs!) and the acks (mark-pending-txs-false!) run only on a sync connection.
  • A graph's first upload (upload-graph! in sync/upload.cljs) sends a snapshot of the whole graph, then marks every pending row done without sending it (clear-pending-txs!).
  • The rest count or show them: the pending count in the sync status (db-sync-status, which the CLI's sync status prints, and the sync indicator of a live connection), the cleanup every 3 hours (cleanup-finished-history-ops!, which deletes only rows with pending 0, so on a graph that never synced it deletes none), and the client-ops export for debugging.

Today a graph without sync keeps 1 row per edit, forever. On a new graph after the 2 sessions measured below (180 measured edits and their setup): 194 rows, all pending, holding 0.79 MB (insert 2.5 KB, delete 1.7 KB, save 1.6 KB per row; the first row, 413 KB, is the new graph's initial data), in a 1.0 MB file.

With this change, a local transaction on a graph that is not remote after it, the transactions of undo and redo included, gets its undo entry where it makes one and nothing in the client-ops database: no reversed datoms, no derived outliner ops, no row, no pending count. gen-undo-ops! reads no row there; the entry keeps :tx-datoms as in #13466. On a remote graph the path is as before. The condition is the one handle-local-tx! had from de1c58b (rows only on remote graphs) until c3df967, "fix: undo/redo doesn't work for local graphs", which dropped it when undo came to read the row.

A graph uploaded in the middle of a session holds undo entries recorded without rows. On a synced graph undo takes an entry's ops from its row, and without the row apply-history-action! returns :missing-history-action, which logs an error and clears the history at that undo. The transaction that makes a graph remote (the upload's set-graph-sync-metadata!) now clears the undo and redo history in handle-local-tx!, so the history ends at the upload instead of at the first undo after it. ADR 0011 makes the client-op row the source of truth for DB undo history, which it still is on a synced graph, and asks that a stack entry whose row is dropped be invalidated rather than left dangling; the stacks already end at a restart ("Session boundary"). This replaces #13466's rule that entries recorded before an upload take the semantic ops (their rows existed then). Keeping the datom replay for those entries after the upload would record each such undo on the synced graph as a row of datoms without semantic ops, the raw undo row that ADR 0011 moves away from.

Rows written before this change on a graph without sync are left as they are, pending: nothing here deletes them, and the status keeps counting them. The first upload marks them done as today, and the cleanup then deletes them.

A graph syncs once it has the flag or a remote graph id in its client-ops database (local-graph? in undo_redo.cljs reads both). start! can connect sync to a graph without the flag when a remote graph has the same name (<resolve-start-graph-id), and records that graph's id; a graph downloaded before 4ce4aed ("download remote graph should set sync metadata too") has the id and no flag. Both keep their rows as before. The history ends only when the flag is set, at an upload or download.

On a graph without sync the listener builds no upload data: the normalized and reversed datoms are computed only on the synced path. A transaction of attributes sync ignores still makes no undo entry, as before.

Measured on the desktop app, release builds of #13466 (a61ab13b5) and this branch, a new graph without sync each, 2 sessions of 30 cycles per build (the order #13466, this branch, this branch, #13466), median (range) over the 60, key to the next editor focused (delete) or to the editor gone (save):

  • 1-block delete: 92.4 ms (78.2 - 161.0) on fix(undo): replay the tx datoms on local graphs #13466, 84.3 ms (70.1 - 162.2) with this change. Per session: 88.6 and 93.7 against 85.4 and 83.4.
  • 1-block save: 77.8 ms (68.9 - 120.5) against 71.3 ms (54.8 - 124.9). Per session: 77.3 and 79.7 against 71.9 and 71.3.
  • Disk syncs from the key to the end of the edit (an fsync logger preloaded into the app, the same count in 30 of 30 edits of each session): delete and save 5 to 4 (the client-ops database 3 to 2), insert 4 to 3. Sync time per delete, median: 49.6 and 49.7 ms against 43.0 and 43.0 ms.
  • On disk after the sessions: 194 rows on fix(undo): replay the tx datoms on local graphs #13466's graph, none on this branch's.
  • With perf(sync): keep checksum only on remote graphs #13476 (checksum only on graphs that sync) on both builds, 1 session each: delete 75.2 ms (56.4 - 132.4) against 65.3 ms (46.6 - 200.7), save 62.8 ms (52.0 - 96.4) against 53.1 ms (42.6 - 90.1). Syncs: delete and save 3 to 2, insert 2 to 1; a delete or save then syncs the graph and search databases and not the client-ops database.

Tests

  • New in frontend.worker.db-sync-test:
    • local-graph-edit-writes-no-sync-record-test: an edit on a graph without sync writes no row and no pending count; its undo entry holds :tx-datoms, and undo and redo restore the title and write no row either. On fix(undo): replay the tx datoms on local graphs #13466 it fails (4 failures: 1 row after the edit, pending count 1, 3 rows after the undo and redo).
    • local-graph-keeps-existing-sync-records-test: a pending row written before this change stays, pending, after an edit and a cleanup run, and no row joins it. On fix(undo): replay the tx datoms on local graphs #13466 it fails (3 failures: a second pending row).
    • upload-ends-undo-history-recorded-without-sync-record-test: 2 edits and an undo on a graph without sync, then upload-graph! with its network calls replaced, through the app's db listener: after the upload the undo and redo stacks are empty and undo changes nothing; an edit after the upload writes its row, and its undo goes through that row. On fix(undo): replay the tx datoms on local graphs #13466 it fails (6 failures: 3 rows before the upload, both stacks kept, and the undo after the upload undid an edit from before it).
    • remote-graph-edit-writes-sync-record-test: an edit on a remote graph writes its row with the semantic ops, and the undo entry takes them from it. Passes on fix(undo): replay the tx datoms on local graphs #13466 too.
    • graph-with-a-remote-id-writes-sync-records-test: a graph with a remote graph id and no flag (attached by name, or downloaded by an older version) writes its pending row and an entry without :tx-datoms.
    • local-graph-edit-builds-no-upload-data-test: an edit on a graph without sync calls no normalize-tx-data, and makes its undo entry.
  • Tests of synced paths now run on remote graphs, as those paths do in the app. In frontend.worker.db-sync-test, with-datascript-conns marks its graph remote (with this change and without that, 82 of its tests fail: they read the rows of edits made on graphs built without the flag), the 3 new tests of graphs without sync use with-local-graph-conns, and 3 tests that build their tx report before that helper mark the graph first. In frontend.worker.undo-redo-test, 7 tests of the semantic ops an entry takes from its row mark the graph synced. In frontend.worker.db-sync-sim-test, 5 client tests use create-synced-conn. fix(undo): replay the tx datoms on local graphs #13466's synced-graph-undo-replays-semantic-ops-test keeps its synced part; its part about entries recorded before an upload is replaced by the upload test above.
  • with-datascript-conns no longer resets the conns and the undo history when a later test has installed its own conn. In a run of the namespace, the cleanups of 8 async tests that call done before the helper's cleanup ran while a later test was running; the one of pull-ok-without-checksum-is-accepted-test emptied the client-ops conn in the middle of the new upload test, which passed when run alone.
  • The property test of test(undo): add outliner undo/redo property test #13461 (frontend.worker.outliner-undo-property-test from its branch, not in this pull request), on a graph without sync, its known-bug list off, every violation counted: seed 20260926, 300 sequences, 0 violations; seed 4242, 300 sequences of up to 20 operations, 0 violations. fix(undo): replay the tx datoms on local graphs #13466 gives the same 0 and 0 on the same runs.
  • In TZ=Etc/GMT+12 and TZ=Pacific/Kiritimati: frontend.worker.undo-redo-test 56 tests, 301 assertions; frontend.worker.db-sync-test 236 tests, 2255 assertions; frontend.worker.db-sync-sim-test 21 tests, 427 assertions; frontend.worker.sync.client-op-test 6 tests, 22 assertions; frontend.worker.db-listener-test 14 tests, 51 assertions; frontend.worker.pipeline-test 42 tests, 193 assertions; frontend.worker.db-core-test 147 tests, 1601 assertions; frontend.worker.db-worker-test, frontend.worker.sync.restart-test, frontend.undo-redo-test, frontend.handler.history-test: 0 failures, 0 errors.
  • The whole unit suite, 2 processes at a time, at TZ=Etc/GMT+12 (2520 tests, 12614 assertions) and its time-zone-dependent namespaces at TZ=Pacific/Kiritimati (1487 tests, 9173 assertions): 0 failures, 0 errors.
  • clj-kondo on the 5 changed files: 0 errors, 0 warnings.

Allow edits from maintainers.


Devin Review


#13620: fix(page): a namespace root and a page with no parent share one name space

Part of logseq/db-test#1346 (its second case; the first, a rename there and back being refused, no longer happens on master since #13516).

Create the page "Baz", then "Foo/Bar" (the Library now holds "Foo"). On the page "Foo", change the title to "Baz": it is accepted, and the graph has 2 top-level pages named "Baz", one of them in the Library. Renaming "Baz" to "Foo" is accepted the same way. Renaming any other page with no parent to "Baz" is refused, and Cmd+K on "Baz" opens the existing page.

validate-unique-for-page in deps/outliner/src/logseq/outliner/validate.cljs scopes the name check by the raw parent: a page with no parent is compared with other pages with no parent, a page with a parent only with its siblings. Top-level pages come in 2 kinds: a page created by name has no parent, a namespace root has the Library as its parent. So a namespace root and a page with no parent never meet in the check.

Both kinds now count as top-level: a page whose parent is the Library is compared with pages with no parent and pages under the Library, and the other way around. Pages inside a namespace keep being compared with their siblings only, so a top-level page may still share a name with a namespace child ("Baz" and "Foo/Baz").

New test rename-is-checked-among-top-level-pages in deps/outliner/test/logseq/outliner/page_test.cljs: a namespace root renamed to a top-level page's name and a top-level page renamed to a namespace root's name are refused (both accepted on master); a top-level page renamed to a namespace child's name and back, and siblings in a namespace, behave as before. The outliner tests in deps/outliner (158 tests) and frontend.handler.db-based.page-test, frontend.modules.outliner.pipeline-test, frontend.worker.undo-redo-test, frontend.worker.outliner-undo-property-test, frontend.worker.db-sync-test, frontend.worker.db-sync-sim-test (with its ^:long tests), frontend.worker.db-listener-test, logseq.api.editor-test pass.


#13626: fix(tag): creating a tag does not return a namespaced tag of that name (dropped from this branch)

Dropped: a namespace child tag ("Baz" in #Foo/Baz) is built with :logseq.property.class/extends Foo, the same link addTagExtends makes, so the data cannot tell "Baz inside Foo" from "a tag that extends Foo". This change left out every tag extending a tag other than Root Tag, which broke master's tag-inheritance-schema-and-object-view-test (clj-e2e graph-properties): #SampleChild in a block created a second SampleChild instead of tagging with the one extending SampleParent. db-test#1345's tag side needs a namespace marker on the tag before a fix can tell the two apart. Kept below for the record.

Part of logseq/db-test#1345 (the tag side; the page side is #13625).

Create the tag "#Foo/Baz", then the tag "#Baz": the second create returns Foo/Baz's "Baz" and no top-level tag "Baz" exists. In the other order, "#Baz" then "#Foo/Baz", both tags exist, and tags in different namespaces may share a name (db-test#466).

create in deps/outliner/src/logseq/outliner/page.cljs looks for an existing tag with ldb/page-exists? and #{:logseq.class/Tag}, which matches the exact title among all tags, whatever they extend, and returns the first. Pages are already checked for a parent before being reused.

When the title has no namespace, create of a tag now leaves out tags that extend a tag other than Root Tag, i.e. tags inside a namespace. A top-level tag with the title is still reused, and a create of a namespaced title goes through split-namespace-pages as before.

New test create-tag-does-not-return-a-namespaced-tag-of-that-name in deps/outliner/test/logseq/outliner/page_test.cljs: "Foo/Baz" then "Baz" as tags gives a new tag Baz extending Root Tag, and creating "Baz" again returns it. On master the second create returns Foo's Baz; with the change it passes. The outliner tests in deps/outliner (158 tests) and frontend.handler.common.page-test, frontend.handler.page-test, frontend.worker.handler.page-test, frontend.handler.db-based.page-test, frontend.components.cmdk-test, frontend.worker.undo-redo-test pass.


#13675: fix(db): an edit deletes the empty page it no longer references (reverted)

Reverted on 2026-11-12 (a1d33a7). Master's CLI E2E case block-update-page-refs (added 11-11) creates Alpha with upsert page, links and unlinks it from a block, and expects the same Alpha (same uuid) afterwards; with this change the unlink deleted Alpha and a later [[Alpha]] made a new page. Master's behaviour (a page is kept when nothing references it) wins, so the orphan check is master's again and orphaned_pages_test.cljs now pins that the empty page stays. Whether an implicitly created, still empty page should go when its last link is removed is a product decision; it would need to tell such a page apart from one created on its own. The lookup-ref fix below (1a9b69f) stays: it is correct on its own.

The original section:

Typing [[Brand new]] in a block creates the page "Brand new". Deleting that reference from the block again is meant to delete the page when it is empty and nothing else references it: save-block calls remove-orphaned-page-refs! for that. It never deletes anything.

ldb/get-orphaned-pages keeps a page that has (:block/properties page). In a DB graph, :block/properties (entity-plus/get-properties) lists every property attribute of the entity, and :block/tags is one: every page has the Page (or Journal) tag, so every page has properties and none ever qualifies.

The fix: only properties other than :block/tags keep a page.

Test: src/test/logseq/outliner/orphaned_pages_test.cljs. An edit from [[Kept]] [[Dropped]] to [[Kept]] deletes the empty page Dropped and keeps Kept (fails on master: Dropped stays); a page with a property (a checkbox set on it) is kept; a save without a title (collapsing the block) keeps the pages the block references, since the cleanup runs only when the title changes. The test is in the app's test build because the outliner library's nbb run does not compute :block/properties. The editor, undo/redo, page, outliner, pipeline and DB core test namespaces pass with the change.


#13686: fix(delete): deleting a tag page turns refs to it into its title, also next to refs to its blocks

Deleting a tag (or property) page leaves the deleted page's [[uuid]] in any block that references the page next to one of the page's own blocks. Example: a block says "see [[Foo]] and [[fb]]", where Foo is a tag and fb a block on Foo's page. After deleting the tag Foo, the block reads see [[<Foo's uuid>]] and fb: a reference to a node that no longer exists, instead of see Foo and fb.

Cause: outliner-page/delete! sends the page's ref rewrite (the block's title with [[Foo]] turned into "Foo") and the retracts in one transaction. ldb/transact! then appends delete-blocks/update-refs-history, which writes the same block's title again, computed from its title before the transaction with only the retracted blocks replaced (fb); pages are not block-entity?, so [[Foo]] stays. Two values for the cardinality-one :block/title in one transaction: the later one wins. When the block references only the page, both rewrites agree, which is why the common case works.

Fix: build-retracted-tx also turns refs to pages retracted in the same transaction into their titles, so its rewrite agrees with the page's own. Which entities count as blocks (for expanding a delete to children) is unchanged.

Test: logseq.outliner.delete-tag-page-refs-test (app test build: the title rewrite reads :block/raw-title, an entity-plus lookup nbb does not have) deletes a tag page with outliner-page/delete! and checks a block referencing the page and its block ("see Foo and fb") and a block referencing only the page ("see Foo"). On master it fails on the first; with the fix it passes. Also with the fix: logseq.db.common.delete-blocks-test, logseq.db-test (33 tests), logseq.outliner.page-test, logseq.outliner.property-test (56 tests) under nbb, and frontend.worker.pipeline-test (45 tests, including page deletes) in the app build: 0 failures. Lint as in CI for deps/db and the app.

Found by mutation testing: and to or in block-entity? made no existing test fail, and the changed version gave "see Foo and fb".


#13728: fix(property): leave recycled values out of a block's displayed properties

What goes wrong

Move a page to the Recycle bin while another page or block uses it as a node property value. The property area still shows that property with the recycled page as its value. When the recycled page is one of several values, it still appears among them. Recycled values are supposed to be left out of the property area, and a property whose only values are recycled is supposed to be hidden.

Cause

src/main/frontend/worker/handler/property.cljs, display-properties: for a stored block, display-properties-for-block reads each ref value as a summary map from plain-value/ref-value->summary. That map carries no :logseq.property/deleted-at and no parent. sanitize-property-values-for-display calls ldb/recycled? on the summary, so it never finds a recycled value.

Fix

Check whether a value is recycled on its entity, looked up by :db/id, in contains-recycled-entity-value? and filter-recycled-entity-values. A value without a :db/id is still checked as given.

Test

frontend.worker.handler.property-test/display-properties-of-a-stored-block-leaves-out-recycled-values recycles a page used as a single-value node property and as one of two values of a many-value node property. It expects the first property to be left out and the second to keep only the live value. Both assertions fail on master and pass with the fix.


#13739: chore: remove code that never runs or never changes a result

Removes code that never runs or never changes a result. Each removal is its own commit, with the reason in its message; behaviour is unchanged.

  • get-sql-rows (db-sync and publish copies): the (array? result) clause. Every JS array has Symbol.iterator, so the iterator clause before it always takes an array first.
  • search-fuzzy/score: a cond clause whose test repeats the clause before it.
  • worker get-all-properties: copying :logseq.property/deleted-at onto each result. Recycled properties (those with deleted-at) are removed first.
  • worker render-bottom-position-property?: node-many?. A :node property already passes (not= :default type) in the same or.
  • migrate ensure-built-in-data-exists!: the *uuids remap. It maps a uuid U to the uuid of the entity found by [:block/uuid U], which is U, so every lookup ref is rewritten to itself.
  • delete-blocks/build-retracted-tx: the unused 1-arity of this private fn.
  • frontend outliner.tree/blocks->vec-tree: the number and string root-id branches. Both callers pass a block uuid or nil.
  • outliner page/create: the convert-to-class branch. With class? the existing page is looked up among pages tagged Tag (or is a journal), so it is never a non-class internal page.
  • outliner build-property-value-tx-data: multiple-values-empty?. The block is an entity in every caller, and an entity's cardinality-many value is a set, never sequential.
  • apply-history-action!: the :unsupported-history-action branch after (seq ops'). ops' falls back to [[:transact ...]], so it is never empty.
  • logseq.db: *debounce-fn and register-debounce-fn!. The atom is read only inside a (comment ...) form.

Found by mutation testing (each was a surviving mutant: removing or changing it changed nothing any test could see), then checked against every caller on master.

fix(outliner): a built-in node refuses task properties with a message

Found by a local key fuzzer (it opened the built-in Page class through the search dialog and typed DONE ): setting a status, scheduled date or deadline also tags the node #Task when no class provides the property, but a built-in node keeps its one built-in tag, so validation rejected the write (should only have one tag for a built-in entity) and the user saw only the generic "DB write failed with invalid data". disallow-task-properties-on-built-in-nodes (validate.cljs) refuses those three properties on built-in nodes with a notification, "Built-in nodes can't be tasks.", from set-block-property! and batch-set-property!'s validation, next to the existing private built-in check; ordinary pages still become tasks.

New test logseq.outliner.property-test/task-properties-on-built-in-nodes: a status on the Page class through both setters is refused with the notification (before the change both failed with "DB write failed with invalid data") and leaves the class untouched; a plain page still becomes a task. The outliner library's suite passes.

fix(db): a deleted block no longer comes back from its batch

What happened. A key fuzzer sent one apply-outliner-ops call that moved three blocks into block X as its children, deleted X, then saved X (a Backspace merge whose previous block was X itself). The whole write failed with "DB write failed with invalid data": the three moved blocks were deleted with X, then came back as stubs holding only :block/order (with blocks moved in from beside X, also :block/parent), which fail validation.

Cause. apply-ops! runs the batch on a temporary conn and replays its datoms in one transact!. With :outliner-op :delete-blocks, which the editor sets on a Backspace merge, expand-delete-blocks-tx (deps/db/src/logseq/db/common/delete_blocks.cljs) ran distinct over that tx-data. DataScript datoms are equal when their e, a and v are equal, whatever added is. So when the move added a block's order and parent and the delete then retracted those same values, distinct dropped the retract as a duplicate of the add and kept the add.

Fix. expand-delete-blocks-tx keeps the tx-data as it is and dedupes only the subtree retracts it appends. After the batch, X and its whole subtree, including the moved blocks, are gone and the transaction is valid.

Tests. frontend.worker.pipeline-test/move-into-block-then-delete-it-does-not-resurrect-moved-blocks-test runs the fuzzer's batch through apply-ops! with the worker pipeline and {:outliner-op :delete-blocks}. It runs twice, once with the moved blocks as X's children and once with them as X's siblings. It checks that X and the moved blocks leave no datoms behind, that the block after X survives, and that validate-db finds no errors. Before the fix it fails with the same "invalid dispatch value" stubs the fuzzer reported.

fix(worker): property reads return nil before the graph is open

Right after a reload the renderer can call :thread-api/get-class-objects, :thread-api/get-property-values and :thread-api/get-bidirectional-properties before the worker has opened the graph. They deref the graph's nil conn and throw No protocol method IDeref.-deref defined for type null (found by a local key fuzzer that reloads mid-session). They now use the same when-let on the conn as the neighbouring read handlers in frontend.worker.handler.property and return nil until the graph is open. The same change for the read handlers in other files is #13862; property.cljs is already in this PR, so its part is here.

New test src/test/frontend/worker/handler/property_graph_not_open_test.cljs property-read-thread-apis-return-nil-before-graph-opens-test: calls the three for a repo with no conn; all three throw on master and return nil with the change.

fix(outliner): text for a number property is refused with a message

Setting a :number property to text that isn't a number through batch-set-property! (the value picker of the add-property dialog) went through convert-ref-property-value, where parse-double returned nil, and the write failed as Property value must be not nil: a raw worker error, nothing shown to the user. It now uses fail-parse-double, as convert-property-input-string already does, so the user gets "Can't convert "x" to a number." (:property.validation/cant-convert-to-number) and nothing is written. Found by a local key fuzzer that typed #status into a number property's value picker.

New test batch-set-property-refuses-a-value-it-cant-convert (deps/outliner/test/logseq/outliner/property_test.cljs): the write is refused with a notification and the block keeps no value; on master it fails with the raw error.

fix(worker): reordering a block's properties answers the renderer

:thread-api/reorder-display-property (dragging a property to a new place in a block's property list) returned the result of ldb/transact!, a tx report, which the worker can't send back to the renderer: the call failed with Cannot write $datascript$db$TxReport$$ although the reorder was saved. It returns nil now. No other thread api returns a transact call's result. Found by a local key fuzzer that drags at random.

New test src/test/frontend/worker/handler/property_reorder_test.cljs reorder-display-property-returns-a-value-the-renderer-can-read-test: the reorder is saved and the result can be written as transit; on master it fails with the tx report.

Master's #13043 (8ab397f, "return a serializable property reorder result") makes the same change; on the rebase onto it this commit keeps master's code and only adds the test, which passes there.

A tag converted to a page no longer stops the graph from opening (fixes #13877)

Converting a tag to a page left the tags that extend it pointing at the page. Once the page was recycled and the 30-day recycle GC removed it, those tags had no parent, the GC write failed validation (:logseq.property.class/extends missing), and because the GC runs while the graph opens, the graph never opened again.

  • logseq.db.frontend.class/detach-child-classes-tx: tags extending a parent that stops being a tag, or is retracted, drop that parent; a tag left with no parent extends Root, the same thing deleting a tag does.
  • convert-tag-to-page uses it, so new conversions leave no stale parent.
  • The recycle GC and permanent delete use it for every page they retract, which repairs graphs already converted on earlier versions (the reporter's graph opens again after the update).
  • maybe-run-recycle-gc! logs a GC failure instead of throwing it into the graph open.

Tests: logseq.outliner.recycle-test/gc-recycled-page-converted-from-parent-tag-keeps-graph-valid (a graph in the state earlier versions left: GC succeeds, the child extends Root, the graph validates), frontend.worker.db-core-test/convert-tag-to-page-moves-its-child-tags-to-root, frontend.worker.handler.transaction-test/a-failing-recycle-gc-does-not-stop-the-graph-from-opening. Each fails without its change.

Fixes logseq/db-test#1421: a graph that will not open because the startup recycle GC deletes a page a tag still extends, leaving the tag with an invalid extends. The GC and permanent delete detach child classes through db-class/detach-child-classes-tx (above). A node-ops fuzzer (random outliner ops including recycle-delete, permanent delete and the GC run as at graph open, checking that the graph validates after each) reproduces the issue's plain-page case on master at seeds 4018, 4110, 4307 and 4320; on this branch none of them fail that way. Pinned by gc-recycled-page-converted-from-parent-tag-keeps-graph-valid.

Rebase onto master 29fd2ed (Nov 11)

  • Master's fix: undo bugs for pages, namespaced pages, tags and properties #13449 makes undo of a page create recycle the page (and its new namespace parents and tags) and redo restore them with their uuids, and pins it with tests on a local graph. This PR's local-graph undo replayed the create's tx datoms, which retracts the page. A page create on a local graph now keeps its client-op row and semantic ops and its undo and redo take the semantic path, as on a synced graph (replays-tx-datoms? in undo_redo.cljs); every other local transaction still replays its datoms. The PR's mark-graph-synced! workaround in redo-create-page-restores-recycled-page-test is gone, and the pipeline replay test expects the page recycled after the undo.
  • Master's fix: exclude Root Tag from Extends choices #13287 ignores adding Root to a tag's Extends when the tag has another parent, so the pipeline replay test now removes Movie's parent tag (which sets Root) instead of setting Root.
  • The local-graph replay tests moved out of undo_redo_test.cljs (master keeps appending there) into frontend.worker.undo-redo-local-replay-test.
  • Conflict resolutions: deps/outliner/.../validate.cljs keeps master's recycled-page skip and this PR's Library-as-top-level argument; deps/outliner/.../property.cljs keeps master's ignore-root-extends-add? guard and drops old-value with multiple-values-empty?.

A page linked by a uuid lookup in a save is not retracted as orphaned

What the user sees. Saving a block whose new title links a page by uuid (Updated Link [[<page uuid>]], as master's input path stores links) failed with "Nothing found for entity id" when that page had no other refs: the save retracted the page it links.

Cause. remove-orphaned-page-refs! reads the new refs by :block/name or :db/id only, so a [:block/uuid id] lookup ref counted as dropped. Master kept such a page because every page's :block/properties hold its tags; this PR's orphan check looks past the tags, so the page became an orphan of its own save. Caught by master's cli-page-block-and-missing-uuid-links in the nightly build.

Change. A lookup ref ([:block/uuid id], or a map with only :block/uuid) has its page name read from the db before the old and new refs are compared.

Test. master's frontend.worker.pipeline-cli-refs-test/cli-page-block-and-missing-uuid-links errors on this branch without the change and passes with it; deps/outliner 173 tests pass.

yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 16, 2026
schema-version->updates-table-test compared the whole migration table,
so any migration added upstream (65.35) broke it: it now checks only the
entries its mutants change. recycled-entity-values-are-filtered-for-display
tested filter-recycled-entity-values with one argument, a private function
logseq#13786 rewrites; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 16, 2026
schema-version->updates-table-test compared the whole migration table,
so any migration added upstream (65.35) broke it: it now checks only the
entries its mutants change. recycled-entity-values-are-filtered-for-display
tested filter-recycled-entity-values with one argument, a private function
logseq#13786 rewrites; dropped.
namespaced-tag? (fn [id]
(let [e (d/entity db id)]
(and (ldb/class? e)
(some #(not= :logseq.class/Root (:db/ident %))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

namespaced-tag? treats every class that extends anything other than Root Tag as a namespace child. A top-level class that extends a user class is not a namespace child.

build-new-class sets :logseq.property.class/extends to Root only when that attribute is missing. A class such as Movie that extends Topic keeps #{Topic} and does not also extend Root. After #Movie exists, create of "Movie" with :class? true (typing #Movie again) runs page-exists?, then remove drops Movie, and a second class with that title is inserted. create does not call validate-unique-by-name-and-tags, which otherwise says class titles are unique regardless of what they extend.

Exclude a class only when it is the child segment of a namespace (its parent in :logseq.property.class/extends is the tag named by the title's parent segment), not merely because it extends some tag other than Root.

;; The graph starts to sync (upload). Its undo entries were recorded
;; without client-op rows, and undo on a synced graph takes an entry's
;; ops from its row, so the history ends here, as it does at a restart.
(worker-undo-redo/clear-history! repo))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local-graph? becomes false as soon as the client-op store has a :graph-uuid. start! writes that id in ensure-client-graph-uuid! when it attaches a remote graph by name, and that path does not set :logseq.kv/graph-remote?. History is cleared only later, here, when the flag flips.

Edits made while the graph was local are undo entries with :tx-datoms and no client-op row. After the id is stored, process-db-op skips the datom replay and calls apply-history-action. There is no row, the result is :missing-history-action, and that reason is not skippable, so clear-history! drops both stacks without restoring the edit.

The same clear also runs before a snapshot upload finishes. create-remote-graph! calls set-graph-sync-metadata!, which transacts the flag, and this listener clears history at that moment. If the snapshot POST then fails, the flag stays set (nothing unsets it) and the local undo entries are already gone.

Replay :tx-datoms until the flag is actually set, or clear history in the same step that stores the remote graph id. Clear only after the snapshot upload succeeds.

Comment thread deps/db/src/logseq/db.cljs Outdated
(not (:block/properties page))
;; every page's properties hold its :block/tags
;; (Page, Journal): only other properties keep it
(empty? (dissoc (:block/properties page) :block/tags))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:block/tags is one property key. Its value is the whole tag set: the built-in Page or Journal tag and any user tags. dissoc of that key drops the user tags too, and :block/journal-day is not in :block/properties (public? is false), so an empty journal is property-less after this check.

remove-orphaned-page-refs! then retracts the page. Removing the last [[today]] from a block deletes that empty journal. An empty page whose only extra data is a user tag is deleted the same way, and the tag assignment goes with it. Before this change the cleanup never ran, because every DB page's property map contained :block/tags.

Keep the page when it is a journal, or when any tag other than Page/Journal is present. A user property already keeps it, which the new test covers.

yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 17, 2026
schema-version->updates-table-test compared the whole migration table,
so any migration added upstream (65.35) broke it: it now checks only the
entries its mutants change. recycled-entity-values-are-filtered-for-display
tested filter-recycled-entity-values with one argument, a private function
logseq#13786 rewrites; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 18, 2026
schema-version->updates-table-test compared the whole migration table,
so any migration added upstream (65.35) broke it: it now checks only the
entries its mutants change. recycled-entity-values-are-filtered-for-display
tested filter-recycled-entity-values with one argument, a private function
logseq#13786 rewrites; dropped.
@yuxi-liu-wired
yuxi-liu-wired force-pushed the fix/db-page-delete-combined branch from a85e694 to 9666fc1 Compare October 18, 2026 11:01
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 18, 2026
schema-version->updates-table-test compared the whole migration table,
so any migration added upstream (65.35) broke it: it now checks only the
entries its mutants change. recycled-entity-values-are-filtered-for-display
tested filter-recycled-entity-values with one argument, a private function
logseq#13786 rewrites; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 19, 2026
schema-version->updates-table-test compared the whole migration table,
so any migration added upstream (65.35) broke it: it now checks only the
entries its mutants change. recycled-entity-values-are-filtered-for-display
tested filter-recycled-entity-values with one argument, a private function
logseq#13786 rewrites; dropped.
@yuxi-liu-wired
yuxi-liu-wired force-pushed the fix/db-page-delete-combined branch from 9666fc1 to b270c25 Compare October 19, 2026 11:01
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 19, 2026
schema-version->updates-table-test compared the whole migration table,
so any migration added upstream (65.35) broke it: it now checks only the
entries its mutants change. recycled-entity-values-are-filtered-for-display
tested filter-recycled-entity-values with one argument, a private function
logseq#13786 rewrites; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 20, 2026
schema-version->updates-table-test compared the whole migration table,
so any migration added upstream (65.35) broke it: it now checks only the
entries its mutants change. recycled-entity-values-are-filtered-for-display
tested filter-recycled-entity-values with one argument, a private function
logseq#13786 rewrites; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 21, 2026
schema-version->updates-table-test compared the whole migration table,
so any migration added upstream (65.35) broke it: it now checks only the
entries its mutants change. recycled-entity-values-are-filtered-for-display
tested filter-recycled-entity-values with one argument, a private function
logseq#13786 rewrites; dropped.
@yuxi-liu-wired
yuxi-liu-wired force-pushed the fix/db-page-delete-combined branch from b270c25 to 7b99195 Compare October 21, 2026 11:01
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 21, 2026
schema-version->updates-table-test compared the whole migration table,
so any migration added upstream (65.35) broke it: it now checks only the
entries its mutants change. recycled-entity-values-are-filtered-for-display
tested filter-recycled-entity-values with one argument, a private function
logseq#13786 rewrites; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 22, 2026
schema-version->updates-table-test compared the whole migration table,
so any migration added upstream (65.35) broke it: it now checks only the
entries its mutants change. recycled-entity-values-are-filtered-for-display
tested filter-recycled-entity-values with one argument, a private function
logseq#13786 rewrites; dropped.
@yuxi-liu-wired
yuxi-liu-wired force-pushed the fix/db-page-delete-combined branch from 7b99195 to b4e4bf8 Compare October 22, 2026 11:01
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 22, 2026
schema-version->updates-table-test compared the whole migration table,
so any migration added upstream (65.35) broke it: it now checks only the
entries its mutants change. recycled-entity-values-are-filtered-for-display
tested filter-recycled-entity-values with one argument, a private function
logseq#13786 rewrites; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 23, 2026
schema-version->updates-table-test compared the whole migration table,
so any migration added upstream (65.35) broke it: it now checks only the
entries its mutants change. recycled-entity-values-are-filtered-for-display
tested filter-recycled-entity-values with one argument, a private function
logseq#13786 rewrites; dropped.
@yuxi-liu-wired
yuxi-liu-wired force-pushed the fix/db-page-delete-combined branch from b4e4bf8 to 9189ef1 Compare October 24, 2026 00:30
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 24, 2026
schema-version->updates-table-test compared the whole migration table,
so any migration added upstream (65.35) broke it: it now checks only the
entries its mutants change. recycled-entity-values-are-filtered-for-display
tested filter-recycled-entity-values with one argument, a private function
logseq#13786 rewrites; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 25, 2026
schema-version->updates-table-test compared the whole migration table,
so any migration added upstream (65.35) broke it: it now checks only the
entries its mutants change. recycled-entity-values-are-filtered-for-display
tested filter-recycled-entity-values with one argument, a private function
logseq#13786 rewrites; dropped.
…space

A page created by name has no parent, a namespace root has the Library
as parent; the uniqueness check compared by raw parent, so renaming the
root "Foo" to an existing "Baz" gave 2 top-level pages named Baz
(db-test logseq#1346). Pages with no parent or the Library as parent are now
checked against each other.
Typing [[Brand new]] in a block creates the page Brand new; deleting the reference from the block again is meant to delete that page when it is empty and nothing else references it (remove-orphaned-page-refs! on save). It never did: get-orphaned-pages keeps a page with (:block/properties page), and in a DB graph every page's :block/properties holds its :block/tags (the Page or Journal tag), so no page ever qualified. Only properties other than :block/tags keep a page now.
With the cleanup working, a save that does not change the title (collapsing a block) must not take the block's pages for orphans: the cleanup runs only when the title changes.
Every JS array has Symbol.iterator, so the iterator clause above it
always takes an array first; the clause never runs.
Its test is the same as the clause above, so it is never chosen.
get-all-properties removes recycled properties (those with deleted-at)
first, so copying deleted-at onto the result never happens.
render-bottom-position-property?: a :node property already passes
(not= :default type), so node-many? adds nothing to the or.
…exists!

*uuids maps a uuid U to the uuid of the entity found by [:block/uuid U],
which is U, so the remap rewrites each lookup ref to itself.
The private fn's only caller passes both arguments.
…s->vec-tree

Both callers (editor handler, plugin API block tree) pass a block uuid
or nil.
With class? the existing page is looked up among pages tagged Tag
(page-exists? with #{:logseq.class/Tag}), or is a journal page, so it is
never a non-class internal page and the branch never runs.
…e-tx-data

block is an entity in every caller, and an entity's cardinality-many
value is a set, never sequential, so the check is always false.
ops' falls back to [[:transact ...]] when there are no semantic ops, so
(seq ops') is always true.
The atom is read only inside a (comment ...) form, so registering the
worker's debounced store has no effect.
Typing DONE (or /todo) while editing the title of a built-in class page,
e.g. the Page class, set :logseq.property/status on the class. Setting a
status, scheduled date or deadline also tags the node #Task when no class
provides the property, but a built-in node keeps its one built-in tag, so
validation rejected the write ("should only have one tag for a built-in
entity") and the user saw only the generic "DB write failed with invalid
data". A local key fuzzer found it through the search dialog's Page result.

disallow-task-properties-on-built-in-nodes refuses those three properties
on built-in nodes with a notification ("Built-in nodes can't be tasks."),
called from set-block-property! and batch-set-property!'s validation, next
to the existing private built-in check. Ordinary pages still become tasks.

task-properties-on-built-in-nodes sets a status on the Page class through
both setters (refused with the notification; before the change both failed
with "DB write failed with invalid data") and on a plain page (it becomes a
task).
A batch of outliner ops that moved blocks into a block and then deleted
that block failed whole ("DB write failed with invalid data"): the moved
blocks came back as stubs holding only :block/order (and :block/parent).

apply-ops! runs the batch on a temp conn and replays its datoms in one
transact!. With :outliner-op :delete-blocks (the editor sets it on a
Backspace merge), expand-delete-blocks-tx ran distinct over that tx-data.
DataScript datoms are equal when e, a and v are, whatever added is, so
the retract of a value the batch had added before (the order and parent
the move gave a block that the delete then removed) was dropped as a
duplicate of the add, and the add was kept.

expand-delete-blocks-tx now keeps the tx-data as it is and dedupes only
the subtree retracts it appends.

move-into-block-then-delete-it-does-not-resurrect-moved-blocks-test runs
the batch, with the moved blocks first as the children and then as the
siblings of the deleted block.
Right after a reload the renderer can call :thread-api/get-class-objects,
:thread-api/get-property-values and
:thread-api/get-bidirectional-properties before the worker has opened
the graph; they deref the graph's nil conn and throw "No protocol method
IDeref.-deref defined for type null". They now use the same when-let on
the conn as the neighbouring read handlers and return nil until the
graph is open (the same change for the other read handlers is logseq#13862;
this file is already in this PR).

property-read-thread-apis-return-nil-before-graph-opens-test calls the
three for a repo with no conn; all three throw without the change.
Setting a :number property to text that isn't a number through
batch-set-property! (the property value picker of the add-property
dialog) went through convert-ref-property-value, where parse-double
returned nil and the write failed as "Property value must be not nil"
(a raw worker error). It now uses fail-parse-double like
convert-property-input-string, so the user gets "Can't convert "x" to a
number." and nothing is written. A local key fuzzer reached it by
typing "#status" into a number property's value picker.

batch-set-property-refuses-a-value-it-cant-convert: the write is
refused with a notification and the block keeps no value; it failed
with the raw error before.
:thread-api/reorder-display-property (dragging a property to a new
place in a block's property list) returned the result of
ldb/transact!, a tx report, which the worker can't send back to the
renderer: the call failed with "Cannot write TxReport" although the
reorder was saved. It returns nil now. It is the only thread api whose
result is a transact call (scripts/thread-api-tx-returns.mjs). A local
key fuzzer that drags at random hit it.

property-reorder-test: the reorder is saved and the call's result can
be written as transit; it failed with the tx report before.
… break the graph's open

Converting a tag to a page left the tags that extend it pointing at the page. When the page was recycled and the 30-day recycle GC removed it, those tags lost their only parent, the GC write failed validation, and since the GC runs while a graph opens, the graph never opened again (logseq#13877).

- `db-class/detach-child-classes-tx`: tags extending a parent that stops being a tag (or is retracted) drop it; one left with no parent extends Root, as when a tag is deleted.
- `convert-tag-to-page` uses it, so new conversions leave no stale parent.
- The recycle GC and permanent delete use it for every page they retract, which repairs graphs converted before this fix.
- A GC failure while the graph opens is logged instead of stopping the open.

Fixes logseq#13877
It is used outside deps/db, by the outliner's recycle and the worker's tag-to-page conversion.
Undo of a block delete on a graph without sync must give the blocks that referred to the deleted block their ((uuid)) reference and refs back (logseq/db-test#1325), and must put a deleted block back with its page link stored by uuid, not by name (logseq/db-test#1326). The PR fixed both by replaying the transaction's own datoms, but no test pinned either. Both tests fail on origin/master's undo_redo.cljs, sync/apply_txs.cljs and pipeline.cljs and pass with the PR's.
The tests of undo and redo replaying a change's datoms on a local graph sat at the end of undo_redo_test.cljs, where master keeps adding undo tests, so each new master test there conflicted with this PR. They now live in frontend.worker.undo-redo-local-replay-test with copies of the fixture and the helpers they use; undo_redo_test.cljs keeps only this PR's edits to its existing tests.
Since master's logseq#13449 the undo of a page create recycles the page and its new namespace parents and tags, and redo restores them with their uuids; master pins this with tests on a local graph. This branch's local-graph undo replayed the create's tx datoms instead, which retracts the page, so those tests failed after the rebase. A page create on a local graph now keeps its client-op row and semantic ops, and its undo and redo take the semantic path as on a synced graph (replays-tx-datoms?); every other local transaction still replays its datoms. The redo-create-page test no longer marks its graph synced, and the pipeline replay test expects the page recycled after the undo.

That pipeline replay test also changed Movie's parent tag to Root with set-block-property; since master's logseq#13287 adding Root next to another parent is ignored, so the change recorded no undo entry. It now removes the parent tag, which gives Movie the Root tag as parent.
…ted as orphaned

Saving a block compares its old and new refs and retracts pages it no longer
refs. The new refs were read by :block/name or :db/id only, so a ref given as
a [:block/uuid id] lookup (master's input path gives one for a `[[uuid]]`
link in the title) counted as dropped. With this PR's orphan check, which no
longer keeps a page only because its properties hold its tags, the save then
retracted the very page it links and failed with "Nothing found for entity
id" (master's cli-page-block-and-missing-uuid-links, in the nightly build).
A lookup ref now has its name read from the db.
Reverts the orphan check of 2c8e758 ("an edit deletes the empty page it no
longer references"). Master's CLI E2E case block-update-page-refs creates
Alpha with `upsert page`, links and unlinks it from a block, and expects the
same Alpha (same uuid) afterwards; with the change the unlink deleted Alpha
and a later [[Alpha]] made a new page. Master's pinned behaviour wins: a page
whose :block/properties hold its tags is kept again. The orphaned-pages test
now pins that the empty page stays.

This branch has not been deployed

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