Repository navigation
fix(db-sync): heal stale local checksum on graph open via covered commit - #13415
Conversation
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
9bee4d4 to
7b48efe
Compare
There was a problem hiding this comment.
🔍 Devin Review: 2 flags
Not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
The stored local checksum is written post-commit to the client-ops sqlite file while the graph data is stored to db.sqlite inside d/transact!, so process death between the graph store and the checksum write leaves the stored checksum permanently stale: every later incremental update keeps building on the wrong base and the client can never converge with the server checksum. This caused the cli-sync-stress flake where a worker killed by outdated-worker cleanup restarted with local-checksum != remote-checksum while content was already converged. update-local-checksum now also records the graph commit (:max-tx) the checksum covers. On graph open, reconcile-local-checksum! compares the stored covered commit with the reopened db's :max-tx and recomputes the checksum once when they disagree, healing bookkeeping drift from lost checksum writes regardless of shutdown cleanliness. Also run the stress script's checksum/graph validators even when the final sync-settle check fails so the recompute diagnostic is always captured.
7b48efe to
0634208
Compare
|
E2E verification of the checksum-heal fix — passed (tested at 1. Stale-marker heal — works. Simulated the exact post-SIGKILL lost-write state: Recomputed checksum equals the true content checksum; 2. Clean path — no recompute. A second open with a consistent marker logged no heal line (verified twice). 3. Baseline regression — clean. Note on earlier "Sync did not settle" failures (environmental)Three prior runs failed on settle — root-caused to a stale Verified by Devin session (testing agent, runtime E2E on local db-sync server + JWKS mock). |
…mit (#13415) The stored local checksum is written post-commit to the client-ops sqlite file while the graph data is stored to db.sqlite inside d/transact!, so process death between the graph store and the checksum write leaves the stored checksum permanently stale: every later incremental update keeps building on the wrong base and the client can never converge with the server checksum. This caused the cli-sync-stress flake where a worker killed by outdated-worker cleanup restarted with local-checksum != remote-checksum while content was already converged. update-local-checksum now also records the graph commit (:max-tx) the checksum covers. On graph open, reconcile-local-checksum! compares the stored covered commit with the reopened db's :max-tx and recomputes the checksum once when they disagree, healing bookkeeping drift from lost checksum writes regardless of shutdown cleanliness. Also run the stress script's checksum/graph validators even when the final sync-settle check fails so the recompute diagnostic is always captured.
…mit (#13415) The stored local checksum is written post-commit to the client-ops sqlite file while the graph data is stored to db.sqlite inside d/transact!, so process death between the graph store and the checksum write leaves the stored checksum permanently stale: every later incremental update keeps building on the wrong base and the client can never converge with the server checksum. This caused the cli-sync-stress flake where a worker killed by outdated-worker cleanup restarted with local-checksum != remote-checksum while content was already converged. update-local-checksum now also records the graph commit (:max-tx) the checksum covers. On graph open, reconcile-local-checksum! compares the stored covered commit with the reopened db's :max-tx and recomputes the checksum once when they disagree, healing bookkeeping drift from lost checksum writes regardless of shutdown cleanliness. Also run the stress script's checksum/graph validators even when the final sync-settle check fails so the recompute diagnostic is always captured.
…mit (#13415) The stored local checksum is written post-commit to the client-ops sqlite file while the graph data is stored to db.sqlite inside d/transact!, so process death between the graph store and the checksum write leaves the stored checksum permanently stale: every later incremental update keeps building on the wrong base and the client can never converge with the server checksum. This caused the cli-sync-stress flake where a worker killed by outdated-worker cleanup restarted with local-checksum != remote-checksum while content was already converged. update-local-checksum now also records the graph commit (:max-tx) the checksum covers. On graph open, reconcile-local-checksum! compares the stored covered commit with the reopened db's :max-tx and recomputes the checksum once when they disagree, healing bookkeeping drift from lost checksum writes regardless of shutdown cleanliness. Also run the stress script's checksum/graph validators even when the final sync-settle check fails so the recompute diagnostic is always captured.
Summary
Fixes the
cli-sync-stressflake seen at https://github.com/logseq/logseq/actions/runs/36001797688/job/107639997944 (same signature on ~7/60 recent runs across unrelated branches — pre-existing, not caused by the PR the job ran on).Root cause.
d/transact!stores graph data todb.sqliteinside the commit (store-after-transact!), then firesrun-callbacks→ the db listener writes the incremental local checksum viaupdate-local-sync-checksum!into the separateclient-ops-/db.sqlite. A process kill in that gap (the stress harness's "Outdated worker cleanup" SIGKILL mid-run) commits the graph data but drops the checksum write. The stored checksum then lags the db by that tx, and because later updates are incremental (update-checksumon the stale base), the client can never converge — reproduces exactly the observedlocal-checksum ≠ remote-checksumwith all txs settled and content identical.Fix — covered-commit marker.
client_op.update-local-checksum repo checksum covered-txnow also stores:db-sync/checksum-covered-txinsync_meta, recording the commit the checksum covers ((:max-tx (:db-after tx-report))— taken from the tx-report itself, not live@conn, since listener work can be queued). On graph open,db_corecallsdb-sync/reconcile-local-checksum!after bootstrap/migration and beforelisten-db-changes!: whencovered-tx ≠ (:max-tx @conn)(missed writes, or legacy graphs with no marker), it recomputes the checksum once viasync-checksum/recompute-checksumand stores it with the current marker — one-shot heal, zero cost on clean opens, and also repairs graphs already carrying a stale checksum.Verified end-to-end on the preserved failing state (corrupted client-ops checksum + worker reopen →
local-checksumheals to the recomputed value matching remote).Test script.
cli-concurrent-edit-stress.mjs: the final per-client settle loop now always runsvalidateClientChecksum+validateClientGrapheven whenwaitForSyncSettledthrows — in CI the diagnostic was skipped on the failing client, which is why the logs couldn't distinguish bookkeeping drift from real divergence.Test coverage
local-checksum-heals-when-covered-commit-lags-test(lost write → reconcile fixes),local-checksum-untouched-when-covered-commit-current-test(consistent marker → no recompute),checksum-covered-tx-roundtrip-test(marker storage).update-local-checksumgained acovered-txparam; all ~21 existing test call sites updated to pass(:max-tx @conn).bb dev:test -v frontend.worker.db-sync-test(231 tests/2218 assertions),frontend.worker.db-core-test(147/1601),frontend.worker.sync.client-op-test— 0 failures; clj-kondo clean on all touched files.frontend.worker.db-sync-sim-testrun pending in background (call-site updates only, no behavior change).Notes
:db-sync/checksum-incremental-drift, with the assert's throw then freezing the stale value for the remaining ~2000 txs.pending-localstuck withws-state: stopped) — orthogonal to this fix.Link to Devin session: https://app.devin.ai/sessions/7f44848565884cf989b5699c0aa980ea
Open in Devin Desktop: https://app.devin.ai/desktop/session/7f44848565884cf989b5699c0aa980ea?variant=devin
Requested by: @tiensonqin