You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(web): propagate offer availability into Omnibus price audit - #1872
Propagates explicit listing availability (OfferAvailability) into OfferDiscountAnalysis and forwards live offers into PriceHistorySection across all product detail routes and lazy size panels so sold-out or discontinued normal_price listings priced at or above currentMinPrice cannot pollute EU Omnibus 30-day prior-floor or 90-day cycle percentile calculations.
Exported OfferAvailability from @/lib/rate-api and @/lib/rate-domain.
Added optional availability?: OfferAvailability on OfferDiscountAnalysis and populated it in getMasterProductPriceHistory via toOfferAvailability(off.availability).
Updated getCachedMasterProductPriceHistory (server/rate/index.ts) to SHA-256 hash all safeOffers tuples including availability, and normalized toOfferAvailability(o.availability) in _getCachedUnknownByOffer (server/rate/item-page.ts).
PriceHistorySection & omnibus-price-audit.ts Forwarding and Precedence:
Forwarded offers={v.offers} from ProductDetailView (apps/web/src/app/[locale]/smartphones/[slug]/page.tsx, shared across all 5 canonical category detail routes) and offers={data.offers} from ItemLazySizePanel.tsx.
Supported optional product_id alongside id on OmnibusReferenceOfferInput (omnibus-price-audit.ts).
Updated PriceHistorySection to resolve explicit availability in strict order (offers -> OfferDiscountAnalysis.availability -> fallback heuristics when availability is unknown), preserve explicit unavailability even on blank-ID reference entries, and evaluate allKnownOffersUnavailable across plausible priced in-stock offers.
Unit Regression Coverage (sale-state.test.ts & offer-plausibility.test.ts):
Verified getMasterProductPriceHistory populates availability (in_stock, out_of_stock, discontinued, and omits undefined when null).
Verified sold-out (27.8M > 27.0M) and discontinued (27.0M === 27.0M) normal_price offers are excluded from Omnibus 30-day prior-floor and 90-day cycle inputs across vi, en, and cs even when offers is omitted.
Verified forwarded offers keeps explicitly in_stock offers eligible when stored minPrice lags, and suppresses phantom Omnibus cards when only sold-out offers and sub-floor bait remain.
Verification & Review Gate
pnpm typecheck - passed
pnpm lint - passed
pnpm --filter @repo/web test - passed
pnpm build - passed
Review Gate: Audited by 2 independent fresh-context research subagents (Reviewer #1 Domain & Pricing Correctness, Reviewer #2 Adversarial Edge Cases, Cache Invalidation & Input Bounds); all Round-1 P2 edge-case findings fixed in e291297e. Note: local Codex CLI is out of quota until Nov 25, 2026, so Codex review did not run.
📌 TL;DR
This PR enhances the price history and Omnibus audit logic by explicitly propagating offer availability states (in_stock, out_of_stock, discontinued) from the API to the UI, ensuring that unavailable offers are correctly excluded from price floor calculations and preventing stale or invalid data from polluting deal signals.
Updates renderPriceHistory to accept and forward the offers array to PriceHistorySection, ensuring the main product detail page passes live offer data.
Core Logic Update: 1. Introduces safeOffersInput to sanitize incoming offers. 2. Refactors unavailableOfferIds calculation to prioritize explicit availability fields over heuristic price checks. 3. Updates effectiveReferenceOffers to map availability states correctly. 4. Adds allKnownOffersUnavailable check to suppress Omnibus audits when no valid in-stock offers exist. 5. Passes currentOfferUnavailable to the audit evaluator.
Adds assertions to verify that availability is correctly populated in byOffer results for sold-out and in-stock scenarios.
apps/web/src/lib/__tests__/sale-state.test.ts
Extensive new test suite (#1871) verifying: 1. Exclusion of sold-out/discontinued offers from Omnibus price floors. 2. Correct handling of offers prop omission vs. forwarding. 3. Suppression of Omnibus cards when all offers are unavailable or "bait" priced. 4. Source code checks to ensure offers are forwarded in UI components.
apps/web/src/lib/omnibus-price-audit.ts
Updates OmnibusReferenceOfferInput to support product_id as a fallback identifier and refactors ID resolution logic in buildOfferExclusionSets.
apps/web/src/lib/rate-api.ts
1. Exports OfferAvailability type. 2. Adds availability field to OfferDiscountAnalysis. 3. Populates availability in getMasterProductPriceHistory using toOfferAvailability.
apps/web/src/lib/rate-domain.ts
Re-exports OfferAvailability type for broader consumption.
apps/web/src/server/rate/index.ts
Updates cache key generation for getCachedMasterProductPriceHistory to include availability in the SHA-256 hash, ensuring cache invalidation when stock status changes.
apps/web/src/server/rate/item-page.ts
Updates cache key generation for unknown offers to include availability status.
📊 Architectural Flow
flowchart TD
subgraph Data Layer
A[API / DB] -->|Offers with Availability| B[rate-api.ts]
end
subgraph Processing
B -->|getMasterProductPriceHistory| C[OfferDiscountAnalysis]
C -->|Includes availability field| D[MasterProductPriceHistorySummary]
end
subgraph UI Components
D --> E[ProductDetailView / ItemLazySizePanel]
E -->|Forwards offers & history| F[PriceHistorySection]
end
subgraph Omnibus Audit Logic
F -->|Sanitizes & Filters| G[Effective Reference Offers]
G -->|Checks Availability| H{Any In-Stock?}
H -->|No| I[Suppress Omnibus Card]
H -->|Yes| J[Calculate Price Floors]
J -->|Excludes Unavailable| K[Omnibus Audit Result]
end
style F fill:#e1f5fe,stroke:#01579b
style H fill:#fff9c4,stroke:#fbc02d
style I fill:#ffcdd2,stroke:#c62828
style K fill:#c8e6c9,stroke:#2e7d32
Loading
Summary by CodeRabbit
Bug Fixes
Price-history displays now account for offer availability, helping prevent sold-out or discontinued listings from being treated as current offers or historical price lows.
Price-history results are more consistent when listings have missing, unrecognized, or stale availability information.
Product and size pages now include their offers when displaying price history, improving the accuracy of availability and pricing details.
Add optional availability on OfferDiscountAnalysis in rate-domain and
populate it in getMasterProductPriceHistory, include availability in
price-history cache keys, forward offers into PriceHistorySection from
ProductDetailView and ItemLazySizePanel, and cover sold-out normal_price
exclusion when offers is omitted (Refs #1871).
Preserve explicit unavailability on blank-ID reference offers, filter
malformed offers entries before fallback, check plausible in-stock
offers for allKnownOffersUnavailable, and hash all offers in
getCachedMasterProductPriceHistory (Refs #1871).
The reason will be displayed to describe this comment to others. Learn more.
⚠️Code review skipped — your organization has no extra usage available to pay for this review.
If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.
Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.
Product detail callers now pass offers to price-history rendering. Offer availability is included in price-history analyses and used to determine whether Omnibus reference offers can contribute to the audit. Price-history cache keys also account for offer availability.
Changes: Price-history availability
Layer / File(s)
Summary
Availability analysis and rendering apps/web/src/lib/rate-api.ts, apps/web/src/lib/rate-domain.ts, apps/web/src/app/[locale]/smartphones/[slug]/page.tsx, apps/web/src/components/product/item/ItemLazySizePanel.tsx, apps/web/src/lib/__tests__/offer-plausibility.test.ts, apps/web/src/lib/__tests__/sale-state.test.ts
OfferDiscountAnalysis now carries normalized availability. Product detail callers pass offers to PriceHistorySection. Tests cover availability in analyses and caller wiring.
Availability-aware Omnibus audit apps/web/src/components/price-history/PriceHistorySection.tsx, apps/web/src/lib/omnibus-price-audit.ts, apps/web/src/lib/__tests__/sale-state.test.ts
The price-history section evaluates reference offers by availability and price plausibility. If all known offers are unavailable, the market audit receives null current and claimed prices and marks the current offer unavailable. Reference offers can use product_id when id is absent. Tests cover sold-out, discontinued, malformed, and unknown-availability offers.
Cache keys include normalized offer availability. The price-history key hashes representations of all supplied offers instead of serializing only the first 20.
DOS/Rate#893: Both PRs modify price-history cache-key construction in apps/web/src/server/rate/index.ts.
DOS/Rate#1698: Both PRs handle unavailable offers in the price-history data path, including getMasterProductPriceHistory.
Suggested reviewers:dos
Merge Risk: Low · up to e2912
This change makes sold-out and discontinued listings stop affecting the Omnibus price audit. The only remaining concern is that a malformed offer entry, which the typed producers should not emit, could hide the Omnibus card. The risk is low and mergeable, with owner awareness of this edge case.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title "fix(web): propagate offer availability into Omnibus price audit" matches the main change. The PR adds explicit offer availability to OfferDiscountAnalysis, forwards offers to PriceHistorySe…
Description check
The description follows the template structure: a Summary with what changed and why, a Closes #1871 line, and a Claimant line. It also includes a Changes section, verification results, and review note…
Linked Issues check
Directly linked active issue #1871 has three coding criteria. (1) Optional availability on OfferDiscountAnalysis: the summary shows OfferAvailability exported from rate-api.ts and rate-domain.ts, a ne…
Out of Scope Changes check
Changes map to issue #1871 or to the availability propagation it requires. Type export and field changes (rate-api.ts, rate-domain.ts) and forwarding changes (page.tsx, ItemLazySizePanel.tsx) implemen…
Full details: Title check
Explanation
The title "fix(web): propagate offer availability into Omnibus price audit" matches the main change. The PR adds explicit offer availability to OfferDiscountAnalysis, forwards offers to PriceHistorySection, and uses availability in the Omnibus audit exclusions. It follows Conventional Commits and is short and specific.
Full details: Description check
Explanation
The description follows the template structure: a Summary with what changed and why, a Closes #1871 line, and a Claimant line. It also includes a Changes section, verification results, and review notes. The template's Checklist, Screenshots, and Notes sections are absent from the author text. The Claimant line keeps the author's session ID rather than the template's placeholder format, and the description does not include the template's Affected areas or Reviewers notes. Those gaps are non-critical, so the description is mostly complete.
Full details: Linked Issues check
Explanation
Directly linked active issue #1871 has three coding criteria. (1) Optional availability on OfferDiscountAnalysis: the summary shows OfferAvailability exported from rate-api.ts and rate-domain.ts, a new availability?: OfferAvailability field, and population via toOfferAvailability(off.availability) in getMasterProductPriceHistory. Unit tests in sale-state.test.ts reportedly check in_stock, out_of_stock, discontinued, and undefined for null. (2) Forwarding offers: the summary shows offers={v.offers} in the smartphones/[slug] page, which the author states is shared by all five canonical category detail routes, and offers={data.offers} in ItemLazySizePanel.tsx. (3) Test: sale-state.test.ts reportedly verifies that sold-out (27.8M > 27.0M) and discontinued (27.0M === 27.0M) normal_price offers are excluded from 30-day prior-floor and 90-day cycle inputs when offers is omitted. Uncertainty: the issue names apps/web/src/app/[locale]/[category]/[slug]/page.tsx, which does not exist at the reviewed head. The changed route file could not be diffed (changed blobs unavailable), so the shared-route claim rests on the PR summary and was not independently verified. The test assertions are taken from the summary, not from the test source.
Full details: Out of Scope Changes check
Explanation
Changes map to issue #1871 or to the availability propagation it requires. Type export and field changes (rate-api.ts, rate-domain.ts) and forwarding changes (page.tsx, ItemLazySizePanel.tsx) implement criteria 1 and 2. The SHA-256 cache-key changes (server/rate/index.ts, server/rate/item-page.ts) add availability to cache identity so cached results reflect stock changes. The product_id fallback and blank-ID handling in omnibus-price-audit.ts and PriceHistorySection.tsx support the offers input path that criterion 2 introduces. The sale-state.test.ts async main and exit handling are test infrastructure for criterion 3. The PR objectives list the blank-ID and malformed-input hardening explicitly. No change was found that is unrelated to #1871. Some hardening (for example allKnownOffersUnavailable and plausibility checks) goes beyond the issue text, but it operates on the same availability data and was not shown to be unrelated.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
688-690: Minor · Functional Correctness · Quick win
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Reject malformed offer objects before selecting the reference source.
If offers is [{} as never], this filter retains the object. effectiveReferenceOffers then skips the valid byOffer analyses. The missing price makes allKnownOffersUnavailable true, so the Omnibus card disappears.
Validate the required price_current field before selecting supplied offers. If no valid entries remain, use the analyses. Preserve valid blank-ID unavailable entries. The current [null] regression does not cover this case.
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: f9f550c7-0c0b-4298-9833-0d160d76461f
Commits
Reviewing files that changed from the base of the PR and between 37c6348 and e291297.
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Propagates explicit listing availability (
OfferAvailability) intoOfferDiscountAnalysisand forwards liveoffersintoPriceHistorySectionacross all product detail routes and lazy size panels so sold-out or discontinuednormal_pricelistings priced at or abovecurrentMinPricecannot pollute EU Omnibus 30-day prior-floor or 90-day cycle percentile calculations.Closes #1871
Claimant: antigravity:11787661-5a2c-4e90-a023-d1c4d248212d
Changes
OfferDiscountAnalysis.availability(rate-api.ts&rate-domain.ts):OfferAvailabilityfrom@/lib/rate-apiand@/lib/rate-domain.availability?: OfferAvailabilityonOfferDiscountAnalysisand populated it ingetMasterProductPriceHistoryviatoOfferAvailability(off.availability).getCachedMasterProductPriceHistory(server/rate/index.ts) to SHA-256 hash allsafeOfferstuples includingavailability, and normalizedtoOfferAvailability(o.availability)in_getCachedUnknownByOffer(server/rate/item-page.ts).PriceHistorySection&omnibus-price-audit.tsForwarding and Precedence:offers={v.offers}fromProductDetailView(apps/web/src/app/[locale]/smartphones/[slug]/page.tsx, shared across all 5 canonical category detail routes) andoffers={data.offers}fromItemLazySizePanel.tsx.product_idalongsideidonOmnibusReferenceOfferInput(omnibus-price-audit.ts).PriceHistorySectionto resolve explicit availability in strict order (offers->OfferDiscountAnalysis.availability-> fallback heuristics when availability is unknown), preserve explicit unavailability even on blank-ID reference entries, and evaluateallKnownOffersUnavailableacross plausible priced in-stock offers.sale-state.test.ts&offer-plausibility.test.ts):getMasterProductPriceHistorypopulatesavailability(in_stock,out_of_stock,discontinued, and omitsundefinedwhennull).27.8M > 27.0M) and discontinued (27.0M === 27.0M)normal_priceoffers are excluded from Omnibus 30-day prior-floor and 90-day cycle inputs acrossvi,en, andcseven whenoffersis omitted.offerskeeps explicitlyin_stockoffers eligible when storedminPricelags, and suppresses phantom Omnibus cards when only sold-out offers and sub-floor bait remain.Verification & Review Gate
pnpm typecheck- passedpnpm lint- passedpnpm --filter @repo/web test- passedpnpm build- passedresearchsubagents (Reviewer #1Domain & Pricing Correctness,Reviewer #2Adversarial Edge Cases, Cache Invalidation & Input Bounds); all Round-1P2edge-case findings fixed ine291297e. Note: local Codex CLI is out of quota until Nov 25, 2026, so Codex review did not run.📌 TL;DR
This PR enhances the price history and Omnibus audit logic by explicitly propagating offer availability states (
in_stock,out_of_stock,discontinued) from the API to the UI, ensuring that unavailable offers are correctly excluded from price floor calculations and preventing stale or invalid data from polluting deal signals.🎯 Type of Change
🔍 Changes Walkthrough
apps/web/src/app/[locale]/smartphones/[slug]/page.tsxrenderPriceHistoryto accept and forward theoffersarray toPriceHistorySection, ensuring the main product detail page passes live offer data.apps/web/src/components/price-history/PriceHistorySection.tsx1. Introduces
safeOffersInputto sanitize incoming offers.2. Refactors
unavailableOfferIdscalculation to prioritize explicitavailabilityfields over heuristic price checks.3. Updates
effectiveReferenceOffersto map availability states correctly.4. Adds
allKnownOffersUnavailablecheck to suppress Omnibus audits when no valid in-stock offers exist.5. Passes
currentOfferUnavailableto the audit evaluator.apps/web/src/components/product/item/ItemLazySizePanel.tsxoffersdata toPriceHistorySectionfor lazy-loaded size panels, maintaining consistency with the main page.apps/web/src/lib/__tests__/offer-plausibility.test.tsavailabilityis correctly populated inbyOfferresults for sold-out and in-stock scenarios.apps/web/src/lib/__tests__/sale-state.test.ts1. Exclusion of sold-out/discontinued offers from Omnibus price floors.
2. Correct handling of
offersprop omission vs. forwarding.3. Suppression of Omnibus cards when all offers are unavailable or "bait" priced.
4. Source code checks to ensure
offersare forwarded in UI components.apps/web/src/lib/omnibus-price-audit.tsOmnibusReferenceOfferInputto supportproduct_idas a fallback identifier and refactors ID resolution logic inbuildOfferExclusionSets.apps/web/src/lib/rate-api.ts1. Exports
OfferAvailabilitytype.2. Adds
availabilityfield toOfferDiscountAnalysis.3. Populates
availabilityingetMasterProductPriceHistoryusingtoOfferAvailability.apps/web/src/lib/rate-domain.tsOfferAvailabilitytype for broader consumption.apps/web/src/server/rate/index.tsgetCachedMasterProductPriceHistoryto includeavailabilityin the SHA-256 hash, ensuring cache invalidation when stock status changes.apps/web/src/server/rate/item-page.tsavailabilitystatus.📊 Architectural Flow
flowchart TD subgraph Data Layer A[API / DB] -->|Offers with Availability| B[rate-api.ts] end subgraph Processing B -->|getMasterProductPriceHistory| C[OfferDiscountAnalysis] C -->|Includes availability field| D[MasterProductPriceHistorySummary] end subgraph UI Components D --> E[ProductDetailView / ItemLazySizePanel] E -->|Forwards offers & history| F[PriceHistorySection] end subgraph Omnibus Audit Logic F -->|Sanitizes & Filters| G[Effective Reference Offers] G -->|Checks Availability| H{Any In-Stock?} H -->|No| I[Suppress Omnibus Card] H -->|Yes| J[Calculate Price Floors] J -->|Excludes Unavailable| K[Omnibus Audit Result] end style F fill:#e1f5fe,stroke:#01579b style H fill:#fff9c4,stroke:#fbc02d style I fill:#ffcdd2,stroke:#c62828 style K fill:#c8e6c9,stroke:#2e7d32Summary by CodeRabbit