Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions docs/native-investigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,13 @@ Binary plist inspection reads the original bytes through an owned file descripto
so conversion cannot erase control characters, fractional dates, negative zero,
or the high word of a 128-bit integer. It accepts at most 64 MiB of input and
reserves an estimated 64 MiB decode budget before parsing; this estimate is not
a hard process-memory bound. Binary-source provenance records the `file`
classification without claiming a `plutil` conversion.
a hard process-memory bound. A refused input reports non-retryable
`resource_constraint` with `reported_limits.maximum_input_bytes`,
`maximum_decoded_bytes` or, for nesting deeper than 128 levels,
`maximum_nesting_depth`. These are fixed allowances: worker limits and host
memory do not raise them, and the unchanged request fails the same way.
Binary-source provenance records the `file` classification without claiming a
`plutil` conversion.

A plist explicitly selected through the path input or as the active plist target
reports an unreadable or malformed selection as `invalid_request`. A missing or
Expand Down
5 changes: 4 additions & 1 deletion src/artifacts/apple/PropertyListDecodeBudget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ function* xmlPreflightTokens(xml: string) {
}
}

/** Deepest binary plist value nesting the reference walk admits. */
export const MAX_BINARY_PLIST_NESTING_DEPTH = 128;

/** Resource or structural failure found while preflighting a plist. */
export type BinaryPlistExpansionFailure = "cycle" | "depth" | "expansion";

