Skip to content

feat: let users mark items as "don't suggest in outfits" - #334

Open
thisloke wants to merge 3 commits into
Anyesh:mainfrom
thisloke:feat/never-suggest-items
Open

thisloke wants to merge 3 commits into
Anyesh:mainfrom
thisloke:feat/never-suggest-items

Conversation

@thisloke

@thisloke thisloke commented Nov 12, 2026 •

Copy link
Copy Markdown

Description

Lets a user keep items such as underwear, socks or worn-out pieces in the wardrobe (visible and searchable) while the AI never uses them. Today the only option is archiving, which hides them.

preferences.excluded_item_ids and POST/DELETE /users/me/preferences/excluded-items/{id} already existed and daily/suggest outfits honoured them, but:

  • pairings (PairingService.get_available_items) and learned pair suggestions (/learning/item-pairs/{id}) ignored them;
  • no UI used them.

This PR:

  • Backend: filters excluded items out of pairing candidates and learned pair suggestions, and returns excluded_item_ids from GET /users/me/preferences so clients can show the state. An excluded item explicitly picked as the pairing source (or force-included in a suggestion) is still allowed, as an explicit choice; no other excluded item is added around it.
  • Frontend: a "Don't suggest in outfits" switch in the item detail dialog (React Query, invalidates preferences) and a subtle eye-off badge on wardrobe cards of excluded items. Strings in all 8 locales.

It would be great if the mobile app exposed the same switch, and search in the archived items view.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)

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
  • My changes don't introduce new warnings or errors

Screenshots

Item detail dialog with the switch on:

Don't suggest in outfits switch

Wardrobe grid: the eye-off badge marks the excluded socks and boxer briefs, which stay visible and searchable:

Wardrobe with excluded items

Testing

  • New tests/test_never_suggest_items.py: endpoint round trip, pairing filter, excluded source item, recommendation candidates, learned pair suggestions.
  • pytest on never_suggest, pairings, preferences, learning_service, recommendation_service: 284 passed. ruff clean.
  • Ran the app locally (dev login, seeded demo items): toggling the switch calls the endpoints, excluded_item_ids is persisted, and badges appear after closing the dialog.
  • Frontend: tsc --noEmit, npm run lint (only the existing <img> warning), npm test 852/852, npm run i18n:check OK.

Test Environment

  • Local development

Summary by Sourcery

Allow users to mark wardrobe items as never suggestible without hiding them, and enforce that preference across outfit generation and pairing features.

New Features:

  • Add a wardrobe item option to prevent it from being suggested in outfits while keeping it visible and searchable.
  • Show excluded-item status in the wardrobe and expose it through the preferences API.

Bug Fixes:

  • Prevent excluded items from appearing in pairing candidates, recommendations, and learned pair suggestions while preserving explicitly selected source items.
  • Handle legacy preferences whose excluded-item list is null when adding or removing exclusions.

Enhancements:

  • Synchronize the exclusion toggle and related learned-pair data through React Query, with localized UI text across all supported locales.

Tests:

  • Add coverage for exclusion endpoints, pairing and recommendation filtering, learned suggestions, explicit source handling, and null preference values.

… suggestions

Items in preferences.excluded_item_ids were filtered for daily/suggest
outfits only. Pairing generation and learned pair suggestions now skip
them as well, and GET /users/me/preferences returns excluded_item_ids so
the UI can show the state.

An excluded item explicitly chosen as the pairing source or force-included
in a suggestion is still allowed (explicit choice); other excluded items are
never added around it.
…items

Item detail dialog gets a switch backed by the existing excluded-items
endpoints (React Query, invalidates preferences), and wardrobe cards show a
subtle eye-off badge for excluded items. Strings added to every locale.
@sourcery-ai

sourcery-ai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Add excluded item IDs to the frontend preferences type so consumers can represent the server-provided setting.

  • frontend/lib/types.ts L169

API

Expose excluded item IDs in the preferences response schema and populate the field when building the response.

  • backend/app/api/preferences.py L65-67
  • backend/app/schemas/preference.py L1-2, L160-163

Uses of the API

