fix(native): report an ownership-helper compile timeout as retryable

When the macOS process-ownership helper's swiftc compile hit
REA_SWIFTC_COMPILE_TIMEOUT_MS, inspect-macho and other native commands
reported a non-retryable provider failure, while process capture
already treated the same fact as retryable. The helper's error now owns
that interpretation (compilerTimedOut and compileTimeout, with its
deadline, message and recovery). Native commands return a retryable
AnalysisTimeoutError naming REA_SWIFTC_COMPILE_TIMEOUT_MS, and process
capture reads the same fact.

Fixes #8936
Supersedes #8938

Based on #8938; the interpretation moves to the error's owner so both
consumers share it.

Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
This commit is contained in:
ducanhnguyen223andgensokyo-dev authored and Ysopwnable committed 2026-11-14 15:32:34 +01:00
1 parent f8fc5be364
commit ba32cd3c28
5 files changed
+248 -4

No files matched your search

@@ -0,0 +1,159 @@
import { describe, expect, it } from "vitest";
import { ArtifactResourceScope } from "../artifacts/ArtifactResourceScope.js";
import { AnalysisTimeoutError } from "../domain/analysisErrorCore.js";
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
import {
DarwinProcessOwnershipInspectionError,
type DarwinCompilerOutcome,
} from "../process/DarwinProcessRunTokenReader.js";
import { NativeCommandFailure } from "./CommandRunner.js";
import { translateNativeCommandFailure } from "./NativeCommandAnalysisError.js";
const preparationFailure = (
compilerOutcome: DarwinCompilerOutcome,
cancellation?: { readonly reason: unknown },
) =>
new NativeCommandFailure(
"lipo",
cancellation === undefined ? "io" : "cancelled",
null,
{
cause: new DarwinProcessOwnershipInspectionError(
"ownership-helper compilation failed",
{
compilerOutcome,
...(cancellation === undefined ? {} : { cancellation }),
},
),
},
);
const compilerTimeout = (timeoutMs?: number): DarwinCompilerOutcome => ({
outcome: "timed_out",
code: "ETIMEDOUT",
signal: "SIGINT",
stderr: "",
stderrTruncated: false,
outputTruncated: false,
killed: true,
...(timeoutMs === undefined ? {} : { timeoutMs }),
});
describe("translateNativeCommandFailure", () => {
it("projects an ownership-helper compiler deadline as a retryable provider timeout", () => {
const error = translateNativeCommandFailure(
"inspect_macho",
preparationFailure(compilerTimeout(1)),
new ArtifactResourceScope(),
60_000,
{
timeoutRecovery: {
userMessage: "native command deadline",
remediationAction: "native_command_timeout_ms",
},
},
);
expect(error).toBeInstanceOf(AnalysisTimeoutError);
if (!(error instanceof AnalysisTimeoutError)) return;
expect(error.timeoutMs).toBe(1);
expect(error.userMessage).toContain("ownership helper compiler");
const projected = projectAnalysisError(error);
expect(projected).toMatchObject({
code: "provider_timeout",
category: "timeout",
retryable: true,
});
expect(projected.message).toContain("1 ms");
expect(projected.remediation.action).toContain(
"REA_SWIFTC_COMPILE_TIMEOUT_MS",
);
expect(projected.remediation.action).not.toContain(
"native_command_timeout_ms",
);
});
it("does not infer a compiler timeout duration when it was not reported", () => {
const error = translateNativeCommandFailure(
"inspect_macho",
preparationFailure(compilerTimeout()),
new ArtifactResourceScope(),
);
expect(error).toBeInstanceOf(ProviderAdapterError);
expect(error).not.toBeInstanceOf(AnalysisTimeoutError);
expect(projectAnalysisError(error)).toMatchObject({
code: "execution_failure",
category: "execution_failure",
retryable: false,
});
});
it("keeps the command deadline primary when the compiler also timed out", () => {
const preparation = new DarwinProcessOwnershipInspectionError(
"ownership-helper compilation timed out",
{ compilerOutcome: compilerTimeout(1) },
);
const error = translateNativeCommandFailure(
"inspect_macho",
new NativeCommandFailure("lipo", "timeout", null, {
cause: preparation,
}),
new ArtifactResourceScope(),
60_000,
{
timeoutRecovery: {
userMessage: "native command deadline",
remediationAction: "native_command_timeout_ms",
},
},
);
expect(error).toBeInstanceOf(AnalysisTimeoutError);
if (!(error instanceof AnalysisTimeoutError)) return;
expect(error.timeoutMs).toBe(60_000);
const projected = projectAnalysisError(error);
expect(projected.remediation.action).toContain("native_command_timeout_ms");
expect(projected.remediation.action).not.toContain(
"REA_SWIFTC_COMPILE_TIMEOUT_MS",
);
});
it("keeps compiler exit failures distinct from deadlines", () => {
const error = translateNativeCommandFailure(
"inspect_macho",
preparationFailure({
outcome: "exited",
code: 1,
signal: null,
stderr: "compiler failed",
stderrTruncated: false,
outputTruncated: false,
killed: false,
}),
new ArtifactResourceScope(),
);
expect(error).toBeInstanceOf(ProviderAdapterError);
expect(projectAnalysisError(error)).toMatchObject({
code: "execution_failure",
category: "execution_failure",
retryable: false,
});
});
it("keeps caller cancellation ahead of a compiler timeout", () => {
const cancellation = new Error("caller stopped");
const error = translateNativeCommandFailure(
"inspect_macho",
preparationFailure(compilerTimeout(1), { reason: cancellation }),
new ArtifactResourceScope(),
);
expect(error).not.toBeInstanceOf(AnalysisTimeoutError);
expect(error).toMatchObject({ _tag: "AnalysisCancelledError" });
});
});