Skip to content

fix(collections): remove a personal collection's artwork when it is deleted - #2939

Merged
Quick104 merged 2 commits into
Silo-Server:mainfrom
Rhainland:fix/2838-personal-collection-artwork-cleanup
Oct 23, 2026
Merged

Quick104 merged 2 commits into
Silo-Server:mainfrom
Rhainland:fix/2838-personal-collection-artwork-cleanup

Conversation

@Rhainland

@Rhainland Rhainland commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #2838
Related issue: #2910
Validation tasks: none affected

Deleting a personal collection removed its database row but left its uploaded poster and its generated collages in artwork storage, under user-collection-images/<collection id>/. Nothing removed them later, so storage grew with every deleted collection that had artwork. This affects any deployment with artwork storage, filesystem or S3. Nothing visible breaks. Admin collections already clean up on delete.

With this change, DeletePersonalCollection removes the collection's artwork directory once the row delete has succeeded.

Approach

After deleteCollectionWithRevision succeeds, the handler calls removeDeletedCollectionArtwork, which runs DeletePrefix on user-collection-images/<id>/. Admin collection delete (cleanupDeletedCollection) now calls the same helper for collection-images/<id>/, so it also gets the detached, time-bounded context described below. Before this change, a client disconnect right after an admin delete could cancel its sweep. The row is already gone at that point, so the cleanup runs on a context that a canceled request can't stop, bounded by the existing 30-second collection artwork cleanup timeout, the same pattern cleanUpReplacedCollectionImage uses. A cleanup failure is logged and the delete still succeeds. A failed row delete or a revision mismatch leaves the artwork in place.

/api/v1 and /api/v2 both reach this method, so both are covered and neither contract changes. jellycompat doesn't delete personal collections. Clients are unaffected.

Not covered here: deleting a profile (PostgresUserStore.DeleteProfile) or an account (the users foreign-key cascade) also removes that profile's or account's personal collections, in SQL. Neither path sweeps their artwork. Covering them needs the store to report which collection IDs it deleted, so it is tracked in #2910.

Validation

  • Go: a handler test covers a successful delete (the collection's poster and collage removed, another collection's artwork kept), a failed row delete (artwork kept, error returned) and a failed cleanup (delete still succeeds). The test failed before the fix.
  • go test ./internal/api/handlers/: pass.
  • go build ./..., go vet ./internal/api/handlers/, gofmt -l: clean.
  • make lint-changed: 0 issues. make verify-size-ratchet and make verify-local-paths: pass.
  • Not run locally: the full make test-go suite and the web, contract and generated-artifact gates. The change touches no web, internal/apiv2, migration or route files.

Evidence

No user-visible change. Results: TestDeletePersonalCollectionRemovesArtwork, run against main at be6527e50 and this branch at 8b108246b. The test seeds artwork for collection c and another collection c2, then deletes c.

main:
collections_lifecycle_service_test.go:178: remaining artwork = [user-collection-images/c/collage/def.webp user-collection-images/c/poster/abc-small.webp user-collection-images/c2/poster/abc-small.webp], want [user-collection-images/c2/poster/abc-small.webp]
--- FAIL: TestDeletePersonalCollectionRemovesArtwork/deleted

this branch:
--- PASS: TestDeletePersonalCollectionRemovesArtwork/deleted
--- PASS: TestDeletePersonalCollectionRemovesArtwork/row_delete_fails
--- PASS: TestDeletePersonalCollectionRemovesArtwork/sweep_fails

Risks

The cleanup deletes everything under one collection's prefix. Collection IDs are non-empty, and the trailing slash stops one ID from matching another (c vs c2). A collage build that is still running when the collection is deleted could write a file after the cleanup; admin collection delete has the same window.

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 (via T3 Code); Codex CLI for code review
  • Tool(s): Claude Code, Codex CLI
  • Model(s): claude-opus-5-5; gpt-6.1-sol (code review)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: independent reviews of the branch diff by claude-opus-5-5 and gpt-6.1-sol for correctness, repository standards and the issue's requirements. They found no correctness or standards problems. One noted that the profile and account delete paths are not covered; that is called out above as a follow-up.

Note

Remove a personal collection's artwork blob directory when it is deleted

Adds a shared removeDeletedCollectionArtwork helper that sweeps the collection's artwork prefix from the blob store with a timeout context detached from request cancellation. CollectionHandler.DeletePersonalCollection calls it after the collection-row deletion succeeds; cleanup failures are logged and do not fail the deletion. Library collection cleanup now reuses the same helper.

  • Behavioral Change: a successfully deleted personal collection now also removes its stored artwork and collages; if the row deletion fails, artwork stays untouched. Other collections' prefixes are not swept.

Macroscope summarized ae56677.

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

silo-kody Bot commented Oct 22, 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 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 41 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ 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: f02942f7-38eb-48b6-89ea-a530e5598604
📥 Commits

Reviewing files that changed from the base of the PR and between da8faa7 and ae56677.

📒 Files selected for processing: 4
  • internal/api/handlers/collection_artwork.go
  • internal/api/handlers/collections_lifecycle_service.go
  • internal/api/handlers/collections_lifecycle_service_test.go
  • internal/api/handlers/library_collections.go
  • Autofix · 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.

@silo-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish labels Oct 22, 2026

