Repository navigation
fix(library): keep a newer play when an older progress update arrives late - #64
Conversation
… late The apps queue progress updates and can send them late: a browser tab closed before its queue drained, a phone back online. updateLibraryItem kept the last write, so that older position overwrote a newer play from another device. Every progress update says when it was played (lastPlayDateTimestamp); an update played strictly before the stored last_play_date now keeps everything except its position, progress, finished flag and play time, and still answers success so the app clears it from its queue. Updates without a play time (mark as finished, a rename) or with 0 (a clear) are never held back.
🟡 Claude PR Review —
|
Log when an older progress update is held back. sync_operations skips playback-only updates, so this is the only trace when someone asks why their progress didn't move.
|
Replies to the review on 2cd6500 (neither finding had a line in the diff, so they're answered here):
|
Log a held-back update at warn: production drops info. A stored play dated in the future (a device clock set ahead) no longer holds updates back, so it can't freeze a book's progress on every other device.
Name the held-back log after the method that raises it.
|
Replies to the round-3 notes on 337f37b (none had a line in the diff):
|
Two 5% samples of production library_items (about 14k played books) found no play time ahead of the server clock: devices set their time from the network, so the case it guarded doesn't happen.
|
Replies to the review on ebd8035. Neither finding had a line in the diff, and neither leads to a change:
|
Problem
The apps queue progress updates and can send them late. On the web, closing the tab within about a second of a pause or a seek leaves the update in the queue, and it goes out the next time the app opens. A phone coming back online does the same.
updateLibraryItemkeeps the last write, so that older position overwrites a newer play from another device.Found while testing bookplayer-web#10 against production: six queued rewinds from the web, stamped 16:31:57, were waiting to overwrite a 16:35:52 play from Safari.
Fix
Every progress update already says when it was played (
lastPlayDateTimestamp: the web sends whole seconds, iOS a fractionaltimeIntervalSince1970, Android its progress timestamp). Before saving,updateObjectreads the row'slast_play_date(by uuid, or by path when there's no uuid):actual_time,percent_completed,is_finishandlast_play_date, so a title or speed in the same update still applies. It answers success, so the app clears the task instead of retrying it forever.The extra read only happens for updates that carry a play time.
Testing
tsc --noEmitpasses.LibraryServiceStaleProgress.test.ts: a late older update is kept out and still answers success; newer and same-second updates apply; the rest of a stale update applies; a stale update can't un-finish a book; mark-as-finished without a timestamp applies; a never-played book takes the first update; the by-path check without a uuid. They run in CI's Postgres. Docker wasn't available locally.After deploy
Open the web build that still holds the six stale updates, let them go out, and check in the database that the book keeps the newer Safari position.
🤖 Generated with Claude Code