Skip to content

Commit 844cac8

Browse files
vibeguiclaude
andcommitted
fix(cache): use separate singleFlight keys for bot vs non-bot requests
Instead of bypassing singleFlight entirely (which wastes CPU on duplicate bot requests), use a prefixed flight key so bots still deduplicate among themselves but never become leader for non-bot callers. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b34270d commit 844cac8

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

blocks/loader.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,13 @@ const wrapLoader = (
360360
return await matched.json();
361361
};
362362

363-
if (isBotRequest) {
364-
// Bots must not participate in shared flights — if a bot becomes the
365-
// leader, its closure skips cache.put and revalidation, which would
366-
// suppress writes for all concurrent non-bot callers sharing the flight.
367-
return await staleWhileRevalidate();
368-
}
369-
return await flights.do(request.url, staleWhileRevalidate);
363+
// Bots use a separate flight key so they deduplicate among themselves
364+
// but never become leader for non-bot requests (bot leaders skip
365+
// cache.put and revalidation, which would suppress writes for non-bots).
366+
const flightKey = isBotRequest
367+
? `bot:${request.url}`
368+
: request.url;
369+
return await flights.do(flightKey, staleWhileRevalidate);
370370
} finally {
371371
const dimension = { loader, status };
372372
if (OTEL_ENABLE_EXTRA_METRICS) {

0 commit comments

Comments
 (0)