From c9ba2ac0251ae3a9dda1371222a2d5023043b37a Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Fri, 20 Mar 2026 12:07:47 +0100 Subject: [PATCH] [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 --- .../src/Features/Compile/ClsiCacheManager.mjs | 3 ++- .../app/src/Features/Compile/ClsiManager.mjs | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/services/web/app/src/Features/Compile/ClsiCacheManager.mjs b/services/web/app/src/Features/Compile/ClsiCacheManager.mjs index aba619dae3..de78c0edc4 100644 --- a/services/web/app/src/Features/Compile/ClsiCacheManager.mjs +++ b/services/web/app/src/Features/Compile/ClsiCacheManager.mjs @@ -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, }, diff --git a/services/web/app/src/Features/Compile/ClsiManager.mjs b/services/web/app/src/Features/Compile/ClsiManager.mjs index 5da6c55c39..4d995208d9 100644 --- a/services/web/app/src/Features/Compile/ClsiManager.mjs +++ b/services/web/app/src/Features/Compile/ClsiManager.mjs @@ -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,