Repository navigation
Conversation
…at rule The outfit prompt now carries the current and peak UV index (and strong wind), and the generic hat mention is replaced by a rule: a cap or sun hat at UV 6+, a warm hat when it is cold or windy, never a hat just to complete the look.
…pting Classify shoes as light, medium or heavy from type, subtype, material, seasons and ai_description keywords. On warm days heavy shoes are penalised strongly, and medium ones mildly when a light pair exists; on cold days light shoes are penalised mildly. The weight is listed on each footwear line of the prompt, with a rule to match footwear weight to the weather.
The stylist may name one wardrobe layer to add if it gets cooler and one of the outfit's own layers to take off if it warms up. Both are validated (in range, available, right role, not already in the outfit / actually in it and still complete without it) and stored as two nullable foreign keys on outfits (ON DELETE SET NULL). They are returned in every outfit response and shown as compact rows on the suggestion card and the outfit page.
…nless it is clearly hot
Reviewer's GuideSchema and migrationsAdd indexed nullable foreign keys for cooler and warmer outfit extras, with deletion clearing the references.
Data structuresAdd outfit relationships and response fields for the two weather extras, and expose their summary shape to frontend consumers.
Extend the weather data structure to carry the daily maximum UV index.
APISerialize weather extras in outfit responses while hiding unavailable, duplicated, or no-longer-valid references.
ImplementationValidate AI-selected cooler and warmer layers, recheck availability before saving, and include UV and wind conditions in prompt and cache context.
Classify footwear warmth, adjust weather scoring and small-wardrobe ordering, and preserve candidates for cooler-layer suggestions.
Fetch and populate the daily maximum UV value from weather-provider responses.
UIRender linked weather-extra rows on suggestion cards and outfit detail pages, with localized labels in all supported locales.
ConfigurationRevise the recommendation prompt with footwear, hat, sun, and weather-extra guidance and the corresponding JSON fields.
TestsCover footwear classification, weather-sensitive ranking, prompt weight labels, and hat scoring behavior.
Check sun and wind prompt context, cache invalidation, and weather-data UV round trips.
Verify extra selection validation, persistence, API responses, deletion behavior, and migration rollback.
Test localized weather-extra rendering, conditional rows, fallback labels, and item links.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 9 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="backend/app/services/recommendation_service.py" line_range="1058" />
<code_context>
condition=weather.condition,
precipitation_chance=weather.precipitation_chance,
temp_range_text=format_temp_range_text(weather),
+ weather_details_text=format_weather_details_text(weather),
preferences_text=preferences_text,
items_text=items_text,
</code_context>
<issue_to_address>
**Cached advice ignores changing sun and wind**
When UV or wind changes while the cache-context fields still match, `suggestion_context()` omits UV and wind, so `cached_suggestion_fits()` accepts the old response and returns hat or layer advice generated for different conditions; users see a stale suggestion.
Include UV and wind in the suggestion cache context.
</issue_to_address>
### Comment 2
<location path="backend/app/services/item_scorer.py" line_range="203-204" />
<code_context>
+ # Warmest and coolest reading to judge shoes against, feels-like included.
+ temp_range = scoring_temp_range(weather)
+ if temp_range is not None:
+ mid = (temp_range[0] + temp_range[1]) / 2
+ return mid, mid
+ return (
+ max(weather.temperature, weather.feels_like),
</code_context>
<issue_to_address>
**Footwear scoring ignores temperature extremes**
When a qualifying temperature range crosses a footwear threshold that its midpoint does not, or the current feels-like reading crosses a threshold the midpoint does not, `_footwear_reference_temps()` returns the range midpoint for both values, so `_footwear_weight_score()` misses the range endpoints and current feels-like conditions; users can get shoes suited to the wrong temperatures.
Use the relevant temperature-range endpoints and current weather readings when calculating footwear reference temperatures.
</issue_to_address>
### Comment 3
<location path="backend/app/services/recommendation_service.py" line_range="136" />
<code_context>
+ if value is None:
+ return None
+ picked = picked_item_ids([value], number_map)
+ if len(picked) != 1 or picked[0] not in item_type_map:
+ logger.debug(f"Dropping {key}={value!r}: not an available item")
+ return None
</code_context>
<issue_to_address>
**Unavailable extras break or pollute saved outfits**
When a candidate extra is archived or deleted after candidate loading but before the outfit is saved, `resolve_layer_extras()` trusts the stale `item_type_map` and accepts the extra; `_save_outfit()` then stores an archived item or fails its foreign-key flush for a deleted item, so the user gets an unavailable extra or a failed request.
Recheck each selected extra's current availability before saving and drop unavailable extras.
Also at `backend/app/models/outfit.py:100`.
</issue_to_address>
### Comment 4
<location path="backend/app/services/item_scorer.py" line_range="644" />
<code_context>
# score_items leaves small wardrobes unscored, so filling a missing piece needs its own
# ranking or it would fall back to database order. Most items tie on fit in mild
# weather, so the least recently worn goes first to avoid adding the same piece every time.
+ light_available = has_light_footwear(items)
+
def key(item: ClothingItem) -> tuple[float, date]:
</code_context>
<issue_to_address>
**Small wardrobes skip footwear weighting**
When the wardrobe has fewer than `MIN_ITEMS_FOR_SCORING` candidates, `score_items()` returns before reaching the new footwear-weight calculation, so light and heavy shoes keep their incoming order and recommendations miss the intended warm-weather weighting.
Apply footwear weighting before the small-wardrobe early return or score those candidates normally.
Also at `backend/app/services/item_scorer.py:501`.
</issue_to_address>
### Comment 5
<location path="backend/app/api/outfits.py" line_range="408-409" />
<code_context>
+ # The outfit's items can change after the AI named its extras (studio edits), so an extra
+ # that no longer fits is hidden rather than shown wrongly.
+ outfit_item_ids = {outfit_item.item_id for outfit_item in outfit.items}
+ if_cooler = outfit.if_cooler_item
+ if if_cooler is not None and if_cooler.id in outfit_item_ids:
+ if_cooler = None
+ if_warmer = outfit.if_warmer_item
</code_context>
<issue_to_address>
**Archived extras remain in outfit responses**
When a referenced extra is archived after its outfit is saved, `outfit_to_response()` checks whether an extra is in the outfit but not whether it remains ready and unarchived, so the API returns an unavailable item and the UI still offers it as a weather suggestion.
Omit extras that are no longer ready and unarchived when building the outfit response.
Also at `backend/app/api/outfits.py:474-475`.
</issue_to_address>
### Comment 6
<location path="backend/app/api/outfits.py" line_range="412-413" />
<code_context>
+ if if_cooler is not None and if_cooler.id in outfit_item_ids:
+ if_cooler = None
+ if_warmer = outfit.if_warmer_item
+ if if_warmer is not None and if_warmer.id not in outfit_item_ids:
+ if_warmer = None
+
feedback_summary = None
</code_context>
<issue_to_address>
**Essential warmer layers appear removable**
When an outfit edit leaves the warmer item in the outfit but makes the outfit incomplete without it, `outfit_to_response()` checks whether the warmer item is present but not whether removing it leaves a complete outfit, so the API returns it as a removable extra and the user sees an invalid weather suggestion.
Validate that the outfit remains complete without the warmer item before returning it as an extra.
</issue_to_address>
### Comment 7
<location path="backend/app/services/recommendation_service.py" line_range="135" />
<code_context>
+ value = outfit_data.get(key)
+ if value is None:
+ return None
+ picked = picked_item_ids([value], number_map)
+ if len(picked) != 1 or picked[0] not in item_type_map:
+ logger.debug(f"Dropping {key}={value!r}: not an available item")
</code_context>
<issue_to_address>
**Available layers go unoffered**
When the wardrobe has more than 70 scored candidates and a fitting layer ranks below the prompt cutoff, `_format_items_for_prompt` numbers only the scored items, and `resolve_layer_extras.pick` can resolve only numbers in that map. A fitting layer omitted by the item limit therefore cannot be suggested, so the cooler extra is missing despite that layer being in the wardrobe.
Reserve suitable mid- and outer-layer candidates when applying the prompt item limit, or otherwise ensure the extras can reference eligible layers outside the top-ranked list.
</issue_to_address>
### Comment 8
<location path="backend/app/services/recommendation_service.py" line_range="137" />
<code_context>
+ return None
+ picked = picked_item_ids([value], number_map)
+ if len(picked) != 1 or picked[0] not in item_type_map:
+ logger.debug(f"Dropping {key}={value!r}: not an available item")
+ return None
+ return picked[0]
</code_context>
<issue_to_address>
**Invalid weather extras go unnoticed**
When the AI returns an invalid extra item number, or the cached item-number mapping is stale, `resolve_layer_extras.pick()` drops an unavailable or malformed AI item number and logs only at debug level, so a prompt or item-number mapping regression can remove the weather extras from suggestions without an operator-visible signal; users see the rows missing.
Emit a warning or increment a metric when an extra is dropped so persistent failures are visible in production.
</issue_to_address>
### Comment 9
<location path="backend/migrations/versions/b3d9f1a2c4e6_add_outfit_weather_extras.py" line_range="28" />
<code_context>
+
+def upgrade() -> None:
+ for column in ("if_cooler_item_id", "if_warmer_item_id"):
+ op.add_column("outfits", sa.Column(column, UUID(as_uuid=True), nullable=True))
+ op.create_foreign_key(
+ f"fk_outfits_{column}",
</code_context>
<issue_to_address>
**Item deletion scans outfits**
When a clothing item referenced by outfits is deleted, postgreSQL must find outfits referencing the deleted clothing item to apply `ON DELETE SET NULL`; without indexes on these new foreign-key columns, deleting an item scans the outfits table, adding work as outfit history grows.
Add indexes on both foreign-key columns in the migration and model.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 9 findings to address first, and the new footwear scoring and AI weather extras can produce different outfit choices, which are saved on outfit records and remain after a revert. The affected outfits and extra-item pointers are bounded and can be edited or deleted; reverting restores future recommendations but does not remove records already created.
Blocking findings: backend/app/services/recommendation_service.py:1058, backend/app/services/item_scorer.py:204, backend/app/services/recommendation_service.py:136, backend/app/services/item_scorer.py:644, backend/app/api/outfits.py:409, and 4 more
… not the midpoint
…he suggestion cache on sun and wind, log dropped extras
…ut so they can be offered as if_cooler
Description
Three changes so suggestions follow the weather more closely.
1. "If it gets cooler / If it warms up"
Each suggested outfit can name one layer from the wardrobe to add if the weather turns (a mid or outer layer not in the outfit), and one layer in the outfit that can come off if it gets warmer. The cooler layer is offered for every outfit unless the day is clearly hot, so people always know how to cover up for a sudden change.
if_coolerandif_warmer(item numbers or null), with rules.resolve_layer_extras()(in range, right role, not archived or excluded, cooler not in the outfit, warmer in the outfit and removable, outfit still complete without it); invalid picks are dropped. Stored as two nullable FKs onoutfits(ON DELETE SET NULL, one migration) and returned inOutfitResponseasif_cooler/if_warmeritem summaries. The cached-suggestion path goes through the same validation.OutfitWeatherExtrasrows with thumbnails on the suggest card and the outfit page, in all 8 locales.2. Footwear weight
All "all-season" shoes used to weigh the same, so a chunky pair could win on a warm day while knit or mesh shoes were available.
footwear_weight()classifies footwear as light, medium or heavy from type, subtype, material, seasons and description keywords (documented constants). When warm, heavy shoes are penalised strongly and medium ones mildly if a light pair exists; when cold, light shoes are penalised mildly. Nothing is excluded. The weight is shown on each footwear line in the prompt, with a rule to match it to the weather.3. Sun and cold hat
The prompt now gets the UV index (current and today's max,
uv_index_maxfrom Open-Meteo) and wind when relevant. The generic "hat" accessory is replaced by a rule: a cap or sun hat when UV is 6 or higher, a warm hat when it is cold or windy, only if it suits the outfit, never just to complete the look. The scorer never favours hats.Type of Change
Checklist
Screenshots
Outfit page with the two rows (test wardrobe with placeholder images):
Testing
tests/test_footwear_weight.py,tests/test_sun_and_cold_hat.py,tests/test_weather_extras.py(classification table, warm-day ranking, prompt contents, extras validation, persistence, API,SET NULLon item delete, migration up/down). Full suite passes locally except twoutctimezone tests that fail the same way onmainon macOS.tests/test_migration_wore_instead_names.pynow inserts with SQL, because the ORM model has the new columns.ruffclean.tsc --noEmit,npm run lint,npm test,npm run i18n:check./outfits/suggest-options):Test Environment
Additional Notes
Notification emails and ntfy messages do not mention the extras yet.
Summary by Sourcery
Make outfit suggestions adapt more closely to changing temperatures, footwear warmth, sun exposure, and wind.
New Features:
Enhancements:
Tests: