Skip to content

fix(collections): clear artwork reference before deleting its variants - #2575

Merged
Quick104 merged 4 commits into
Silo-Server:mainfrom
Rhainland:fix/2419-collection-artwork-clear-order
Oct 31, 2026
Merged

Quick104 merged 4 commits into
Silo-Server:mainfrom
Rhainland:fix/2419-collection-artwork-clear-order

Conversation

@Rhainland

@Rhainland Rhainland commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #2419
Related issue: N/A
Validation tasks: none changed. The fix is on the clear path next to #193 S6 and #194 A3; assigning and replacing artwork are unchanged.

When an admin or a collection owner removes a collection's poster or backdrop and one stored image variant fails to delete, the request returns 500 and the collection keeps pointing at artwork that is now partly gone. Its poster stays broken until someone clears it again and every delete succeeds. This change clears the database reference first and deletes the stored variants afterwards, so a failed delete only leaves unused files behind.

Both clear paths had this order: DeletePersonalCollectionImage for personal collections and DeleteAdminCollectionArtwork for admin collections. The filesystem store fails this way today, because Filesystem.Delete stops at the first error. Since #1665, S3 deployments report per-object delete failures too.

Approach

Both paths now save the cleared reference, then remove the revision the clear displaced. They reuse cleanUpReplacedCollectionImage, which already does this after a replacement: it runs after the database update, keeps going if the client disconnects (bounded by the same 30-second timeout), and only logs failures. It deletes only the revision the row held before the clear, never everything else in the directory, so an upload that commits a new revision during the clear keeps its files. If the row points at the same revision again on a fresh read (the same image re-uploaded), nothing is deleted.

The endpoint's response changes: a failed cleanup now returns success instead of 500 "Failed to delete images". The issue asked a maintainer to confirm this. The alternative, returning 500 after clearing the reference, would report an error for a request that did what the user asked.

No API schema, client, or jellycompat change. Collages live in a separate directory and are not affected.

Validation

  • go build ./..., gofmt, go vet ./..., make lint-changed, make verify-local-paths: pass.
  • make test-go: passes except TestPlaybackInfoWithoutStripOrToneMapStillHasNoRoute and TestPlaybackInfoSkipsStripWhenRPUCannotBeStripped in internal/jellycompat, which fail the same way on main. They appear to depend on the local ffmpeg build.
  • New tests make the store fail partway through a delete. They cover the personal path, the admin path (poster and backdrop, against a migrated Postgres), and a clear leaving another revision in the same directory alone. The personal and admin tests fail on the old ordering.
  • internal/api/handlers against a migrated Postgres: everything passes except TestAdminSubtitleListPageDB and TestCatalogTransferPersistsJobsAndSignedLink, which fail the same way on main. They appear to compare local time with UTC and are unrelated to this change.
  • Checked on a local server with filesystem storage and one variant file made undeletable; see Evidence.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-server/pr-2575/

Same DELETE on main and on this branch, local server with filesystem storage, with one variant of each image made undeletable. Admin collection poster:

main:   DELETE /api/v1/admin/collections/<id>/image?type=poster -> HTTP 500
        poster_url still set; GET poster_url -> HTTP 404
branch: DELETE /api/v1/admin/collections/<id>/image?type=poster -> HTTP 204
        poster_url: ""; the undeletable variant stays as an unused file and a warning is logged

The admin backdrop and the personal collection poster behave the same way; the evidence page has all three. There are no screenshots: the test collections have no titles, so the Collections page shows the same empty tile on both builds.

Risks

A failed cleanup now leaves unused files in storage instead of a broken reference. A later clear does not remove them, because it only deletes the revision it displaced. Deleting an admin collection still removes its whole image directory; personal collections have no such sweep, so files left by a failed personal-poster cleanup stay until removed by hand. An upload that commits between the clear's first read and its update has its reference cleared and its files orphaned, but nothing the row references is deleted.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code (in T3 Code)
  • Tool(s): Claude Code; Codex CLI (review only)
  • Model(s): claude-opus-5-5; gpt-6.1-sol (review only)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: claude-opus-5-5 and gpt-6.1-sol reviewed the full branch diff independently, at medium effort. They checked the order of operations, cancellation and timeout handling, the revision kept on re-read, and the effect on collages. Neither reported a defect. The Opus review pointed out an upload race. A later review comment showed the cleanup could still delete a revision an upload committed during the clear, so the clear now deletes only the revision it displaced; both models reviewed that change and found only a stale test comment, which was fixed.

Note

Fix collection artwork deletion to clear DB reference before deleting variants

  • Collection artwork deletion (admin and personal) now clears the stored poster/backdrop path in the database first, then runs targeted cleanup of the displaced revision's objects.
  • Removes removeCollectionImageVariants and deleteCollectionImages, which listed and batch-deleted every object under an image prefix before updating the database.
  • Cleanup failures are logged instead of failing the handler; orphaned objects may remain after a partial deletion, but the database no longer points at deleted artwork.
  • Adds regression tests for partial variant-deletion failures in admin_collections_service_test.go and collections_lifecycle_service_test.go, plus a partialDeleteStore fixture; the admin test is registered in db-contracts.txt.
  • Behavioral Change: if cleanup fails partway, deleted variants stay gone and remaining variants become orphans; concurrent uploads of a newer revision are preserved by targeting only the displaced revision.

