DB Sync: rejected duplicate-order repairs regenerate indefinitely and accumulate failed transactions

オープン
#1,515 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
18/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
clojure, javascript, sqlite

調査の方向性

Start in frontend.worker.sync.apply-txs/rollback-and-mark-failed-txs! and repair-applied-txs! (with sync-fix-tx-meta), which regenerate a fresh-UUID :fix transaction after each rejection, then logseq.db-sync.order/fix-duplicate-orders!. Run the isolated DataScript replay from the issue to see the rollback→repair→rejection loop. Done means repeated rejection stops generating equivalent repairs and failed rows stop growing while pending user edits are preserved.

索引モデルが issue の本文から書いたものです。

説明

Search first
  • I searched and no similar issues were found

Searched logseq/db-test, logseq/logseq, and the Logseq Forum for transaction rejection, duplicate orders, and repair loops. Related rejection reports include #775 and #789, but neither documents the rollback → equivalent repair with a new UUID → rejection cycle reported here.

What Happened?

DB Sync repeatedly rejects automatic duplicate-block-order repairs with reason: "db transact failed". Reject handling rolls back the repair, recreates the duplicate orders, then immediately generates another equivalent :fix transaction with a new UUID. Repeated rejection keeps the graph stuck and accumulates failed client_ops rows rather than terminating or surfacing a recoverable state.

This report distinguishes two findings:

  • Observed live: repeated tx-rejected errors with changing failed transaction UUIDs while the WebSocket remains open and local/remote transaction positions remain equal. A captured queue contained 66,961 failed :fix operations and 178 pending :fix operations; there were no other failed operation types in that capture.
  • Reproduced offline: the installed client's actual rollback/rebase/repair and transaction persistence code regenerates equivalent repairs when rejection is injected. This reproduces the client feedback loop, not the underlying server exception.

The exact captured repair changes the order of two siblings from duplicate b5w values to b5wV and b5x. It is valid against the captured local graph and schema using the installed ldb/transact! with validation active. Reverse/apply each changes four datoms; repeating the repair changes zero datoms.

Reproduce the Bug

Scope: a deterministic client reject-path reproduction, not a demonstrated UI-only trigger for the original server rejection. Use an isolated connection and queue, never a production graph.

  1. Create an isolated DataScript connection with :block/uuid as unique identity and :block/parent as a reference. Create a parent and three sibling blocks. The first two have :block/order "b5w"; the following sibling has :block/order "b5xV". Use ascending UUIDs for the first two siblings.
  2. Register the connection and a real SQLite client_ops store with the worker's normal local-transaction listener/persistence path. Apply logseq.db-sync.order/fix-duplicate-orders! to the initial transaction report with :outliner-op :fix and undo generation disabled. This creates a pending repair with a forward and reverse payload.
  3. The generated repair sets the first two siblings to b5wV and b5x. Optionally add a subsequent local edit to exercise rebase/preservation of unrelated pending changes.
  4. Inject rejection of the pending repair. The offline experiment directly called the installed frontend.worker.sync.apply-txs/rollback-and-mark-failed-txs! with the pending repair's UUID—the function invoked by handle-tx-reject! for a matching in-flight :failed-tx-id.
  5. Inspect both the DataScript state and SQLite queue. The original repair is failed, but a new pending :fix transaction repairs the same duplicate orders with a different UUID.
  6. Reject that replacement transaction. A second equivalent replacement is generated and another failed row is retained. The pending repair count remains stable while failed rows increase.

Synthetic structural fixture (fictional IDs and UUIDs):

;; Minimal DataScript shape for the isolated order/reject experiment;
;; not an importable full Logseq graph or an input to a production graph.
(def schema
  {:block/uuid   {:db/unique :db.unique/identity}
   :block/parent {:db/valueType :db.type/ref}})

