Repository navigation
Conversation
… 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.
Reviewer's GuideData structuresAdd excluded item IDs to the frontend preferences type so consumers can represent the server-provided setting.
APIExpose excluded item IDs in the preferences response schema and populate the field when building the response.
Uses of the APICall the existing excluded-item endpoints from a mutation hook and invalidate preferences and learned-pair queries after either outcome.
ImplementationFilter excluded items from pairing candidates and learned-pair query results while preserving the explicitly selected pairing source.
Handle NULL stored exclusion lists when adding or removing an item exclusion.
UIAdd a never-suggest switch to the item detail dialog and show an eye-off indicator on excluded wardrobe items, with localized labels.
TestsCover excluded-item preference round trips, NULL-list toggles, and filtering behavior across pairing, recommendations, and learned pair suggestions.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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
…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
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_idsandPOST/DELETE /users/me/preferences/excluded-items/{id}already existed and daily/suggest outfits honoured them, but:PairingService.get_available_items) and learned pair suggestions (/learning/item-pairs/{id}) ignored them;This PR:
excluded_item_idsfromGET /users/me/preferencesso 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.It would be great if the mobile app exposed the same switch, and search in the archived items view.
Type of Change
Checklist
Screenshots
Item detail dialog with the switch on:
Wardrobe grid: the eye-off badge marks the excluded socks and boxer briefs, which stay visible and searchable:
Testing
tests/test_never_suggest_items.py: endpoint round trip, pairing filter, excluded source item, recommendation candidates, learned pair suggestions.pyteston never_suggest, pairings, preferences, learning_service, recommendation_service: 284 passed.ruffclean.excluded_item_idsis persisted, and badges appear after closing the dialog.tsc --noEmit,npm run lint(only the existing<img>warning),npm test852/852,npm run i18n:checkOK.Test Environment
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:
Bug Fixes:
Enhancements:
Tests: