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

Abierto
#1,515 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
18/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
clojure, javascript, sqlite

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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!)
Lenguaje dominante
Sin datos de lenguaje
Estrellas
29
Forks
2
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de logseq/db-test

Todos los issues de logseq/db-test

Issues similares

Más issues de Data Engineering

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.