Macroscope summarized 8864cdd.

@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Oct 16, 2026
@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Caution

Review failed

The pull request is closed.

Walkthrough

Admin and personal collection artwork deletion now clears database references before attempting image cleanup. Cleanup runs after the collection update succeeds. Tests cover partial deletion failures and revision-scoped cleanup.

Changes: Collection artwork reference clearing

Layer / File(s) Summary
Clear references before cleanup
internal/api/handlers/admin_collections_service.go, internal/api/handlers/admin_collections_service_test.go, internal/api/handlers/collections_lifecycle_service.go, internal/api/handlers/collections_lifecycle_service_test.go, internal/api/handlers/library_collections.go, internal/api/handlers/collection_artwork.go, scripts/ci/db-contracts.txt
Admin poster and backdrop deletion, and personal poster deletion, save the previous path and update the collection before cleanup. Tests cover partial delete failures. The broad image-variant deletion helpers are removed.
Verify revision-scoped cleanup
internal/api/handlers/collection_artwork.go, internal/api/handlers/collection_artwork_test.go
Comments describe cleanup after replacement or clearing. Tests verify that cleanup deletes only the displaced revision when the current path is empty or points to a concurrent replacement.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: quick104, blurbery

Merge Risk: Minimal · up to 8864c

Clearing collection artwork now clears the database reference first, so a failed image cleanup no longer leaves a broken reference or returns a 500. A rare concurrent identical-bytes upload during a clear could lose its files and would need a re-upload. That edge case also exists when replacing artwork today, so it does not block merging.

Security architecture risk: Low · up to 8864c

The change improves failure containment by clearing artwork references before deleting files and limits deletion to the displaced revision. Administrative and collection-owner restrictions remain intact. Cleanup remains best-effort, and concurrent uploads of identical content are not fully coordinated with deletion.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The inspected deletion flow is bounded to one selected collection, artwork kind, and displaced revision per operation. Administrative callers retain administrative collection authority; personal callers remain limited by creator checks. No new ability to delete another collection's keys was established.

Trust Boundaries and Controls

  • observed — Request-selected artwork kinds are restricted to poster/backdrop for administrative collections and poster for personal collections. Storage cleanup additionally validates the database-sourced previous path against the computed collection/kind directory and filters listed keys before invoking the deletion sink.

Resilience and Maintainability Implications

  • inferred — Identical bytes reuse object keys. An authorized upload can republish the displaced revision after cleanup's reference reread but before deletion, leaving a live reference to deleted objects. The same non-atomic helper existed for replacements at the base, and base clear operations could also delete objects before a concurrent upload published its reference. The PR narrows deletion for distinct revisions but does not establish atomic live-reference protection for identical-content uploads; expanded security exposure was not established.

Hardening Proposals

  • proposed — If strict live-reference integrity is required, coordinate upload publication and cleanup for each collection/artwork slot across participating writers, or use non-reused generations with reachability-aware garbage collection. Another uncoordinated reference reread alone would not close the deletion race.
- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@silo-kody

silo-kody Bot commented Oct 16, 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 bug Something isn't working go Pull requests that update go code needs-review Needs maintainer review to resolve uncertain classification, scope, or changed evidence. priority: P2 Limited scope, workaround exists, or polish triaged High-confidence review completed; does not mean fixed, validated, or accepted for release. labels Oct 16, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 16, 2026

Copy link
Copy Markdown

Artwork clearing is visible: after a partial storage-delete failure, personal collection artwork is now cleared (so the fallback collage can show), and admin collection poster or backdrop artwork is cleared rather than retaining its reference. The Evidence section’s prose does not provide captures or API response excerpts.

  • internal/api/handlers/collections_lifecycle_service.go: add before-and-after captures of the same personal collection screen during a partial-delete failure, showing the artwork/fallback and request outcome.
  • internal/api/handlers/admin_collections_service.go: add before-and-after captures of the same admin collection screen for poster and backdrop clears during a partial-delete failure.

Identify the affected surface(s) and the build or commit used for the captures. If UI captures are unavailable, provide before-and-after response excerpts for the same request; the current “Before/After” text describes results but is not a response excerpt.

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 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 Oct 17, 2026
@silo-kody

silo-kody Bot commented Oct 17, 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 ❌

@Rhainland

Copy link
Copy Markdown
Contributor Author

Added before-and-after evidence for the visible-change check. On a local server with filesystem storage, one variant of each image was made undeletable, and the same DELETE ran on main and on this branch for the admin poster, the admin backdrop, and a personal collection poster. On main each request returns 500 and the reference stays; for both posters the referenced URL then returns 404. On this branch each returns 204, the reference is cleared, and the undeletable file stays behind with a logged warning. The PR body has an excerpt and the Evidence link has all three. There are no screenshots, because the test collections have no titles and the Collections page looks the same on both builds.

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

