This document describes the handling of cycles formed between multiple blocks in the implementation of db-sync.
deps/db-sync/src/logseq/db_sync/worker.cljs.logseq.db-sync.cycle/detect-cycle which inspects updates to :block/parent (and other special attrs like class extends).{:type "tx/reject" :reason "cycle" ...}.attr: the attribute that introduced the cycle (for blocks this is :block/parent).server-values: a map of the affected entities to the server’s current value for attr (from logseq.db-sync.cycle/server-values-for).tx/reject with reason "cycle" in src/main/frontend/worker/db_sync.cljs.reconcile-cycle! which builds :db/add / :db/retract ops to restore attr to the server values, then transacts them locally with :rtc-tx? true.:block/parent, :logseq.property.class/extends) from the rejected inflight txs, requeues the remaining changes, and flushes pending txs so other attribute updates still sync.pull/ok, after applying remote txs, the client checks cycle-related attrs touched by the tx. If a cycle is detected:
:block/parent, reparent the affected block to its page root (top-level) and persist the op so it is uploaded to the server.:logseq.property.class/extends), retract the attr locally.