Repository navigation
fix(sync): keep children moved out by a merge-delete - #14296
Merged
tiensonqin merged 4 commits intoDec 1, 2026
Merged
Conversation
Merging a block that has children (Backspace at its start, or forward Delete into it) moves the children to the previous block and retracts the merged block in one :delete-blocks tx. Delete expansion looked up descendants in the db before the tx, so the server, other clients and rebase replay also deleted the moved children. The uploading client kept them, and every later edit to them was rejected with "Nothing found for entity id" and rolled back. Expansion now keeps descendants that still reach a page once the tx applies (delete-blocks/detached-ids). Descendants nobody moved, such as children added concurrently, are still deleted.
prithvihv
marked this pull request as ready for review
November 30, 2026 22:15
The second client now applies the txs the server journaled for the merge, as a pulling client does, instead of the first client's upload.
Resolve temporary IDs in the transaction preview, keep dependent deletes and moves in the same chunk, and reuse parent and descendant checks.
tiensonqin
approved these changes
Dec 1, 2026
Contributor
There was a problem hiding this comment.
@prithvihv Thanks a lot for the report and the fix, and elixir rocks!
prithvihv
added a commit
to prithvihv/logseq-db-nix
that referenced
this pull request
Dec 1, 2026
* bump logseq to f082a88 and update nixpkgs Picks up logseq/logseq#14296 (fix(sync): keep children moved out by a merge-delete), which stops the sync server and other clients from deleting the children of a block merged into its previous block. Pinned to the fix's merge commit rather than master tip, which adds a further journal-title data migration (schema 65.37). - logseq 22263c3 (2026-10-01) -> f082a88 (2026-12-01); graph schema 65.34 -> 65.36 - pnpm dependency hashes updated for db-sync and the web app; clj deps unchanged - nixpkgs c59305b (2026-10-01) -> e713fda (2026-11-29) Co-Authored-By: Claude Opus 5.5 <[email protected]> * logseq-db-app: stop removing forge.config.test.js Upstream deleted resources/forge.config.test.js in logseq/logseq#14069, so it no longer lands in static/ and the rm in installPhase failed. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Helllooo Logseq Team 🌈
Thank you so much for working on this amazing tool! I have been using it for a very long time now and am absolutely sure it's the best note taking tool for me.
I ran into this bug often so i started looking into it. I did use claude to learn about the project and understand my change, i write elixir in my day job so i somewhat understand programming i would say 🙃. Please let me know what you think, or if i can contribute to this issue in other ways.
Problem
Screen.Recording.2026-11-30.at.22.54.46.mov
Merging a block that has children into the previous block deletes those children on the sync server and on other clients, while the device that did the merge keeps them.
Steps to reproduce (DB graph with sync):
AandB, and giveBa childC.Band press Backspace.Bmerges intoA, andCbecomesA's child.C.Expected: the edit syncs. Actual: the edit appears, then reverts. The server rejects every tx that touches
Cwithdb transact failed/Nothing found for entity id [:block/uuid C](:missing-block-uuids [C]), the client rolls it back, and other devices no longer haveCor its subtree.The same path is taken by:
Root cause
The editor runs the merge as one
:outliner-op :delete-blockstx: move the children to the previous block, then delete the merged block.ldb/batch-transact-with-temp-conn!runs those ops in order, so expansion on the uploading client sees the children already moved, then replays the combined datoms with:replay-datoms? true("already expanded").transact!drops that flag from tx-meta, so the uploaded tx keeps the:delete-blockslabel without it:Delete expansion then treats
[:db/retractEntity B]as "delete B's subtree" and looks up that subtree in the db before the tx, whereCis still underB. So it adds retracts forCand its descendants. This happens in three places:tx-sanitize/sanitize-txwith:retract-touched-descendants?ldb/transact!expansion:delete-blocks/expand-delete-blocks-tx, on the server and on every client applying a remote:delete-blockstxexpand-block-retracts-to-descendantsinfrontend.worker.sync.apply-txsFix
New shared helper
logseq.db.common.delete-blocks/detached-ids: of the candidate descendants, return only those that have no path to a page once the tx applies.:block/parentof none of the candidates, the candidates are returned unchanged, so ordinary deletes keep the existing behavior and cost.d/with, and each candidate is kept if its:block/parentchain still reaches a page.All three expansion sites now pass their candidate descendants through
detached-ids. Children the tx moves out of the deleted block are kept. Children nobody moved, for example ones another client added concurrently, are still deleted, so no orphans are left.The server can't simply trust the client's expansion and skip its own: the uploader expanded against its own view of the tree, which doesn't include children added concurrently on the server.
Tests
New tests (each checks the merge case and that an unmoved child is still deleted):
deps/db:delete-blocks-test/delete-blocks-keeps-children-moved-out-in-same-txdeps/db-sync:tx-sanitize-test/sanitize-delete-blocks-keeps-descendants-moved-out-testdeps/db-sync:worker-handler-sync-test/tx-batch-delete-blocks-keeps-children-moved-out-of-deleted-block-test, throughhandle-tx-batch!with the tx shape the editor uploads, plus a child added concurrently on the serverdb-sync-test/rebase-delete-expansion-keeps-children-moved-out-in-same-tx-test(rebase replay)db-sync-test/merge-delete-keeps-moved-children-on-server-and-other-clients-test, end to end. Client A runs the editor's merge ops throughoutliner-op/apply-ops!, its real pending upload goes throughsync-handler/apply-tx-entry!, client B applies what the server journaled (storage/fetch-tx-since, decoded aspull/okdoes) throughapply-remote-txs!, and the test asserts that A, the server and B have the same tree and checksums.All new tests fail without the source changes. Without the fix, the end-to-end test shows the server and client B losing the moved child and grandchild, with checksums that differ from client A's.
Results:
deps/dbdeps/db-syncdeps/outlinerbb dev:lint-and-test)bb dev:lint-and-test(lint and unit tests) passes locally. Not run locally: e2e.Notes and trade-offs
d/withpreview runs only when a delete tx also moves a block out of the deleted subtree, which in practice means merges.expand-block-retracts-to-descendantsnow walks each deleted block's subtree once to computedetachedand again in the existing loop that emits retracts. This keeps the diff to that function minimal. It's cheap for the subtrees replayed during rebase, and could be removed by reusing the first walk at the cost of restructuring the loop.Not addressed here (follow-ups)
handle-tx-reject!only rolls back and marks the tx failed. There is no repair path for:missing-block-uuidswhen the block still exists locally.handle-tx-batch-ok!ignores the canonical txs the server returns, so server-side rewrites never reach the uploading client. The checksum check that would detect the divergence (verify-sync-checksum!) runs only in dev/test builds.devports the same three expansion sites (db_sync_tx_sanitize.ml,delete_blocks.ml,sync_replay.ml) and needs the same change.Related
tx-rejected, "Nothing found for entity id"), different causeexpand-delete-blocks-tx, so a small conflict is likely depending on merge order