Skip to content

fix(collections): record a failed personal collection sync and say why - #3487

Merged
Quick104 merged 4 commits into
Silo-Server:mainfrom
blurbery:fix/collection-sync-now-failure
Nov 5, 2026
Merged

Quick104 merged 4 commits into
Silo-Server:mainfrom
blurbery:fix/collection-sync-now-failure

Conversation

@blurbery

@blurbery blurbery commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

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

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; 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.
  • Adversarial review: n/a

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.
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

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.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related PRs

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: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning 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 Passed checks: 4 passed
Check name Status Explanation
Title check Passed 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 Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed 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-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Nov 4, 2026
@silo-kody

silo-kody Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

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 settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@macroscopeapp

macroscopeapp Bot commented Nov 4, 2026

Copy link
Copy Markdown

The linked evidence describes before-and-after Collections screenshots, but the PR text does not identify phone-width captures:

  • Failed status on the collection card (web/src/hooks/queries/collectionScope.ts): include before-and-after mobile web captures of the same collection.
  • The Sync now failure message (internal/api/handlers/user_collection_imports.go): include before-and-after mobile web captures of the same flow.

Suggested fix: add the corresponding phone-width captures to the linked Evidence page, or show that these changes are not visible at mobile widths.

Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

@silo-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code impact: usability Core flow broken or severely blocked javascript Pull requests that update javascript code priority: P2 Limited scope, workaround exists, or polish labels Nov 4, 2026
Comment thread internal/usercollections/sync.go Resolved
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.
@silo-kody

silo-kody Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

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 settings
Review 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

Comment thread internal/usercollections/sync.go Resolved
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.
@silo-kody

silo-kody Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

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 settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7def2416-4b26-4efb-9e7f-f24544fc3970
Commits

Reviewing files that changed from the base of the PR and between 6aa6791 and efe6a35.

Files selected for processing: 5
  • internal/api/handlers/user_collection_imports.go
  • internal/usercollections/sync.go
  • internal/usercollections/sync_owner_access_test.go
  • internal/usercollections/sync_tmdb_list_test.go
  • web/src/hooks/queries/collectionScope.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

Comment thread internal/usercollections/sync.go Resolved
…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.
@silo-kody

silo-kody Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

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 settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@silo-triage silo-triage Bot added size/L 200–499 added + deleted lines (all files); change volume, not priority. and removed size/M 50–199 added + deleted lines (all files); change volume, not priority. labels Nov 4, 2026
@Quick104
Quick104 merged commit 46418e9 into Silo-Server:main Nov 5, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code impact: usability Core flow broken or severely blocked javascript Pull requests that update javascript code priority: P2 Limited scope, workaround exists, or polish size/L 200–499 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants