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:
morluto authored and GitHub committed 2026-11-10 05:11:20 -05:00
1 parent 55b6d2ca20
commit cb4e5cfbff
515 files changed
+21066 -3637

No files matched your search

+47 -20
View File
@@ -1,3 +1,8 @@
import {
sourceMapLimitSelection,
sourceMapLimitRecovery,
type SourceMapLimits,
} from "../../domain/sourceMapLimits.js";
import { randomUUID } from "node:crypto";
import { writeFile } from "node:fs/promises";
import { join } from "node:path";
@@ -15,7 +20,6 @@ import { ProviderAdapterError } from "../../domain/providerAdapterError.js";
import { ProviderCleanupError } from "../../domain/providerCleanupError.js";
import type { JsonValue } from "../../domain/jsonValue.js";
import { err, type Result } from "../../domain/result.js";
import { noRuntimeOverrideSentence } from "../../domain/browserDeadline.js";
import {
DEFAULT_WEB_SOURCE_MAP_DECODE_TIMEOUT_MS,
WEB_SOURCE_MAP_LIMITS,
@@ -43,9 +47,6 @@ import { prepareProcessOwnershipInspection } from "../../process/ProcessOwnershi
const OPERATION = "trace_web_source_location";
const PROVIDER = "source-map-decoder";
/** Process commit limit enforced on the codec; null where V8 heap flags apply. */
export const SOURCE_MAP_CODEC_MEMORY_LIMIT_BYTES =
javaScriptWorkerMemoryLimitBytes(WEB_SOURCE_MAP_LIMITS.codecHeapMiB);
/** Launcher seam retains the actual codec protocol and ownership supervisor. */
export type SourceMapCodecLauncher = (
options: OwnedProviderProcessSpawnOptions,
@@ -83,7 +84,7 @@ type CodecPhysicalObservation =
readonly message: string;
readonly cause: Error;
}
| { readonly kind: "output-limit" };
| { readonly kind: "output-limit"; readonly stream: "stdout" | "stderr" };
type CodecOutcome =
| {
readonly kind: "physical";
@@ -109,6 +110,7 @@ export const runSourceMapCommand = async (
dependencies: SourceMapDecoderDependencies,
retainedCleanup: SourceMapCleanupRetention,
decodeTimeoutMs: number = DEFAULT_WEB_SOURCE_MAP_DECODE_TIMEOUT_MS,
limits: SourceMapLimits = WEB_SOURCE_MAP_LIMITS,
): Promise<Result<WebSourceMapReport, AnalysisError>> => {
try {
await (dependencies.prepareOwnership ?? prepareProcessOwnershipInspection)(
@@ -136,14 +138,21 @@ export const runSourceMapCommand = async (
decodeTimeoutMs,
options?.signal,
);
const command = new OwnedCodec(path, dependencies, deadline, decodeTimeoutMs);
const command = new OwnedCodec(
path,
dependencies,
deadline,
decodeTimeoutMs,
limits,
);
let result: Result<WebSourceMapReport, AnalysisError>;
try {
await command.start(request);
result = parseSourceMapReply(
await command.collect(),
path,
SOURCE_MAP_CODEC_MEMORY_LIMIT_BYTES,
javaScriptWorkerMemoryLimitBytes(limits.codecHeapMiB),
limits.codecHeapMiB,
);
} catch (cause: unknown) {
result = err(command.failure(cause));
@@ -189,6 +198,7 @@ class OwnedCodec implements SourceMapCleanupOwner {
readonly dependencies: SourceMapDecoderDependencies,
readonly deadline: ProviderStartupDeadline,
readonly decodeTimeoutMs: number,
readonly limits: SourceMapLimits,
) {
this.#onInterruption = () => this.#observeInterruption();
if (deadline.signal.aborted) this.#observeInterruption();
@@ -227,20 +237,25 @@ class OwnedCodec implements SourceMapCleanupOwner {
)({
command: process.execPath,
arguments: [
`--max-old-space-size=${String(WEB_SOURCE_MAP_LIMITS.codecHeapMiB)}`,
`--max-old-space-size=${String(this.limits.codecHeapMiB)}`,
"--max-semi-space-size=8",
"--v8-pool-size=1",
"--single-threaded",
"--stack_size=2048",
fileURLToPath(new URL("./SourceMapCodecProcess.js", import.meta.url)),
requestPath,
JSON.stringify(sourceMapLimitSelection(this.limits)),
],
runId: this.#runId,
cwd: this.#runtime.path,
hostEnvironment: environment,
...(SOURCE_MAP_CODEC_MEMORY_LIMIT_BYTES === null
...(javaScriptWorkerMemoryLimitBytes(this.limits.codecHeapMiB) === null
? {}
: { memoryLimitBytes: SOURCE_MAP_CODEC_MEMORY_LIMIT_BYTES }),
: {
memoryLimitBytes: javaScriptWorkerMemoryLimitBytes(
this.limits.codecHeapMiB,
)!,
}),
signal: this.deadline.signal,
});
this.#supervisor = new ProviderProcessSupervisor(
@@ -252,7 +267,7 @@ class OwnedCodec implements SourceMapCleanupOwner {
(() => cleanupOwnedProcessGroup(spawned.ownership)),
},
{
maxDiagnosticBytes: WEB_SOURCE_MAP_LIMITS.outputBytes + 1024 * 1024,
maxDiagnosticBytes: this.limits.outputBytes + 1024 * 1024,
onDiagnostic: (event) => {
if (
event.type === "exit" &&
@@ -274,10 +289,13 @@ class OwnedCodec implements SourceMapCleanupOwner {
(event.truncated === true ||
event.totalBytes >
(event.stream === "stdout"
? WEB_SOURCE_MAP_LIMITS.outputBytes
? this.limits.outputBytes
: 1024 * 1024))
) {
this.#recordPhysicalFailure({ kind: "output-limit" });
this.#recordPhysicalFailure({
kind: "output-limit",
stream: event.stream,
});
}
},
},
@@ -375,7 +393,7 @@ class OwnedCodec implements SourceMapCleanupOwner {
}
if (observation.kind === "process-error")
return this.#processErrorFailure(observation, snapshot);
return this.#outputLimitFailure(snapshot);
return this.#outputLimitFailure(snapshot, observation.stream);
}
#exitFailure(
@@ -425,6 +443,7 @@ class OwnedCodec implements SourceMapCleanupOwner {
#outputLimitFailure(
snapshot: ProviderProcessSnapshot | undefined,
stream: "stdout" | "stderr",
): AnalysisError {
const outputComplete = this.#supervisor?.observedOutputClose() ?? false;
const capturedOutput = this.#capturedOutput(
@@ -434,8 +453,14 @@ class OwnedCodec implements SourceMapCleanupOwner {
);
return new AnalysisOutputError(
OPERATION,
"Codec output exceeds its complete-evidence or diagnostic budget.",
stream === "stdout"
? "Codec output exceeds its complete-evidence budget."
: "Codec diagnostic output exceeds its 1048576-byte allowance.",
{
remediationAction:
stream === "stdout"
? sourceMapLimitRecovery("output_bytes", this.limits.outputBytes)
: "The codec stderr diagnostic allowance is fixed at 1048576 bytes; no source_map_limits field raises it. Inspect retained diagnostics before another call.",
capturedOutput: {
stdout: capturedOutput?.stdout ?? "",
stderr: capturedOutput?.stderr ?? "",
@@ -469,9 +494,11 @@ class OwnedCodec implements SourceMapCleanupOwner {
return new AnalysisResourceConstraintError(
OPERATION,
"memory",
`Source-map codec reached its ${SOURCE_MAP_CODEC_MEMORY_LIMIT_BYTES === null ? "" : `${String(SOURCE_MAP_CODEC_MEMORY_LIMIT_BYTES)}-byte `}process memory limit for ${this.path}; no partial evidence was returned. ${noRuntimeOverrideSentence(`The ${String(WEB_SOURCE_MAP_LIMITS.codecHeapMiB)} MiB codec heap stays fixed.`, "decode_timeout_ms")}`,
`Source-map codec reached its ${javaScriptWorkerMemoryLimitBytes(this.limits.codecHeapMiB) === null ? "" : `${String(javaScriptWorkerMemoryLimitBytes(this.limits.codecHeapMiB))}-byte `}process memory limit for ${this.path}; no partial evidence was returned. ${sourceMapLimitRecovery("codec_heap_mib", this.limits.codecHeapMiB)}`,
{
codec_process_memory_limit_bytes: SOURCE_MAP_CODEC_MEMORY_LIMIT_BYTES,
codec_process_memory_limit_bytes: javaScriptWorkerMemoryLimitBytes(
this.limits.codecHeapMiB,
),
},
{
capturedOutput: {
@@ -481,9 +508,9 @@ class OwnedCodec implements SourceMapCleanupOwner {
snapshot.diagnosticTruncated === true ||
!(this.#supervisor?.observedOutputClose() ?? false),
},
remediationAction: noRuntimeOverrideSentence(
`The ${String(WEB_SOURCE_MAP_LIMITS.codecHeapMiB)} MiB codec heap, ${String(WEB_SOURCE_MAP_LIMITS.mapBytes)}-byte map budget, and ${String(WEB_SOURCE_MAP_LIMITS.outputBytes)}-byte reply budget stay fixed.`,
"decode_timeout_ms",
remediationAction: sourceMapLimitRecovery(
"codec_heap_mib",
this.limits.codecHeapMiB,
),
},
);