@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 8b10824. The fix is right and its test fails on the base for the reported reason. One cleanup finding is inline. Two lower-severity notes that don't block this PR:

  • Other delete paths and retries (low, follow-up). The sweep runs only on the HTTP delete. Profile delete and account cascades are already disclosed and tracked in #2910. The Audiobookshelf collection delete (ABSCollectionStore.DeleteCollection) also removes user_personal_collections rows of type manual, and it doesn't sweep. Nothing retries a sweep that fails or never runs because the node died after the row delete: a repeated DELETE gets 404, so the uploaded poster stays. Collages are already covered, because the user_personal_collection_poster_variants_queue_deleted trigger hands them to the artwork revision collector on every delete path. A matching AFTER DELETE trigger on user_personal_collections that queues OLD.poster_url would give the uploaded poster the same durable backstop on every path. That fits better in #2910 than here. The prefix sweep should stay either way, since it also reclaims displaced revisions the collector has no record of, and the SQLite user store.
  • Shared references (low). Collection imports store a client-supplied poster_url verbatim, so a crafted import can point collection B at a key under collection A's directory. Deleting A now removes the poster B names. Only a hand-built request can do this, and the damage is limited to the crafted collection's own poster. Real clients send template paths or URLs.

Rhainland and others added 2 commits October 23, 2026 15:07
…eleted

Deleting a personal collection removed its row but left its poster
revisions and collages under user-collection-images/<id>/ for good.
Sweep that prefix after the row delete commits, as admin collection
deletion already does. A sweep failure only logs.
Admin and personal collection deletes now remove the collection's artwork
directory through one helper. The admin path gains the detached,
time-bounded context the personal path uses, so a client disconnect after
the row delete no longer cancels its sweep.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Quick104
Quick104 force-pushed the fix/2838-personal-collection-artwork-cleanup branch from 8b10824 to ae56677 Compare October 23, 2026 19:07
@silo-kody

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

Copy link
Copy Markdown
Contributor

Review summary

Reviewed head: ae5667795 (rebased onto current main; the branch was rewritten with a lease against 8b108246b).

Addressed

  • Deleted-collection artwork cleanup now lives in one helper, removeDeletedCollectionArtwork in collection_artwork.go, shared by personal and admin collection deletes. Admin deletes gain the detached, 30-second-bounded context, so a client disconnect after the row delete can no longer cancel that sweep. Fixed in ae56677.

Left for maintainers (not blocking)

Tests

  • TestDeletePersonalCollectionRemovesArtwork fails on the base (be6527e50) with the leftover artwork the PR describes, and passes on the head. go test ./internal/api/handlers/, make lint-changed, make verify-size-ratchet, verify-bidi, and verify-local-paths pass on the new head.

Overlap with #2575

Validated features: none affected. No passed case on the v1.0 board touches collections. Validation tasks: none affected is correct.

User manual: unaffected. This is storage housekeeping with no setting, label, or visible behavior.

Apple/Android: no client change. /api/v1 and /api/v2 responses are unchanged, and jellycompat has no personal-collection delete.

Cross-provider review: two rounds with Codex (gpt-6.1-sol). The first raised the shared-reference note above. The second tested whether a collector trigger should replace the prefix sweep. It shouldn't: the sweep also reclaims displaced revisions the collector doesn't know about, and it covers the SQLite store. A trigger is a follow-up, not a replacement.

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

  • Fit: closes a real storage leak with the same pattern admin collections already use, at the handler that owns the delete, and adds no settings or API surface.
  • Readiness: the regression test fails on the base, and the remaining gaps are separate delete paths tracked for follow-up.

🤖 Generated with Claude Code (claude-opus-5-5), cross-provider review by Codex (gpt-6.1-sol).

@macroscopeapp

macroscopeapp Bot commented Oct 23, 2026

Copy link
Copy Markdown

Visible: deleting a personal collection can also remove artwork shown by another collection when its imported poster_url points into the deleted collection’s artwork directory (internal/api/handlers/collection_artwork.go). The Evidence section says there is no visible change but includes no captures; add before-and-after captures of the surviving collection showing its poster before and after deletion, on each affected client surface.

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

Posted via Macroscope — Visible change evidence

}
ctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), collectionImageCleanupTimeout)
defer cancel()
if _, err := store.DeletePrefix(ctx, fmt.Sprintf("%s/%s/", prefix, collectionID)); err != nil {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Kody Rules high

Orphaned artwork can persist without a durable retry because best-effort deletion runs after the collection row deletion commits, leaving a failure window for crashes or storage errors; immediate deletion also ignores issued-URL protection deadlines. Enqueue the removed artwork references and their protection deadlines in the same database transaction as the collection deletion, then let a retirement worker delete them when eligible.

Kody rule violation: Retire displaced media revisions transactionally and preserve URL deadlines

Prompt for LLM

File internal/api/handlers/collection_artwork.go:

Line 372:

Orphaned artwork can persist without a durable retry because best-effort deletion runs after the collection row deletion commits, leaving a failure window for crashes or storage errors; immediate deletion also ignores issued-URL protection deadlines. Enqueue the removed artwork references and their protection deadlines in the same database transaction as the collection deletion, then let a retirement worker delete them when eligible.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

@Quick104
Quick104 merged commit 620f2ab into Silo-Server:main Oct 23, 2026
20 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 priority: P2 Limited scope, workaround exists, or polish size/M 50–199 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Deleting a personal collection leaves its poster and collages in artwork storage

2 participants