fix(capture): retain Electron observations and HAR resource failures
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
AnalysisCapabilityUnavailableError,
|
||||
AnalysisInputError,
|
||||
AnalysisOutputError,
|
||||
AnalysisResourceConstraintError,
|
||||
AnalysisTimeoutError,
|
||||
} from "../../domain/analysisErrorCore.js";
|
||||
import { ProviderAdapterError } from "../../domain/providerAdapterError.js";
|
||||
@@ -17,6 +18,7 @@ import {
|
||||
type InspectWebNetworkCaptureInput,
|
||||
} from "../../domain/webNetworkCapture.js";
|
||||
import { OwnedCommandFailure } from "../../process/OwnedCommand.js";
|
||||
import { HAR_CAPTURE_HEAP_LIMITS } from "./CaptureRelease.js";
|
||||
const OPERATION = "inspect_web_network_capture";
|
||||
|
||||
/** Preserve the origin and typed cause of a historical capture failure. */
|
||||
@@ -55,6 +57,18 @@ export const historicalCaptureFailure = (
|
||||
);
|
||||
if (cause.reason === "output-limit")
|
||||
return new AnalysisOutputError(OPERATION, cause.message);
|
||||
if (
|
||||
phase === "decoder" &&
|
||||
input.format === "har" &&
|
||||
cause.reason === "process" &&
|
||||
cause.snapshot?.signal === "SIGABRT" &&
|
||||
/FATAL ERROR:[^\r\n]*heap out of memory/u.test(cause.snapshot.stderr.text)
|
||||
)
|
||||
return captureMemoryFailure(
|
||||
input,
|
||||
"The HAR decoder exhausted its fixed V8 heap",
|
||||
cause,
|
||||
);
|
||||
}
|
||||
if (options?.signal?.aborted) return new AnalysisCancelledError(OPERATION);
|
||||
if (
|
||||
@@ -144,3 +158,44 @@ export const historicalCaptureFailure = (
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
/** Preserve a decoder's observed memory failure and its actual workload limits. */
|
||||
export const captureMemoryFailure = (
|
||||
input: InspectWebNetworkCaptureInput,
|
||||
reason: string,
|
||||
cause?: unknown,
|
||||
): AnalysisResourceConstraintError =>
|
||||
new AnalysisResourceConstraintError(
|
||||
OPERATION,
|
||||
"memory",
|
||||
`${reason}: ${input.capture_path}. No complete capture result is available.`,
|
||||
{
|
||||
boundary: "historical-capture-decoder",
|
||||
capture_path: input.capture_path,
|
||||
format: input.format,
|
||||
maximum_input_bytes: WEB_NETWORK_CAPTURE_LIMITS.inputBytes,
|
||||
maximum_reply_bytes: WEB_NETWORK_CAPTURE_LIMITS.outputBytes,
|
||||
...(input.format === "har"
|
||||
? {
|
||||
old_generation_heap_mib: HAR_CAPTURE_HEAP_LIMITS.oldGenerationMiB,
|
||||
semi_space_heap_mib: HAR_CAPTURE_HEAP_LIMITS.semiSpaceMiB,
|
||||
}
|
||||
: {}),
|
||||
...(cause instanceof OwnedCommandFailure
|
||||
? { observed_signal: cause.snapshot?.signal ?? null }
|
||||
: {}),
|
||||
},
|
||||
{
|
||||
cause,
|
||||
remediationAction: `Use a smaller capture exported by its producer, or another decoder with sufficient capacity for the original capture. Preserve the original for provenance; a subset does not establish complete-capture coverage.${input.format === "har" ? ` REA's HAR old-generation heap is fixed at ${HAR_CAPTURE_HEAP_LIMITS.oldGenerationMiB} MiB; inherited NODE_OPTIONS cannot raise it.` : ""}`,
|
||||
...(cause instanceof OwnedCommandFailure && cause.snapshot !== null
|
||||
? {
|
||||
capturedOutput: {
|
||||
stdout: cause.snapshot.stdout.text,
|
||||
stderr: cause.snapshot.stderr.text,
|
||||
truncated: cause.snapshot.diagnosticTruncated ?? false,
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
);
|
||||
|
||||
@@ -5,6 +5,12 @@ export const HAR_CAPTURE_PROVIDER_IDENTITY = {
|
||||
version: "har-schema@2.0.0;jsonc-parser@3.3.1;lossless-json@4.3.1",
|
||||
} as const;
|
||||
|
||||
/** Fixed V8 heap settings used by the owned HAR decoder process. */
|
||||
export const HAR_CAPTURE_HEAP_LIMITS = {
|
||||
oldGenerationMiB: 192,
|
||||
semiSpaceMiB: 8,
|
||||
} as const;
|
||||
|
||||
/** Native executable profile verified with unchanged mitmproxy raw-state decoding. */
|
||||
export const MITMPROXY_CAPTURE_PROVIDER_IDENTITY = {
|
||||
id: "mitmproxy-native-tnetstring",
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { fileURLToPath } from "node:url";
|
||||
import type { HistoricalCaptureFormatAdapter } from "./HistoricalCaptureFormatAdapter.js";
|
||||
import { HAR_CAPTURE_PROVIDER_IDENTITY } from "./CaptureRelease.js";
|
||||
import {
|
||||
HAR_CAPTURE_PROVIDER_IDENTITY,
|
||||
HAR_CAPTURE_HEAP_LIMITS,
|
||||
} from "./CaptureRelease.js";
|
||||
|
||||
/** HAR's parser/schema packages run in one bounded Node heap, without network or target execution. */
|
||||
export class HarCaptureAdapter implements HistoricalCaptureFormatAdapter {
|
||||
@@ -12,8 +15,8 @@ export class HarCaptureAdapter implements HistoricalCaptureFormatAdapter {
|
||||
return {
|
||||
command: process.execPath,
|
||||
arguments: [
|
||||
"--max-old-space-size=192",
|
||||
"--max-semi-space-size=8",
|
||||
`--max-old-space-size=${HAR_CAPTURE_HEAP_LIMITS.oldGenerationMiB}`,
|
||||
`--max-semi-space-size=${HAR_CAPTURE_HEAP_LIMITS.semiSpaceMiB}`,
|
||||
"--v8-pool-size=1",
|
||||
"--single-threaded",
|
||||
fileURLToPath(new URL("./HarCaptureProcess.js", import.meta.url)),
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { historicalCaptureFailure } from "./CaptureFailures.js";
|
||||
import {
|
||||
historicalCaptureFailure,
|
||||
captureMemoryFailure,
|
||||
} from "./CaptureFailures.js";
|
||||
import { projectAnalysisError } from "../../domain/analysisErrorProjection.js";
|
||||
import type { HistoricalCaptureFormatAdapter } from "./HistoricalCaptureFormatAdapter.js";
|
||||
import { randomUUID } from "node:crypto";
|
||||
@@ -160,7 +163,9 @@ export class HistoricalCaptureDecoder {
|
||||
},
|
||||
},
|
||||
]);
|
||||
if (reply.reason === "decoder" || reply.reason === "resource-limit")
|
||||
if (reply.reason === "resource-limit")
|
||||
throw captureMemoryFailure(input, reply.message);
|
||||
if (reply.reason === "decoder")
|
||||
throw new ProviderAdapterError(input.format, OPERATION, {
|
||||
diagnostics: {
|
||||
phase: "decoder",
|
||||
|
||||
Reference in New Issue
Block a user