Skip to content

feat: remove the background while uploading - #277

Open
TheBlackSide243 wants to merge 2 commits into
Anyesh:mainfrom
TheBlackSide243:pr/upload-background-removal
Open

TheBlackSide243 wants to merge 2 commits into
Anyesh:mainfrom
TheBlackSide243:pr/upload-background-removal

Conversation

@TheBlackSide243

@TheBlackSide243 TheBlackSide243 commented Oct 18, 2026 •

Copy link
Copy Markdown

Description

Adds a "Remove the background automatically" switch to the upload dialog (single and bulk). When
it is on, the new item goes to the image worker first and the AI tags the cleaned-up photo
afterwards, so the user does not have to run the removal item by item later.

  • remove_background form field on POST /items and POST /items/bulk.
  • remove_item_background_job takes an optional then_tag_path: when set it queues tagging once
    the removal is done; a failed removal still hands the item to tagging with its original photo,
    so an upload is never left untagged.
  • Translations for all 8 locales.

This is one of a set of small, independent PRs (each branches from main and can be reviewed or
dropped on its own); they only overlap in the nav/router registration lines.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • CI/CD or build changes

Checklist

  • I have read the CONTRIBUTING guide
  • My code follows the project's coding style
  • I have added tests that prove my fix/feature works
  • New and existing tests pass locally
  • I have updated documentation as needed
  • My changes don't introduce new warnings or errors

Testing

  • Backend: ruff check, ruff format --check, migration heads check and the full pytest suite on top of current main (2031 passed).
  • Frontend: npm run lint, i18n:check, vocab:check, tsc --noEmit and vitest (693 passed).
  • Running on my own self-hosted instance (Docker Compose on TrueNAS, Ollama).

Test Environment

  • Docker Compose
  • Kubernetes
  • Local development

🤖 Generated with Claude Code

Summary by Sourcery

Enable automatic background removal during image uploads while preserving reliable downstream tagging.

New Features:

  • Add an upload option for automatically removing image backgrounds for single and bulk uploads, with the preference remembered in the browser.
  • Chain background removal and AI tagging so cleaned images are tagged automatically while failed removals still proceed to tagging using the original image.

Enhancements:

  • Support background-removal settings throughout queued and chunked bulk uploads.
  • Run background removal independently when AI tagging is skipped.

Tests:

  • Add coverage for single and bulk upload processing, tagging chains, and fallback behavior when background removal fails.

Chores:

  • Add translated labels and guidance for the new upload option across all supported locales.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sourcery-ai

sourcery-ai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Introduces a remembered upload-dialog switch for automatic background removal across single, bulk, and deferred uploads, with backend job chaining that tags the cleaned image—or the original image if removal fails—so uploads remain AI-processed.

Sequence diagram for upload background removal and tagging

sequenceDiagram
    participant User
    participant UploadDialog
    participant ItemsAPI
    participant ImageWorker
    participant TaggingWorker

    User->>UploadDialog: Select removeBackground
    UploadDialog->>ItemsAPI: POST /items or POST /items/bulk
    ItemsAPI->>ImageWorker: remove_item_background_job(item_id, bg_color_hex, full_image_path)
    ImageWorker->>ImageWorker: remove_background
    alt Background removal succeeds
        ImageWorker->>TaggingWorker: tag_item_image(item_id, cleaned_image_path)
    else Background removal fails
        ImageWorker->>TaggingWorker: tag_item_image(item_id, original_image_path)
    end
    TaggingWorker-->>User: Upload remains AI-processed
Loading

File-Level Changes

Change Details Files
Adds an upload-time option that routes new images through background removal before AI tagging, for both direct and queued bulk uploads.
  • Adds a remove_background form parameter to single and bulk item creation.
  • Centralizes upload job selection and marks background-removal processing state.
  • Propagates the option through bulk chunking, IndexedDB queue records, retry/drain logic, and upload requests.
  • Adds a remembered frontend checkbox with localized label and hint in all supported locales.
backend/app/api/items.py
frontend/components/add-item-dialog.tsx
frontend/lib/hooks/use-items.ts
frontend/lib/upload-manager.ts
frontend/lib/upload-queue.ts
frontend/messages/de/wardrobe.json
frontend/messages/en/wardrobe.json
frontend/messages/fr/wardrobe.json
frontend/messages/it/wardrobe.json
frontend/messages/ja/wardrobe.json
frontend/messages/ko/wardrobe.json
frontend/messages/zh-CN/wardrobe.json
frontend/messages/zh-TW/wardrobe.json
Extends background-removal processing to optionally chain AI tagging and preserve the no-untagged-upload guarantee when removal fails.
  • Accepts an optional tagging image path and queues tagging on the tagging queue after removal.
  • Uses the original image path when removal fails, while retaining an error result from the removal job.
  • Handles tagging enqueue failures through existing stale-processing recovery behavior and updates item processing metadata.
backend/app/workers/background_removal.py
Adds coverage for the upload routing and background-removal-to-tagging workflow.
  • Verifies single and bulk uploads enqueue removal when enabled and tagging otherwise.
  • Verifies successful removal queues tagging and updates item state.
  • Verifies failed removal still queues tagging with the original image.
