You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(collections): record a failed personal collection sync and say why - #3487
When a personal collection's sync fails, only the first sync on import records it. Sync now and scheduled syncs leave the collection showing its last recorded sync, often a success, so nobody can see the list has stopped syncing. Sync now also answers every failure with a 500, so the web shows "An unexpected error occurred." whatever went wrong. This affects every source: MDBList, TMDB presets and TMDB lists.
I found it on my own server. A personal collection's MDBList list went private, its nightly sync has failed every night since, and the collection still shows the result of a sync from days earlier. The scheduler only logs the failure. Pressing Sync now on it just gives the generic error.
Approach
usercollections.RunSync now records a failed sync on the collection whenever it fails before the members change (reading the config, owner access, fetching the source, choosing members, or replacing the members fails): status failed, the error's message, and the members, item count and next run kept as they were. RunSync now replaces the members itself before applyResult, which only records the sync, so a failure after the members changed isn't recorded over them with the old item count. That's what admin collection syncs and the import's first sync already do, and what ownerFilter already did for its own failure, which now shares the same helper. The write runs detached from the sync's context, so a sync that hit its timeout still records why. The message goes through logredact.SanitizeURLError, as the admin path does.
A failure to read the source list now comes back as a SourceError. On v2, Sync now answers it with dependency_unavailable (503) and Sync failed: <reason>, without Retry-After. That status is already in the operation's contract, so there's no new problem type or response code. The handler is shared with the frozen v1 route, which keeps answering 500 as before; the handler attaches the SourceError as the cause and only the v2 layer maps it. Other failures, such as a database error, still answer 500 on both.
A failed sync records only while the collection's last_sync_at is still the one it started from (a new opt-in RequireLastSyncAt condition on the sync state update). Two Sync nows can run at once, and without this an earlier one that failed late would overwrite the result of a later one that finished first.
The import handler's own failure write is gone, since RunSync now records the same state. The web refreshes the collection after a failed Sync now, so the card shows "Sync failed" without a reload.
Validation
go test ./internal/usercollections/: pass. The TMDB list fetch-error test now also checks that the failure is recorded with the redacted message, the item count is kept, the members aren't replaced, and the error is a SourceError. A new table test covers the two write failures: a failed member replacement is recorded with the item count kept, and a failed state write after the members changed isn't recorded over them.
go test ./internal/apiv2/ -run 'TestPersonalSyncProblem|TestCollectionProblem': pass. The new test covers the source-failure and other-failure answers.
go test ./internal/userstore/pgstore/ ./internal/usercollections/ against a migrated Postgres: pass. TestPostgresFailedSyncKeepsANewerResult (added to scripts/ci/db-contracts.txt) fails without the new condition and passes with it; a service test covers the same race through RunSync.
go vet on the changed packages: clean. Prettier and ESLint on the changed web file: clean.
End to end on a local build, same database for both runs: a collection that had synced, then had its MDBList list removed. On main, Sync now gave a 500 and left the collection reporting success. On this branch it gave 503 with the reason, and the collection recorded the failure. A scheduled run on the branch recorded the failure too. Details under Evidence.
Lint and the rest of the gate run in CI on this PR.
The new branch in the Sync now handler has no unit test of its own; the end-to-end run covers it.
Sync now on the Collections page after the collection's MDBList list was removed (web app at desktop and phone width, local build; main at 6aa6791ea vs this branch at 128cfff6e):
Before
After
Toast
An unexpected error occurred.
Sync failed: mdblist request failed with status 404
Card
No failure shown
Sync failed
last_sync_status / last_sync_message
success / Matched 0 of 72 entries
failed / mdblist request failed with status 404
The evidence page has desktop and phone-width screenshots from both builds, the steps used, the v1 and v2 responses from both builds (v1 answers 500 on both), and the scheduled run.
Risks
A sync that fails before its members change now changes last_sync_status, last_sync_message and last_sync_at on the collection where it used to leave them alone. That's the intended fix, and it matches admin collections.
On v2, Sync now can answer 503 dependency_unavailable where it answered 500. v1 is unchanged. The web shows the problem's detail. I found no personal collection sync call in silo-apple or silo-android, so the native apps shouldn't be affected, and jellycompat has no equivalent operation.
Checklist
I read and can explain the complete diff.
This pull request addresses one concern.
Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
The Evidence section shows every change a user can see, or says there is none.
AI Disclosure
Harness: Claude Code (desktop app)
Tool(s): Claude Code
Model(s): claude-opus-5-5
Involvement: AI-assisted. AI-assisted with Claude Opus. I directed the task and designed the work.
Only the first sync on import recorded a failure. Sync now and scheduled
syncs left the collection on its last recorded sync, and Sync now answered
every failure with a 500, so the web showed "An unexpected error occurred."
RunSync now records every failed sync on the collection, keeping its
members and next run, as admin collection syncs already do. A failure to
read the source list comes back as a SourceError, which Sync now answers
with dependency_unavailable and the reason, as MDBList search does. The
web refreshes the collection after a failed sync so the recorded state
shows.
RunSync now records covered sync failures, and source-fetch errors use a distinct type. The API maps those errors to HTTP 502. The client invalidates collection queries after a sync error.
Changes: Collection Sync Failures
Layer / File(s)
Summary
Record sync failures and preserve collection state internal/usercollections/sync.go, internal/usercollections/sync_owner_access_test.go, internal/usercollections/sync_tmdb_list_test.go
RunSync records failed status for covered errors. It preserves members and collection metadata in the specified failure cases, and wraps MDBList and TMDB fetch errors as SourceError. Tests cover write failures and source-fetch error details.
Report sync errors and refresh collection queries internal/api/handlers/user_collection_imports.go, web/src/hooks/queries/collectionScope.ts
The import handler relies on RunSync to record failure state and returns HTTP 502 for SourceError. The client invalidates collection queries after a sync error.
Silo-Server/silo-server#2615: Changes to member replacement affect the failure behavior when sync replaces collection members.
Silo-Server/silo-server#3481: Changes to MDBList fetch errors relate to how this PR wraps and reports source failures.
Suggested reviewers:quick104
Merge Risk: Moderate · up to efe6a
A failed overlapping sync can leave a collection’s recorded count inconsistent with its members, and source-fetch failures return an unexpected API status. Resolve both before merging.
Security architecture risk: Low · up to efe6a
Collection ownership and access checks remain intact, and stored failure messages receive URL-credential redaction. The main identified risk is bounded to overlapping syncs of the same collection: a late failure can overwrite newer count and status metadata without changing the newer members.
Retained concerns
Low · reliability · inferred: A failed sync is not fully contained to its own state snapshot. If another run replaces members and records their new count first, the new failure path can subsequently write its older ItemCount while leaving those newer members untouched. Manual sync checks scheduled activity but does not reserve the collection against another manual run. This broadens a pre-existing concurrency weakness to source, selection and replacement failures; the resulting metadata inconsistency remains scoped to the same collection.
Security review details
Security Blast Radius
observed — The inspected manual-sync path obtains the authenticated account's store, requires collection visibility and creator-profile ownership, and passes that collection into RunSync. Collection metadata reads remain access-controlled. The identified stale-write scenario affects one account-owned collection rather than granting cross-account mutation authority.
Trust Boundaries and Controls
observed — Owner-access resolution remains fail-closed: failure returns before source matching or member replacement. Membership selection uses owner accessibility rather than the stored item count or sync status, limiting the identified metadata race's security significance.
observed — Stored URL errors have userinfo, query strings, fragments and recognized signed-token path segments removed. The manual API still includes the returned error text, but it already included that text before this PR; changing its error classification alone does not establish a new disclosure path.
Resilience and Maintainability Implications
inferred — Transactional replacement prevents ordinary interleaving of member diffs, and scheduler claims reduce duplicate scheduled runs. Neither control orders all manual runs or protects terminal metadata against stale failure snapshots. Consequently, failure containment is incomplete even though the inspected access controls remain independent of that metadata.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta…
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 4 passed
Check name
Status
Explanation
Title check
The title "fix(collections): record a failed personal collection sync and say why" matches the main change. RunSync now records failed syncs on personal collections before member replacement, and Sync…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description check
The description is specific and on-topic. It names the affected code paths (RunSync, SourceError, the Sync now handler, the import handler, the web refresh). It states the problem, the approach, valid…
Full details: Title check
Explanation
The title "fix(collections): record a failed personal collection sync and say why" matches the main change. RunSync now records failed syncs on personal collections before member replacement, and Sync now returns a 503 with the failure reason instead of a generic 500. The title names the primary fix and the user-visible error message change. It is specific and conventional-commit formatted.
Full details: Description check
Explanation
The description is specific and on-topic. It names the affected code paths (RunSync, SourceError, the Sync now handler, the import handler, the web refresh). It states the problem, the approach, validation steps, end-to-end evidence, risks, and the affected sources (MDBList, TMDB presets, TMDB lists). Every part of it relates to the changeset in the raw summary.
Full details: Docstring Coverage
Explanation
Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 5 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
silo-triageBot
added
the
size/M
50–199 added + deleted lines (all files); change volume, not priority.
label
Nov 4, 2026
applyResult replaces the members before it records the sync, so recording
its failure would write the old item count over the new members. Record
the failures that happen before any write, and leave applyResult's own.
Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.
Reviewing changes in Silo
Include the related issue, expected behavior, and validation steps in the PR description.
For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
Follow this repository's AGENTS.md and CONTRIBUTING.md.
Request another review with @kody start-review in a PR comment.
React with 👍 or 👎 to give feedback on individual suggestions.
Review settingsReview Options
The following review options are enabled or disabled:
Options
Enabled
Bug
✅
Performance
✅
Security
✅
Business Logic
❌
⚠️ 4 Kody Rule(s) were not evaluated
These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:
Preserve optional store capabilities through production wrappers
Detach mandatory cleanup from request cancellation and bound its lifetime
Preserve durable media identity and share identity-evidence precedence
Bound decoder throughput trades and share direct-play eligibility
Replacing the members wrote nothing when it failed, so that failure is safe
to record. Replace them in RunSync before applyResult, which now only
records the sync, so only a failure after the members changed is left
unrecorded.
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.
…ilure
Sync now's handler is shared with the frozen v1 route, so it keeps
answering 500 and carries the SourceError as the cause; v2 answers it as
dependency_unavailable with the reason and no Retry-After.
A failed sync now records only while the collection's last_sync_at is
still the one it started from, so a sync that started earlier and failed
later can't overwrite a newer result.
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
bugSomething isn't workinggoPull requests that update go codeimpact: usabilityCore flow broken or severely blockedjavascriptPull requests that update javascript codepriority: P2Limited scope, workaround exists, or polishsize/L200–499 added + deleted lines (all files); change volume, not priority.
2 participants
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.
Problem
Related issue: N/A
Validation tasks: none
When a personal collection's sync fails, only the first sync on import records it. Sync now and scheduled syncs leave the collection showing its last recorded sync, often a success, so nobody can see the list has stopped syncing. Sync now also answers every failure with a 500, so the web shows "An unexpected error occurred." whatever went wrong. This affects every source: MDBList, TMDB presets and TMDB lists.
I found it on my own server. A personal collection's MDBList list went private, its nightly sync has failed every night since, and the collection still shows the result of a sync from days earlier. The scheduler only logs the failure. Pressing Sync now on it just gives the generic error.
Approach
usercollections.RunSyncnow records a failed sync on the collection whenever it fails before the members change (reading the config, owner access, fetching the source, choosing members, or replacing the members fails): statusfailed, the error's message, and the members, item count and next run kept as they were.RunSyncnow replaces the members itself beforeapplyResult, which only records the sync, so a failure after the members changed isn't recorded over them with the old item count. That's what admin collection syncs and the import's first sync already do, and whatownerFilteralready did for its own failure, which now shares the same helper. The write runs detached from the sync's context, so a sync that hit its timeout still records why. The message goes throughlogredact.SanitizeURLError, as the admin path does.A failure to read the source list now comes back as a
SourceError. On v2, Sync now answers it withdependency_unavailable(503) andSync failed: <reason>, withoutRetry-After. That status is already in the operation's contract, so there's no new problem type or response code. The handler is shared with the frozen v1 route, which keeps answering 500 as before; the handler attaches theSourceErroras the cause and only the v2 layer maps it. Other failures, such as a database error, still answer 500 on both.A failed sync records only while the collection's
last_sync_atis still the one it started from (a new opt-inRequireLastSyncAtcondition on the sync state update). Two Sync nows can run at once, and without this an earlier one that failed late would overwrite the result of a later one that finished first.The import handler's own failure write is gone, since
RunSyncnow records the same state. The web refreshes the collection after a failed Sync now, so the card shows "Sync failed" without a reload.Validation
go test ./internal/usercollections/: pass. The TMDB list fetch-error test now also checks that the failure is recorded with the redacted message, the item count is kept, the members aren't replaced, and the error is aSourceError. A new table test covers the two write failures: a failed member replacement is recorded with the item count kept, and a failed state write after the members changed isn't recorded over them.go test ./internal/apiv2/ -run 'TestPersonalSyncProblem|TestCollectionProblem': pass. The new test covers the source-failure and other-failure answers.go test ./internal/userstore/pgstore/ ./internal/usercollections/against a migrated Postgres: pass.TestPostgresFailedSyncKeepsANewerResult(added toscripts/ci/db-contracts.txt) fails without the new condition and passes with it; a service test covers the same race throughRunSync.go veton the changed packages: clean. Prettier and ESLint on the changed web file: clean.main, Sync now gave a 500 and left the collection reporting success. On this branch it gave 503 with the reason, and the collection recorded the failure. A scheduled run on the branch recorded the failure too. Details under Evidence.The new branch in the Sync now handler has no unit test of its own; the end-to-end run covers it.
Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-3487/
Sync now on the Collections page after the collection's MDBList list was removed (web app at desktop and phone width, local build;
mainat6aa6791eavs this branch at128cfff6e):An unexpected error occurred.Sync failed: mdblist request failed with status 404Sync failedlast_sync_status/last_sync_messagesuccess/Matched 0 of 72 entriesfailed/mdblist request failed with status 404The evidence page has desktop and phone-width screenshots from both builds, the steps used, the v1 and v2 responses from both builds (v1 answers 500 on both), and the scheduled run.
Risks
last_sync_status,last_sync_messageandlast_sync_aton the collection where it used to leave them alone. That's the intended fix, and it matches admin collections.dependency_unavailablewhere it answered 500. v1 is unchanged. The web shows the problem's detail. I found no personal collection sync call insilo-appleorsilo-android, so the native apps shouldn't be affected, and jellycompat has no equivalent operation.Checklist
AI Disclosure