Skip to content

fix: isolate force bypass from concurrent stale revalidation#133

Closed
cursor[bot] wants to merge 1 commit into
masterfrom
cursor/critical-bug-investigation-58fe
Closed

fix: isolate force bypass from concurrent stale revalidation#133
cursor[bot] wants to merge 1 commit into
masterfrom
cursor/critical-bug-investigation-58fe

Conversation

@cursor

@cursor cursor Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

When ?force=true was sent concurrently with a normal request during the stale-while-revalidate window, the force request could return stale cached data with X-Cache-Status: STALE instead of fresh data with BYPASS. This defeats explicit cache invalidation under load — the exact scenario where operators use ?force=true to guarantee a fresh origin fetch.

Root cause

@keyvhq/memoize deduplicates in-flight requests using only the cache storage key (URL path). During SWR, a normal request holds pending[key] while serving stale data and revalidating in the background. A concurrent force-bypass request joined that same pending promise and inherited the stale fast-path, even though forceExpiration was true.

The recent @keyvhq/memoize@2.2.4 bump fixed the sequential case (force after stale) but not this concurrent race.

Fix

  • Vendor memoize@2.2.4 with separate pending keys for forced vs normal requests (${key}:${forceExpiration === true})
  • Add regression test covering concurrent normal + force requests during stale window

Validation

  • All 27 existing tests pass
  • New test: BYPASS for forcing refresh when response is stale concurrently
  • Manual reproduction script confirmed fix
Open in Web View Automation 

When ?force=true raced a normal request during stale-while-revalidate,
@keyvhq/memoize deduplicated in-flight work by cache key only, so the
force request could inherit the stale fast-path and return old data while
reporting STALE instead of BYPASS.

Vendor memoize@2.2.4 with separate pending keys for forced bypass and add
a concurrent regression test.

Co-authored-by: kikohumanbeatbox <kikohumanbeatbox@gmail.com>
@Kikobeats Kikobeats closed this Jun 14, 2026
@Kikobeats Kikobeats deleted the cursor/critical-bug-investigation-58fe branch June 14, 2026 07:55
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.

2 participants