`batch-transact-with-temp-conn!` leaves `:max-tx` behind its datoms, so the next transaction reuses a tx id
評価
調査の方向性
deps/db/src/logseq/db.cljs の batch-transact-with-temp-conn!(L273)と、その transact! 呼び出し(L312)から始めてください。再生される Datom レコードが一時的な tx ID を保持している一方で、:max-tx が一度だけ進むことを比較してください。issue にあるコマンドを使って src/test/logseq/db/batch_transact_tx_id_repro_test.cljs の再現テストを実行し、提案された tx なしの ops の transact を適用して再実行してください。両方のアサーションが通り、次のトランザクションの tx ID が未使用であれば完了です。deps/db/src/logseq/db/common/sqlite.cljs の get-storage-conn は関連するコンテキストです。
索引モデルが issue の本文から書いたものです。
説明
Search first
- I searched and no similar issues were found
What Happened?
Continuing the Opus 5.5 epic from last week. Claude follows.
ldb/batch-transact-with-temp-conn! runs an operation on a temporary conn, possibly as several transactions, and then replays the collected datoms into the real conn with one transact!. The replayed datoms keep the tx ids of the temporary transactions, but the real conn's :max-tx advances only once. When the operation made more than one inner transaction, the conn's :max-tx ends up lower than the tx of datoms it holds, and the next transaction takes a tx id that earlier datoms already carry.
outliner-op/apply-ops! goes through this function, so ordinary edits reach it: in our test an insert followed by a move produced a transaction report whose datoms carried two tx ids while :max-tx covered only the first.
Reproduce the Bug
Save this test as src/test/logseq/db/batch_transact_tx_id_repro_test.cljs, then run
clojure -M:test compile test
node static/tests.js -n logseq.db.batch-transact-tx-id-repro-test
(ns logseq.db.batch-transact-tx-id-repro-test
(:require [cljs.test :refer [deftest is]]
[datascript.core :as d]
[logseq.db :as ldb]))
(deftest batch-transact-with-temp-conn-keeps-tx-ids-unique-test
(let [conn (d/create-conn {})]
(d/transact! conn [{:db/id -1 :item/name "a"}])
(ldb/batch-transact-with-temp-conn!
conn {}
(fn [temp-conn _]
(d/transact! temp-conn [{:db/id -1 :item/name "b"}])
(d/transact! temp-conn [{:db/id -1 :item/name "c"}])))
(let [db @conn
max-datom-tx (reduce max (map :tx (d/datoms db :eavt)))]
(is (>= (:max-tx db) max-datom-tx))
(let [new-tx (:tx (first (:tx-data (d/transact! conn [{:db/id -1 :item/name "d"}]))))]
(is (not-any? #(= new-tx (:tx %)) (d/datoms db :eavt)))))))
Expected Behavior
After the batch, :max-tx is at least the tx of every datom, and the next transaction gets a tx id that no earlier datom carries.
Actual on master logseq/logseq@9af1a190bc:
FAIL expected: (>= (:max-tx db) max-datom-tx)
actual: (not (>= 536870914 536870915))
FAIL expected: (not-any? (fn* [p1__155722#] (= new-tx (:tx p1__155722#))) (d/datoms db :eavt))
actual: (not (not-any? #object[Function] (#datascript/Datom [1 :item/name "a" 536870913 true] #datascript/Datom [2 :item/name "b" 536870914 true] #datascript/Datom [3 :item/name "c" 536870915 true])))
The next transaction takes tx 536870915, which datom 3 already carries.
Screenshots
No response
Files
No response
Browser, Desktop or Mobile Platform Information
Unit test on master logseq/logseq@9af1a190bc (2026-11-19), Node 24, Linux x86_64. No UI involved.
Additional Context
Cause. batch-transact-with-temp-conn! (logseq/db.cljs#L273) collects the temporary conn's tx-data as Datom records and passes them to transact! (L312). Datascript inserts a Datom record with its own tx, and increments :max-tx once per transact!.
Related code. get-storage-conn (common/sqlite.cljs#L23) already raises :max-tx on restore to the largest tx of the tail's datoms (tail-max-tx), and its docstring describes these multi-tx entries. That covers a reopen from the tail, but not the conn in memory, and not a full store, which writes the lower :max-tx into the root. logseq/logseq#13911 moves that restore code without changing this.
Possible effects (not verified). The worker pipeline stamps :block/tx-id with (inc (:max-tx db-after)) (pipeline.cljs#L743), so two operations can stamp the same revision. Anything that keys data by tx id can merge two transactions.
Suggested fix. Transact the collected changes as ops without their tx, so the final transact! stamps them all with one new tx id:
(transact! conn
(mapv (fn [d] [(if (:added d) :db/add :db/retract) (:e d) (:a d) (:v d)]) tx-data)
(transform-tx-meta tx-meta))
On our fork this makes the test above pass, the whole unit-test suite passes with it (2,744 tests, bb dev:run-test-namespaces), and a storage property test that checks :max-tx after every transaction (100 random sequences with write failures and crashes) no longer finds the problem. I can open a PR with the change and the test.
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 を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
logseq/db-test のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
Potential Dataloss: Deleting an entry from the property page's node table has no confirmation dialog対応中かも @tiensonqin が 59 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
Disabling Flashcards in Settings does not disable Flashcard shortcuts or tags対応中かも @tiensonqin が 60 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
似ている issue
-
HTTP `batch.Send` returns nil and inserts no rows when the block does not encode対応中かも @Indian-boult が今日担当しました。 オープンbug queries
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
ClickHouse/clickhouse-go#2155 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
-
PNI-only contacts synced from Storage Service are left with RegisteredState.UNKNOWN and never appear in New Chat対応中かも @ArviFoxy が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
signalapp/Signal-Android#15142 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
bug P2 tools
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信