fix(sync): flush pending CRDT write-backs on shutdown instead of dropping them#554
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No React Doctor issues found in this scan.
Generated by React Doctor. Questions? Contact founders@million.dev. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On shutdown,
CrdtProvider.destroy()calledcancelPendingWritebacks(), which cleared the debounced (500 ms) markdown write-back timers without running them. Any note/journal edit made within ~500 ms of quit never reached the on-disk.mdfile or the search index. The CRDT state is persisted (so the edit isn't permanently lost), but the file silently lagged the true content and did not self-heal — only a new edit re-triggered a write-back. For a "files on disk, not a database" product, that on-disk/UI divergence (which also propagates stale via folder sync and stale search results) is a real correctness gap.This flushes pending write-backs on shutdown instead of cancelling them.
Closes #543.
Changes
crdt-writeback.ts—pendingTimersnow stores{ timer, doc }per pending note (was just the timer handle, which a flush couldn't reach). New exportedasync flushPendingWritebacks(): snapshots pending entries, clears their timers, and runs everyperformWritebackto completion; per-note failures are caught and logged, so the flush never rejects.cancelPendingWritebacks()is retained (still used elsewhere).crdt-provider.ts—destroy()nowawait flushPendingWritebacks()as its first line, before theentry.doc.destroy()loop (the flush reads from the liveY.Docs).destroy()is already awaited fromstopSyncRuntime()→ the Electronbefore-quithandler, so the async flush is awaited on the real shutdown path.Tests
Added 4 cases to
crdt-writeback.test.ts(fake timers, so the only way a write happens is the flush):Two existing test files that mock
./crdt-writebackand exercisedestroy()were updated to addflushPendingWritebacksto their module mocks (crdt-provider.test.tsalso flips itsdestroy()assertion to the new function).Verification
pnpm --filter @memry/desktop typecheck:node— exit 0pnpm exec vitest run --config config/vitest.config.ts --project mainfor the 3 sync test files — 44 passed (incl. the 4 new)pnpm lint— exit 0 (0 errors)Notes
MEMRY_DOCS_IMPACT_SKIP=1): internal shutdown-sequencing correctness fix; no public API or user-facing config, and no existing doc describes the prior drop-on-quit behavior.