backend/tests/test_upload_background.py

Possibly linked issues

  • #unknown: The PR implements background removal during single and bulk uploads, directly addressing the requested feature.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions github-actions Bot added javascript Pull requests that update javascript code python Pull requests that update python code labels Oct 18, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="backend/app/api/items.py" line_range="228" />
<code_context>
     primary_color: str | None = Form(None),
     favorite: bool = Form(False),
     skip_ai: bool = Form(False),
+    remove_background: bool = Form(False),
 ) -> ItemResponse:
     # Validate and process image
</code_context>
<issue_to_address>
**Requested background removal is skipped**

When the user requests background removal while AI tagging is skipped or disabled, the upload handlers call `_queue_upload_processing` only when `do_auto_tag` is true; otherwise they mark the item ready without queuing removal. The selected option is silently ignored, and the uploaded image keeps its original background.

Queue background removal whenever it is requested, independently of automatic tagging, and add tagging only when `do_auto_tag` is true.

Also at `backend/app/api/items.py:303-305`, `backend/app/api/items.py:326-328`, `backend/app/api/items.py:474-476`, `frontend/components/add-item-dialog.tsx:535-541`.
</issue_to_address>

### Comment 2
<location path="backend/tests/test_upload_background.py" line_range="80" />
<code_context>
+                headers=auth_headers,
+            )
+        assert response.status_code == 201
+        assert redis.enqueue_job.call_args.args[0] == "tag_item_image"
+
+
</code_context>
<issue_to_address>
**Extra jobs go undetected**

When the bulk endpoint enqueues a tagging job followed by an additional background-removal job when the option is absent, `test_without_the_option_only_tags` checks only `call_args.args[0]` (line 80), so it passes when the bulk upload first queues tagging and then also queues background removal; the test does not establish that it only tags.

Assert the enqueue call count is one and that its arguments and queue name are the expected tagging job.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 2 findings to address first, and when enabled—which is the default for new browser preferences—the worker replaces the stored item image with a white-background version before tagging. Reverting stops future processing but does not restore images already changed; the saved original-image path makes those changes bounded and repairable.

Blocking findings: backend/app/api/items.py:228, backend/tests/test_upload_background.py:80


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread backend/app/api/items.py
primary_color: str | None = Form(None),
favorite: bool = Form(False),
skip_ai: bool = Form(False),
remove_background: bool = Form(False),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Requested background removal is skipped

When the user requests background removal while AI tagging is skipped or disabled, the upload handlers call _queue_upload_processing only when do_auto_tag is true; otherwise they mark the item ready without queuing removal. The selected option is silently ignored, and the uploaded image keeps its original background.

Queue background removal whenever it is requested, independently of automatic tagging, and add tagging only when do_auto_tag is true.

Also at backend/app/api/items.py:303-305, backend/app/api/items.py:326-328, backend/app/api/items.py:474-476, frontend/components/add-item-dialog.tsx:535-541.

Prompt for AI agents
In `backend/app/api/items.py` at line 228:

**Requested background removal is skipped**

When the user requests background removal while AI tagging is skipped or disabled, the upload handlers call `_queue_upload_processing` only when `do_auto_tag` is true; otherwise they mark the item ready without queuing removal. The selected option is silently ignored, and the uploaded image keeps its original background.

Queue background removal whenever it is requested, independently of automatic tagging, and add tagging only when `do_auto_tag` is true.

Also at `backend/app/api/items.py:303-305`, `backend/app/api/items.py:326-328`, `backend/app/api/items.py:474-476`, `frontend/components/add-item-dialog.tsx:535-541`.

Comment thread backend/tests/test_upload_background.py Outdated
headers=auth_headers,
)
assert response.status_code == 201
assert redis.enqueue_job.call_args.args[0] == "tag_item_image"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Extra jobs go undetected

When the bulk endpoint enqueues a tagging job followed by an additional background-removal job when the option is absent, test_without_the_option_only_tags checks only call_args.args[0] (line 80), so it passes when the bulk upload first queues tagging and then also queues background removal; the test does not establish that it only tags.

Assert the enqueue call count is one and that its arguments and queue name are the expected tagging job.

Prompt for AI agents
In `backend/tests/test_upload_background.py` at line 80:

**Extra jobs go undetected**

When the bulk endpoint enqueues a tagging job followed by an additional background-removal job when the option is absent, `test_without_the_option_only_tags` checks only `call_args.args[0]` (line 80), so it passes when the bulk upload first queues tagging and then also queues background removal; the test does not establish that it only tags.

Assert the enqueue call count is one and that its arguments and queue name are the expected tagging job.

The upload handlers queued background removal only together with AI
tagging, so with tagging skipped or disabled the option was silently
ignored. The removal is now queued on its own and the worker marks the
item ready; a failed enqueue no longer strands the item in processing.
The 'only tags' test asserts the single tagging job and its queue.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

javascript Pull requests that update javascript code python Pull requests that update python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants