Skip to content

fix(web): propagate offer availability into Omnibus price audit - #1872

Merged
JOY (JOY) merged 2 commits into
devfrom
fix/1871-omnibus-offer-availability
Nov 22, 2026
Merged

JOY (JOY) merged 2 commits into
devfrom
fix/1871-omnibus-offer-availability

Conversation

@JOY

@JOY JOY (JOY) commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

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.

Closes #1871
Claimant: antigravity:11787661-5a2c-4e90-a023-d1c4d248212d

Changes

  1. OfferDiscountAnalysis.availability (rate-api.ts & rate-domain.ts):
    • 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).
  2. 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.
  3. 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.

🎯 Type of Change

  • 🚀 New feature
  • 🐛 Bugfix
  • 🧹 Refactor
  • ⚡ Performance
  • 📚 Documentation
  • ⚙️ CI / Configuration

🔍 Changes Walkthrough

File Summary of Changes
apps/web/src/app/[locale]/smartphones/[slug]/page.tsx Updates renderPriceHistory to accept and forward the offers array to PriceHistorySection, ensuring the main product detail page passes live offer data.
apps/web/src/components/price-history/PriceHistorySection.tsx 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.
apps/web/src/components/product/item/ItemLazySizePanel.tsx Forwards offers data to PriceHistorySection for lazy-loaded size panels, maintaining consistency with the main page.
apps/web/src/lib/__tests__/offer-plausibility.test.ts 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).

@claude claude 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.

⚠️ 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.

@vercel

vercel Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
rate Ready Ready Preview Nov 22, 2026 5:54pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Explain Change →

Walkthrough

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.
Availability-aware cache keys
apps/web/src/server/rate/index.ts, apps/web/src/server/rate/item-page.ts
Cache keys include normalized offer availability. The price-history key hashes representations of all supplied offers instead of serializing only the first 20.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Possibly related issues

Possibly related PRs

  • 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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed 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 Passed 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 Passed 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.

Share

dos[bot]
dos Bot approved these changes Nov 22, 2026

@dos dos 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.

⏱️ Code Review completed (10 eligible files · 35,344 chars · 1 model call(s) · 2 PR unit(s))

Whole diff with bounded context at base 37c6348 / head e291297.

✅ CLEAN_PASS: Complete diff reviewed

@coderabbitai coderabbitai 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.

Additional comments: 1

apps/web/src/components/price-history/PriceHistorySection.tsx-688-690: 1

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.

Files selected for processing: 10

  • apps/web/src/app/[locale]/smartphones/[slug]/page.tsx
  • apps/web/src/components/price-history/PriceHistorySection.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
  • apps/web/src/lib/omnibus-price-audit.ts
  • apps/web/src/lib/rate-api.ts
  • apps/web/src/lib/rate-domain.ts
  • apps/web/src/server/rate/index.ts
  • apps/web/src/server/rate/item-page.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@JOY

Copy link
Copy Markdown
Contributor Author

PO acceptance: merge at e291297

@JOY
JOY (JOY) merged commit 5e2bc21 into dev Nov 22, 2026
23 checks passed
@JOY
JOY (JOY) deleted the fix/1871-omnibus-offer-availability branch November 22, 2026 18:07

This branch was successfully deployed

1 active deployment
Preview — e291297e Deployed Nov 22, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:frontend Frontend / Next.js / UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(web): propagate explicit offer availability into OfferDiscountAnalysis and PriceHistorySection

1 participant