perf(javascript): keep the worker reusable after a final discovery refusal

The worker's reuse state cleared its last failure only on success, so a
member-mutation refusal of the last discovered source still closed the
worker and discarded every retained static checkpoint. The worker now
owns the recoverable-refusal rule, and the scope uses the same predicate.

Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
This commit is contained in:
gensokyo-dev
2026-11-23 23:40:19 +08:00
committed by Ysopwnable
co-authored by gensokyo-dev
parent ef59a1f0a3
commit c2779ae514
3 changed files with 48 additions and 37 deletions
@@ -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<JavaScriptSourceAnalysisPort["analyze"]> {
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;