Expand Down Expand Up @@ -299,7 +302,7 @@ export const estimateBinaryPlistExpansion = (
continue;
}
pendingObjectCount -= 1;
if (entry.depth > 128)
if (entry.depth > MAX_BINARY_PLIST_NESTING_DEPTH)
throw fail("depth", `binary plist nesting exceeds ${budget}`);
if (active.has(entry.object))
throw fail("cycle", `binary plist reference cycle exceeds ${budget}`);
Expand Down
51 changes: 47 additions & 4 deletions src/domain/analysisErrorCore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { JsonValue } from "./jsonValue.js";
import type { FixedAllowance } from "./fixedAllowanceRemediation.js";
import {
AnalysisError,
type AnalysisErrorOptions,
Expand Down Expand Up @@ -33,6 +34,12 @@ export const ANALYSIS_RESOURCE_KINDS = [
export class AnalysisResourceConstraintError extends AnalysisError {
readonly _tag = "AnalysisResourceConstraintError";
readonly remediationAction: string | undefined;
/**
* The fixed format, decoder, or capture allowance that refused the request.
* Worker limits and host resources do not raise it, so recovery derives from
* this allowance rather than from `resource`.
*/
readonly fixedAllowance: FixedAllowance | undefined;
/**
* Whether retrying the same request can succeed. A caller-selected bound is
* deterministic for the same input, so it is not retryable even when its
Expand All @@ -45,17 +52,53 @@ export class AnalysisResourceConstraintError extends AnalysisError {
readonly resource: (typeof ANALYSIS_RESOURCE_KINDS)[number],
readonly reason: string,
readonly reportedLimits: Readonly<Record<string, JsonValue>> | null,
options?: AnalysisErrorOptions & {
readonly remediationAction?: string;
readonly retryable?: boolean;
},
options?: AnalysisErrorOptions & ResourceConstraintRecovery,
) {
super(`Resource constraint during ${operation}: ${reason}`, options);
this.remediationAction = options?.remediationAction;
this.fixedAllowance = options?.fixedAllowance;
this.retryable = options?.retryable;
}
}

/** Carry one refusal's recovery to an error re-attributed or redacted elsewhere. */
export const resourceConstraintRecovery = (
error: AnalysisResourceConstraintError,
text: (value: string) => string = (value) => value,
): ResourceConstraintRecovery =>
error.fixedAllowance !== undefined
? {
fixedAllowance: {
name: text(error.fixedAllowance.name),
kind: error.fixedAllowance.kind,
},
...retryable(error),
}
: {
...(error.remediationAction === undefined
? {}
: { remediationAction: text(error.remediationAction) }),
...retryable(error),
};

const retryable = (
error: AnalysisResourceConstraintError,
): { readonly retryable?: boolean } =>
error.retryable === undefined ? {} : { retryable: error.retryable };

/** Producer-specific recovery, or a fixed allowance whose recovery is derived. */
export type ResourceConstraintRecovery =
| {
readonly remediationAction?: string;
readonly fixedAllowance?: never;
readonly retryable?: boolean;
}
| {
readonly fixedAllowance: FixedAllowance;
readonly remediationAction?: never;
readonly retryable?: boolean;
};

/** Provider-neutral invalid analysis input or output at an application boundary. */
export class AnalysisProtocolError extends AnalysisError {
readonly _tag = "AnalysisProtocolError";
Expand Down
24 changes: 15 additions & 9 deletions src/domain/analysisErrorPresentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { ProviderSelectionError } from "./providerSelectionError.js";
import { ProviderAdapterError } from "./providerAdapterError.js";
import { UnknownRegistryError } from "./unknownRegistryError.js";
import { providerRetryAction } from "./providerOperationHealth.js";
import { fixedAllowanceRemediation } from "./fixedAllowanceRemediation.js";
import {
resolvedAnalysisError,
type AnalysisError,
Expand Down Expand Up @@ -67,15 +68,20 @@ export const analysisErrorRemediationAction = (
if (error instanceof AnalysisResourceConstraintError)
return (
error.remediationAction ??
(error.resource === "capacity"
? "Wait for an active analysis to complete, then retry within the reported admission limits."
: error.resource === "transport"
? "Discover retained records with get_evidence_bundle and detail: summary, then inspect compatible records through inspect_analysis_view using an exact Evidence reference. Export complete retained session evidence through export_evidence_bundle to a caller-selected path, or use complete CLI JSON output. The connection remains usable."
: error.resource === "cpu"
? "Review the reported worker CPU limits and observed signal. Retry with sufficient CPU time or a smaller artifact; REA retains tighter inherited limits."
: error.resource === "file-size"
? "Review the reported worker file-size limits and write failure. Retry with a sufficient file-size allowance for the evidence reply; REA retains tighter inherited limits."
: "Review the reported worker memory limits and available host memory. Retry with sufficient memory or a smaller artifact; REA retains tighter inherited limits.")
(error.fixedAllowance !== undefined
? fixedAllowanceRemediation(
error.fixedAllowance.name,
error.fixedAllowance.kind,
)
: error.resource === "capacity"
? "Wait for an active analysis to complete, then retry within the reported admission limits."
: error.resource === "transport"
? "Discover retained records with get_evidence_bundle and detail: summary, then inspect compatible records through inspect_analysis_view using an exact Evidence reference. Export complete retained session evidence through export_evidence_bundle to a caller-selected path, or use complete CLI JSON output. The connection remains usable."
: error.resource === "cpu"
? "Review the reported worker CPU limits and observed signal. Retry with sufficient CPU time or a smaller artifact; REA retains tighter inherited limits."
: error.resource === "file-size"
? "Review the reported worker file-size limits and write failure. Retry with a sufficient file-size allowance for the evidence reply; REA retains tighter inherited limits."
: "Review the reported worker memory limits and available host memory. Retry with sufficient memory or a smaller artifact; REA retains tighter inherited limits.")
);
if (
error instanceof AnalysisTimeoutError &&
Expand Down
11 changes: 2 additions & 9 deletions src/domain/explicitSensitiveFailure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
AnalysisOutputError,
AnalysisCapabilityUnavailableError,
AnalysisResourceConstraintError,
resourceConstraintRecovery,
AnalysisCancelledError,
AnalysisTimeoutError,
} from "./analysisErrorCore.js";
Expand Down Expand Up @@ -183,15 +184,7 @@ const redactFailure = (
error.resource,
text(error.reason),
error.reportedLimits === null ? null : diagnostics(error.reportedLimits),
{
...context,
...(error.remediationAction === undefined
? {}
: { remediationAction: text(error.remediationAction) }),
...(error.retryable === undefined
? {}
: { retryable: error.retryable }),
},
{ ...context, ...resourceConstraintRecovery(error, text) },
);
if (error instanceof ProviderCleanupError)
return new ProviderCleanupError(
Expand Down
11 changes: 9 additions & 2 deletions src/domain/fixedAllowanceRemediation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,18 @@ export const fixedAllowanceRemediation = (
}
};

/** A named deterministic allowance and the recovery family it belongs to. */
export interface FixedAllowance {
/** Display name, such as "The tshark JSON decoding allowance". */
readonly name: string;
readonly kind: FixedAllowanceKind;
}

/** Non-retryable options for a fixed allowance. Occupied capacity stays retryable. */
export const fixedAllowanceOptions = (
allowance: string,
kind: FixedAllowanceKind,
): { readonly retryable: false; readonly remediationAction: string } => ({
): { readonly retryable: false; readonly fixedAllowance: FixedAllowance } => ({
retryable: false,
remediationAction: fixedAllowanceRemediation(allowance, kind),
fixedAllowance: { name: allowance, kind },
});
25 changes: 14 additions & 11 deletions src/ida/IdaSessionClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
AnalysisInputError,
AnalysisTimeoutError,
AnalysisResourceConstraintError,
resourceConstraintRecovery,
} from "../domain/analysisErrorCore.js";
import { AnalysisError } from "../domain/analysisErrorBase.js";
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
Expand Down Expand Up @@ -530,33 +531,35 @@ export class IdaSessionClient implements AnalysisClient {
...(cause.userMessage === undefined
? {}
: { userMessage: cause.userMessage }),
...(cause.remediationAction === undefined
? {}
: { remediationAction: cause.remediationAction }),
diagnostics: {
...cause.diagnostics,
startup_operation: cause.operation,
},
};
const action =
cause.remediationAction === undefined
? {}
: { remediationAction: cause.remediationAction };
// Startup is shared, but each accepted operation owns its attribution.
// Keep the original cached failure unchanged for later callers.
const failure =
cause instanceof AnalysisTimeoutError
? new AnalysisTimeoutError(operation, cause.timeoutMs, options)
? new AnalysisTimeoutError(operation, cause.timeoutMs, {
...options,
...action,
})
: cause instanceof AnalysisResourceConstraintError
? new AnalysisResourceConstraintError(
operation,
cause.resource,
cause.reason,
cause.reportedLimits,
{
...options,
...(cause.retryable === undefined
? {}
: { retryable: cause.retryable }),
},
{ ...options, ...resourceConstraintRecovery(cause) },
)
: new ProviderAdapterError(cause.providerId, operation, options);
: new ProviderAdapterError(cause.providerId, operation, {
...options,
...action,
});
throw failure
.bindCleanupDependencies([cause])
.bindCleanupResourceOwner(cause);
Expand Down
34 changes: 24 additions & 10 deletions src/native/NativePlistSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ import {
} from "../artifacts/ArtifactFileOperation.js";
import type { ArtifactResourceScope } from "../artifacts/ArtifactResourceScope.js";
import { NATIVE_MACOS_PROVIDER_IDENTITY as IDENTITY } from "./NativeMacOSProviderMetadata.js";
import { MAX_NATIVE_PLIST_BYTES } from "./parsers/plist.js";
import {
MAX_NATIVE_PLIST_BYTES,
NATIVE_PLIST_INPUT_ALLOWANCE,
} from "./parsers/plist.js";
import { fixedAllowanceOptions } from "../domain/fixedAllowanceRemediation.js";

/** Resolved lookup identity and selection intent, independent of file readiness. */
export interface NativePlistSelection {
Expand Down Expand Up @@ -214,15 +218,25 @@ export const nativePlistFailure = (
);
if (cause instanceof ArtifactReaderFailure && cause.reason === "limit") {
const resource = cause.boundary ?? "memory";
return new AnalysisResourceConstraintError(
"inspect_plist",
resource,
cause.message,
resource === "file-size"
? { maximum_input_bytes: MAX_NATIVE_PLIST_BYTES }
: null,
{ cause, capturedOutput, retryable: false },
);
return resource === "file-size"
? new AnalysisResourceConstraintError(
"inspect_plist",
resource,
cause.message,
{ maximum_input_bytes: MAX_NATIVE_PLIST_BYTES },
{
cause,
capturedOutput,
...fixedAllowanceOptions(NATIVE_PLIST_INPUT_ALLOWANCE, "input"),
},
)
: new AnalysisResourceConstraintError(
"inspect_plist",
resource,
cause.message,
null,
{ cause, capturedOutput, retryable: false },
);
}
if (selection === undefined)
return new ProviderAdapterError(IDENTITY.id, "inspect_plist", {
Expand Down
22 changes: 20 additions & 2 deletions src/native/parsers/plist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,22 @@ import {
} from "../../artifacts/apple/PlistScalars.js";
import {
estimateBinaryPlistExpansion,
MAX_BINARY_PLIST_NESTING_DEPTH,
PropertyListDecodeBudgetFailure,
} from "../../artifacts/apple/PropertyListDecodeBudget.js";
import { fixedAllowanceOptions } from "../../domain/fixedAllowanceRemediation.js";
import { hasBinaryPlistSignature } from "../../domain/apple/appleArchiveFormat.js";

/** Input ceiling matches native command output; projection is bounded separately. */
export const MAX_NATIVE_PLIST_BYTES = 64 * 1024 * 1024;
const MAX_NATIVE_PLIST_DECODE_BYTES = 64 * 1024 * 1024;

const mebibytes = (bytes: number): string =>
`${String(bytes / (1024 * 1024))} MiB`;

/** Recovery name for the fixed source-size ceiling. */
export const NATIVE_PLIST_INPUT_ALLOWANCE = `the fixed ${mebibytes(MAX_NATIVE_PLIST_BYTES)} native plist input allowance`;

const plistObject = z.record(z.string(), z.unknown());

/** Stable bundle metadata projected from one plist value. */
Expand Down Expand Up @@ -287,8 +295,18 @@ export const parsePlistBinary = (
"inspect_plist",
"memory",
cause.message,
{ maximum_decoded_bytes: MAX_NATIVE_PLIST_DECODE_BYTES },
{ cause, retryable: false },
cause.kind === "depth"
? { maximum_nesting_depth: MAX_BINARY_PLIST_NESTING_DEPTH }
: { maximum_decoded_bytes: MAX_NATIVE_PLIST_DECODE_BYTES },
{
cause,
...fixedAllowanceOptions(
cause.kind === "depth"
? `The ${String(MAX_BINARY_PLIST_NESTING_DEPTH)}-level native binary plist nesting allowance`
: `The ${mebibytes(MAX_NATIVE_PLIST_DECODE_BYTES)} native binary plist decode allowance`,
"parser",
),
},
),
);
return err(
Expand Down
11 changes: 2 additions & 9 deletions src/providers/AnalysisClientFailure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
AnalysisAccessDeniedError,
AnalysisArtifactChangedError,
AnalysisResourceConstraintError,
resourceConstraintRecovery,
AnalysisOutputError,
AnalysisTimeoutError,
} from "../domain/analysisErrorCore.js";
Expand Down Expand Up @@ -237,15 +238,7 @@ export const analysisClientFailureForOperation = (
cause.resource,
cause.reason,
cause.reportedLimits,
{
...context,
...(cause.retryable === undefined
? {}
: { retryable: cause.retryable }),
...(cause.remediationAction === undefined
? {}
: { remediationAction: cause.remediationAction }),
},
{ ...context, ...resourceConstraintRecovery(cause) },
);
else
result = new ProviderAdapterError(providerId, operation, {
Expand Down
5 changes: 3 additions & 2 deletions tests/boundary/captures/captureProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { createDeferred } from "../../fixtures/binarySession.js";
import { Cli } from "incur";
import { registerCaptureCommands } from "../../../src/cli/captureCommands.js";
import { silentLogger } from "../../../src/logger.js";
import { analysisErrorRemediationAction } from "../../../src/domain/analysisErrorPresentation.js";

// A command-boundary simulator: real process ownership/filesystem, not real TShark coverage.
const fixture = async (mode = "ok", failCleanup = false) => {
Expand Down Expand Up @@ -623,10 +624,10 @@ it.each([
reportedLimits: { output_bytes: 32 * 1024 * 1024 },
retryable: false,
});
expect(result.error.remediationAction).toContain(
expect(analysisErrorRemediationAction(result.error)).toContain(
"The retained command-output allowance",
);
expect(result.error.remediationAction).not.toMatch(
expect(analysisErrorRemediationAction(result.error)).not.toMatch(
/Review the reported worker memory limits/u,
);
}
Expand Down
Loading
Loading