(def seed
  [{:db/id 1 :block/uuid #uuid "00000000-0000-4000-8000-000000000001"}
   {:db/id 2 :block/uuid #uuid "00000000-0000-4000-8000-000000000002"
    :block/parent 1 :block/order "b5w" :block/title "example"}
   {:db/id 3 :block/uuid #uuid "00000000-0000-4000-8000-000000000003"
    :block/parent 1 :block/order "b5w"}
   {:db/id 4 :block/uuid #uuid "00000000-0000-4000-8000-000000000004"
    :block/parent 1 :block/order "b5xV"}])

;; Expected forward repair (two cardinality-one replacements;
;; the transaction report contains four datoms, including retractions):
[[:db/add 2 :block/order "b5wV"]
 [:db/add 3 :block/order "b5x"]]

;; Reverse payload restores the collision:
[[:db/add 2 :block/order "b5w"]
 [:db/add 3 :block/order "b5w"]]

Recorded isolated replay against a copy of the captured real queue:

Stage Pending operations Failed operations Total rows
Before injected rejection 178 66,961 67,410
After first injected rejection 178 66,962 67,411
After second injected rejection 178 66,963 67,412

The graph remains locally repaired after each completed cycle; rollback temporarily restores the collision, which is what generates the replacement repair. The original server rejection cause is not established by this experiment.

Expected Behavior

Rejecting an automatic repair should not generate an unbounded sequence of equivalent repairs with fresh UUIDs and growing failed-operation storage. The client should preserve pending user edits and surface an actionable failure/reconciliation state rather than remain in this feedback loop.

Merely skipping order repair is not sufficient: the isolated experiment then leaves duplicate orders, and later repair processing regenerates the repair.

Screenshots

Not applicable: this report concerns worker transaction handling and SQLite queue state. Sanitized structural input and recorded results are included above.

Files

No real graph, SQLite database, full datom capture, or unreviewed console dump is attached because these contain private data. The structural fixture and aggregate replay results above contain no original graph names, block UUIDs, entity IDs, note content, local paths, account identifiers, or credentials.

Browser, Desktop or Mobile Platform Information
  • Platform: macOS desktop, Apple Silicon (arm64), Darwin 25.6.0.
  • Logseq: 2.0.1, reported revision 5a23230a56-dirty.
  • Graph: database graph, using DB Sync, not a Markdown/file graph.
  • The installed build reports -dirty; reproduction is against installed code. Behavior on the latest upstream build has not been established.
  • Relevant browser-worker and Node-worker source-map sources were compared and matched for rollback/rebase/repair and the DataScript/database functions exercised by the offline replay.
Additional Context
Relevant client path

Revision-linked source locations (installed source-map line numbers below may differ from the public commit because the installed build reports -dirty):

  1. frontend.worker.sync.handle-message/handle-tx-reject!, installed lines 167–228: filters rejection IDs against in-flight IDs and dispatches rollback.
  2. frontend.worker.sync.apply-txs/rollback-and-mark-failed-txs!, installed lines 752–802: reverses the rejected transaction and subsequent pending transactions, rebases non-rejected pending transactions, then calls repair-applied-txs!.
  3. repair-applied-txs! / sync-fix-tx-meta in the same file, installed lines 1580–1589: repair metadata contains :outliner-op :fix and a fresh (random-uuid).
  4. logseq.db-sync.order/fix-duplicate-orders!, installed lines 5–46: detects sibling order collisions and transacts replacement fractional order keys.
Local validity and persistence checks
  • The exact captured forward/reverse repair was exercised against 191,529 captured datoms and the captured schema through the installed ldb/transact!, with local validation active. Repeating it and all 178 captured pending repairs produced no additional datom changes on the already-repaired local state.
  • A separate synthetic replay with a later user edit preserved that edit locally and pending under its original transaction UUID across two rejected repairs and a fresh Node process reopening the SQLite queue. The repair failure mechanism remained after reopening.
  • Rejection was injected in offline experiments. No claim is made that missing remote blocks, a particular server schema error, or the cleanup plugin caused the actual rejection.
Reversible live containment test

Using the native worker APIs, transaction uploads were paused for approximately 15 seconds and then restored:

  • After one already-in-flight rejection, the last rejection UUID/timestamp stayed unchanged at the 2-, 8-, and 15-second observations.
  • 190 pending local operations remained, the WebSocket stayed open, and queue file size remained unchanged during those observations.
  • thread-api/db-sync-resume-upload restored the gate but did not immediately flush in this test. Calling thread-api/db-sync-start for the already-active client enqueued a flush and fresh rejections resumed.
  • The native control used was thread-api/db-sync-stop-upload with the local repository argument. It is containment, not a sync repair; it pauses outgoing database transaction uploads and resets in a fresh worker process. Remote-edit delivery during the pause was not tested.
  • No live graph/queue/binary edits or app restarts were performed. Uploads were restored after the test.
Missing server diagnostics

The installed handle-tx-reject! retains the reason and transaction metadata but does not retain :error-detail or :retryable in its recorded rejection data. The current public server handler emits those fields for transaction exceptions. The deployed server revision and actual exception are unknown; retaining sanitized error detail would help determine why this locally valid repair is rejected.

Are you willing to submit a PR? If you know how to fix the bug.
  • I'm willing to submit a PR (Thank you!)
主要言語
言語のデータがありません
スター
29
フォーク
2
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

logseq/db-test のほかの issue

logseq/db-test の issue をすべて見る

似ている issue

Data Engineering の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。