Repository navigation
feat(api): let a profile change its synced list's schedule - #1899
Conversation
The collection editor needs to change how often a profile's synced list syncs. Until now a personal schedule could only be picked at import, so a profile had to delete and re-import a list to change it. updateCollection takes sync_schedule on a synced list: daily, weekly, monthly, or "" to stop scheduled syncs. Cron expressions are refused for every account, and manual and smart collections take no schedule. The shared handler field is json:"-", so the frozen /api/v1 update still ignores it. Reads report sync_cadence (custom for any other stored expression) on /api/v2 only, and the capabilities report sync_schedule_editable. A sync now writes next_sync_at only while the stored schedule is the one it started with, and a failed scheduled sync pushes back only a next_sync_at that is still due, so a schedule edited while a sync runs on any node keeps what the edit wrote. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
listDue picks due rows with the database's NOW(), but the failure push-back compared against the node's own clock. A node running behind the database skipped the push-back and retried a broken source on every tick. Compare against NOW() and keep the node time only for the next run. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 61c8d95d1a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| SET last_sync_at = $1, last_sync_status = $2, last_sync_message = $3, | ||
| item_count = $4, next_sync_at = $5, updated_at = $6 | ||
| item_count = $4, updated_at = $6, | ||
| next_sync_at = CASE WHEN sync_schedule IS NOT DISTINCT FROM $9 THEN $5 ELSE next_sync_at END |
There was a problem hiding this comment.
Track schedule edits instead of comparing cadence values
When a sync starts on daily and the profile PATCHes daily again—or changes away from and back to daily—before completion, sync_schedule still equals $9, so this CASE overwrites the next_sync_at established by the latest PATCH. The race also applies across cluster nodes, so same-cadence or ABA edits can be silently lost despite the advertised preservation behavior; compare a schedule revision or the starting schedule state rather than only the cadence value.
AGENTS.md reference: AGENTS.md:L13-L18
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in bf2933f. The sync now records the next_sync_at it started with as well as the schedule, and writes its own next run only while the row still holds both. A same-cadence save or a change-and-back during the sync rewrites next_sync_at, so the edit now wins. This is still one UPDATE, so it also holds across nodes, with no migration. New store tests cover a same-cadence save and a daily→weekly→daily change during a sync, and both fail without the fix.
|
The v2 update path adds an owner-only Suggested Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
…-sync' into feat/api-personal-sync-schedule # Conflicts: # contracts/api/v2/fixtures/get_collection_capabilities_ok.json # contracts/api/v2/fixtures/get_system_info_ok.json # contracts/api/v2/fixtures/index.json # contracts/api/v2/openapi.json # internal/apiv2/personal_collections.go # internal/apiv2/personal_collections_test.go # internal/usercollections/validate.go
The sync-state compare-and-set only compared the stored cadence with the one the sync started on. Saving the same cadence again, or changing it and back, during a sync left the cadence equal, so the finishing sync replaced the next_sync_at the save wrote. The sync now also requires next_sync_at to be the value it started with. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Updated the description: the |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bf2933f70c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| WHEN sync_schedule IS NOT DISTINCT FROM $9 AND next_sync_at IS NOT DISTINCT FROM $10 THEN $5 | ||
| ELSE next_sync_at |
There was a problem hiding this comment.
Distinguish failure retries from schedule edits
When two cluster nodes select the same due weekly or monthly collection, one sync can fail and advance next_sync_at by 24 hours before the other succeeds. This CASE treats that retry update as if it were a profile edit, so the successful sync preserves the retry time instead of installing the next weekly/monthly run, causing an unnecessary sync the following day. Since scheduler in-flight tracking is node-local, this interleaving is reachable; use an edit revision or another user-edit witness rather than treating every next_sync_at change as a schedule edit.
AGENTS.md reference: AGENTS.md:L13-L18
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 1ab773d. The scheduler now claims a due list before syncing it: one UPDATE moves next_sync_at past the minimum interval while the row is still due, and only the node whose UPDATE matched runs the sync. A second node that listed the same list skips it, so a failed sync on one node can no longer leave its retry time for another node's successful sync to mistake for an edit. The claimed time is the retry time on failure, so the separate failure write is gone. A new DB test runs the list on two schedulers and checks that the second one skips it.
…-sync' into feat/api-personal-sync-schedule Brings in #1875 login-wide personal collection sharing and the scrobble lock fixes. The sync_schedule update field and sync_cadence response field sit on top of #1875's model: allowed_profile_ids is gone from /api/v2, the group_id doc now says groups are unsupported, and the schedule DB test creates shared collections without an allow list. Contract artifacts are regenerated. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9cf633e087
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ScheduleAtStart: collection.SyncSchedule, | ||
| NextSyncAtAtStart: collection.NextSyncAt, |
There was a problem hiding this comment.
Return the preserved schedule after a concurrent edit
When another node PATCHes the collection while its initial import sync is running, this compare-and-set correctly preserves that edit in PostgreSQL, but applyResult still constructs updated from the pre-sync collection and assigns its own nextSyncAt; createImportedCollection then serializes that stale value. The import response can therefore report the old sync_schedule, sync_cadence, and next_sync_at even though the database retained the edit, potentially causing a client to replace fresh state with stale state. Re-read the collection after updating the sync state, or return whether the conditional assignment occurred.
AGENTS.md reference: AGENTS.md:L13-L18
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 1ab773d. applyResult now reads the row back after writing the sync state, so the import and sync-now responses show the schedule and next_sync_at the database kept. The import's failed-sync path reads it back as well, and falls back to the old copy only if that read fails. A unit test checks that a schedule edited during the sync is the one returned.
…-personal-sync-schedule # Conflicts: # contracts/api/v2/fixtures/get_system_info_ok.json
…as stored Every node runs the user collection scheduler, so two nodes could sync the same due list. When one failed first, its retry time looked like a schedule edit to the other's successful sync, which kept it and synced again the next day. The scheduler now claims a due list before syncing it: one UPDATE moves next_sync_at past the minimum interval while the row is still due, and only the node that made that move runs the sync. The claimed time is the retry time on failure, so the separate failure write is gone. A sync and an import also built the collection they return from the copy read before the sync, so a schedule saved while the sync ran came back stale even though the database kept it. Both now read the stored row back. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1ab773debe
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
| defer s.inFlight.Delete(dc.CollectionID) | ||
|
|
||
| if claimed, err := s.claim(ctx, dc); !claimed { |
There was a problem hiding this comment.
Preserve edits made after claiming a scheduled sync
If a profile saves the schedule after claim updates next_sync_at but before SyncCollection performs its GetCollection, the sync loads the edited schedule and next-run value as its starting state. Its compare-and-set completion then considers that edit part of the original state and overwrites the profile's newly computed next_sync_at with the sync's next run, so same-cadence edits in this claim-to-load window are lost. Capture and pass the schedule state that was claimed (or otherwise distinguish the claim from a user edit) instead of reloading it as the sync start state.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not a defect. A save that lands before SyncCollection reads the collection is a save made before the sync started. The sync then runs with the saved schedule and source and starts from the saved next_sync_at. On success it writes that same schedule's next run after the sync finished. That is what happens for any save made before a sync, and it was already the case before the claim, when the scheduler listed the row as due and the sync loaded it later. The saved schedule is kept. Only next_sync_at moves, from the saved schedule's next run after the save to its next run after the sync that followed it. A save that turns syncing off is kept too: the sync starts with no schedule and writes a null next_sync_at. The compare-and-set guards saves made while the sync runs, after it has read its starting state, and those still win.
Problem
Related issue: #192; supersedes the named-schedule part of #930
Validation tasks: changes #193 S2, S7; S7 remains blocked by #1615
Stacked on #1896 (
feat/api-collection-capabilities-sync).A profile picks a synced list's schedule (daily, weekly or monthly) when it imports the list from MDBList, TMDB or Trakt, and can't change it afterwards:
PATCH /api/v2/collections/{id}has no schedule member. To sync less often, or to stop scheduled syncs, the profile has to delete the list and import it again. A client that wants to show the schedule has to recognize the cron expression the server stores.updateCollectionnow acceptssync_schedule(daily,weekly,monthly, or""to stop scheduled syncs). Collection reads reportsync_cadence, and the capability document reportssync_schedule_editable. If the schedule changes while a sync is running, on any node, the change survives the sync.Approach
nulland a schedule on a manual or smart collection. A cadence setsnext_sync_atto its next run;""clears the schedule andnext_sync_at.If-Matchcheck, theimportsfeature check and the rule that only the collection's creator edits it.sync_schedule_editabletherefore followsimportsinstead of always being true.sync_cadenceisdaily,weekly,monthly,""for a collection that isn't synced, orcustomfor any other stored expression. Only the/api/v2mapping sets it.next_sync_atit started with. When it finishes, the same UPDATE writesnext_sync_atonly if the row still holds both, so saving the same cadence again during a sync also keeps the next run the save set. Status, message, item count and sync time are written either way. The scheduler's retry after a failed sync also movesnext_sync_atonly while it is still due by the database clock. Without that second change, a failed sync would replace a schedule turned off during it with a retry 24 hours later./api/v1is unchanged. The shared handler struct carries the field asjson:"-", so the v1 update ignores it, and v1 responses carry nosync_cadence.docs/catalog-api.mddescribes the member,sync_cadenceand what happens to an edit made during a sync, next to the other personal collection sections (there is no separate collections API doc). The OpenAPI document, fixtures, system-info digest and web types are regenerated.This re-implements the named-schedule part of #930 by @bulderi, as the maintainer decided for the collections redesign. Admin cron schedules on personal lists (#925) and #930's migration of existing schedules are not included.
No web code sends the field yet; the synced list editor will. jellycompat needs no change. Follow-ups are not filed yet: in
silo-appleandsilo-android, readsync_cadenceand offer a schedule picker whensync_schedule_editableis true.Validation
make lint-changedagainstfeat/api-collection-capabilities-syncare clean.make test-gopasses.usercollections,userstore,apiv2andapi/handlerspackages ran against a freshly migrated database. The new tests cover each cadence and its next run,""turning syncing off, and cron strings refused for a regular and an admin account with the row and ETag unchanged. They also cover manual and smart collections refused,sync_cadencefor each value, the v1 update ignoring the member and v1 responses keeping their keys. They restate Collections — Server #193 S2: a profile that can see a shared collection it didn't create gets 403, a profile that can't see it and another login get 404, and the row is unchanged.TestAdminSubtitleListPageDBandTestCatalogTransferPersistsJobsAndSignedLink.verify-apiv2-openapi,verify-apiv2-contract(11 additive changes, none breaking),verify-apiv2-fixtures,verify-apiv2-web-types,verify-route-inventory,verify-migration-ledgerandTestCommittedArtifactMatchesRouterpass. So doverify-settings-bindings-all,verify-playback-fixtures,verify-scenario-catalogsandverify-offline-routes.tsc -bandmake test-webpass.make verify-local-pathspasses.Risks
/api/v2:sync_cadenceis a new required property on every personal collection response,sync_schedule_editableon the capability document, andupdateCollectiongains an optional member. The contract isn't locked yet, and clients that don't know the fields ignore them.updateCollectionmatches cadence names exactly, soDailygets 422. The import routes still accept the names in any case.If-Matchcheck and the 403 and 404 answers to other profiles and logins are unchanged, and the new member follows the same creator-only rule. S7 also covers owner-only changes, but it stays blocked by Personal collections: owner-only management and a single share-with-all-profiles switch #1615, which this PR does not implement.Checklist
AI Disclosure
next_sync_atwith the node's clock, while the scheduler selects due rows by the database clock. The retry now uses the database clock, with a test for a node whose clock runs behind. No findings remain open.🤖 Generated with Claude Code
Note
Add profile-editable sync schedules for synced lists in the v2 API
sync_schedulefield on v2 collection updates, accepting empty, daily, weekly, and monthly cadences. Only syncable collections and the list creator can edit the schedule; an empty value turns scheduling off. See personal_collections_lifecycle.go and collections_lifecycle_service.go.sync_cadence(normalized label, includingcustom) and async_schedule_editablecapability driven by the account's imports feature. Contract and TypeScript schema updates in openapi.json.next_sync_atso a schedule edited during a running sync is not overwritten; the scheduler now atomically claims due collections in the database so only one node runs each sync and claims set the retry time before execution. See collections.go and scheduler.go.sync_cadenceis a required member in v2 collection response schemas, so strict contract consumers must be regenerated;updatePersonalCollectionon manual and smart collections withsync_schedulenow returns a validation error.sync_schedulebecause collections.go excludes the field from generic JSON decoding.Macroscope summarized 1ab773d.