diff --git a/src/javascript/analysis/JavaScriptAnalysisWorker.ts b/src/javascript/analysis/JavaScriptAnalysisWorker.ts index 5fb034577a6..d8bcb8522e7 100644 --- a/src/javascript/analysis/JavaScriptAnalysisWorker.ts +++ b/src/javascript/analysis/JavaScriptAnalysisWorker.ts @@ -5,6 +5,7 @@ import { import { DEFAULT_JAVASCRIPT_MEMBER_MUTATION_ALLOWANCE, javaScriptMemberMutationAllowanceField, + isJavaScriptMemberMutationRefusal, javaScriptMemberMutationRefusal, reportsJavaScriptMemberMutationRefusal, } from "../../domain/javascript/javascriptSemanticWorkAllowance.js"; @@ -140,6 +141,20 @@ type WorkerPrimaryFailure = }; /** One sequential owned worker, retained between source files and closed after analysis. */ +/** + * Preload discovery skips a source whose member-mutation allowance the worker + * refused and reported; the normal pass recomputes and reports it. That + * refusal leaves the process healthy, so it does not block reuse and the + * static checkpoints discovery retained survive. + */ +export const isRecoverableJavaScriptWorkerFailure = ( + purpose: "analysis" | "preload-discovery", + result: Result, +): boolean => + purpose === "preload-discovery" && + !result.ok && + isJavaScriptMemberMutationRefusal(result.error.error); + export class JavaScriptAnalysisWorker { readonly #runId = `rea-javascript-analysis-${randomUUID()}`; readonly #runtime: OwnedWorkerRuntime; @@ -623,7 +638,8 @@ export class JavaScriptAnalysisWorker { if (this.#deadline === deadline) this.#deadline = undefined; if (this.#activeJobId === id) this.#activeJobId = undefined; } - if (result.ok) this.#lastFailure = undefined; + if (result.ok || isRecoverableJavaScriptWorkerFailure(purpose, result)) + this.#lastFailure = undefined; else if (!(result.error.error instanceof ProviderCleanupError)) this.#lastFailure = result.error.error; // Child stop must be verified before temporary files are released. On diff --git a/src/javascript/analysis/JavaScriptSourceAnalysis.ts b/src/javascript/analysis/JavaScriptSourceAnalysis.ts index a2eb38647a4..83a4e5740a4 100644 --- a/src/javascript/analysis/JavaScriptSourceAnalysis.ts +++ b/src/javascript/analysis/JavaScriptSourceAnalysis.ts @@ -1,13 +1,13 @@ -import { - DEFAULT_JAVASCRIPT_MEMBER_MUTATION_ALLOWANCE, - isJavaScriptMemberMutationRefusal, -} from "../../domain/javascript/javascriptSemanticWorkAllowance.js"; +import { DEFAULT_JAVASCRIPT_MEMBER_MUTATION_ALLOWANCE } from "../../domain/javascript/javascriptSemanticWorkAllowance.js"; import { resolveJavaScriptSemanticPrecision } from "../../domain/javascript/javascriptSemanticPrecision.js"; import type { JavaScriptSourceAnalysisLimits, JavaScriptSourceAnalysisPort, } from "../../domain/javascript/javascriptSourceAnalysis.js"; -import { JavaScriptAnalysisWorker } from "./JavaScriptAnalysisWorker.js"; +import { + isRecoverableJavaScriptWorkerFailure, + JavaScriptAnalysisWorker, +} from "./JavaScriptAnalysisWorker.js"; import type { spawnOwnedProviderProcess } from "../../process/ProviderProcess.js"; import { WorkerCleanupRegistry } from "../../process/OwnedWorkerRuntime.js"; import { ArtifactResourceScope } from "../../resources/index.js"; @@ -184,17 +184,10 @@ class ScopeJavaScriptSourceAnalysis implements JavaScriptSourceAnalysisPort { ): ReturnType { const purpose = args[5]; return this.worker.analyze(...args).then((result) => { - // Preload discovery skips a source whose member-mutation allowance the - // worker refused and reported; the normal pass recomputes and reports - // it. That refusal leaves the process healthy, so the worker can still - // park and keep the static checkpoints discovery retained. canReuse - // still checks the process before parking. + // canReuse still checks the process before parking. if ( !result.ok && - !( - purpose === "preload-discovery" && - isJavaScriptMemberMutationRefusal(result.error.error) - ) + !isRecoverableJavaScriptWorkerFailure(purpose ?? "analysis", result) ) this.#failed = true; return result; diff --git a/tests/boundary/javascript/javascriptSourceAnalysisWorker.test.ts b/tests/boundary/javascript/javascriptSourceAnalysisWorker.test.ts index ab2640e79c5..79117bfca73 100644 --- a/tests/boundary/javascript/javascriptSourceAnalysisWorker.test.ts +++ b/tests/boundary/javascript/javascriptSourceAnalysisWorker.test.ts @@ -1005,11 +1005,13 @@ it("keeps wrapped route ancestry, navigation and unknown named parents in the re }); it.each([ - ["preload-discovery", 1], - ["analysis", 2], + ["preload-discovery", "before", 1], + ["preload-discovery", "after", 1], + ["analysis", "before", 2], + ["analysis", "after", 2], ] as const)( - "after a %s member-mutation refusal, the next checkout uses %i launch(es)", - async (purpose, expectedLaunches) => { + "after a %s member-mutation refusal %s an accepted source, the next checkout uses %i launch(es)", + async (purpose, order, expectedLaunches) => { const scope = new ArtifactResourceScope(); const launches: number[] = []; const launcher: typeof spawnOwnedProviderProcess = async (request) => { @@ -1043,24 +1045,24 @@ it.each([ }); try { const capacity = { nodes: 0, unknowns: 0 }; - const refusal = await first.analyze( - refused, - capacity, - undefined, - undefined, - "commonjs", - purpose, - ); - expect(refusal.ok).toBe(false); - const success = await first.analyze( - accepted, - capacity, - undefined, - undefined, - "commonjs", - purpose, - ); - if (!success.ok) throw success.error.error; + const analyze = (file: typeof accepted) => + first.analyze( + file, + capacity, + undefined, + undefined, + "commonjs", + purpose, + ); + // A refusal of the last discovered source must not discard the + // healthy worker either. + for (const file of order === "before" + ? [refused, accepted] + : [accepted, refused]) { + const result = await analyze(file); + if (file === accepted && !result.ok) throw result.error.error; + if (file === refused) expect(result.ok).toBe(false); + } } finally { await first.close(); }