[web] enable clsi-cache for all compiles for 20min during outages (#32337)

* [web] enable clsi-cache for all compiles for 20min during outages

* [web] populate clsi-cache when compile from history is enabled

* [web] hide history snapshot from frontend

GitOrigin-RevId: e46c8b5ab401ebdc2407e44eb95439e4d43400da
This commit is contained in:
Jakob Ackermann
2026-03-23 09:06:00 +00:00
committed by Copybot
parent b87053a932
commit c9ba2ac025
2 changed files with 19 additions and 3 deletions
@@ -62,7 +62,8 @@ async function getLatestBuildFromCache(projectId, userId, filename, signal) {
isUpToDate,
lastUpdated,
size,
allFiles,
// Hide history snapshot from frontend
allFiles: allFiles.filter(f => f !== 'history-resync.json.gz'),
shard,
zone,
},
@@ -42,6 +42,10 @@ const CLSI_COOKIES_ENABLED = (Settings.clsiCookie?.key ?? '') !== ''
// The timeout in services/clsi/app.js is 10 minutes, so we'll be on the safe side with 12 minutes
const COMPILE_REQUEST_TIMEOUT_MS = 12 * 60 * 1000
// Enable clsi-cache for all compiles for 20min when detecting low capacity.
const ENABLE_COMPILE_FROM_CACHE_ON_503_MS = 20 * 60 * 1000
let enableCompileFromCacheUntil = 0
function _baseHistoryVersionKey(projectId, userId) {
return `baseHistoryVersion:${projectId}:${userId}`
}
@@ -678,6 +682,8 @@ async function _postToClsi(
} else if (err.response.status === 423) {
return { response: { compile: { status: 'compile-in-progress' } } }
} else if (err.response.status === 503) {
enableCompileFromCacheUntil =
Date.now() + ENABLE_COMPILE_FROM_CACHE_ON_503_MS
return { response: { compile: { status: 'unavailable' } } }
} else if (err.response.status === 504) {
return { response: { compile: { status: 'timedout' } } }
@@ -1104,11 +1110,20 @@ function _finaliseRequest(projectId, options, project, docs, files) {
compileGroup: options.compileGroup,
// Overleaf alpha/staff users get compileGroup=alpha (via getProjectCompileLimits in CompileManager), enroll them into the premium rollout of clsi-cache.
compileFromClsiCache:
['alpha', 'priority'].includes(options.compileGroup) &&
// enable for premium compiles
(['alpha', 'priority'].includes(options.compileGroup) ||
// enable for free for short period when we saw low capacity
enableCompileFromCacheUntil > Date.now()) &&
options.compileFromClsiCache,
populateClsiCache:
// enable for premium compiles
(['alpha', 'priority'].includes(options.compileGroup) ||
options.metricsPath === 'clsi-cache-template') &&
// enable when populating template cache
options.metricsPath === 'clsi-cache-template' ||
// populate indefinitely for free when we saw low capacity
!!enableCompileFromCacheUntil ||
// populate with compile from history enabled to re-use snapshot from cache
!!options.rawChangeOperations) &&
options.populateClsiCache,
enablePdfCaching:
(Settings.enablePdfCaching && options.enablePdfCaching) || false,