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 <noreply@anthropic.com>
This commit is contained in:
Shekhar Vaidya 2026-07-08 19:47:09 +05:30
parent e5d9dc3d61
commit 8b430fab5d

View file

@ -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)
}