Skip to content

feat(api): let a profile change its synced list's schedule - #1899

Merged
Quick104 merged 7 commits into
feat/collections-revampfrom
feat/api-personal-sync-schedule
Oct 4, 2026
Merged

Quick104 merged 7 commits into
feat/collections-revampfrom
feat/api-personal-sync-schedule

Conversation

@Quick104

@Quick104 Quick104 commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

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.

updateCollection now accepts sync_schedule (daily, weekly, monthly, or "" to stop scheduled syncs). Collection reads report sync_cadence, and the capability document reports sync_schedule_editable. If the schedule changes while a sync is running, on any node, the change survives the sync.

Approach

  • The value goes through the same name check the import routes use. A cron expression gets 422 from every account, administrators included, and so do null and a schedule on a manual or smart collection. A cadence sets next_sync_at to its next run; "" clears the schedule and next_sync_at.
  • The member uses the existing update path, with its If-Match check, the imports feature check and the rule that only the collection's creator edits it. sync_schedule_editable therefore follows imports instead of always being true.
  • sync_cadence is daily, weekly, monthly, "" for a collection that isn't synced, or custom for any other stored expression. Only the /api/v2 mapping sets it.
  • A sync now records the schedule and next_sync_at it started with. When it finishes, the same UPDATE writes next_sync_at only 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 moves next_sync_at only 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/v1 is unchanged. The shared handler struct carries the field as json:"-", so the v1 update ignores it, and v1 responses carry no sync_cadence.
  • docs/catalog-api.md describes the member, sync_cadence and 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-apple and silo-android, read sync_cadence and offer a schedule picker when sync_schedule_editable is true.

Validation

  • Go: build, gofmt, vet and make lint-changed against feat/api-collection-capabilities-sync are clean. make test-go passes.
  • The usercollections, userstore, apiv2 and api/handlers packages 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_cadence for 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.
  • Edits during a sync: a TMDB list sync is held mid-fetch while the schedule is turned off or changed through the update handler, and the edit survives. Store and scheduler tests cover a schedule turned off, changed, changed and changed back, saved again with the same cadence, or turned on during a sync, and a failed scheduled sync, including a node whose clock runs behind the database. With the store and scheduler changes reverted, the edit-during-sync tests fail.
  • Two DB-backed tests this branch doesn't touch fail on that database, the same way on the base branch: TestAdminSubtitleListPageDB and TestCatalogTransferPersistsJobsAndSignedLink.
  • Contract: verify-apiv2-openapi, verify-apiv2-contract (11 additive changes, none breaking), verify-apiv2-fixtures, verify-apiv2-web-types, verify-route-inventory, verify-migration-ledger and TestCommittedArtifactMatchesRouter pass. So do verify-settings-bindings-all, verify-playback-fixtures, verify-scenario-catalogs and verify-offline-routes.
  • Web: lint, format:check, build, budget:check, tsc -b and make test-web pass.
  • make verify-local-paths passes.

Risks

  • Additive on /api/v2: sync_cadence is a new required property on every personal collection response, sync_schedule_editable on the capability document, and updateCollection gains an optional member. The contract isn't locked yet, and clients that don't know the fields ignore them.
  • updateCollection matches cadence names exactly, so Daily gets 422. The import routes still accept the names in any case.
  • The compare-and-set and the failed-sync retry are each one UPDATE, so they hold when the sync and the edit run on different nodes.
  • Collections — Server #193 S2 (Pass on build 1012) covers edits through the update route this PR extends, so S2 needs a re-test after merge. The existing edits, the If-Match check 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

  • I read and can explain the complete diff.
  • This pull request addresses one concern.

AI Disclosure

  • Harness: Claude Code (in T3 Code)
  • Tool(s): Claude Code subagents (implementer, independent reviewer)
  • Model(s): claude-opus-5-5[1m]
  • Involvement: Fully AI-generated, human review pending
  • Adversarial review: An independent reviewer subagent read the full diff, checked every caller of the sync-state write and the contract diff, and ran the new tests on its own migrated database. In a scratch copy it reverted the store and scheduler changes to confirm the edit-during-sync tests fail without them. It approved with one nit: the failed-sync retry compared next_sync_at with 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

  • Lets a profile update its synced list's schedule via an optional sync_schedule field 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.
  • v2 responses now include sync_cadence (normalized label, including custom) and a sync_schedule_editable capability driven by the account's imports feature. Contract and TypeScript schema updates in openapi.json.
  • Sync completion uses a compare-and-set on next_sync_at so 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.
  • Risk: sync_cadence is a required member in v2 collection response schemas, so strict contract consumers must be regenerated; updatePersonalCollection on manual and smart collections with sync_schedule now returns a validation error.
  • Behavioral Change: v1 update requests continue to ignore sync_schedule because collections.go excludes the field from generic JSON decoding.

Macroscope summarized 1ab773d.

Quick104 and others added 2 commits October 4, 2026 05:38
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]>
@coderabbitai

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bc730f93-0834-49a2-a887-8d2163912a42

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-04T20:59:28.169764Z 1ab773d New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@macroscopeapp

macroscopeapp Bot commented Oct 4, 2026

Copy link
Copy Markdown

The v2 update path adds an owner-only sync_schedule write. Build 1012 evidence for #193 S2 covers existing collection creation, edits, and member operations, not schedule writes on synced lists. The PR must make clear why this changes the validated edit surface, and S2 needs re-validation after merge. This also adds a mutation within S7's owner-management scope, but #193 S7 remains blocked by #1615: this diff does not implement the required sharing and read-visibility behavior, so it does not unblock S7.

Suggested Validation tasks: line:
Validation tasks: changes #193 S2, S7; S7 remains blocked by #1615

Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.

Posted via Macroscope — v1 validation impact

Quick104 and others added 2 commits October 4, 2026 08:38
…-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]>
@Quick104

Quick104 commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

Updated the description: the Validation tasks: line now reads changes #193 S2, S7; S7 remains blocked by #1615, and Risks explains why S2 needs a re-test after merge.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +878 to +879
WHEN sync_schedule IS NOT DISTINCT FROM $9 AND next_sync_at IS NOT DISTINCT FROM $10 THEN $5
ELSE next_sync_at

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +579 to +580
ScheduleAtStart: collection.SyncSchedule,
NextSyncAtAtStart: collection.NextSyncAt,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Base automatically changed from feat/api-collection-capabilities-sync to feat/collections-revamp October 4, 2026 20:20
Quick104 and others added 2 commits October 4, 2026 16:45
…-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]>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Quick104
Quick104 merged commit 55cd117 into feat/collections-revamp Oct 4, 2026
23 checks passed
@Quick104
Quick104 deleted the feat/api-personal-sync-schedule branch October 4, 2026 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant