fix(sync): progress compares client clock with itself; mobile retries failed reading sessions - #695
Merged
Merged
Conversation
mrviduus
enabled auto-merge (squash)
October 4, 2026 20:01
mrviduus
disabled auto-merge
October 4, 2026 20:07
mrviduus
force-pushed
the
fix/progress-clock-and-sessions
branch
2 times, most recently
from
October 4, 2026 21:17
b64e617 to
6a9b123
Compare
…ries failed reading sessions - reading_progresses.client_updated_at: catalog progress stale-write guard compared client UpdatedAt with server-stamped UpdatedAt, so a device clock behind the server had newer writes refused with 200. Now compared only with the stored client stamp (ProgressClock), clamped to server now + 5 min so a future clock can't freeze the row. - mobile stamps progress with the time it was recorded (snapshot), like web. - mobile: failed session submits queued in AsyncStorage (cap 50), flushed after each session, on sign-in/app start and on reconnect; cleared on sign-out. Queue rules shared with web. - server: session dedup pre-check covers edition sessions too (unique index already existed). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
mrviduus
force-pushed
the
fix/progress-clock-and-sessions
branch
from
October 4, 2026 21:42
6a9b123 to
8de3efb
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.
Why
Architecture review 2026-10, #12: silent data loss.
What
UserDataEndpoints.UpsertProgress, both normal and insert-race paths) compared the client'sUpdatedAtwith the server-clockUpdatedAt→ a device whose clock is behind had its newer writes rejected with 200. NewProgressClock: incoming client stamp (clamped to server now + 5 min) vs storedClientUpdatedAt; null on either side → accept.UpdatedAtstays the server write time.ProgressClientUpdatedAt— adds nullablereading_progresses.client_updated_atonly.updateProgresstakesrecordedAt; mobile now stamps record time (web already did)..catch(()=>{})). Now a persisted AsyncStorage queue (reading.pendingSessions, cap 50, drop ≥6 days, serialised ops) flushed on submit, sign-in/app start and reconnect; cleared on sign-out. Pure rules inpackages/shared/src/reader/pendingSessions.ts. Server already dedups by (user, book, started_at); pre-check now covers edition sessions too.Backward compat
Request/response shapes unchanged; old rows null → first write accepted; old mobile builds (send-time stamps) still correct.
Verified
UnitTests 1476 (10 new
ProgressClockTests); mobile vitest 458 (5 new); shared vitest 560 (18 new); web hooks 152; tsc clean everywhere;dotnet formatclean. Integration: the old "known defect" test inverted toMarkFinished_DeviceClockBehindTheServer_NewerWriteStillWins+ new stale-write test — run by CIdockerjob.Rollback
Revert (column is additive; leave it).
🤖 Generated with Claude Code