Skip to content

fix: stale KV fallback + never cache null on /perps cohort fetch - #1687

Merged
Flotapponnier merged 2 commits into
devfrom
fix/perps-stale-fallback
Jul 29, 2026
Merged

fix: stale KV fallback + never cache null on /perps cohort fetch#1687
Flotapponnier merged 2 commits into
devfrom
fix/perps-stale-fallback

Conversation

@Flotapponnier

Copy link
Copy Markdown
Collaborator

Summary

  • When the worker hasn't written a fresh KV snapshot in < 2 min AND Prometheus is unreachable (always the case on Vercel — VPS Prom not public), fetchPerpCohortRaw() was returning null
  • That null was being cached by unstable_cache for 60 s → a single worker hiccup blanked the page for all users for up to a minute
  • Same issue for fetchPerpByAssetMatrixRaw (cached empty array for 120 s)

Fixes:

  1. Stale KV fallback: if both the fresh snapshot check and the Prom fallback fail, serve the KV snapshot up to 10 min old rather than returning null. Covers brief worker gaps without hiding sustained outages (> 10 min still shows the banner).
  2. Never cache null/empty: throw on null/empty so unstable_cache does not store the failure — the next request always retries instead of serving a cached failure for the full revalidate window.

Test plan

  • Visit /perps on staging — should show data consistently
  • Confirm "temporarily unavailable" banner only appears when worker has been down > 10 min

🤖 Generated with Claude Code

@Flotapponnier
Flotapponnier merged commit a2c2072 into dev Jul 29, 2026
0 of 2 checks passed
@Flotapponnier
Flotapponnier deleted the fix/perps-stale-fallback branch July 29, 2026 15:17
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