mirror of
https://github.com/morluto/rea.git
synced 2026-12-01 02:49:12 +00:00
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:
1 parent
ef59a1f0a3
commit
c2779ae514
3 files changed
+48
-37
No files matched your search
@@ -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<JavaScriptAnalyzedSource, JavaScriptSourceAnalysisFailure>,
|
||||
): 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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user