mirror of
https://github.com/morluto/rea.git
synced 2026-11-15 19:23:24 +00:00
* fix(pcap): report a refused tool launch as an unavailable tool When a capture read's tool launch was refused with EPERM, pcap reported it as unreadable tool output (AnalysisProtocolError) instead of an unavailable tool. Pcap also never told "not executable" apart from "missing". Add classifyLaunchFailure in src/process as the one owner of which spawn errnos mean missing (ENOENT, ENOTDIR) and which mean present but not executable (EACCES, EPERM, ENOEXEC, EISDIR). Pcap, apktool and gdb used three different errno lists; all three now use it. * refactor(process): classify owned command outcomes through one owner Add ProviderOutcome, read once from the supervisor's facts, and classifyProviderOutcome, the one mapping from an outcome to a typed error. Migrate pcap and the shared artifact producer command failure (TShark, sigrok). Add the rea/provider-failure-classifier lint rule with a shrink-only baseline of per-site (cause: unknown) => AnalysisError functions. * refactor(process): classify Java and adb launch refusals with the shared owner (#10598) The Ghidra and JADX Java probes and adb's version probe now take missing-versus-not-executable from classifyLaunchFailure instead of their own errno checks. ELOOP and ENAMETOOLONG join the owner's missing set, so adb keeps its existing classification and both Java probes now treat a non-directory path component as a missing runtime. * fix(pcap): preserve command launch attribution * test(pcap): expect an unknown failing stage when a limited capture tool exits unsuccessfully * refactor(process): classify owned command outcomes through one owner Add ProviderOutcome, read once from the supervisor's facts, and classifyProviderOutcome, the one mapping from an outcome to a typed error. Migrate pcap and the shared artifact producer command failure (TShark, sigrok). Add the rea/provider-failure-classifier lint rule with a shrink-only baseline of per-site (cause: unknown) => AnalysisError functions. * test(lint): cover baselined files in the provider-failure classifier rule * fix(apktool): report the decoder JVM's heap exhaustion as memory, not a target refusal The supervisor now watches for a managed runtime's out-of-memory report while output streams (JVM java.lang.OutOfMemoryError, V8 'JavaScript heap out of memory'), so a retention budget cannot hide it. ProviderOutcome gains a runtime-exhausted kind and classifyProviderOutcome maps it once. Apktool decode opts in and moves to the shared classifier; Ghidra's single-purpose output token becomes the JVM runtime option and its area matching reuses the shared table. * fix(process): keep the runtime's out-of-memory report on the memory error it supports * fix(pcap): attribute a limited capture's exit through the prlimit wrapper * fix(process): keep a shortened out-of-memory line marked as shortened * fix(process): identify the refused executable for every launcher shape Name the executable on errnos Node throws synchronously from spawn (ENOEXEC, ENOTDIR, ...) and read the Windows native launcher's executable-launch constraint, so pcap attributes those refusals to the selected tool or limiter instead of an unknown stage. * test(pcap): prove synchronous launch naming with ENOTDIR on every POSIX host * fix(apktool): advise the JVM limit that governs the reported memory area * fix(ghidra): read the supervisor's parsed OOM area instead of reparsing lines * fix(sqlite,capture): read V8 heap exhaustion from streamed output, not retained stderr (#10724) The SQLite worker and the Node capture decoders now declare runtime: "v8", so the supervisor observes V8's heap report as output streams. Both classifiers read the runtime-exhausted outcome instead of matching retained stderr, so a report beyond the retention budget, or one whose process then overflowed its output budget, is still reported as memory exhaustion. * refactor(evm): classify EVMole worker outcomes through the shared provider classifier (#10716) * refactor(evm): classify EVMole worker outcomes through the shared provider classifier The EVMole worker's cancellation, deadline, output budget and CPU/file-size signals now go through classifyProviderOutcome; only the prlimit launch refusal and the reserved EFBIG exit remain in its dialect. The worker is opted into V8 exhaustion scanning so a heap report names its fixed 256 MiB heap. providerOutcomeOf now reads a launch refusal only from a spawn errno, so a private-storage or carrier read errno is no longer reported as a limiter launch failure. * fix(evm): keep a stream failure's exit status and update Linux worker expectations * refactor(process): read launch refusals through the launcher identity owner * refactor(wasm): classify WABT command outcomes through the shared provider classifier (#10727) * refactor(wasm): classify WABT command outcomes through the shared provider classifier WABT's cancellation, command deadline, output budget, and inherited-limit signals now go through classifyProviderOutcome; its dialect keeps only the configuration-probe and launch-refusal unavailability and the unclassified-exit output error. A tool ended by SIGXCPU/SIGXFSZ or the memory limit is now a resource constraint instead of an output error, and a refused launch in the producer phase is reported as unavailable. The shared timeout context gains the analysis setting that selected the deadline, and the output-limit context may name its exceeded budget. * fix(wasm): keep setup guidance when a WABT version probe's output cannot be collected * refactor(providers): classify raw provider failures through one owner * refactor(process): build classified cancellations with cancelledBy and the carried caller reason * chore(lint): count runOwned's close-failure mapper from main in the classifier baseline * fix(process): carry the runtime's exhaustion report on every memory error that claims it SQLite and historical-capture memory errors recognised a streamed V8 heap report but dropped it, so a report outside retained output reached callers without its source line or omission flags. One projection, runtimeExhaustionReport, now owns that shape for the shared classifier and both consumers. Also lowers the EVMole and WABT cancellation-constructor baselines. * fix(process): keep the provider's recovery for a native-thread exhaustion report The shared classifier replaced the provider-supplied recovery with generic capacity advice whenever the JVM reported it could not create a native thread, dropping Apktool's launcher guidance and flipping retryable to true. The provider's recovery now wins; the capacity advice remains the fallback for providers that supply none. * refactor(pwntools): classify pwntools failures through the shared provider classifier (#10782) * refactor(pwntools): classify pwntools failures through the shared provider classifier pwntools' per-site classifier is replaced by pwntoolsFailureDialect for classifyProviderFailure. Command outcomes go through classifyProviderOutcome, launch refusals through launcherRefusalOf instead of a 'spawn ' syscall prefix check, the input limit through the file dialect's fileSize, and the cleanup report through commandCleanup. The shared read cancellation now carries the reader's partial observation, and resource-signal reports accept provider detail. * fix(pwntools): report a failed command's output once and expect resource_constraint for overflow The shared outcome owner already attaches the command's output as capturedOutput, so the pwntools adapter fallback no longer copies the same text into diagnostics.stdout, diagnostics.stderr and diagnostics.captured_output; diagnostics keep the exit facts. Update the overflow expectations the dialect migration missed (layout provider cleanup and over-budget rows, pwntools cleanup) to resource_constraint. * refactor(wasm): leave WABT cancellation to the shared owners WabtFailures matched any Error named AbortError as a cancellation. No WABT path produces one: reads, path checks and owned commands report cancellation as ArtifactReaderFailure or OwnedCommandFailure, which classifyProviderFailure and classifyProviderOutcome already classify with the caller's reason. The provider's two signal checks now build the cancellation with cancelledBy. Lowers the AnalysisCancelledError constructor baseline for both WABT files to zero. * fix(wasm): report a cancelled snapshot write as the caller's cancellation The private snapshot write passed the caller's signal to Node's writeFile, whose abort envelope reached the dialect's unclassified output failure once the name-based AbortError guess was removed. The write now turns the envelope carrying its own signal's reason into cancelledBy at the producer. * refactor(firmware): classify firmware failures through the shared provider classifier (#10810) Firmware producers now report their own deadline expiry: the start check, the output inventory and launcher admission throw the phase timeout where they observe the abort, and a read the phase signal cancelled reports it through the dialect's interruption. The classifier no longer rereads a cancellation's reason as a timeout. A new readCleanup hook keeps firmware's cleanup report shape. * refactor(captures): classify TShark, sigrok and pcap failures through the shared provider classifier TsharkCaptureProvider and SigrokRecordingProvider replace #failure with a dialect, and PcapProvider replaces analysisFailure and the tool-identity classifier. ArtifactAnalysisResources exposes its command context and a readCleanupFailure composer so the readCleanup hook keeps each provider's cleanup report shape. * refactor(jeb): classify JEB failures through the shared provider classifier JEB's raw MCP failures go through classifyProviderFailure with a JEB dialect; a typed attribution step reports a shared phase's failure under the REA operation. Each MCP phase deadline now reports its own interruption when it aborts, deciding a cancellation's owner from the caller's own signal instead of comparing abort reasons. A refusal carrying the JVM's OutOfMemoryError report becomes a resource constraint naming JEB's Java heap. * fix(jeb): advise the JVM limit that governs the reported memory area * refactor(ghidra): classify Ghidra failures through the shared provider classifier PSP extension inspection reports through classifyProviderFailure with a Ghidra dialect. The startup deadline decides at abort time whether the shared startup owner closed it, so Ghidra and Hopper no longer compare the abort reason with the owner's sentinel, and Ghidra's startup no longer compares a producer cancellation's reason with the deadline's. Three helpers that only construct one error kind now name that kind instead of AnalysisError. * refactor(hopper): classify original-source read failures through the shared provider classifier (#10838) * test(ghidra): pin the aborted startup deadline over a producer cancellation * refactor(kuna): classify Kuna failures through the shared provider classifier Session operations, the workspace copy and the project export report raw failures through classifyProviderFailure with Kuna dialects; the copy and export keep their cleanup report shapes through the readCleanup hook. * refactor(adb): report a pulled file's digest failure from its own type * refactor(sqlite): classify worker-reply read failures through the shared provider classifier * refactor(ida): classify IDA operation failures through the shared provider classifier * refactor(process): let artifact-resource consumers classify through the shared provider classifier (#10867) * test(providers): pin attribution of a cleanup-failed read's typed primary * refactor(sqlite): classify database failures through the shared provider classifier * refactor(providers): keep a cancelled read's partial observation and provider diagnostics * refactor(ghidra): classify Ghidra failures through the shared provider classifier (#10836) * refactor(ghidra): classify Ghidra failures through the shared provider classifier PSP extension inspection reports through classifyProviderFailure with a Ghidra dialect. The startup deadline decides at abort time whether the shared startup owner closed it, so Ghidra and Hopper no longer compare the abort reason with the owner's sentinel, and Ghidra's startup no longer compares a producer cancellation's reason with the deadline's. Three helpers that only construct one error kind now name that kind instead of AnalysisError. * refactor(hopper): classify original-source read failures through the shared provider classifier (#10838) * test(ghidra): pin the aborted startup deadline over a producer cancellation * refactor(kuna): classify Kuna failures through the shared provider classifier (#10843) Session operations, the workspace copy and the project export report raw failures through classifyProviderFailure with Kuna dialects; the copy and export keep their cleanup report shapes through the readCleanup hook. * chore(guards): shrink the cancellation construction baseline after merging the base * refactor(ida): classify IDA operation failures through the shared provider classifier (#10859) * refactor(ida): classify IDA operation failures through the shared provider classifier * refactor(process): let artifact-resource consumers classify through the shared provider classifier (#10867) * test(providers): pin attribution of a cleanup-failed read's typed primary
298 lines
11 KiB
TypeScript
298 lines
11 KiB
TypeScript
import {
|
|
ArtifactReaderFailure,
|
|
type CleanupFailedRead,
|
|
} from "../artifacts/ArtifactReader.js";
|
|
import {
|
|
ArtifactFileCleanupFailure,
|
|
artifactFileCancellationCause,
|
|
artifactFileCompletion,
|
|
artifactFilePrimaryFacts,
|
|
bindArtifactFileCleanup,
|
|
} from "../artifacts/ArtifactFileOperation.js";
|
|
import {
|
|
projectSelectedArtifactFileFailure,
|
|
stableArtifactInputFailure,
|
|
type RequestField,
|
|
readerIntegrityFailure,
|
|
} from "../artifacts/StableArtifactFailure.js";
|
|
import { completedStableArtifactObservation } from "../artifacts/StableArtifactObservation.js";
|
|
import {
|
|
AnalysisError,
|
|
type AnalysisCapturedOutput,
|
|
type AnalysisErrorOptions,
|
|
} from "../domain/analysisErrorBase.js";
|
|
import { analysisErrorWithCleanupFailure } from "../domain/analysisErrorCleanup.js";
|
|
import { cancelledBy, carriedReason } from "../domain/analysisErrorCore.js";
|
|
import type { JsonValue } from "../domain/jsonValue.js";
|
|
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
|
|
import {
|
|
classifyProviderOutcome,
|
|
type ProviderOutcomeContext,
|
|
} from "../process/classifyProviderOutcome.js";
|
|
import { OwnedCommandFailure } from "../process/OwnedCommand.js";
|
|
import {
|
|
providerOutcomeOf,
|
|
type ProviderOutcome,
|
|
} from "../process/ProviderOutcome.js";
|
|
|
|
/** The selected file one provider phase reads, and how it names it. */
|
|
export interface ProviderFileDialect {
|
|
readonly path: string;
|
|
/** Names the file in an unreadable-path refusal, such as "bytecode carrier". */
|
|
readonly description: string;
|
|
/** The request field that selected the file; `path` when omitted. */
|
|
readonly field?: RequestField;
|
|
/** The provider's read budget and recovery for a file larger than it admits. */
|
|
readonly fileSize?: (
|
|
cause: ArtifactReaderFailure,
|
|
details: AnalysisErrorOptions,
|
|
) => AnalysisError;
|
|
/**
|
|
* Retain the completed read's byte identity on the reported failure. A
|
|
* provider that retains richer acquired evidence itself leaves this off.
|
|
*/
|
|
readonly retainCompletedIdentity?: boolean;
|
|
}
|
|
|
|
/**
|
|
* What one provider supplies so its raw failures can be classified: its own
|
|
* typed refusals, its command dialect, the file it read, and what it reports
|
|
* for a cause nothing recognised. Everything else is shared.
|
|
*/
|
|
export interface ProviderFailureDialect {
|
|
readonly providerId: string;
|
|
readonly operation: string;
|
|
/**
|
|
* Attribution for a typed failure a lower layer already classified, such as
|
|
* the accepted operation and the redacted endpoint it reached. Without it a
|
|
* typed failure passes through unchanged.
|
|
*/
|
|
readonly attribute?: (failure: AnalysisError) => AnalysisError;
|
|
/**
|
|
* Provider-owned typed failures, examined before the shared file facts.
|
|
* `details` carries the unresolved cleanup of a failed read.
|
|
*/
|
|
readonly recognise?: (
|
|
cause: unknown,
|
|
details: AnalysisErrorOptions,
|
|
) => AnalysisError | undefined;
|
|
/** How this provider's owned commands report; absent when none ran. */
|
|
readonly command?: (outcome: ProviderOutcome) => ProviderOutcomeContext;
|
|
/**
|
|
* Report for a command whose cleanup failed, given its classified primary.
|
|
* Without it the primary is composed with the unresolved resources.
|
|
*/
|
|
readonly commandCleanup?: (
|
|
failure: CleanupFailedCommand,
|
|
primary: AnalysisError,
|
|
outcome: ProviderOutcome,
|
|
) => AnalysisError;
|
|
/** The selected file this phase reads; absent when it reads none. */
|
|
readonly file?: ProviderFileDialect;
|
|
/**
|
|
* What the producing phase's own signal reports when it cancelled a read,
|
|
* such as that phase's deadline timeout; undefined when the phase's caller
|
|
* cancelled it. The phase owns this fact. Without it, or when it reports
|
|
* nothing, the read's cancellation is reported as a cancellation.
|
|
*/
|
|
readonly interruption?: (
|
|
details: Omit<AnalysisErrorOptions, "cause">,
|
|
) => AnalysisError | undefined;
|
|
/**
|
|
* Report for a selected-file read whose own cleanup failed, given what the
|
|
* read reports apart from that cleanup: its classified failed outcome or its
|
|
* cancellation, or undefined when only the cleanup failed. Without it the
|
|
* unresolved cleanup is attached to the reported failure.
|
|
*/
|
|
readonly readCleanup?: (
|
|
read: CleanupFailedRead,
|
|
primary: AnalysisError | undefined,
|
|
) => AnalysisError;
|
|
/** Facts this provider reports with a cancelled read, such as its path. */
|
|
readonly diagnostics?: Readonly<Record<string, JsonValue>>;
|
|
/** Output a finished command left before a later read was cancelled. */
|
|
readonly observedOutput?: AnalysisCapturedOutput | undefined;
|
|
/** What the provider reports for a cause none of the above recognised. */
|
|
readonly unclassified: (
|
|
cause: unknown,
|
|
details: AnalysisErrorOptions,
|
|
) => AnalysisError;
|
|
}
|
|
|
|
type CleanupFailedCommand = OwnedCommandFailure & {
|
|
readonly cleanupFailure: string;
|
|
};
|
|
|
|
const cleanupFailedRead = (cause: unknown): cause is CleanupFailedRead =>
|
|
cause instanceof ArtifactReaderFailure && cause.cleanup !== undefined;
|
|
|
|
/**
|
|
* A read's cancellation: the producing phase's interruption, else a
|
|
* cancellation. Either keeps what the read had already established, the
|
|
* output a finished command left, and the provider's facts about the read.
|
|
*/
|
|
const readCancellation = (
|
|
reason: unknown,
|
|
read: ArtifactReaderFailure,
|
|
dialect: ProviderFailureDialect,
|
|
details: Omit<AnalysisErrorOptions, "cause"> = {},
|
|
): AnalysisError => {
|
|
const reported = {
|
|
...details,
|
|
...(read.partialObservation === undefined
|
|
? {}
|
|
: { partialObservation: read.partialObservation }),
|
|
...(dialect.observedOutput === undefined
|
|
? {}
|
|
: { capturedOutput: dialect.observedOutput }),
|
|
...(dialect.diagnostics === undefined
|
|
? {}
|
|
: { diagnostics: { ...details.diagnostics, ...dialect.diagnostics } }),
|
|
};
|
|
return (
|
|
dialect.interruption?.(reported) ??
|
|
cancelledBy(dialect.operation, carriedReason(reason), reported)
|
|
);
|
|
};
|
|
|
|
/** What a read whose cleanup failed reports apart from that cleanup. */
|
|
const readPrimary = (
|
|
read: CleanupFailedRead,
|
|
dialect: ProviderFailureDialect,
|
|
): AnalysisError | undefined => {
|
|
if (read instanceof ArtifactFileCleanupFailure) {
|
|
const outcome = read.fileCleanupFailure.outcome;
|
|
if (outcome.kind === "failed")
|
|
return classifyProviderFailure(outcome.cause, dialect);
|
|
const cancellation = artifactFileCompletion(read)?.cancellation;
|
|
if (cancellation !== undefined)
|
|
return readCancellation(cancellation.reason, read, dialect);
|
|
}
|
|
return read.reason === "cancelled"
|
|
? readCancellation(artifactFileCancellationCause(read), read, dialect)
|
|
: undefined;
|
|
};
|
|
|
|
const cleanupFailed = (cause: unknown): cause is CleanupFailedCommand =>
|
|
cause instanceof OwnedCommandFailure && cause.cleanupFailure !== null;
|
|
|
|
const commandFailure = (
|
|
cause: unknown,
|
|
outcome: ProviderOutcome,
|
|
dialect: ProviderFailureDialect,
|
|
command: (outcome: ProviderOutcome) => ProviderOutcomeContext,
|
|
): AnalysisError => {
|
|
const context = command(outcome);
|
|
if (!cleanupFailed(cause)) return classifyProviderOutcome(outcome, context);
|
|
if (dialect.commandCleanup === undefined)
|
|
return analysisErrorWithCleanupFailure(
|
|
classifyProviderOutcome(outcome, context),
|
|
new ProviderCleanupError(
|
|
dialect.providerId,
|
|
cause.resources,
|
|
{ reason: cause.cleanupFailure },
|
|
{ operation: dialect.operation, cause },
|
|
),
|
|
dialect.operation,
|
|
);
|
|
// The provider's cleanup report retains the output once; its primary needs
|
|
// only recovery facts.
|
|
const primary = classifyProviderOutcome(
|
|
{ ...outcome, output: undefined },
|
|
context,
|
|
);
|
|
return dialect.commandCleanup(cause, primary, outcome);
|
|
};
|
|
|
|
/** Shared facts about a selected file read. */
|
|
const fileFailure = (
|
|
cause: unknown,
|
|
dialect: ProviderFailureDialect,
|
|
details: AnalysisErrorOptions,
|
|
): AnalysisError | undefined => {
|
|
const { operation, file } = dialect;
|
|
const { cause: physical, origin } = artifactFilePrimaryFacts(cause);
|
|
if (
|
|
origin === "owned-or-classified" &&
|
|
physical instanceof ArtifactReaderFailure
|
|
) {
|
|
if (physical.reason === "cancelled") {
|
|
// The reader's recorded abort reason is the cancellation's cause.
|
|
const { cause: _reader, ...cancellationDetails } = details;
|
|
return readCancellation(
|
|
artifactFileCancellationCause(physical),
|
|
physical,
|
|
dialect,
|
|
cancellationDetails,
|
|
);
|
|
}
|
|
if (file === undefined) return undefined;
|
|
if (physical.reason === "integrity")
|
|
return readerIntegrityFailure(operation, file.path, physical, {
|
|
...details,
|
|
cause,
|
|
});
|
|
if (physical.reason === "limit" && physical.boundary === "file-size")
|
|
return file.fileSize?.(physical, { ...details, cause });
|
|
if (physical.reason === "path" || physical.reason === "format")
|
|
return stableArtifactInputFailure(
|
|
physical,
|
|
operation,
|
|
file.field,
|
|
details,
|
|
);
|
|
return undefined;
|
|
}
|
|
return file === undefined
|
|
? undefined
|
|
: projectSelectedArtifactFileFailure(
|
|
physical,
|
|
operation,
|
|
file.path,
|
|
file.description,
|
|
file.field,
|
|
details,
|
|
);
|
|
};
|
|
|
|
/**
|
|
* The one mapping from a raw provider failure to a typed error. Typed analysis
|
|
* errors pass through, attributed by the dialect when it says how; supervised command outcomes go to
|
|
* `classifyProviderOutcome`; selected-file failures go to the shared stable
|
|
* artifact projections, keeping the read's cleanup and identity. Only what none of them recognises reaches the
|
|
* provider's `unclassified` report.
|
|
*/
|
|
export const classifyProviderFailure = (
|
|
cause: unknown,
|
|
dialect: ProviderFailureDialect,
|
|
): AnalysisError => {
|
|
if (cause instanceof AnalysisError)
|
|
return dialect.attribute?.(cause) ?? cause;
|
|
const outcome =
|
|
dialect.command === undefined ? undefined : providerOutcomeOf(cause);
|
|
if (outcome !== undefined && dialect.command !== undefined)
|
|
return commandFailure(cause, outcome, dialect, dialect.command);
|
|
const { file } = dialect;
|
|
const observation =
|
|
file?.retainCompletedIdentity === true
|
|
? completedStableArtifactObservation(cause, file.path)
|
|
: undefined;
|
|
if (dialect.readCleanup !== undefined && cleanupFailedRead(cause)) {
|
|
// The read's report carries what it completed onto its primary.
|
|
if (observation !== undefined) cause.retainPartialObservation(observation);
|
|
return dialect.readCleanup(cause, readPrimary(cause, dialect));
|
|
}
|
|
// A failed read's unresolved cleanup stays on whatever it is reported as.
|
|
const details: AnalysisErrorOptions =
|
|
cause instanceof ArtifactReaderFailure && cause.cleanup !== undefined
|
|
? { cleanup: cause.cleanup }
|
|
: {};
|
|
const failure =
|
|
dialect.recognise?.(cause, details) ??
|
|
fileFailure(cause, dialect, details) ??
|
|
dialect.unclassified(cause, details);
|
|
if (observation !== undefined) failure.retainPartialObservation(observation);
|
|
bindArtifactFileCleanup(cause, failure);
|
|
return failure;
|
|
};
|