Call the existing excluded-item endpoints from a mutation hook and invalidate preferences and learned-pair queries after either outcome.

  • frontend/lib/hooks/use-preferences.ts L51-72

Implementation

Filter excluded items from pairing candidates and learned-pair query results while preserving the explicitly selected pairing source.

  • backend/app/services/learning_service.py L698-718
  • backend/app/services/pairing_service.py L54-58, L64

Handle NULL stored exclusion lists when adding or removing an item exclusion.

  • backend/app/services/preference_service.py L128-131, L139-143

UI

Add a never-suggest switch to the item detail dialog and show an eye-off indicator on excluded wardrobe items, with localized labels.

  • frontend/app/dashboard/wardrobe/page.tsx L143-149 (+6 small edits)
  • frontend/components/item-detail-dialog.tsx L302-310, L918-934 (+4 small edits)
  • frontend/messages/de/wardrobe.json L181-185, L270
  • frontend/messages/en/wardrobe.json L181-185, L270
  • frontend/messages/fr/wardrobe.json L181-185, L270
  • frontend/messages/it/wardrobe.json L181-185, L270
  • frontend/messages/ja/wardrobe.json L181-185, L270
  • frontend/messages/ko/wardrobe.json L181-185, L270
  • frontend/messages/zh-CN/wardrobe.json L181-185, L270
  • frontend/messages/zh-TW/wardrobe.json L181-185, L270

Tests

Cover excluded-item preference round trips, NULL-list toggles, and filtering behavior across pairing, recommendations, and learned pair suggestions.

  • backend/tests/test_never_suggest_items.py L1-168
  • backend/tests/test_preferences.py L24
  • frontend/tests/wardrobe-page.test.tsx L33

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 Nov 12, 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 6 issues

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

## Individual Comments

### Comment 1
<location path="backend/app/services/learning_service.py" line_range="729" />
<code_context>
+            select(UserPreference.excluded_item_ids).where(UserPreference.user_id == user_id)
+        )
+        excluded_ids = set(excluded_result.scalar_one_or_none() or [])
+        paired_ids = [i for i in paired_ids if i not in excluded_ids]
+        if not paired_ids:
+            return []
</code_context>
<issue_to_address>
**Eligible suggestions get crowded out**

When excluded pairs occupy enough of the highest-ranked `limit * 2` rows while eligible pairs rank below them, `get_item_pair_suggestions` applies the limit before filtering excluded IDs and does not fetch more rows, so it returns fewer suggestions than requested—or none—even when eligible pairs exist.

Apply the exclusion filter before limiting results, or keep fetching ranked pairs until enough eligible suggestions are collected.
</issue_to_address>

### Comment 2
<location path="frontend/app/dashboard/wardrobe/page.tsx" line_range="340" />
<code_context>
   const searchParams = useSearchParams();
   const router = useRouter();
   const userTimezone = useUserTimezone();
+  const { data: preferences } = usePreferences();
+  const neverSuggestedIds = new Set(preferences?.excluded_item_ids ?? []);
   const t = useTranslations('wardrobe');
</code_context>
<issue_to_address>
**First toggle can fail**

When a user toggles an item before the first preferences request has created their preference row, the preferences GET and toggle POST can both enter `get_or_create_preferences` and try to insert the same `user_id`; one insert hits the primary-key conflict, so the toggle or preferences load fails.

Make preference-row creation atomic so concurrent requests reuse the same row.

Also at `frontend/lib/hooks/use-preferences.ts:59`, `frontend/components/item-detail-dialog.tsx:930-931`.
</issue_to_address>

### Comment 3
<location path="frontend/lib/hooks/use-preferences.ts" line_range="59-60" />
<code_context>
+    mutationFn: ({ itemId, excluded }: { itemId: string; excluded: boolean }) => {
+      applySessionToken(session);
+      const path = `/users/me/preferences/excluded-items/${itemId}`;
+      return excluded
+        ? api.post<{ excluded_item_ids: string[] }>(path)
+        : api.delete<{ excluded_item_ids: string[] }>(path);
+    },
</code_context>
<issue_to_address>
**Concurrent toggles lose exclusions**

