Offline-aware, conflict-safe document sync (timestamp merge + pending set)#57
Merged
Merged
Conversation
… set) Stops auto-sync from stomping edits and makes offline changes safe. - Every garage record carries updatedAt: added to Vehicle/VehicleType; stamped in each storage save* (the sync write path keeps the cloud value). - merge.ts (pure, tested): decideSync = pending-wins + last-write-wins by the record's own updatedAt (not the server row time). - pendingSync.ts: persistent offline "pending changes" set in the plugin KV. - syncEngine.reconcileDocs: timestamp-aware two-way merge (pull cloud-newer, push local-newer/-only), skipping pending keys; replaces pushDocs/pullDocs. - autoSync: tracks navigator.onLine + window online/offline; records changes as pending when offline or on failed push; on reconnect/sign-in flushes pending first (priority-1, replacing cloud) then reconciles the rest. - StoragePanel flags offline state + the pending-change count. https://claude.ai/code/session_01K4mWVsXnwhtEi92FVBVhB3
Coverage SummaryLines: 14.57% (1548/10622) · Statements: 13.93% · Functions: 10.54% · Branches: 10.9% Per-file coverage
|
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
Makes the document auto-sync conflict-safe and offline-aware so it stops
"stomping" edits — directly addressing the timestamp-merge follow-up.
The merge model (you chose: pending-wins + timestamp LWW)
updatedAt— added toVehicle/VehicleType,and stamped in each storage
save*(the sync write pathwriteOnekeeps thecloud value, so a pull never re-stamps).
merge.ts(pure, unit-tested) —decideSync:pushed up, replacing the cloud copy, regardless of clocks;
updatedAt(its logical edittime — never the server row time, so a late-uploaded stale edit can't win);
Offline handling
pendingSync.ts— a persistent "pending changes" set in the plugin KV, sooffline edits survive a reload.
autoSynctracksnavigator.onLine+ windowonline/offline. Whileoffline (or on a failed push) a change is recorded pending; on reconnect /
sign-in it flushes pending first (priority-1), then
reconcileDocsdoes atimestamp-aware two-way merge of the rest (skipping pending keys).
StoragePanelflags offline state and shows the pending-change count.Engine
reconcileDocs(userId, pendingKeys)replaces the oldpushDocs/pullDocs(unconditional cloud-wins) with the merge above.
Logs are untouched (no auto-sync there yet, per scope). Manual push/pull in the
Cloud Sync panel is unchanged.
Test plan
npm run lint/npm run typecheck/npm run test:run(335; +7 merge cases) /npm run builddecideSynccovered: pending-put push, pending-delete skip, local-only push, cloud-only pull, LWW both directions, equal/none skiphttps://claude.ai/code/session_01K4mWVsXnwhtEi92FVBVhB3
Generated by Claude Code