Skip to content

fix: handle stale sync tx data - #12850

Merged
tiensonqin merged 8 commits into
masterfrom
logseq/fix-stale-sync-tx
Jul 6, 2026
Merged

fix: handle stale sync tx data#12850
tiensonqin merged 8 commits into
masterfrom
logseq/fix-stale-sync-tx

Conversation

@tiensonqin

@tiensonqin tiensonqin commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix db-sync stale transaction handling and stabilize incremental checksum updates without falling back to recomputing checksums during normal operation.

  • Treat stale move-like operations targeting already-missing entities as no-op batches.
  • Sanitize delete operations by dropping redundant writes to entities being retracted and retracting current server descendants.
  • Add request context to transaction metadata so failure diagnostics include graph id, client revision, and username where available.
  • Tag inner batch tx reports with stable :batch-tx-report? metadata and use that metadata for checksum/local-tx decisions instead of mutable @conn :batch-tx? state.

Root Cause

The server stale-tx issue came from client-materialized outliner tx data that could pass the coarse t-before revision check while still containing entity references that were no longer valid in the server DB. Delete batches could also leave descendant/property-value blocks in an invalid parent state, causing legitimate server tx/reject failures.

The incremental checksum mismatch was a separate client/server shared implementation bug: checksum and local pending-tx logic inferred whether a tx report was an inner batch report from mutable connection state. Under concurrent batch/sync activity, a non-batch tx report could be processed while @conn :batch-tx? was still true, so real graph changes were skipped by the incremental checksum path even though the data had changed.

Validation

  • rtk bb dev:test -v frontend.worker.db-sync-test/local-checksum-updates-non-batch-report-with-stale-batch-flag-test -v frontend.worker.db-sync-test/local-checksum-updates-ldb-non-batch-report-with-stale-batch-flag-test -v frontend.worker.db-sync-test/batch-transact-tags-inner-tx-reports-test
  • rtk bb dev:test -v logseq.db-sync.worker-handler-sync-test/tx-batch-delete-blocks-ignores-redundant-updates-and-deletes-descendants-test -v logseq.db-sync.worker-handler-sync-test/tx-batch-stale-retract-block-includes-current-descendants-test -v logseq.db-sync.worker-handler-sync-test/tx-batch-stale-retract-page-includes-current-page-tree-test -v logseq.db-sync.worker-handler-sync-test/tx-batch-rejects-move-blocks-when-target-is-missing-test
  • Local-worker CLI stress sync, 2000 ops, 3 clients, concurrency 4, checksum assertions enabled: all clients ended at checksum 2af3643cb98c7388; no tx/reject, checksum mismatch, or sync error log matches.
  • rtk git diff --check

Copilot AI review requested due to automatic review settings July 3, 2026 18:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves db-sync robustness when client-generated outliner tx data becomes stale relative to the server DB even though t-before still matches, by sanitizing tx batches more aggressively and enriching transaction metadata with request context for diagnostics.

Changes:

  • Add request context (graph-id, client-revision, username) into transact metadata for WS and HTTP tx/batch handlers.
  • Treat move-like operations that target already-missing entities as sanitizable no-ops (drop missing-entity ops), and sanitize delete operations (drop redundant writes + retract current descendants).
  • Add/extend worker handler tests to cover request-context tx-meta and stale tx sanitization scenarios.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
deps/db-sync/src/logseq/db_sync/worker/handler/ws.cljs Captures graph/user context on WS and passes it through to tx/batch handling.
deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs Adds request-context support and expands tx sanitization options for stale move/delete outliner ops.
deps/db-sync/src/logseq/db_sync/tx_sanitize.cljs Adds helpers to drop ops targeting missing/retracted entities before transact, supporting stale/no-op batches and cleaner deletes.
deps/db-sync/test/logseq/db_sync/worker_handler_ws_test.cljs Adds WS test asserting request context is present in tx-meta.
deps/db-sync/test/logseq/db_sync/worker_handler_sync_test.cljs Adds sync handler tests for request-context meta and stale-move/delete sanitization behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread deps/db-sync/src/logseq/db_sync/worker/handler/sync.cljs
Comment thread deps/db-sync/test/logseq/db_sync/worker_handler_sync_test.cljs Outdated
@tiensonqin
tiensonqin force-pushed the logseq/fix-stale-sync-tx branch from a8217fa to ba040ff Compare July 3, 2026 18:35
@tiensonqin
tiensonqin force-pushed the logseq/fix-stale-sync-tx branch from 08d9c31 to 2e3647c Compare July 6, 2026 10:22
@tiensonqin
tiensonqin merged commit b29e720 into master Jul 6, 2026
26 checks passed
@tiensonqin
tiensonqin deleted the logseq/fix-stale-sync-tx branch July 6, 2026 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants