From 8b430fab5dc12fc57e4552ffb19930350b14e0e1 Mon Sep 17 00:00:00 2001 From: Shekhar Vaidya Date: Wed, 8 Jul 2026 19:47:09 +0530 Subject: [PATCH] fix(backend): don't mislabel fresh lockdown-gate cache hits as stale The Sentinel lockdown gate served any linkCache hit as "stale" regardless of whether the entry was still within its own TTL. A link just contributed via CLI (still valid for ~24h) would get labeled stale, causing the frontend to hide it and show the CLI-only banner again instead of the working link it just received. Now checks the entry's actual expiry: still-fresh entries are labeled "cached" (frontend shows the link normally); only genuinely expired entries are labeled "stale". Co-Authored-By: Claude Sonnet 4.6 --- backend/main.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/backend/main.go b/backend/main.go index a6d945d..112ca01 100644 --- a/backend/main.go +++ b/backend/main.go @@ -1199,10 +1199,20 @@ func handleProxy(w http.ResponseWriter, r *http.Request) { staleEntry, hasStale := linkCache[cacheKey] linkCacheMu.RUnlock() if hasStale { - atomic.AddInt64(&mLinkStale, 1) - log.Printf("/proxy: product_id=%s sku_id=%s -> lockdown active, serving stale (expires %s)\n", - productID, skuID, lockdownEntry.ExpiresAt.Format(time.RFC3339)) - w.Header().Set("X-MSDL-Link-Status", "stale") + if time.Now().Before(staleEntry.ExpiresAt) { + // Entry is still within its normal TTL (e.g. just contributed by + // a CLI run) — genuinely fresh, not actually stale, just being + // served via the lockdown gate before the usual cache check. + atomic.AddInt64(&mLinkCacheHits, 1) + log.Printf("/proxy: product_id=%s sku_id=%s -> lockdown active, serving cached (expires %s)\n", + productID, skuID, staleEntry.ExpiresAt.Format(time.RFC3339)) + w.Header().Set("X-MSDL-Link-Status", "cached") + } else { + atomic.AddInt64(&mLinkStale, 1) + log.Printf("/proxy: product_id=%s sku_id=%s -> lockdown active, serving stale (expires %s)\n", + productID, skuID, lockdownEntry.ExpiresAt.Format(time.RFC3339)) + w.Header().Set("X-MSDL-Link-Status", "stale") + } if exp := extractRawExpiry(staleEntry.RawJSON); exp != "" { w.Header().Set("X-MSDL-Link-Expires", exp) }