Repository navigation
fix(library): clean orphaned provisional items - #76
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📥 CommitsReviewing files that changed from the base of the PR and between 49ad1a1863740be40daae851a30cc3cd6e1b9db9 and 2d922c3. 📒 Files selected for processing (5)
💤 Files with no reviewable changes (4)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR implements comprehensive cleanup of orphaned provisional media items: a new OrphanedProvisionalCleaner with SQL predicate and batched deletes, folder-delete late-orphan handling, skeleton-creation revalidation and cleanup on failure, a CleanupOrphanedMediaItemsTask with tests, and a DB migration. ChangesOrphaned Provisional Media Items Cleanup
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@codex review |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/metadata/service_test.go`:
- Around line 84-89: The fakeItemRepo.Delete implementation currently returns a
formatted error when an item is missing; change it to return the sentinel error
catalog.ErrItemNotFound so callers using errors.Is(err, catalog.ErrItemNotFound)
will match. Update the branch in fakeItemRepo.Delete that checks if _, ok :=
r.items[contentID]; !ok to return nil, catalog.ErrItemNotFound (preserving the
mutex handling) so tests and service cleanup paths behave like production.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: b1cb0bc2-45bd-49b4-ad75-852e61b2faad
📥 Commits
Reviewing files that changed from the base of the PR and between 0c5ec1f34bbf0c26bdba6e248b80c4f1e3e30c13 and 49ad1a1863740be40daae851a30cc3cd6e1b9db9.
📒 Files selected for processing (9)
cmd/silo/main.gointernal/catalog/folder_repo.gointernal/catalog/orphan_cleanup.gointernal/metadata/service.gointernal/metadata/service_test.gointernal/scanner/file_repo.gointernal/taskmanager/tasks/cleanup_orphaned_media_items.gointernal/taskmanager/tasks/cleanup_orphaned_media_items_test.gomigrations/sql/20260607220000_cleanup_orphaned_provisional_items.sql
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 49ad1a1863
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 82a7373383
ℹ️ 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".
f799e61 to
d8975d2
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d8975d234b
ℹ️ 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".
| const deleteOrphanedProvisionalIDsByContentIDSQL = ` | ||
| DELETE FROM public.media_items mi | ||
| WHERE mi.content_id = ANY($1) | ||
| AND ` + orphanedProvisionalMediaItemConditions |
There was a problem hiding this comment.
Delete matched items created after the first orphan sweep
When an in-flight matcher passes the enabled-library checks just before the delete request disables the library, it can still insert the skeleton membership after Phase 1 has already swept orphans and then enrich the item to matched before Phase 3 deletes that membership. This late cleanup only re-deletes rows matching orphanedProvisionalMediaItemConditions (pending, unmatched, ambiguous), so the now-detached matched row and its external IDs survive the library deletion—the same stale catalog state this path is trying to prevent.
Useful? React with 👍 / 👎.
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
This was to cover a bug that I found when deleting libraries, It should not happen again but it also added a "Clean Orphaned Media Items" scheduled task that is by default not scheduled (only run manually). This should be safe to run any time but I felt that it should be used ad-hoc and not scheduled. What do you think @Quick104? Other than that, I believe this LGTM, I ran multiple adversarial reviews. |
* fix(library): clean orphaned provisional items * test(metadata): use item not found sentinel in fake repo * fix(library): preserve abs references during orphan cleanup * fix(library): avoid dropped abs cleanup tables * fix(library): harden provisional orphan cleanup * fix(library): preserve home dismissal series orphans * fix(library): Delete matched items created after the first orphan sweep
* fix(library): clean orphaned provisional items * test(metadata): use item not found sentinel in fake repo * fix(library): preserve abs references during orphan cleanup * fix(library): avoid dropped abs cleanup tables * fix(library): harden provisional orphan cleanup * fix(library): preserve home dismissal series orphans * fix(library): Delete matched items created after the first orphan sweep

Summary
cleanup_orphaned_media_itemsadmin task for installs where the original libraries no longer exist.Root Cause
A library delete could disable and queue the library while in-flight metadata workers still had already-claimed work. The delete job removed existing orphaned items before deleting the remaining membership rows, so a worker that created an unmatched skeleton during that window could lose its file and library membership later without a second orphan sweep. Stale external IDs then remained because their parent
media_itemsrow was never deleted.Validation
go test ./internal/catalog ./internal/taskmanager ./internal/taskmanager/tasks ./internal/metadata ./internal/scanner ./migrationsgo test ./internal/... ./migrations ./scripts/backfill-library-matchingNotes
go test ./cmd/silocannot run in the fresh worktree untilweb/distexists for the frontend embed.AI Use
Implemented with OpenAI Codex.
Summary by CodeRabbit
New Features
Bug Fixes
Tests