Repository navigation
fix(userstore): keep a played mark made in the same second as an unplayed mark - #2217
Conversation
RealtimeEventsProvider loads with the app and imported adminDownloadStorageRootKey from the download storage API module, which pulled that whole module into the launch chunk. The key now lives in adminDownloadStorageCache, as adminSessionsKey does, so the API stays in the admin Downloads chunk. The launch bundle drops from 326,619 B to 326,313 B brotli, back inside the budget check's tolerance.
A history removal stores its watermark to the microsecond, but imported progress and history were checked against it as whole-second RFC 3339 text. A played mark in the same second as an earlier removal compared at or before the watermark and stayed hidden, while webhook sync recorded the event as applied. The Postgres store now compares imported writes with the watermark as timestamptz, and watch state hands imported history to the store with its full time. Imported history keeps its whole-second stamp unless that second is at or before the watermark, so replays still match rows stored before. SQLite keeps whole-second text and truncates sub-second input.
An import that lands in a removal's second keeps its precise time, so an exact-time duplicate check let the same play through twice when two sources reported it a few milliseconds apart. Imported history now treats any row in the same second as the same play, which also still matches whole-second rows stored before. AddHistory inserts the time it checked.
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
…second-replay # Conflicts: # scripts/ci/db-contracts.txt
…dle" This branch only carried that commit so the web launch bundle budget check would pass. Silo-Server#2246 fixed the budget on main, so the change now stays in Silo-Server#2204 alone. This reverts commit e954671.
…second-replay # Conflicts: # scripts/ci/db-contracts.txt
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review summary (head
|
|
The
Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
|
I'm keeping the line. In this repository, The cases are reachable:
|
Problem
Closes #2193
Related issue: N/A
Validation tasks: unblocks #1238 C1, C2; unblocks #1240 C3, #1241 C3, #1242 C3
If an item is marked unplayed and then played again within the same second, for example a quick double toggle in Jellyfin or Emby, the mapped Silo profile ends up unwatched. Webhook sync logs both events as applied, so resending doesn't fix it. With this change the played mark lands and the item is watched.
A history removal stores its watermark (
hidden_before) to the microsecond. The Postgres user store checked imported progress and history against it as whole-second RFC 3339 text, and watch state also handed imported history to the store in whole seconds. So a played write at 12:00:00.9 was checked as 12:00:00, which is before a removal at 12:00:00.5, and was dropped. This hits every write that carries its own event time: Jellyfin and Emby webhook sync (including theTogglePlayedmarks from #2178), history import, watch-provider sync and client progress sync.Approach
SetProgressAtandSetProgressIfNewerpass the event time itself to the watermark check, so Postgres compares two timestamptz values at the same precision. Those rows were already stored at full precision; only the check was rounded.AddHistoryIfMissingcompares that with the watermark at full precision. It still stores the whole second, as imports always have, unless that second is at or before the watermark; then it keeps the precise time, which is what keeps the row visible. Any row in the same second counts as the same play, so reruns still match rows written before this change, and a webhook mark and a later import of the same play don't both land.updated_atandwatched_atas whole-second RFC 3339. Sub-second history rows already exist (a mark after a removal is stored athidden_beforeplus one second), and history paging already handles them.AddHistoryIfMissingthere now cuts the new sub-second input back to whole seconds, because...:05.5Zsorts before...:05Zas text. Unplayed then played within one second still ends up unwatched on SQLite. I didn't change its storage format because the SQLite store is retired at 1.0.Validation
mainand pass on this branch: a Postgres store test of the removal boundary (writes at and before the removal stay hidden, a write later in the same second is visible, duplicates within the second are refused) and a webhook sync test that sends JellyfinTogglePlayedand Embyitem.markunplayedthenitem.markplayedwithin one second against the real Postgres store. Both are pinned inscripts/ci/db-contracts.txt.go testpasses forinternal/userstore/pgstore,internal/webhooksync,internal/userdb,internal/watchstateandinternal/historyimport.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-2217/
The same Jellyfin
UserDataSaved/TogglePlayeddeliveries sent to a local server built frommainand from this branch: played at 11:59:00, unplayed at 12:00:00.5, played at 12:00:00.9. After each one I read the profile's progress. Data is synthetic (one movie, one webhook connection, fresh database).Before (
main, bf63b3d):After (this branch, f5ca1ff):
Surface and build:
GET /api/v1/progress(native API, profile-scoped), local integrated server on PostgreSQL 18. The branch's later commit only changes duplicate detection within one second, which this sequence doesn't exercise.Benchmarks
Not applicable. The change alters which timestamp a write is compared and stored at, not how much work it does: the same single-row lookups by primary key, with one extra parameter.
Risks
watched_at. Reads already truncate history to the second for paging, so clients see the same whole-second value as before.AddHistoryandAddHistoryIfMissingnow parsewatched_atas RFC 3339 before querying. Every caller already passes RFC 3339; a string only Postgres could read would now fail with a parse error.Checklist
AI Disclosure
AI-assisted with Claude Opus. I directed the task and designed the work.
AddHistoryinsert the time it checks, which I did. Its note on an unreachable helper with the same rounding was left out of scope.Note
Normalize imported watched-at timestamps to UTC whole seconds in
userdb.AddHistoryIfMissingParses valid RFC 3339 watched-at values in the history import helper in progress.go and stores them as UTC whole-second text. The same normalized value is used for the SQLite visibility check and the insert. Inputs that cannot be parsed keep the prior handling.
Macroscope summarized ff8c348.