Review of af60b76. One finding below, plus a merge conflict with main. I'm fixing both on this branch, so there's no need to change anything yourself.

Merge conflict. #2817 on main deleted the database tests in admin_collections_service_test.go that CI never ran, and this branch appends a test to the end of that file. I'm rebasing onto main, keeping main's deletions and this PR's new test. The rebase rewrites the branch, so I'll push with --force-with-lease.

@Quick104

Copy link
Copy Markdown
Contributor

Review summary

Reviewed head: 14a079c (af60b76 rebased onto main, plus one commit). The fix is correct. Committing the cleared reference before deleting the displaced revision is the order the replace path already uses, and it's the option #2419 suggested.

Addressed

  • The new admin test (TestDeleteAdminCollectionArtworkClearsReferenceWhenVariantDeleteFailsDB) was never selected by CI, so it always skipped. 14a079c lists it in scripts/ci/db-contracts.txt.
  • The branch conflicted with main, because test: remove low-value and never-run tests #2817 deleted the never-run DB tests in admin_collections_service_test.go. I rebased onto main, kept main's deletions and this PR's test, and force-pushed with a lease. The three original commits are unchanged apart from the conflict resolution.

Verification

  • Both new handler tests fail on the base for the reported reason. The personal test fails with internal_error: Failed to delete images. The admin test, run against a freshly migrated Postgres, fails with deleting collection variants: permission denied for poster and backdrop. Both pass on this branch.
  • TestCleanUpReplacedCollectionImage_ClearKeepsConcurrentUpload also passes on the base. It exercises the existing helper, so it guards the narrowed cleanup but doesn't detect the fix.
  • go build ./..., go vet, the full internal/api/handlers package, make lint-changed (0 issues), and make verify-local-paths pass on the rebased branch.
  • Cross-provider review (Codex, gpt-6.1-sol, one round) independently found the CI selection gap. It found no other defect in path selection, callbacks, cancellation, collages, or routing.

Left for the maintainers

  • Maintainer decision: a failed cleanup now returns success instead of 500. [bug] Clearing collection artwork leaves a broken poster when a variant fails to delete #2419 asked for this to be confirmed. I recommend keeping it. The user's request did complete, and a 500 would invite retries that can't reclaim anything.
  • Orphans from a failed cleanup are no longer reclaimed by a later clear. The PR's Risks section discloses this. Admin collections still sweep their directory when the collection is deleted. Personal collections never did, which predates this PR and is now tracked in [bug] Deleting a personal collection leaves its poster and collages in artwork storage #2838.
  • The shared cleanup helper has a narrow race that predates this PR, since the replace path has it too. If the same bytes are re-uploaded between the helper's fresh read and its delete, the identical keys get deleted. Main's clear path swept the whole directory, which was worse. No change requested here.

Validated features: no passed case reaches this code. #193 S6 is recorded as Partial and #194 A3 as Not run. Assigning and replacing artwork are unchanged.
Validation tasks: none

User manual: unaffected. The collections pages don't describe clearing artwork or its errors.
Apple/Android: no client change. The only response change is a 500 that becomes success, and no client depends on the 500.

Fit: 9/10 · Readiness: 9/10 — ready (assuming CI is green)

  • Fit: it fixes a data-integrity bug at its owning boundary by reusing the existing post-commit cleanup, and adds no new surface.
  • Readiness: both regression tests fail on the base and pass here, the author's before/after on filesystem storage matches, and the admin test now runs in CI. One product decision is open (above).

@silo-kody

silo-kody Bot commented Oct 21, 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 ❌

Rhainland and others added 4 commits October 30, 2026 23:58
Clearing a personal or admin collection poster/backdrop deleted the stored
variants first and the database reference second. A delete that failed
partway returned 500 and skipped the update, leaving the collection pointing
at partly deleted artwork.

Both paths now clear the reference first and then run
cleanUpClearedCollectionImage, which sweeps the image directory as best-effort
cleanup that only logs on failure. Like replacement cleanup, it re-reads the
row and keeps any revision committed after the clear.

Closes Silo-Server#2419
…lear

Sweeping the whole image directory after the clear could delete a revision
that a concurrent upload committed between the re-read and the delete,
leaving the row pointing at missing artwork. The clear now removes only the
revision it displaced, the same way a replacement does.
…in CI

The test needs a database, and no CI list or job selected it, so it always
skipped. List it in db-contracts.txt so the DB contracts job runs it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Quick104
Quick104 force-pushed the fix/2419-collection-artwork-clear-order branch from 14a079c to 8864cdd Compare October 31, 2026 04:00
@silo-kody

silo-kody Bot commented Oct 31, 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 ❌

@Quick104
Quick104 merged commit 9249983 into Silo-Server:main Oct 31, 2026
20 of 21 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 needs-review Needs maintainer review to resolve uncertain classification, scope, or changed evidence. priority: P2 Limited scope, workaround exists, or polish size/L 200–499 added + deleted lines (all files); change volume, not priority. triaged High-confidence review completed; does not mean fixed, validated, or accepted for release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Clearing collection artwork leaves a broken poster when a variant fails to delete

2 participants