fix(windows): preserve transient runtime admission failures (#2467)
Fixes #2257. Thanks to @chqcjq for the native self-test retry diagnosis in #2266. Preserve retry disposition through analysis workflows. Native warm admission requires exact sharing/lock codes and affirmative pre-allocation evidence; cleanup ownership takes precedence. No automatic retry or new analysis cache. Verified with real Windows 11 CLI, same-connection SDK MCP normal/conflict/recovery, the Windows native verifier, 99 focused tests and static/docs gates. Official npm 11.16.0 launcher sources were the application input. No IDA or Ghidra engine was used for this change. Win32 5 was not reproduced; no resolution claim for #1701/#2196. Performance measurements and limits are recorded in experiments/analysis-efficiency/windows-runtime-retry.md.
This commit is contained in:
@@ -100,18 +100,24 @@ export class AnalysisOutputError extends AnalysisError {
|
||||
export class AnalysisCapabilityUnavailableError extends AnalysisError {
|
||||
readonly _tag = "AnalysisCapabilityUnavailableError";
|
||||
override readonly userMessage: string | undefined;
|
||||
/** Incomplete cleanup must settle before the operation can be retried. */
|
||||
readonly retryable: boolean;
|
||||
|
||||
constructor(
|
||||
readonly providerId: string,
|
||||
readonly operation: string,
|
||||
readonly reason: string,
|
||||
options?: AnalysisErrorOptions & { readonly userMessage?: string },
|
||||
options?: AnalysisErrorOptions & {
|
||||
readonly userMessage?: string;
|
||||
readonly retryable?: boolean;
|
||||
},
|
||||
) {
|
||||
super(
|
||||
`Provider ${providerId} cannot execute ${operation}: ${reason}`,
|
||||
options,
|
||||
);
|
||||
this.userMessage = options?.userMessage;
|
||||
this.retryable = options?.retryable === true && !this.cleanupIncomplete;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
AnalysisAccessDeniedError,
|
||||
AnalysisArtifactChangedError,
|
||||
AnalysisCapabilityUnavailableError,
|
||||
AnalysisInputError,
|
||||
AnalysisUnsupportedTargetError,
|
||||
AnalysisResourceConstraintError,
|
||||
@@ -33,6 +34,8 @@ import type { AnalysisErrorProjection } from "./analysisErrorProjection.js";
|
||||
export const analysisErrorRemediationAction = (
|
||||
error: AnalysisError,
|
||||
): string => {
|
||||
if (error instanceof AnalysisCapabilityUnavailableError && error.retryable)
|
||||
return "Review details.reason, then retry the same analysis after the condition clears.";
|
||||
if (error instanceof EvidenceFileError && error.published !== undefined)
|
||||
return "Use the published file at details.published_path and resolve the reported staging cleanup failure.";
|
||||
if (error instanceof AnalysisSnapshotMismatchError)
|
||||
@@ -112,6 +115,8 @@ export const analysisErrorRemediationAction = (
|
||||
export const analysisErrorCategory = (
|
||||
error: AnalysisError,
|
||||
): AnalysisErrorProjection["category"] => {
|
||||
if (error instanceof AnalysisCapabilityUnavailableError && error.retryable)
|
||||
return "unavailable";
|
||||
if (
|
||||
error instanceof BinaryTargetError &&
|
||||
error.constraint === "load_selection_rejected"
|
||||
@@ -220,6 +225,8 @@ export const analysisErrorUserMessage = (error: AnalysisError): string => {
|
||||
const hopperMessage = hopperErrorUserMessage(error);
|
||||
if (hopperMessage !== undefined) return hopperMessage;
|
||||
if (error.userMessage !== undefined) return error.userMessage;
|
||||
if (error instanceof AnalysisCapabilityUnavailableError && error.retryable)
|
||||
return "Required runtime controls are unavailable for this attempt.";
|
||||
const standardMessage = standardErrorMessage(error._tag);
|
||||
if (standardMessage !== undefined) return standardMessage;
|
||||
if (error instanceof ArtifactOperationError) return artifactMessage(error);
|
||||
|
||||
@@ -25,6 +25,91 @@ import { ProviderSelectionError } from "./providerSelectionError.js";
|
||||
import { analysisErrorProjectionSchema } from "../contracts/errorSchemas.js";
|
||||
import { nativeCallPartialObservationSchema } from "./native/nativeCallPartialObservation.js";
|
||||
|
||||
describe("capability failure retry disposition", () => {
|
||||
it.each([
|
||||
{ options: {}, retryable: false, category: "unsupported_provider" },
|
||||
{
|
||||
options: { retryable: false },
|
||||
retryable: false,
|
||||
category: "unsupported_provider",
|
||||
},
|
||||
{ options: { retryable: true }, retryable: true, category: "unavailable" },
|
||||
] as const)(
|
||||
"preserves the producer's $retryable disposition",
|
||||
({ options, retryable, category }) => {
|
||||
const reason = "Native self-test failed with a sharing violation";
|
||||
const projected = projectAnalysisError(
|
||||
new AnalysisCapabilityUnavailableError(
|
||||
"fixture-provider",
|
||||
"inspect",
|
||||
reason,
|
||||
options,
|
||||
),
|
||||
);
|
||||
expect(projected).toMatchObject({
|
||||
code: "capability_unavailable",
|
||||
category,
|
||||
retryable,
|
||||
details: { reason },
|
||||
});
|
||||
if (retryable) {
|
||||
expect(projected.message).toBe(
|
||||
"Required runtime controls are unavailable for this attempt.",
|
||||
);
|
||||
expect(projected.remediation.action).toContain(
|
||||
"retry the same analysis",
|
||||
);
|
||||
}
|
||||
expect(analysisErrorProjectionSchema.safeParse(projected).success).toBe(
|
||||
true,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it("preserves a caller-selected message for a retryable failure", () => {
|
||||
expect(
|
||||
projectAnalysisError(
|
||||
new AnalysisCapabilityUnavailableError(
|
||||
"fixture-provider",
|
||||
"inspect",
|
||||
"temporary failure",
|
||||
{
|
||||
retryable: true,
|
||||
userMessage: "Selected runtime diagnostic",
|
||||
},
|
||||
),
|
||||
).message,
|
||||
).toBe("Selected runtime diagnostic");
|
||||
});
|
||||
|
||||
it("retains cleanup ownership before allowing a transient operation to retry", () => {
|
||||
expect(
|
||||
projectAnalysisError(
|
||||
new AnalysisCapabilityUnavailableError(
|
||||
"fixture-provider",
|
||||
"inspect",
|
||||
"temporary failure",
|
||||
{
|
||||
retryable: true,
|
||||
cleanup: {
|
||||
reason: "owned handle is still live",
|
||||
resources: ["native-owner"],
|
||||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
).toMatchObject({
|
||||
code: "cleanup_incomplete",
|
||||
retryable: false,
|
||||
details: {
|
||||
cleanup: "incomplete",
|
||||
resources: ["native-owner"],
|
||||
execution_failure: "capability_unavailable",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("projects a published file receipt alongside retained cleanup failure", () => {
|
||||
const projected = projectAnalysisError(
|
||||
new EvidenceFileError("write", "io", {
|
||||
|
||||
@@ -83,6 +83,8 @@ export const projectAnalysisError = (
|
||||
message: analysisErrorUserMessage(error),
|
||||
retryable:
|
||||
RETRYABLE_CODES.has(code) ||
|
||||
(error instanceof AnalysisCapabilityUnavailableError &&
|
||||
error.retryable) ||
|
||||
(code === "resource_constraint" &&
|
||||
error instanceof AnalysisResourceConstraintError &&
|
||||
error.resource === "capacity"),
|
||||
|
||||
@@ -27,10 +27,8 @@ import { ProviderAdapterError } from "../../domain/providerAdapterError.js";
|
||||
import { ProviderCleanupError } from "../../domain/providerCleanupError.js";
|
||||
import { ok, err, type Result } from "../../domain/result.js";
|
||||
import { javaScriptRuntime } from "../../domain/runtimeVersion.js";
|
||||
import {
|
||||
PrivateRuntimeRoot,
|
||||
PrivateRuntimeRootUnavailableError,
|
||||
} from "../../process/PrivateRuntimeRoot.js";
|
||||
import { PrivateRuntimeRoot } from "../../process/PrivateRuntimeRoot.js";
|
||||
import { PrivateRuntimeRootUnavailableError } from "../../process/PrivateRuntimeRootUnavailableError.js";
|
||||
import { javaScriptWorkerMemoryLimitBytes } from "../../process/JavaScriptWorkerMemoryLimit.js";
|
||||
import {
|
||||
ProviderProcessSupervisor,
|
||||
@@ -735,7 +733,7 @@ export class JavaScriptAnalysisWorker {
|
||||
PROVIDER,
|
||||
OPERATION,
|
||||
cause.message,
|
||||
{ cause },
|
||||
{ cause, retryable: cause.retryable },
|
||||
)
|
||||
: new ProviderAdapterError(PROVIDER, OPERATION, {
|
||||
cause,
|
||||
|
||||
@@ -16,10 +16,8 @@ import { ProviderCleanupError } from "../../domain/providerCleanupError.js";
|
||||
import type { JsonValue } from "../../domain/jsonValue.js";
|
||||
import { err, ok, type Result } from "../../domain/result.js";
|
||||
import { WEB_SOURCE_MAP_LIMITS } from "../../domain/webSourceLocation.js";
|
||||
import {
|
||||
PrivateRuntimeRoot,
|
||||
PrivateRuntimeRootUnavailableError,
|
||||
} from "../../process/PrivateRuntimeRoot.js";
|
||||
import { PrivateRuntimeRoot } from "../../process/PrivateRuntimeRoot.js";
|
||||
import { PrivateRuntimeRootUnavailableError } from "../../process/PrivateRuntimeRootUnavailableError.js";
|
||||
import { ProviderStartupDeadline } from "../../process/ProviderDeadline.js";
|
||||
import { javaScriptWorkerMemoryLimitBytes } from "../../process/JavaScriptWorkerMemoryLimit.js";
|
||||
import { cleanupOwnedProcessGroup } from "../../process/ProcessOwnership.js";
|
||||
@@ -261,7 +259,7 @@ class OwnedCodec implements SourceMapCleanupOwner {
|
||||
PROVIDER,
|
||||
OPERATION,
|
||||
cause.message,
|
||||
{ cause },
|
||||
{ cause, retryable: cause.retryable },
|
||||
)
|
||||
: new ProviderAdapterError(PROVIDER, OPERATION, {
|
||||
cause,
|
||||
|
||||
@@ -3,6 +3,7 @@ import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { WindowsPrivateRuntime } from "../windows/WindowsPrivateRuntime.js";
|
||||
import { PrivateRuntimeRootUnavailableError } from "./PrivateRuntimeRootUnavailableError.js";
|
||||
|
||||
import {
|
||||
windowsNativeCapabilities,
|
||||
@@ -34,16 +35,6 @@ export const privateRuntimeRootCapability = (
|
||||
? windowsNativeCapabilities(platform).private_runtime_dacl
|
||||
: { available: true, reason: null, proof: "posix-mkdtemp-owner-only" };
|
||||
|
||||
/** Expected failure when a runtime root's privacy boundary is unavailable. */
|
||||
export class PrivateRuntimeRootUnavailableError extends Error {
|
||||
readonly code = "private-runtime-root-authority-unavailable";
|
||||
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = "PrivateRuntimeRootUnavailableError";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Owns a private temporary runtime root and removes it idempotently.
|
||||
*
|
||||
@@ -66,7 +57,9 @@ export class PrivateRuntimeRoot {
|
||||
const platform = options.platform ?? process.platform;
|
||||
const capability = privateRuntimeRootCapability(platform);
|
||||
if (!capability.available)
|
||||
throw new PrivateRuntimeRootUnavailableError(capability.reason);
|
||||
throw new PrivateRuntimeRootUnavailableError(capability.reason, {
|
||||
retryable: capability.retryable === true,
|
||||
});
|
||||
if (platform === "win32") {
|
||||
const runtime = WindowsPrivateRuntime.create(
|
||||
options.parent ?? tmpdir(),
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
/** Expected failure when a runtime root's privacy boundary is unavailable. */
|
||||
export class PrivateRuntimeRootUnavailableError extends Error {
|
||||
readonly code = "private-runtime-root-authority-unavailable";
|
||||
readonly retryable: boolean;
|
||||
|
||||
constructor(
|
||||
message: string,
|
||||
options?: ErrorOptions & { readonly retryable?: boolean },
|
||||
) {
|
||||
super(message, options);
|
||||
this.name = "PrivateRuntimeRootUnavailableError";
|
||||
this.retryable = options?.retryable ?? false;
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ export type WindowsNativeCapability =
|
||||
readonly available: false;
|
||||
readonly reason: string;
|
||||
readonly proof: "not-proven" | "not-applicable";
|
||||
readonly retryable?: true;
|
||||
};
|
||||
|
||||
/** Security controls required before REA may claim Windows isolation. */
|
||||
@@ -52,6 +53,7 @@ export const windowsNativeCapabilities = (
|
||||
available: false,
|
||||
reason: loaded.reason,
|
||||
proof: "not-proven",
|
||||
...(loaded.retryable === true ? { retryable: true as const } : {}),
|
||||
} as const);
|
||||
return {
|
||||
job_object_process_ownership: capability,
|
||||
|
||||
@@ -3,12 +3,11 @@ import { join } from "node:path";
|
||||
import { expect, it } from "vitest";
|
||||
import { createTestTempDirectory } from "../../tests/fixtures/temporaryDirectory.js";
|
||||
import { WabtArtifactProvider } from "./WabtArtifactProvider.js";
|
||||
import {
|
||||
PrivateRuntimeRoot,
|
||||
PrivateRuntimeRootUnavailableError,
|
||||
} from "../process/PrivateRuntimeRoot.js";
|
||||
import { PrivateRuntimeRoot } from "../process/PrivateRuntimeRoot.js";
|
||||
import { PrivateRuntimeRootUnavailableError } from "../process/PrivateRuntimeRootUnavailableError.js";
|
||||
import { spawnOwnedProviderProcess } from "../process/ProviderProcess.js";
|
||||
import { OwnedCommandFailure } from "../process/OwnedCommand.js";
|
||||
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
||||
|
||||
const failureTags: Readonly<Record<string, string>> = {
|
||||
invalid: "AnalysisInputError",
|
||||
@@ -40,40 +39,51 @@ it("returns actionable unavailable without creating a workspace when tools are a
|
||||
});
|
||||
});
|
||||
|
||||
it("reports an unavailable private runtime root without a misleading WABT remediation", async () => {
|
||||
const toolRoot = await createTestTempDirectory("rea-wabt-tool-root-");
|
||||
for (const tool of ["wasm-validate", "wasm-objdump", "wasm2wat"])
|
||||
await writeFile(
|
||||
join(toolRoot, tool + (process.platform === "win32" ? ".exe" : "")),
|
||||
"source-owned executable seam",
|
||||
{ mode: 0o700 },
|
||||
);
|
||||
const provider = new WabtArtifactProvider(
|
||||
{ REA_WABT_BIN_DIRECTORY: toolRoot },
|
||||
undefined,
|
||||
() => {
|
||||
throw new PrivateRuntimeRootUnavailableError(
|
||||
"REA Windows native controls are unavailable: probe failure",
|
||||
it.each([false, true])(
|
||||
"reports an unavailable private runtime root with retryable=%s without a misleading WABT remediation",
|
||||
async (retryable) => {
|
||||
const toolRoot = await createTestTempDirectory("rea-wabt-tool-root-");
|
||||
for (const tool of ["wasm-validate", "wasm-objdump", "wasm2wat"])
|
||||
await writeFile(
|
||||
join(toolRoot, tool + (process.platform === "win32" ? ".exe" : "")),
|
||||
"source-owned executable seam",
|
||||
{ mode: 0o700 },
|
||||
);
|
||||
},
|
||||
);
|
||||
expect(
|
||||
await provider.inspect({
|
||||
const provider = new WabtArtifactProvider(
|
||||
{ REA_WABT_BIN_DIRECTORY: toolRoot },
|
||||
undefined,
|
||||
() => {
|
||||
throw new PrivateRuntimeRootUnavailableError(
|
||||
"REA Windows native controls are unavailable: probe failure",
|
||||
{ retryable },
|
||||
);
|
||||
},
|
||||
);
|
||||
const result = await provider.inspect({
|
||||
path: "/module.wasm",
|
||||
glue_paths: [],
|
||||
candidate_paths: [],
|
||||
}),
|
||||
).toMatchObject({
|
||||
ok: false,
|
||||
error: {
|
||||
_tag: "AnalysisCapabilityUnavailableError",
|
||||
userMessage: undefined,
|
||||
message: expect.stringContaining(
|
||||
"REA Windows native controls are unavailable",
|
||||
),
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
error: {
|
||||
_tag: "AnalysisCapabilityUnavailableError",
|
||||
retryable,
|
||||
userMessage: undefined,
|
||||
message: expect.stringContaining(
|
||||
"REA Windows native controls are unavailable",
|
||||
),
|
||||
},
|
||||
});
|
||||
if (result.ok)
|
||||
throw new Error("Unavailable runtime must refuse inspection");
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
code: "capability_unavailable",
|
||||
retryable,
|
||||
category: retryable ? "unavailable" : "unsupported_provider",
|
||||
});
|
||||
},
|
||||
);
|
||||
it.each([
|
||||
"success",
|
||||
"invalid",
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
} from "../domain/analysisErrorCore.js";
|
||||
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
|
||||
import { OwnedCommandFailure } from "../process/OwnedCommand.js";
|
||||
import { PrivateRuntimeRootUnavailableError } from "../process/PrivateRuntimeRoot.js";
|
||||
import { PrivateRuntimeRootUnavailableError } from "../process/PrivateRuntimeRootUnavailableError.js";
|
||||
import { WABT_LIMITS, WABT_PROVIDER_IDENTITY } from "./WabtRelease.js";
|
||||
/** Preserve lifecycle failures and diagnostic bytes instead of returning partial success. */
|
||||
export const wabtFailure = (
|
||||
@@ -76,7 +76,7 @@ export const wabtFailure = (
|
||||
WABT_PROVIDER_IDENTITY.id,
|
||||
"inspect_wasm_artifact",
|
||||
reason,
|
||||
{ cause },
|
||||
{ cause, retryable: cause.retryable },
|
||||
);
|
||||
if (phase === "configuration")
|
||||
return new AnalysisCapabilityUnavailableError(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { win32 } from "node:path";
|
||||
|
||||
import { z } from "zod";
|
||||
import { PrivateRuntimeRootUnavailableError } from "../process/PrivateRuntimeRootUnavailableError.js";
|
||||
|
||||
import {
|
||||
requireWindowsNativeAuthority,
|
||||
@@ -23,6 +24,13 @@ const fileSchema = windowsFileIdentitySchema.extend({
|
||||
handle: windowsHandleSchema,
|
||||
});
|
||||
const runtimes = new Map<string, WindowsPrivateRuntime>();
|
||||
// Retry only a proven pre-allocation sharing/lock conflict, never opaque text
|
||||
// or an operation that may already own an unpublished runtime directory.
|
||||
const transientRuntimeAdmissionSchema = z.object({
|
||||
code: z.literal("ERR_REA_WINDOWS_NATIVE"),
|
||||
win32Code: z.union([z.literal(32), z.literal(33)]),
|
||||
runtimeAllocation: z.literal("not-started"),
|
||||
});
|
||||
|
||||
/** Retain private DACL and path handles until native recursive cleanup settles. */
|
||||
export class WindowsPrivateRuntime {
|
||||
@@ -40,9 +48,21 @@ export class WindowsPrivateRuntime {
|
||||
/** Create a new directory with its private DACL installed at creation. */
|
||||
static create(parent: string, prefix: string): WindowsPrivateRuntime {
|
||||
const authority = requireWindowsNativeAuthority();
|
||||
const observation = runtimeSchema.parse(
|
||||
authority.call("runtime_create", [parent, prefix]),
|
||||
);
|
||||
let observed: unknown;
|
||||
try {
|
||||
observed = authority.call("runtime_create", [parent, prefix]);
|
||||
} catch (cause: unknown) {
|
||||
if (
|
||||
cause instanceof Error &&
|
||||
transientRuntimeAdmissionSchema.safeParse(cause).success
|
||||
)
|
||||
throw new PrivateRuntimeRootUnavailableError(cause.message, {
|
||||
cause,
|
||||
retryable: true,
|
||||
});
|
||||
throw cause;
|
||||
}
|
||||
const observation = runtimeSchema.parse(observed);
|
||||
const runtime = new WindowsPrivateRuntime(observation, authority);
|
||||
runtimes.set(windowsRuntimeIdentityKey(observation), runtime);
|
||||
return runtime;
|
||||
|
||||
Reference in New Issue
Block a user