When different items are toggled from multiple tabs or devices before the requests finish, `add_excluded_item` and `remove_excluded_item` read the same current array and write replacement arrays, so one request overwrites the other and a successful toggle is missing from the saved preferences.

Serialize exclusion changes or update the array atomically so concurrent requests cannot overwrite one another.
</issue_to_address>

### Comment 4
<location path="frontend/lib/hooks/use-preferences.ts" line_range="62" />
<code_context>
+      return excluded
+        ? api.post<{ excluded_item_ids: string[] }>(path)
+        : api.delete<{ excluded_item_ids: string[] }>(path);
+    },
+    onSuccess: () => {
+      queryClient.invalidateQueries({ queryKey: queryKeys.preferences });
</code_context>
<issue_to_address>
**Cached recommendations keep excluded items**

When a pairing, learned-pair, or generated recommendation containing the item is cached when the user excludes it, the mutation invalidates only the preferences query, leaving the cached recommendation queries unchanged, so the excluded item remains in suggestions or recommendations.

Invalidate the affected pairing, learned-pair, and generated recommendation queries when the exclusion mutation succeeds.

Also at `frontend/lib/hooks/use-preferences.ts:64-65`.
</issue_to_address>

### Comment 5
<location path="frontend/lib/hooks/use-preferences.ts" line_range="62" />
<code_context>
+      return excluded
+        ? api.post<{ excluded_item_ids: string[] }>(path)
+        : api.delete<{ excluded_item_ids: string[] }>(path);
+    },
+    onSuccess: () => {
+      queryClient.invalidateQueries({ queryKey: queryKeys.preferences });
</code_context>
<issue_to_address>
**Committed toggles appear to fail**

When the server commits an exclusion update but the response fails to reach the client, the endpoint can commit the exclusion before its response is lost; the mutation then rejects and skips `onSuccess`, leaving the preferences cache and switch at their old values even though the server saved the new state.

Reconcile preferences after mutation settlement, including ambiguous network failures, so the UI reflects the persisted state.
</issue_to_address>

### Comment 6
<location path="frontend/lib/hooks/use-preferences.ts" line_range="59-61" />
<code_context>
+    mutationFn: ({ itemId, excluded }: { itemId: string; excluded: boolean }) => {
+      applySessionToken(session);
+      const path = `/users/me/preferences/excluded-items/${itemId}`;
+      return excluded
+        ? api.post<{ excluded_item_ids: string[] }>(path)
+        : api.delete<{ excluded_item_ids: string[] }>(path);
+    },
+    onSuccess: () => {
</code_context>
<issue_to_address>
**Toggle fails for null exclusions**

When an existing preference row has `excluded_item_ids` set to NULL, the new switch sends a POST to the existing add endpoint, whose `add_excluded_item` checks membership in `preferences.excluded_item_ids` without handling `None`. For a preference row with a null array, that check raises `TypeError`, so the switch cannot mark the item excluded.

Normalize a null array to an empty list before membership checks and writes, or make the column non-null and backfill existing null rows.
</issue_to_address>

Sourcery assessment

Approval pending. 6 findings to address first.

Blocking findings: backend/app/services/learning_service.py:729, frontend/app/dashboard/wardrobe/page.tsx:340, frontend/lib/hooks/use-preferences.ts:60, frontend/lib/hooks/use-preferences.ts:62, frontend/lib/hooks/use-preferences.ts:62, and 1 more


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

Comment thread frontend/lib/hooks/use-preferences.ts Resolved
Comment thread frontend/lib/hooks/use-preferences.ts Resolved
Comment thread frontend/lib/hooks/use-preferences.ts Resolved
Comment thread frontend/lib/hooks/use-preferences.ts Resolved
…on settle

- learned pair suggestions drop excluded items in the query, so excluded pairs
  ranked above eligible ones can no longer crowd them out of the limit window
- adding or removing an exclusion works when a stored list is NULL
- the switch refetches preferences on settle, not only on success, and also
  refreshes learned item pairs that may list the newly excluded item
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