mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
* fix(errors)!: derive retryable from the producer's declared retry class `retryable` means the unchanged request may succeed, but it was computed downstream as an OR of a code table and five class rules. Every error classification now declares a retry class (same_call, change_first, never, unknown_outcome); `retryable` is `same_call` after one incomplete-cleanup check, and the RETRYABLE_CODES table is deleted. Producer corrections: - update_unknown revision conflicts are change_first and report details.current_revision; duplicate record_unknown reports details.existing_unknown_id. - close_gdb_session's explicit-disposition refusal is change_first. - Per-call artifact reader limits are change_first (never when the limit cannot rise). - An exited or unreachable Hopper bridge, and a Hopper start that another REA session owns, are change_first. - File-descriptor exhaustion (EMFILE/ENFILE) outside process launch is occupied host capacity (same_call) for private workspaces, model and GPU readers and JavaScript application reads. - apktool JVM native-thread exhaustion follows the shared capacity default. BREAKING CHANGE: these refusals now report `retryable: false` (descriptor pressure now reports `retryable: true` as `resource_constraint`). Callers that repeated them unchanged should follow the remediation first: re-read the unknown and retry with details.current_revision, dispose GDB inferiors, raise the reported reader limit, or restart the Hopper provider. * fix(errors): require producers to name recovery for conforming refusals A refusal whose arguments match the input schema was presented as a schema error whenever its producer left out remediation, and many producers did. AnalysisInputError's options are now a union: a conforming refusal must supply both its outcome (userMessage) and next step (remediationAction), so the compiler lists every producer; only contract violations may fall back to the schema guidance. Producers fixed: unknown Frida session and script, decompile_all output-directory state, the duplicate unknown build computer factory (collapsed), stale Cutter sessions, Mach-O architecture selection, output roots that already exist, selected files the host refuses, Ghidra lookups the bridge could not resolve, YARA path refusals, unresolved native symbol names, apt key files and withheld sign-in state. A missing selected APK is now target_unavailable like every other selected-file reader. The capability fallback "Choose another analysis or target" is deleted; a capability refusal without its own recovery names details.reason and binary_session. Refs #15312 * fix(errors): classify caller selections and target bytes by their real failure Several refusals reported a code that reads as corruption or a crash: - a missing unknown_id and a missing Evidence reference now report invalid_request instead of execution_failure and evidence_integrity_mismatch; - close_binary with snapshot_path in a resource-only session reports invalid_request instead of evidence_integrity_mismatch; - ADB push onto an existing device path and pulls into an occupied output directory are conforming invalid_request refusals naming overwrite or output_directory, not unreadable_output; - damaged APK ZIP, signing-block, signer and central-directory structures are malformed targets, not invalid input; - NuGet and VSIX bytes without a ZIP signature are unrecognized, not malformed; - a historical source graph file whose entries contradict its root commitment is an integrity failure, not invalid input; - a CDP protocol failure states what happened instead of the unclassified fallback message. Refs #15319 * feat(errors): expose the producer's retry class as retry_class Every error projection now carries retry_class (same_call, change_first, never or unknown_outcome) beside retryable, which stays true exactly for same_call. The field is additive: the error schema accepts errors retained by earlier releases without it. Refs #15323 * fix(errors): address review of the folded error-contract PRs Keep a provider's own capability message as its remediation; the binary_session fallback applies only to a bare declared reason. Delete the unused conformingInputRefusal helper. Compose both retry fields for a refused publication whose cleanup is incomplete. Report descriptor exhaustion from a JavaScript directory opendir as occupied capacity. Let an exited Hopper startup attempt without a setup failure code retry unchanged. Declare retry for the Ghidra superseded checkpoint and unknown IDA readiness. Redact ambiguous selector candidates. Give a Ghidra document miss its own recovery. Drop an unchanged-files claim the journal repair cannot make. Name each withheld sign-in refusal's step. Hash the source graph commitment before the cancellation yield. Keep the browser protocol_error message neutral. Add tests for mutation-audit survivors C3, C5, P2, P4, P8, H1, H4 and H5. * fix(errors): keep a missing Evidence reference an integrity failure and state only the observed commitment mismatch * test(desktop): assert the unknown build computer refusal's remediation, not its message The refusal now carries its next step in remediation.action instead of the message, so the closed-computer checks assert the exact code, message and remediation facts. * fix(errors): keep producer retry choices apart from cleanup and fixed ceilings A capture's retryable flag no longer folds in pending cleanup, so the projection applies the cleanup rule once and a transient capture with pending cleanup reports change_first instead of never. A release-fixed artifact allowance reports never, and a stale admitted session identity reports change_first (reopen, then retry); both have catalogue rows. The bare capability-unavailable remediation names binary_session only for a binary-analysis session, so standalone bridges such as Cutter are pointed at their own reason. * test(vsix): expect a non-ZIP selection to be refused as unrecognized This PR reports bytes without a ZIP signature as another format (unrecognized), not a damaged package; the exact-reason assertion added on main still expected malformed. * test(delivery): expect the capacity refusal's retry class in delivered failure facts The exact failure facts asserted on main predate the projection's retry_class; occupied capacity reports same_call. * fix(errors): mark a sent Hopper cancellation unknown and missing Evidence recoverable A cancellation Hopper already received may still apply, so its retry class is unknown_outcome instead of same_call; an unsent cancellation keeps same_call. A missing EvidenceReferenceError is change_first, since importing the referenced records lets the same request succeed; other reference failures stay never. Both have catalogue rows. * fix(hopper): ask for changed launch arguments before retrying an unencodable launch A launcher path or argument that cannot be encoded as an AppleScript literal meets the same pre-launch guard on every attempt, so the start refusal is change_first and its retry_action is unknown; a start failure without a declared reason stays same_call. * fix(errors): keep a one-shot cleanup failure's retry class with its cleanup state A one-shot reply that reports cleanup_incomplete spread the primary or cleanup projection and overrode only retryable, so a timed-out read whose close also failed carried retry_class same_call. The reply now reads its retry class from the typed composed failure, and never offers the same call before cleanup settles. * test(evtx): expect an unreadable selected log to be refused with its own recovery This PR treats a well-formed path the host refused as a regular file as conforming input with its own remediation; the evtx boundary test still expected a schema-recovery refusal. * test(javascript): expect a broken source-graph commitment as an integrity failure This PR reports a well-formed historical source graph whose entries disagree with its root_sha256 as evidence_integrity_mismatch, not an input issue; the exact refusal assertion added on main still expected invalid_request.
297 lines
10 KiB
TypeScript
297 lines
10 KiB
TypeScript
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
|
|
import { analysisErrorWithCancellation } from "../domain/analysisErrorCancellation.js";
|
|
import { expect, it } from "vitest";
|
|
import {
|
|
AnalysisCapabilityUnavailableError,
|
|
AnalysisCancelledError,
|
|
AnalysisOutputError,
|
|
AnalysisTimeoutError,
|
|
AnalysisResourceConstraintError,
|
|
AnalysisArtifactChangedError,
|
|
} from "../domain/analysisErrorCore.js";
|
|
import { analysisSettingLimit } from "../domain/analysisSettingDefinitions.js";
|
|
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
|
|
import type { FileOffsetPartialObservation } from "../domain/native/fileOffsetPartialObservation.js";
|
|
import { analysisClientFailureForOperation } from "./AnalysisClientFailure.js";
|
|
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
|
import { regexMatchingDeadlineError } from "../process/RegexMatcher.js";
|
|
import {
|
|
ProviderOwnedAnalysisError,
|
|
providerErrorTag,
|
|
type AnalysisErrorOptions,
|
|
type AnalysisErrorOwnPresentation,
|
|
type ProviderRequestFailure,
|
|
} from "../domain/analysisErrorBase.js";
|
|
import { releaseOwnedCleanup } from "../../tests/support/cleanupRelease.js";
|
|
|
|
const observation: FileOffsetPartialObservation = {
|
|
operation: "address_to_file_offset",
|
|
address: "0x1000",
|
|
provider_file_offset: 32,
|
|
provider_source_path: "/selected/image",
|
|
provider_image_header_hex: null,
|
|
original_file_offset: { available: false, reason: "not mapped" },
|
|
};
|
|
|
|
it.each([false, true])(
|
|
"preserves completed cleanup evidence when the source is already resolved: %s",
|
|
(resolved) => {
|
|
const source = new ProviderCleanupError(
|
|
"native",
|
|
["snapshot descriptor"],
|
|
{ reason: "descriptor close failed" },
|
|
{ operation: "provider_mapping", completedObservation: observation },
|
|
);
|
|
if (resolved) releaseOwnedCleanup(source);
|
|
|
|
const attributed = analysisClientFailureForOperation(
|
|
source,
|
|
"native",
|
|
"address_to_file_offset",
|
|
);
|
|
expect(attributed).toBeInstanceOf(ProviderCleanupError);
|
|
if (!(attributed instanceof ProviderCleanupError))
|
|
throw new Error("Expected the cleanup subtype");
|
|
expect(attributed.operation).toBe("address_to_file_offset");
|
|
expect(attributed.completedObservation).toBe(observation);
|
|
expect(attributed.cleanupIncomplete).toBe(!resolved);
|
|
expect(attributed.cleanupResources).toEqual(["snapshot descriptor"]);
|
|
|
|
// Attribution must keep the source owner's later cleanup confirmation live.
|
|
releaseOwnedCleanup(source);
|
|
expect(attributed.cleanupIncomplete).toBe(false);
|
|
if (!resolved) expect(attributed.cleanupResources).toEqual([]);
|
|
expect(attributed.completedObservation).toBe(observation);
|
|
},
|
|
);
|
|
|
|
it("does not promote ordinary partial evidence into a completed result", () => {
|
|
const source = new ProviderCleanupError(
|
|
"native",
|
|
["snapshot descriptor"],
|
|
{},
|
|
{ partialObservation: observation },
|
|
);
|
|
const attributed = analysisClientFailureForOperation(
|
|
source,
|
|
"native",
|
|
"address_to_file_offset",
|
|
);
|
|
expect(attributed).toBeInstanceOf(ProviderCleanupError);
|
|
if (!(attributed instanceof ProviderCleanupError))
|
|
throw new Error("Expected the cleanup subtype");
|
|
expect(attributed.partialObservation).toBe(observation);
|
|
expect(attributed.completedObservation).toBeUndefined();
|
|
});
|
|
|
|
it("keeps a regex deadline's continuing-session guidance when attributing it to a provider operation", () => {
|
|
const source = regexMatchingDeadlineError("search_procedures");
|
|
const attributed = analysisClientFailureForOperation(
|
|
source,
|
|
"hopper",
|
|
"search_procedures",
|
|
);
|
|
for (const lifetime of ["continuing", "invocation"] as const) {
|
|
const delivered = projectAnalysisError(attributed, lifetime);
|
|
const owned = projectAnalysisError(source, lifetime);
|
|
expect(delivered.message).toBe(owned.message);
|
|
expect(delivered.remediation).toEqual(owned.remediation);
|
|
expect(delivered.details?.limit).toEqual(owned.details?.limit);
|
|
}
|
|
// The two lifetimes receive different guidance from the same owner.
|
|
expect(projectAnalysisError(attributed).remediation).not.toEqual(
|
|
projectAnalysisError(attributed, "invocation").remediation,
|
|
);
|
|
expect(
|
|
projectAnalysisError(attributed, "invocation").details?.limit,
|
|
).toMatchObject({
|
|
setting: "regex.matching_deadline_ms",
|
|
scope: "rea-invocation",
|
|
environment: "REA_REGEX_MATCHING_DEADLINE_MS",
|
|
});
|
|
});
|
|
|
|
it("preserves sibling operations, sibling reasons, and remediation action when rebuilding capability unavailable errors", () => {
|
|
const source = new AnalysisCapabilityUnavailableError(
|
|
"kuna",
|
|
"procedure_assembly",
|
|
"Kuna project export failed",
|
|
{
|
|
userMessage: "Export failed",
|
|
remediationAction: "Retry without project requirement",
|
|
fallbackRemediationAction: "Review provider choices",
|
|
siblingOperations: ["procedure_assembly", "analyze_function"],
|
|
siblingReasons: {
|
|
analyze_function: "analyze_function export failed",
|
|
},
|
|
retry: "same_call",
|
|
},
|
|
);
|
|
const attributed = analysisClientFailureForOperation(
|
|
source,
|
|
"kuna",
|
|
"procedure_assembly",
|
|
);
|
|
expect(attributed).toBeInstanceOf(AnalysisCapabilityUnavailableError);
|
|
if (!(attributed instanceof AnalysisCapabilityUnavailableError))
|
|
throw new Error("Expected AnalysisCapabilityUnavailableError");
|
|
expect(attributed.siblingOperations).toEqual([
|
|
"procedure_assembly",
|
|
"analyze_function",
|
|
]);
|
|
expect(attributed.siblingReasons).toEqual({
|
|
analyze_function: "analyze_function export failed",
|
|
});
|
|
expect(attributed.remediationAction).toBe(
|
|
"Retry without project requirement",
|
|
);
|
|
expect(attributed.fallbackRemediationAction).toBe("Review provider choices");
|
|
expect(attributed.userMessage).toBe("Export failed");
|
|
expect(attributed.retryable).toBe(true);
|
|
});
|
|
|
|
it("keeps the structured limit when a resource refusal changes operation", () => {
|
|
const limit = analysisSettingLimit(
|
|
"bridge.max_request_bytes",
|
|
8192,
|
|
"runtime",
|
|
);
|
|
const source = new AnalysisResourceConstraintError(
|
|
"cutter_command",
|
|
"transport",
|
|
"status exceeded the ceiling",
|
|
{ max_request_bytes: 8192 },
|
|
{
|
|
remediationAction: "Raise the ceiling.",
|
|
retryable: false,
|
|
limit,
|
|
related: {
|
|
parameters: ["max_output_bytes"],
|
|
operations: ["analyze_function"],
|
|
},
|
|
},
|
|
);
|
|
const attributed = analysisClientFailureForOperation(
|
|
source,
|
|
"ghidra",
|
|
"binary_overview",
|
|
);
|
|
expect(attributed).toBeInstanceOf(AnalysisResourceConstraintError);
|
|
if (!(attributed instanceof AnalysisResourceConstraintError))
|
|
throw new Error("expected a resource constraint");
|
|
expect(attributed.operation).toBe("binary_overview");
|
|
expect(attributed.retryable).toBe(false);
|
|
expect(attributed.limit).toEqual(source.limit);
|
|
expect(attributed.related).toEqual(source.related);
|
|
expect(projectAnalysisError(attributed)).toMatchObject({
|
|
code: "resource_constraint",
|
|
details: {
|
|
related_parameters: ["max_output_bytes"],
|
|
related_operations: ["analyze_function"],
|
|
limit: {
|
|
setting: "bridge.max_request_bytes",
|
|
effective_value: 8192,
|
|
source: "runtime",
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
it.each([
|
|
new ProviderAdapterError("fixture", "open_binary"),
|
|
new AnalysisOutputError("open_binary", "physical parse failure"),
|
|
new AnalysisTimeoutError("open_binary", 123),
|
|
])("preserves recorded secondary failures when rebinding $_tag", (physical) => {
|
|
const reason = { caller: "stop after physical outcome" };
|
|
const cancelled = new AnalysisCancelledError("open_binary", {
|
|
cause: reason,
|
|
});
|
|
const sibling = new AnalysisOutputError(
|
|
"read-sibling",
|
|
"independent physical sibling",
|
|
);
|
|
physical.retainSecondaryFailure(sibling);
|
|
analysisErrorWithCancellation(physical, cancelled);
|
|
const attributed = analysisClientFailureForOperation(
|
|
physical,
|
|
"fixture",
|
|
"health",
|
|
);
|
|
expect(attributed).toMatchObject({ operation: "health" });
|
|
expect(attributed.secondaryFailures).toEqual([sibling, cancelled]);
|
|
expect(attributed.secondaryFailures[0]).toBe(sibling);
|
|
expect(attributed.secondaryFailures[1]).toBe(cancelled);
|
|
expect(cancelled.cause).toBe(reason);
|
|
const again = analysisClientFailureForOperation(
|
|
attributed,
|
|
"fixture",
|
|
"binary_overview",
|
|
);
|
|
expect(again.secondaryFailures).toEqual([sibling, cancelled]);
|
|
expect(projectAnalysisError(again).details?.secondary_failures).toHaveLength(
|
|
2,
|
|
);
|
|
});
|
|
|
|
it("reattributes a provider-owned failure through the request facts it reports", () => {
|
|
class ExampleRequestError extends ProviderOwnedAnalysisError {
|
|
readonly _tag = providerErrorTag("ExampleRequestError");
|
|
constructor(
|
|
readonly operation: string,
|
|
options: AnalysisErrorOptions = {},
|
|
) {
|
|
super(`Example ${operation} failed`, options);
|
|
}
|
|
override ownPresentation(): AnalysisErrorOwnPresentation {
|
|
return {
|
|
code: "execution_failure",
|
|
category: "execution_failure",
|
|
retry: "never",
|
|
};
|
|
}
|
|
override providerRequest(): ProviderRequestFailure {
|
|
return {
|
|
facts: { operation: this.operation, request_id: 7 },
|
|
reattribute: (operation, options) =>
|
|
new ExampleRequestError(operation, options),
|
|
};
|
|
}
|
|
}
|
|
const source = new ExampleRequestError("wire_request", {
|
|
diagnostics: { bridge: "observed" },
|
|
});
|
|
|
|
const attributed = analysisClientFailureForOperation(
|
|
source,
|
|
"example",
|
|
"decompile",
|
|
);
|
|
|
|
expect(attributed).toBeInstanceOf(ExampleRequestError);
|
|
expect(attributed).toMatchObject({
|
|
operation: "decompile",
|
|
cause: source,
|
|
diagnostics: {
|
|
provider_request: { operation: "wire_request", request_id: 7 },
|
|
provider_diagnostics: { bridge: "observed" },
|
|
},
|
|
});
|
|
});
|
|
|
|
it("keeps the named integrity check when an artifact change changes operation", () => {
|
|
const attributed = analysisClientFailureForOperation(
|
|
new AnalysisArtifactChangedError(
|
|
"inspect_artifact",
|
|
"/target.app",
|
|
"member changed",
|
|
{ integrityCheck: "member-identity" },
|
|
),
|
|
"ghidra",
|
|
"binary_overview",
|
|
);
|
|
expect(projectAnalysisError(attributed)).toMatchObject({
|
|
code: "artifact_changed",
|
|
details: { integrity_check: "member-identity" },
|
|
});
|
|
});
|