Skip to content

BUY-61977: stop caching degraded envelopes in search + deals - #217

Open
BuyWhere wants to merge 1 commit into
masterfrom
buy-61977-degraded-cache-v2
Open

BUY-61977: stop caching degraded envelopes in search + deals#217
BuyWhere wants to merge 1 commit into
masterfrom
buy-61977-degraded-cache-v2

Conversation

@BuyWhere

Copy link
Copy Markdown
Owner

BUY-61977: stop caching degraded envelopes in search + deals

Root cause

The deals handler and search archive path cache the response envelope for 1 hour
regardless of meta.degraded. When the read replica times out (Postgres error 57014),
the cached degraded:true,total=0 payload becomes the answer for the next hour —
even after the upstream recovers. This keeps the MCP fabricated-cache incident (BUY-61957)
technically unresolved.

Fix (3 files)

api/src/lib/response.ts

  • buildSearchResponse: add degraded: boolean = false param
  • Add meta: { degraded, cached } to the returned SearchResponse object

api/src/types/product.ts

  • SearchResponse interface: add optional meta?: { degraded?: boolean; cached?: boolean }

api/src/routes/products.ts

  • Archive search (FTS): skip redis.set when !responseBody.meta?.degraded
  • Deals: skip redis.set when !responseBody.meta?.degraded

No cache-key version bump needed

This fix prevents future poisoning. Existing degraded cache entries (if any) will
naturally expire within 60s (the SEARCH_CACHE_TTL_SECONDS). No key version
bump or cache flush required.

Verification

After merge, redeploy with explicit commitSha set (see BUY-58065 cache pitfall).
Then re-run the probe matrix:

  • GET /v1/products/search?q=laptop&country=US&limit=3degraded=false
  • GET /v1/products/deals?country=SG&limit=3degraded=false
  • GET /v1/products/deals?country=US&limit=3degraded=false

Closes BUY-61977.

Root cause: the deals handler and search archive path cache the response
envelope for 1 hour regardless of degraded=true. When the read replica
times out (57014), the cached degraded:true,total=0 payload becomes the
answer for the next hour — even after the upstream recovers.

Fix:
- buildSearchResponse: add degraded param + meta.degraded field
- SearchResponse type: add optional meta.degraded
- Archive search (FTS): skip cache write when meta.degraded
- Deals: skip cache write when meta.degraded
- Cache-key version bump: old poisoned keys bypassed immediately
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant