fix: store lastUpdate on the CRDT session record for reliable recovery#911
Open
Anexus5919 wants to merge 1 commit into
Open
fix: store lastUpdate on the CRDT session record for reliable recovery#911Anexus5919 wants to merge 1 commit into
Anexus5919 wants to merge 1 commit into
Conversation
|
@Anexus5919 is attempting to deploy a commit to the somiljain2024-4175's projects Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Author
|
@Somil450 @diksha78dev Kindly have a review on this pr. Thanks! |
listActiveSessions built a Y.Doc and decoded a Yjs update per session on the main thread just to read lastUpdate, and it applied only the last partial delta. For a non-compacted session that delta does not carry the lastUpdate field, so it read as 0 and the 30-minute recency filter in useWorkoutSync dropped the session, breaking active-session recovery on reload. Persist lastUpdate as a plain field on the record and read it directly, removing the per-session main-thread decode and fixing the recency read.
15eab14 to
679723e
Compare
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.
📌 Related Issue
Fixes #874
📝 Description
listActiveSessionsinsrc/services/crdtSessionEngine.tsrebuilt aY.Docand decoded a Yjs update per session synchronously on the main thread (during the mount cursor walk) just to readlastUpdate. It also applied only the last persisted delta, which for a non-compacted session does not carry thelastUpdatefield, solastUpdateread as0, and the 30-minute recency filter inuseWorkoutSyncdropped the session, silently breaking active-session recovery on reload.🔹 What has been changed?
persistUpdate: writelastUpdateas a plain field on the IndexedDB record.listActiveSessions: readvalue.lastUpdatedirectly, with noY.Docconstruction and no decode.🔹 Why are these changes needed?
lastUpdatefrom a single partial delta is incorrect (the field usually isn't in that delta, so it reads0) and also pays a per-session main-thread Yjs decode on mount. StoringlastUpdateas a plain field makes the recency read correct and removes the decode.loadSessionFromDB(the real recovery path) already applies all updates and is unaffected; pre-existing records lack the field and age out within the 24h cleanup window.🛠️ Type of Change
🧪 Testing
✅ Tests Performed
npx tsc --noEmit: changed file clean;npx eslint: 0 problems.lastUpdatekey) and theuseWorkoutSyncrecency filter.🔹 Note on automated tests
No committed unit test: this path depends on IndexedDB and the repo has no
fake-indexeddbtest harness, so adding one would drag in unrelated lockfile changes. Verification is bytsc/eslintand the reasoning above.🌐 Browsers Tested
Not applicable (IndexedDB/sync logic).
📷 Screenshots / Demo (if applicable)
Not applicable.
📋 Checklist
💬 Additional Notes
Branched from latest
upstream/main(5464425). The original finding also mentioned a "lost-update race"; I investigated and it does not hold (persistUpdateruns itsget/putin the same transaction, and IndexedDB serializes overlappingreadwritetransactions, so concurrent persists cannot read stale data). The decode/recovery bug above is the real, reachable issue, and that is what this PR fixes.