mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 13:12:26 +00:00
feat(analysis): make resource budgets recoverable across CLI and MCP (#9706)
* refactor(analysis): centralize resource budgets and recovery facts * feat(analysis): expose ASAR and Ghidra runtime admission controls * feat(artifacts): expose reader admission and preserve limited recognition * feat(javascript): expose recoverable semantic precision budgets * feat(web): add recoverable source-map budgets and compact retained views * feat(web): make historical capture decoding budgets recoverable * fix(desktop): enforce selected view policies across capture and export * feat(runtime): make Frida and LLDB retention budgets selectable * feat(native): expose diagnostic budgets and preserve exhaustion causes * feat(managed): expose recoverable snapshot and representation budgets * feat(metadata): make Go and Rust inspection budgets recoverable * feat(wasm): expose representation and producer admissions * feat(evm): expose per-call worker resource budgets * feat(android): make resource and string-pool omissions recoverable * feat(producers): expose command and recorded-capture budgets * docs(analysis): record recovery contracts and integrated validation * fix(docs): link calibration oracle from published verification pages * fix(docs): restore desktop task anchors and receipt links * test(analysis): align fixtures with selectable budget contracts * fix(analysis): remove source-location projector dependency cycle * test(analysis): refresh budget recovery and verifier regressions * test(analysis): preserve format and publication recovery expectations * test(windows): align conformance with owned runtime admission * fix(desktop): preserve selected alias kinds in exported state * test(analysis): align provider fixtures with recoverable budgets * test(desktop): validate emitted alias metadata structurally * fix(ghidra): classify bounded Windows endpoint refusals * test(cli): assert selectable artifact admission recovery * fix(cli): preserve capture provenance in environment builds
This commit is contained in:
1 parent
55b6d2ca20
commit
cb4e5cfbff
515 files changed
+21066
-3637
No files matched your search
@@ -20,6 +20,18 @@ it.each([
|
||||
path: "/module",
|
||||
command_timeout_ms,
|
||||
})),
|
||||
...[
|
||||
"max_input_bytes",
|
||||
"max_tool_bytes",
|
||||
"max_output_bytes",
|
||||
"max_interface_bytes",
|
||||
"max_artifact_paths",
|
||||
].flatMap((name) =>
|
||||
[0, -1, 1.5, Number.MAX_SAFE_INTEGER + 1, "1000", null].map((value) => ({
|
||||
path: "/module",
|
||||
[name]: value,
|
||||
})),
|
||||
),
|
||||
])("rejects invalid selection before effects: %j", async (input) => {
|
||||
const service = new WasmArtifactService({
|
||||
close: () => Promise.resolve(),
|
||||
@@ -52,19 +64,22 @@ it("preserves the selected command budget in provider input and Evidence", async
|
||||
expect(result.value.normalized_result).toEqual(value);
|
||||
});
|
||||
|
||||
it("rejects a provider report that silently changes the selected command budget", async () => {
|
||||
const value = wasmArtifactFixture();
|
||||
const service = new WasmArtifactService({
|
||||
close: () => Promise.resolve(),
|
||||
inspect: async () => ok(wasmArtifactExecution(value)),
|
||||
});
|
||||
expect(
|
||||
await service.inspect({
|
||||
path: value.artifact.path,
|
||||
command_timeout_ms: 42_000,
|
||||
}),
|
||||
).toMatchObject({ ok: false, error: { _tag: "AnalysisOutputError" } });
|
||||
});
|
||||
it.each([{ command_timeout_ms: 42_000 }, { max_output_bytes: 1024 }])(
|
||||
"rejects a provider report that silently changes the selected budget: %j",
|
||||
async (selection) => {
|
||||
const value = wasmArtifactFixture();
|
||||
const service = new WasmArtifactService({
|
||||
close: () => Promise.resolve(),
|
||||
inspect: async () => ok(wasmArtifactExecution(value)),
|
||||
});
|
||||
expect(
|
||||
await service.inspect({
|
||||
path: value.artifact.path,
|
||||
...selection,
|
||||
}),
|
||||
).toMatchObject({ ok: false, error: { _tag: "AnalysisOutputError" } });
|
||||
},
|
||||
);
|
||||
it.each(["path", "subject-path", "digest", "wat", "candidates", "glue"])(
|
||||
"rejects mismatched upstream observation: %s",
|
||||
async (problem) => {
|
||||
|
||||
@@ -1,19 +1,30 @@
|
||||
import type { AnalysisSettingsReader } from "../../domain/analysisSettings.js";
|
||||
import { constants as bufferConstants } from "node:buffer";
|
||||
import type { ExecutionOptions } from "../AnalysisProvider.js";
|
||||
import { createAnalysisExecutionEvidence } from "../../domain/analysisObservation.js";
|
||||
import {
|
||||
analysisExecutionEnvelopeForAdmission,
|
||||
createAnalysisExecutionEvidence,
|
||||
} from "../../domain/analysisObservation.js";
|
||||
import type { WasmArtifactPort } from "./WasmArtifactPort.js";
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import { AnalysisOutputError } from "../../domain/analysisErrorCore.js";
|
||||
import {
|
||||
AnalysisOutputError,
|
||||
AnalysisResourceConstraintError,
|
||||
} from "../../domain/analysisErrorCore.js";
|
||||
import type { Evidence } from "../../domain/evidence.js";
|
||||
import {
|
||||
inspectWasmArtifactInputSchema,
|
||||
wasmArtifactSchema,
|
||||
wasmArtifactMatchesSubject,
|
||||
DEFAULT_WASM_COMMAND_TIMEOUT_MS,
|
||||
DEFAULT_WASM_ARTIFACT_PATHS,
|
||||
MAX_WASM_ARTIFACT_PATHS,
|
||||
wasmResourceLimits,
|
||||
} from "../../domain/wasm/wasmArtifact.js";
|
||||
import { err, type Result } from "../../domain/result.js";
|
||||
import { completeProviderEvidence } from "../ProviderOperationExecution.js";
|
||||
import { parseAnalysisInput } from "../AnalysisInput.js";
|
||||
import { requireAuthenticationHeadroom } from "../JsonAuthenticationHeadroom.js";
|
||||
|
||||
const OPERATION = "inspect_wasm_artifact";
|
||||
|
||||
@@ -41,6 +52,32 @@ export class WasmArtifactService {
|
||||
options?.signal,
|
||||
);
|
||||
if (!input.ok) return input;
|
||||
const maximumPaths =
|
||||
input.value.max_artifact_paths ?? DEFAULT_WASM_ARTIFACT_PATHS;
|
||||
for (const field of ["glue_paths", "candidate_paths"] as const) {
|
||||
if (input.value[field].length > maximumPaths)
|
||||
return err(
|
||||
new AnalysisResourceConstraintError(
|
||||
OPERATION,
|
||||
"capacity",
|
||||
`${field} exceeds max_artifact_paths (${String(maximumPaths)} paths)`,
|
||||
{
|
||||
maximum_paths: maximumPaths,
|
||||
default_paths: DEFAULT_WASM_ARTIFACT_PATHS,
|
||||
source:
|
||||
input.value.max_artifact_paths === undefined
|
||||
? "default"
|
||||
: "request",
|
||||
selected_paths: input.value[field].length,
|
||||
input_field: field,
|
||||
},
|
||||
{
|
||||
retryable: false,
|
||||
remediationAction: `Raise max_artifact_paths to at least ${String(input.value[field].length)} (maximum ${String(MAX_WASM_ARTIFACT_PATHS)}), or use --max-artifact-paths on the CLI; then retry the same selection. The value applies on the next inspection without restart. File and command byte budgets remain independent.`,
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
const timeout =
|
||||
input.value.command_timeout_ms ??
|
||||
this.settings?.().overrides["wasm.command_timeout_ms"] ??
|
||||
@@ -51,12 +88,29 @@ export class WasmArtifactService {
|
||||
});
|
||||
if (!inspected.ok) return inspected;
|
||||
const execution = inspected.value;
|
||||
const admission = requireAuthenticationHeadroom(
|
||||
analysisExecutionEnvelopeForAdmission(
|
||||
OPERATION,
|
||||
input.value,
|
||||
execution,
|
||||
"observed",
|
||||
),
|
||||
{
|
||||
operation: OPERATION,
|
||||
path: input.value.path,
|
||||
description: "Complete WASM Evidence cannot be assembled",
|
||||
serializedCodeUnitLimit: bufferConstants.MAX_STRING_LENGTH,
|
||||
},
|
||||
);
|
||||
if (!admission.ok) return admission;
|
||||
const report = wasmArtifactSchema.safeParse(execution.result);
|
||||
if (
|
||||
!report.success ||
|
||||
report.data.artifact.path !== input.value.path ||
|
||||
execution.subject.path !== input.value.path ||
|
||||
report.data.tool_profile.timeout_ms !== timeout ||
|
||||
report.data.tool_profile.output_budget_bytes !==
|
||||
wasmResourceLimits(input.value).outputBytes ||
|
||||
!wasmArtifactMatchesSubject(report.data.artifact, execution.subject) ||
|
||||
JSON.stringify(report.data.glue.map((item) => item.artifact.path)) !==
|
||||
JSON.stringify(input.value.glue_paths) ||
|
||||
|
||||
@@ -6,11 +6,7 @@ import { wasmInterfaceComparisonSchema } from "../../contracts/wasm/wasmComparis
|
||||
import { compareWasmInterfaces } from "./WasmInterfaceComparisonService.js";
|
||||
import { retainAnalysisResultSources } from "../investigation/recordEvidenceSources.js";
|
||||
import { ok } from "../../domain/result.js";
|
||||
import {
|
||||
WASM_INTERFACE_REPRESENTATION_BYTES,
|
||||
wasmInterfaceEntryRepresentationBytes,
|
||||
type WasmInterface,
|
||||
} from "../../domain/wasm/wasmInterface.js";
|
||||
import type { WasmInterface } from "../../domain/wasm/wasmInterface.js";
|
||||
import { wasmArtifactFixture } from "../../../tests/fixtures/wasm/artifact.js";
|
||||
|
||||
const facts = (
|
||||
@@ -240,69 +236,43 @@ it("resolves exact retained references and permits cancellation between comparis
|
||||
expect(cancelled.error.partialObservation).toBeUndefined();
|
||||
});
|
||||
|
||||
/** One inventory under the comparison cap; two of them exceed it together. */
|
||||
const admittedInventory = (label: string): WasmInterface => {
|
||||
const base = facts(label).entries[0]!;
|
||||
const minimum = Math.floor(WASM_INTERFACE_REPRESENTATION_BYTES / 2) + 4096;
|
||||
let low = 0;
|
||||
let high = 4_000_000;
|
||||
let best = 0;
|
||||
while (low <= high) {
|
||||
const mid = Math.floor((low + high) / 2);
|
||||
const name = `${label}-${"n".repeat(mid)}`;
|
||||
const bytes = wasmInterfaceEntryRepresentationBytes({
|
||||
...base,
|
||||
name,
|
||||
wat_form: `(export "${name}" (func 0))`,
|
||||
});
|
||||
if (bytes >= minimum) {
|
||||
best = mid;
|
||||
high = mid - 1;
|
||||
} else low = mid + 1;
|
||||
}
|
||||
const name = `${label}-${"n".repeat(best)}`;
|
||||
const entry = {
|
||||
...base,
|
||||
name,
|
||||
wat_form: `(export "${name}" (func 0))`,
|
||||
};
|
||||
const bytes = wasmInterfaceEntryRepresentationBytes(entry);
|
||||
if (
|
||||
bytes >= WASM_INTERFACE_REPRESENTATION_BYTES ||
|
||||
bytes + 512 >= WASM_INTERFACE_REPRESENTATION_BYTES
|
||||
)
|
||||
throw new Error("Sized inventory is not individually admitted");
|
||||
return { state: "complete", issues: [], entries: [entry] };
|
||||
};
|
||||
|
||||
it("refuses two admitted inventories that together exceed the comparison cap", async () => {
|
||||
const left = admittedInventory("left");
|
||||
const right = admittedInventory("right");
|
||||
const empty: WasmInterface = { state: "complete", issues: [], entries: [] };
|
||||
it("admits each selected inventory independently and recovers a combined comparison with more capacity", async () => {
|
||||
const left = evidence(facts("left"));
|
||||
const right = evidence(facts("right"));
|
||||
const empty = evidence({ state: "complete", issues: [], entries: [] });
|
||||
const alone = await compareWasmInterfaces({
|
||||
left: evidence(left),
|
||||
right: evidence(empty),
|
||||
left,
|
||||
right: empty,
|
||||
scope: "both",
|
||||
max_interface_bytes: 2048,
|
||||
});
|
||||
expect(alone.ok).toBe(true);
|
||||
const selected = { left, right, scope: "both" as const };
|
||||
const combined = await compareWasmInterfaces({
|
||||
left: evidence(left),
|
||||
right: evidence(right),
|
||||
scope: "both",
|
||||
...selected,
|
||||
max_interface_bytes: 2048,
|
||||
});
|
||||
if (combined.ok) throw new Error("Expected comparison allowance refusal");
|
||||
if (combined.ok)
|
||||
throw new Error("Expected combined comparison capacity refusal");
|
||||
const projected = projectAnalysisError(combined.error);
|
||||
expect(projected.retryable).toBe(false);
|
||||
expect(projected.code).toBe("resource_constraint");
|
||||
expect(combined.error).toMatchObject({ resource: "capacity" });
|
||||
expect(projected.remediation.action).toContain(
|
||||
"The WASM interface comparison inventory",
|
||||
);
|
||||
expect(projected.remediation.action).toContain("fixed byte allowance");
|
||||
expect(projected.remediation.action).not.toContain("fixed count");
|
||||
expect(projected.remediation.action).not.toMatch(
|
||||
/Wait for an active analysis/u,
|
||||
);
|
||||
expect(projected).toMatchObject({
|
||||
code: "resource_constraint",
|
||||
retryable: false,
|
||||
details: { reported_limits: { maximum_bytes: 2048, source: "request" } },
|
||||
});
|
||||
expect(projected.remediation.action).toContain("max_interface_bytes");
|
||||
const recovered = await compareWasmInterfaces({
|
||||
...selected,
|
||||
max_interface_bytes: 8192,
|
||||
});
|
||||
if (!recovered.ok) throw recovered.error;
|
||||
expect(recovered.value.evidence.normalized_result).toMatchObject({
|
||||
coverage: "complete-within-inputs",
|
||||
summary: { added: 1, removed: 1 },
|
||||
});
|
||||
expect(recovered.value.evidence.parameters).toMatchObject({
|
||||
max_interface_bytes: 8192,
|
||||
});
|
||||
});
|
||||
|
||||
it.each([false, true])(
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
import {
|
||||
WASM_INTERFACE_REPRESENTATION_BYTES,
|
||||
wasmInterfaceEntryRepresentationBytes,
|
||||
} from "../../domain/wasm/wasmInterface.js";
|
||||
import { wasmInterfaceEntryRepresentationBytes } from "../../domain/wasm/wasmInterface.js";
|
||||
import { setImmediate } from "node:timers/promises";
|
||||
import { constants as bufferConstants } from "node:buffer";
|
||||
import { requireAuthenticationHeadroom } from "../JsonAuthenticationHeadroom.js";
|
||||
import { ARTIFACT_COMPARISON_PROVIDER } from "../../domain/comparisonEvidenceIdentity.js";
|
||||
import {
|
||||
compareWasmInterfacesInputSchema,
|
||||
wasmInterfaceComparisonSchema,
|
||||
} from "../../contracts/wasm/wasmComparisonContracts.js";
|
||||
import { createEvidence, type Evidence } from "../../domain/evidence.js";
|
||||
import {
|
||||
createEvidence,
|
||||
evidenceEnvelopeForAdmission,
|
||||
type Evidence,
|
||||
} from "../../domain/evidence.js";
|
||||
import {
|
||||
wasmArtifactSchema,
|
||||
wasmArtifactMatchesSubject,
|
||||
@@ -18,9 +21,8 @@ import type { WasmInterfaceEntry } from "../../domain/wasm/wasmInterface.js";
|
||||
import {
|
||||
AnalysisCancelledError,
|
||||
AnalysisInputError,
|
||||
AnalysisResourceConstraintError,
|
||||
} from "../../domain/analysisErrorCore.js";
|
||||
import { fixedAllowanceOptions } from "../../domain/fixedAllowanceRemediation.js";
|
||||
import { WasmInterfaceBudget } from "../../domain/wasm/wasmInterfaceBudget.js";
|
||||
import { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import { err, ok, type Result } from "../../domain/result.js";
|
||||
import {
|
||||
@@ -131,6 +133,10 @@ export const compareWasmInterfaces = async (
|
||||
entry: WasmInterfaceEntry;
|
||||
}
|
||||
>();
|
||||
const budget = new WasmInterfaceBudget(
|
||||
resolved.value.input.max_interface_bytes,
|
||||
OPERATION,
|
||||
);
|
||||
let work = 0;
|
||||
for (const [side, inspection] of [
|
||||
["left", left],
|
||||
@@ -142,9 +148,11 @@ export const compareWasmInterfaces = async (
|
||||
assertActive();
|
||||
}
|
||||
if (!selected(entry)) continue;
|
||||
budget.reserve(wasmInterfaceEntryRepresentationBytes(entry));
|
||||
const key = JSON.stringify([entry.direction, entry.module, entry.name]);
|
||||
let group = groups.get(key);
|
||||
if (group === undefined) {
|
||||
budget.reserve(512);
|
||||
group = { left: [], right: [], entry };
|
||||
groups.set(key, group);
|
||||
}
|
||||
@@ -162,29 +170,7 @@ export const compareWasmInterfaces = async (
|
||||
unchanged: 0,
|
||||
unknown: 0,
|
||||
};
|
||||
let remaining = WASM_INTERFACE_REPRESENTATION_BYTES;
|
||||
for (const group of groups.values()) {
|
||||
remaining -=
|
||||
512 +
|
||||
group.left.reduce(
|
||||
(sum, entry) => sum + wasmInterfaceEntryRepresentationBytes(entry),
|
||||
0,
|
||||
) +
|
||||
group.right.reduce(
|
||||
(sum, entry) => sum + wasmInterfaceEntryRepresentationBytes(entry),
|
||||
0,
|
||||
);
|
||||
if (remaining < 0)
|
||||
throw new AnalysisResourceConstraintError(
|
||||
OPERATION,
|
||||
"capacity",
|
||||
"WASM comparison exceeds typed interface representation capacity",
|
||||
{ maximum_bytes: WASM_INTERFACE_REPRESENTATION_BYTES },
|
||||
fixedAllowanceOptions(
|
||||
"The WASM interface comparison inventory",
|
||||
"bytes",
|
||||
),
|
||||
);
|
||||
if (++work % 256 === 0) {
|
||||
await setImmediate();
|
||||
assertActive();
|
||||
@@ -251,7 +237,7 @@ export const compareWasmInterfaces = async (
|
||||
"Exact declared interface equality is not runtime/ABI compatibility, successful linking or original-source identity.",
|
||||
"Typed facts come from the selected validated WABT decoding; unsupported signature semantics and duplicate names remain unknown.",
|
||||
];
|
||||
const report = wasmInterfaceComparisonSchema.parse({
|
||||
const observedReport = {
|
||||
left: {
|
||||
evidence_id: left.evidence.evidence_id,
|
||||
artifact: left.result.artifact,
|
||||
@@ -265,20 +251,42 @@ export const compareWasmInterfaces = async (
|
||||
changes,
|
||||
summary,
|
||||
limitations,
|
||||
});
|
||||
const evidence = createEvidence(undefined, ARTIFACT_COMPARISON_PROVIDER, {
|
||||
};
|
||||
const observation = {
|
||||
operation: OPERATION,
|
||||
predicateType: "rea.wasm-interface-comparison",
|
||||
parameters: {
|
||||
left_evidence_id: left.evidence.evidence_id,
|
||||
right_evidence_id: right.evidence.evidence_id,
|
||||
scope,
|
||||
...(resolved.value.input.max_interface_bytes === undefined
|
||||
? {}
|
||||
: { max_interface_bytes: resolved.value.input.max_interface_bytes }),
|
||||
},
|
||||
result: report,
|
||||
confidence: "derived",
|
||||
authority: "analyst-inference",
|
||||
result: observedReport,
|
||||
confidence: "derived" as const,
|
||||
authority: "analyst-inference" as const,
|
||||
limitations,
|
||||
evidenceLinks: [left.evidence.evidence_id, right.evidence.evidence_id],
|
||||
};
|
||||
const admission = requireAuthenticationHeadroom(
|
||||
evidenceEnvelopeForAdmission(
|
||||
undefined,
|
||||
ARTIFACT_COMPARISON_PROVIDER,
|
||||
observation,
|
||||
),
|
||||
{
|
||||
operation: OPERATION,
|
||||
path: "selected WASM Evidence",
|
||||
description: "Complete WASM comparison Evidence cannot be assembled",
|
||||
serializedCodeUnitLimit: bufferConstants.MAX_STRING_LENGTH,
|
||||
},
|
||||
);
|
||||
if (!admission.ok) return admission;
|
||||
const report = wasmInterfaceComparisonSchema.parse(observedReport);
|
||||
const evidence = createEvidence(undefined, ARTIFACT_COMPARISON_PROVIDER, {
|
||||
...observation,
|
||||
result: report,
|
||||
});
|
||||
await setImmediate();
|
||||
const completed = completeProviderEvidence(evidence, options?.signal);
|
||||
|
||||
Reference in new issue
Block a user