From d76f3937132862641c400298844fc6b170c86fff Mon Sep 17 00:00:00 2001 From: Chuan-kai Lin Date: Mon, 10 Mar 2025 10:32:13 -0700 Subject: [PATCH] Do not set --expect-discarded-cache on "cleanup-level: overlay" When a user specifies "cleanup-level: overlay", it suggests that the user wishes to preserve the evaluation cache for future use. So in this case we should not set --expect-discarded-cache when running queries. --- src/analyze-action.ts | 12 ++++++------ src/analyze.test.ts | 1 + src/analyze.ts | 17 ++++++++++------- src/codeql.test.ts | 2 +- src/codeql.ts | 1 - 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/analyze-action.ts b/src/analyze-action.ts index 5c2ab3cb9..249e38191 100644 --- a/src/analyze-action.ts +++ b/src/analyze-action.ts @@ -295,12 +295,16 @@ async function run() { logger, ); + const cleanupLevel = + actionsUtil.getOptionalInput("cleanup-level") || "brutal"; + if (actionsUtil.getRequiredInput("skip-queries") !== "true") { runStats = await runQueries( outputDir, memory, util.getAddSnippetsFlag(actionsUtil.getRequiredInput("add-snippets")), threads, + cleanupLevel, diffRangePackDir, actionsUtil.getOptionalInput("category"), config, @@ -309,12 +313,8 @@ async function run() { ); } - if (actionsUtil.getOptionalInput("cleanup-level") !== "none") { - await runCleanup( - config, - actionsUtil.getOptionalInput("cleanup-level") || "brutal", - logger, - ); + if (cleanupLevel !== "none") { + await runCleanup(config, cleanupLevel, logger); } const dbLocations: { [lang: string]: string } = {}; diff --git a/src/analyze.test.ts b/src/analyze.test.ts index 20cde745b..c7e1856d2 100644 --- a/src/analyze.test.ts +++ b/src/analyze.test.ts @@ -101,6 +101,7 @@ test("status report fields", async (t) => { memoryFlag, addSnippetsFlag, threadsFlag, + "brutal", undefined, undefined, config, diff --git a/src/analyze.ts b/src/analyze.ts index a3508e545..1fcce7f98 100644 --- a/src/analyze.ts +++ b/src/analyze.ts @@ -548,6 +548,7 @@ export async function runQueries( memoryFlag: string, addSnippetsFlag: string, threadsFlag: string, + cleanupLevel: string, diffRangePackDir: string | undefined, automationDetailsId: string | undefined, config: configUtils.Config, @@ -555,20 +556,22 @@ export async function runQueries( features: FeatureEnablement, ): Promise { const statusReport: QueriesStatusReport = {}; + const queryFlags = [memoryFlag, threadsFlag]; + + if (cleanupLevel !== "overlay") { + queryFlags.push("--expect-discarded-cache"); + } statusReport.analysis_is_diff_informed = diffRangePackDir !== undefined; - const dataExtensionFlags = diffRangePackDir - ? [ - `--additional-packs=${diffRangePackDir}`, - "--extension-packs=codeql-action/pr-diff-range", - ] - : []; + if (diffRangePackDir) { + queryFlags.push(`--additional-packs=${diffRangePackDir}`); + queryFlags.push("--extension-packs=codeql-action/pr-diff-range"); + } const sarifRunPropertyFlag = diffRangePackDir ? "--sarif-run-property=incrementalMode=diff-informed" : undefined; const codeql = await getCodeQL(config.codeQLCmd); - const queryFlags = [memoryFlag, threadsFlag, ...dataExtensionFlags]; for (const language of config.languages) { try { diff --git a/src/codeql.test.ts b/src/codeql.test.ts index 04b903aef..3e4212ab0 100644 --- a/src/codeql.test.ts +++ b/src/codeql.test.ts @@ -957,7 +957,7 @@ test("runTool recognizes fatal internal errors", async (t) => { await codeqlObject.databaseRunQueries(stubConfig.dbLocation, []), { instanceOf: CliError, - message: `Encountered a fatal error while running "codeql-for-testing database run-queries --expect-discarded-cache --intra-layer-parallelism --min-disk-free=1024 -v". Exit code was 1 and error was: Oops! A fatal internal error occurred. Details: + message: `Encountered a fatal error while running "codeql-for-testing database run-queries --intra-layer-parallelism --min-disk-free=1024 -v". Exit code was 1 and error was: Oops! A fatal internal error occurred. Details: com.semmle.util.exception.CatastrophicError: An error occurred while evaluating ControlFlowGraph::ControlFlow::Root.isRootOf/1#dispred#f610e6ed/2@86282cc8 Severe disk cache trouble (corruption or out of space) at /home/runner/work/_temp/codeql_databases/go/db-go/default/cache/pages/28/33.pack: Failed to write item to disk. See the logs for more details.`, }, diff --git a/src/codeql.ts b/src/codeql.ts index 2bb155caf..84a4c82d9 100644 --- a/src/codeql.ts +++ b/src/codeql.ts @@ -805,7 +805,6 @@ export async function getCodeQLForCmd( "run-queries", ...flags, databasePath, - "--expect-discarded-cache", "--intra-layer-parallelism", "--min-disk-free=1024", // Try to leave at least 1GB free "-v",