mirror of
https://github.com/morluto/rea.git
synced 2026-11-17 04:04:25 +00:00
refactor(process): route remaining captured output and cancellations through their owners (#11787)
Migrate the remaining 2 direct AnalysisCancelledError constructions onto cancelledBy and the remaining 14 process-snapshot stdout/stderr copy sites onto capturedProviderOutput, burning down both architecture-guard baselines to zero.
This commit is contained in:
1 parent
1e9df09f68
commit
62f5946ba1
17 files changed
+94
-123
No files matched your search
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"src/gdb/GdbSessionManager.ts": 1,
|
||||
"src/process/ownedDebuggerSession.ts": 1
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
{
|
||||
"src/apktool/ApktoolProvider.ts": 1,
|
||||
"src/application/reverse/ReverseEngineeringService.ts": 3,
|
||||
"src/browser/history/CaptureFailures.ts": 2,
|
||||
"src/captures/TsharkCaptureProvider.ts": 1,
|
||||
"src/desktop/TaskReaderProcess.ts": 1,
|
||||
"src/evm/EvmoleInterfaceProvider.ts": 1,
|
||||
"src/gdb/GdbSessionManager.ts": 1,
|
||||
"src/javascript/recovery/WakaruCommand.ts": 1,
|
||||
"src/javascript/sourceMaps/SourceMapCommand.ts": 1,
|
||||
"src/native/pwntools/PwntoolsDecoder.ts": 1,
|
||||
"src/pcap/PcapCommand.ts": 1,
|
||||
"src/providers/NativeCommandRunner.ts": 1,
|
||||
"src/signals/SigrokRecordingProvider.ts": 1,
|
||||
"src/wasm/WabtArtifactProvider.ts": 1
|
||||
}
|
||||
@@ -180,7 +180,8 @@ const runApktool = async (
|
||||
},
|
||||
signal === undefined ? {} : { signal },
|
||||
);
|
||||
return ok({ stdout: output.stdout.text, stderr: output.stderr.text });
|
||||
const { stdout, stderr } = capturedProviderOutput(output);
|
||||
return ok({ stdout, stderr });
|
||||
} catch (cause) {
|
||||
return err(
|
||||
commands.retainFailure(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { unknownTarget } from "../../domain/targetIdentity.js";
|
||||
import { capturedProviderOutput } from "../../process/capturedProviderOutput.js";
|
||||
import { HOST_PLATFORM } from "../../platform/HostPlatform.js";
|
||||
import { nativeDeadlineRecovery } from "../../domain/native/nativeDeadlines.js";
|
||||
import { Budget } from "../../domain/budget.js";
|
||||
@@ -1372,39 +1373,29 @@ const runOwnedCommandOutput =
|
||||
},
|
||||
{ signal: options.signal },
|
||||
);
|
||||
if (snapshot.signal !== null && snapshot.signal !== undefined)
|
||||
throw new OwnedOutputFailure({
|
||||
stdout: snapshot.stdout.text,
|
||||
stderr: snapshot.stderr.text,
|
||||
code: snapshot.exitCode ?? null,
|
||||
signal: snapshot.signal,
|
||||
outputTruncated: snapshot.diagnosticTruncated === true,
|
||||
stdoutInvalidUtf8: snapshot.stdout.invalidUtf8 === true,
|
||||
stderrInvalidUtf8: snapshot.stderr.invalidUtf8 === true,
|
||||
stdoutBytes: snapshot.stdout.bytes,
|
||||
stderrBytes: snapshot.stderr.bytes,
|
||||
});
|
||||
if (snapshot.exitCode !== 0)
|
||||
throw new OwnedOutputFailure({
|
||||
stdout: snapshot.stdout.text,
|
||||
stderr: snapshot.stderr.text,
|
||||
code: snapshot.exitCode ?? null,
|
||||
signal: null,
|
||||
outputTruncated: snapshot.diagnosticTruncated === true,
|
||||
stdoutInvalidUtf8: snapshot.stdout.invalidUtf8 === true,
|
||||
stderrInvalidUtf8: snapshot.stderr.invalidUtf8 === true,
|
||||
stdoutBytes: snapshot.stdout.bytes,
|
||||
stderrBytes: snapshot.stderr.bytes,
|
||||
});
|
||||
return {
|
||||
stdout: snapshot.stdout.text,
|
||||
stderr: snapshot.stderr.text,
|
||||
outputTruncated: snapshot.diagnosticTruncated === true,
|
||||
const captured = capturedProviderOutput(snapshot);
|
||||
const output = {
|
||||
stdout: captured.stdout,
|
||||
stderr: captured.stderr,
|
||||
outputTruncated: captured.truncated,
|
||||
stdoutInvalidUtf8: snapshot.stdout.invalidUtf8 === true,
|
||||
stderrInvalidUtf8: snapshot.stderr.invalidUtf8 === true,
|
||||
stdoutBytes: snapshot.stdout.bytes,
|
||||
stderrBytes: snapshot.stderr.bytes,
|
||||
};
|
||||
if (snapshot.signal !== null && snapshot.signal !== undefined)
|
||||
throw new OwnedOutputFailure({
|
||||
...output,
|
||||
code: captured.exit_code ?? null,
|
||||
signal: snapshot.signal,
|
||||
});
|
||||
if (snapshot.exitCode !== 0)
|
||||
throw new OwnedOutputFailure({
|
||||
...output,
|
||||
code: captured.exit_code ?? null,
|
||||
signal: null,
|
||||
});
|
||||
return output;
|
||||
} catch (cause) {
|
||||
if (!(cause instanceof OwnedCommandFailure)) throw cause;
|
||||
if (cause.cleanupOwner !== undefined && cause.cleanupFailure !== null)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { capturedProviderOutput } from "../../process/capturedProviderOutput.js";
|
||||
import { javaScriptWorkerMemoryLimitBytes } from "../../process/JavaScriptWorkerMemoryLimit.js";
|
||||
import { isAbortOf } from "../../process/SignalAbort.js";
|
||||
import { captureBudgets } from "./CaptureBudgets.js";
|
||||
@@ -322,10 +323,7 @@ export const historicalCaptureFailure = (
|
||||
cause instanceof OwnedCommandFailure &&
|
||||
cause.snapshot !== null
|
||||
? {
|
||||
exit_code: cause.snapshot.exitCode ?? null,
|
||||
signal: cause.snapshot.signal ?? null,
|
||||
stdout: cause.snapshot.stdout.text,
|
||||
stderr: cause.snapshot.stderr.text,
|
||||
...capturedProviderOutput(cause.snapshot),
|
||||
diagnostic_truncated: cause.snapshot.diagnosticTruncated ?? false,
|
||||
}
|
||||
: {}),
|
||||
@@ -405,11 +403,7 @@ export const captureMemoryFailure = (
|
||||
}),
|
||||
...(cause instanceof OwnedCommandFailure && cause.snapshot !== null
|
||||
? {
|
||||
capturedOutput: {
|
||||
stdout: cause.snapshot.stdout.text,
|
||||
stderr: cause.snapshot.stderr.text,
|
||||
truncated: cause.snapshot.diagnosticTruncated ?? false,
|
||||
},
|
||||
capturedOutput: capturedProviderOutput(cause.snapshot),
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
|
||||
@@ -279,9 +279,9 @@ export class TsharkCaptureProvider implements PacketCapturePort {
|
||||
operation,
|
||||
{
|
||||
diagnostics: {
|
||||
exit_code: output.exitCode ?? null,
|
||||
stdout: output.stdout.text,
|
||||
stderr: output.stderr.text,
|
||||
exit_code: capturedOutput.exit_code ?? null,
|
||||
stdout: capturedOutput.stdout,
|
||||
stderr: capturedOutput.stderr,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
|
||||
import type { ReaderCommandResult } from "../domain/desktop/appTaskReaders.js";
|
||||
import { capturedProviderOutput } from "../process/capturedProviderOutput.js";
|
||||
import { runOwnedCommand } from "../process/OwnedCommand.js";
|
||||
|
||||
/** The most a reader runner prints, its one answer line, plus room for what Python says when it fails. */
|
||||
@@ -33,10 +34,11 @@ export const runReaderHere = async (
|
||||
},
|
||||
signal === undefined ? {} : { signal },
|
||||
);
|
||||
const { exit_code, stdout, stderr } = capturedProviderOutput(snapshot);
|
||||
return {
|
||||
exit_code: snapshot.exitCode ?? null,
|
||||
stdout: snapshot.stdout.text,
|
||||
stderr: snapshot.stderr.text,
|
||||
exit_code: exit_code ?? null,
|
||||
stdout,
|
||||
stderr,
|
||||
timed_out: false,
|
||||
};
|
||||
};
|
||||
@@ -773,8 +773,8 @@ export class EvmoleInterfaceProvider implements EvmInterfacePort {
|
||||
phase,
|
||||
failure_kind: reply.reason,
|
||||
reason: reply.message,
|
||||
stdout: execution.stdout.text,
|
||||
stderr: execution.stderr.text,
|
||||
stdout: capturedOutput.stdout,
|
||||
stderr: capturedOutput.stderr,
|
||||
captured_output: { ...capturedOutput },
|
||||
},
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
unknownTarget,
|
||||
type SessionTargetIdentity,
|
||||
} from "../domain/targetIdentity.js";
|
||||
import { capturedProviderOutput } from "../process/capturedProviderOutput.js";
|
||||
import {
|
||||
observeDebuggerLaunchFile,
|
||||
retryDebuggerStartupFileCleanup,
|
||||
@@ -1014,19 +1015,9 @@ export class GdbSessionManager {
|
||||
: []),
|
||||
],
|
||||
});
|
||||
const processOutput = session.supervisor.snapshot();
|
||||
const capturedOutput = {
|
||||
stdout: processOutput.stdout.text,
|
||||
stderr: processOutput.stderr.text,
|
||||
truncated:
|
||||
processOutput.diagnosticTruncated === true ||
|
||||
processOutput.stdout.observedBytes > processOutput.stdout.bytes ||
|
||||
processOutput.stderr.observedBytes > processOutput.stderr.bytes,
|
||||
stdout_bytes: processOutput.stdout.observedBytes,
|
||||
stderr_bytes: processOutput.stderr.observedBytes,
|
||||
exit_code: processOutput.exitCode ?? null,
|
||||
signal: processOutput.signal ?? null,
|
||||
};
|
||||
const capturedOutput = capturedProviderOutput(
|
||||
session.supervisor.snapshot(),
|
||||
);
|
||||
const stopped = await this.#stopDebuggerOnly(session);
|
||||
if (stopped.status === "incomplete") {
|
||||
this.#sessions.add(session);
|
||||
@@ -2258,10 +2249,13 @@ export class GdbSessionManager {
|
||||
);
|
||||
return;
|
||||
}
|
||||
const cancellation = new AnalysisCancelledError(operation, {
|
||||
cause: signal?.reason,
|
||||
partialObservation: evidence,
|
||||
});
|
||||
const cancellation = cancelledBy(
|
||||
operation,
|
||||
carriedReason(signal?.reason),
|
||||
{
|
||||
partialObservation: evidence,
|
||||
},
|
||||
);
|
||||
const cleanupFailure = this.#sessions.retainCleanupFailure(
|
||||
session,
|
||||
operation,
|
||||
|
||||
@@ -267,8 +267,8 @@ export const runWakaruCommand = async (context: WakaruCommandContext) => {
|
||||
if (failure === undefined || failure instanceof AnalysisError)
|
||||
failure = analysisErrorWithCancellation(failure, cancelled);
|
||||
}
|
||||
if (failure instanceof AnalysisError)
|
||||
failure.retainCapturedOutput(capturedProviderOutput(snapshot));
|
||||
const captured = capturedProviderOutput(snapshot);
|
||||
if (failure instanceof AnalysisError) failure.retainCapturedOutput(captured);
|
||||
if (stopped.status === "incomplete")
|
||||
throw new WakaruCleanupFailure(
|
||||
supervisor,
|
||||
@@ -280,10 +280,10 @@ export const runWakaruCommand = async (context: WakaruCommandContext) => {
|
||||
);
|
||||
if (failure !== undefined) throw failure;
|
||||
return {
|
||||
exit_code: snapshot.exitCode ?? null,
|
||||
signal: snapshot.signal ?? null,
|
||||
stdout: snapshot.stdout.text,
|
||||
stderr: snapshot.stderr.text,
|
||||
exit_code: captured.exit_code ?? null,
|
||||
signal: captured.signal ?? null,
|
||||
stdout: captured.stdout,
|
||||
stderr: captured.stderr,
|
||||
command: context.command,
|
||||
arguments: [...context.arguments],
|
||||
resource_limiter: context.limiter,
|
||||
|
||||
@@ -49,6 +49,7 @@ import {
|
||||
type SpawnedOwnedProviderProcess,
|
||||
} from "../../process/ProviderProcess.js";
|
||||
import { prepareProcessOwnershipInspection } from "../../process/ProcessOwnershipObservation.js";
|
||||
import { capturedProviderOutput } from "../../process/capturedProviderOutput.js";
|
||||
import { errorMessage } from "../../kernel/errorMessage.js";
|
||||
|
||||
const OPERATION = "trace_web_source_location";
|
||||
@@ -544,15 +545,14 @@ class OwnedCodec implements SourceMapCleanupOwner {
|
||||
outputComplete: boolean,
|
||||
) {
|
||||
if (snapshot === undefined) return undefined;
|
||||
const captured = capturedProviderOutput(
|
||||
exit === undefined
|
||||
? snapshot
|
||||
: { ...snapshot, exitCode: exit.code, signal: exit.signal },
|
||||
);
|
||||
return {
|
||||
stdout: snapshot.stdout.text,
|
||||
stderr: snapshot.stderr.text,
|
||||
truncated: snapshot.diagnosticTruncated === true || !outputComplete,
|
||||
stdout_bytes: snapshot.stdout.observedBytes,
|
||||
stderr_bytes: snapshot.stderr.observedBytes,
|
||||
...(exit === undefined
|
||||
? {}
|
||||
: { exit_code: exit.code, signal: exit.signal }),
|
||||
...captured,
|
||||
truncated: captured.truncated || !outputComplete,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -612,8 +612,8 @@ export class PwntoolsDecoder<
|
||||
phase,
|
||||
failure_kind: reply.reason,
|
||||
reason: reply.message,
|
||||
stdout: execution.stdout.text,
|
||||
stderr: execution.stderr.text,
|
||||
stdout: capturedOutput.stdout,
|
||||
stderr: capturedOutput.stderr,
|
||||
captured_output: { ...capturedOutput },
|
||||
},
|
||||
});
|
||||
|
||||
@@ -200,18 +200,19 @@ export const runPcapCommand = async (options: {
|
||||
},
|
||||
},
|
||||
);
|
||||
const unredacted = capturedProviderOutput(output);
|
||||
if (selectedLimiter !== undefined)
|
||||
await assertArtifactCommandPath(selectedLimiter, operation, {
|
||||
get capturedOutput() {
|
||||
return captureDiagnostic(output);
|
||||
return projectDiagnostic(unredacted);
|
||||
},
|
||||
});
|
||||
return {
|
||||
get capturedOutput() {
|
||||
return captureDiagnostic(output);
|
||||
return projectDiagnostic(unredacted);
|
||||
},
|
||||
stdout: output.stdout.text,
|
||||
stderr: output.stderr.text,
|
||||
stdout: unredacted.stdout,
|
||||
stderr: unredacted.stderr,
|
||||
invalidUtf8Streams: [
|
||||
...(output.stdout.invalidUtf8 === true ? (["stdout"] as const) : []),
|
||||
...(output.stderr.invalidUtf8 === true ? (["stderr"] as const) : []),
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
AnalysisCancelledError,
|
||||
AnalysisCapabilityUnavailableError,
|
||||
AnalysisResourceConstraintError,
|
||||
cancelledBy,
|
||||
type AnalysisTimeoutRecovery,
|
||||
} from "../domain/analysisErrorCore.js";
|
||||
import type {
|
||||
@@ -203,15 +204,16 @@ export const retainedDebuggerCleanupFailure = (
|
||||
diagnostics: { ...callerOptions.diagnostics, ...diagnostics },
|
||||
};
|
||||
const primary = options.cause;
|
||||
if (primary instanceof AnalysisCancelledError)
|
||||
return new AnalysisCancelledError(operation, {
|
||||
...options,
|
||||
cause: primary.cause,
|
||||
if (primary instanceof AnalysisCancelledError) {
|
||||
const { cause: _, ...cancelledOptions } = options;
|
||||
return cancelledBy(operation, primary, {
|
||||
...cancelledOptions,
|
||||
capturedOutput: options.capturedOutput ?? primary.capturedOutput,
|
||||
partialObservation:
|
||||
options.partialObservation ?? primary.partialObservation,
|
||||
cleanup,
|
||||
});
|
||||
}
|
||||
return new AnalysisCapabilityUnavailableError(
|
||||
debugger_.provider,
|
||||
operation,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { ProcessInspectionFailure } from "../process/ProcessInspectionCleanup.js";
|
||||
import { capturedProviderOutput } from "../process/capturedProviderOutput.js";
|
||||
import { HOST_PLATFORM } from "../platform/HostPlatform.js";
|
||||
import { processInspectionFailure } from "./OwnedCommandCleanup.js";
|
||||
import { snapshotEnvironment } from "../process/snapshotEnvironment.js";
|
||||
@@ -593,14 +594,17 @@ const processFailureReason = (
|
||||
|
||||
const processCaptureFromSnapshot = (
|
||||
snapshot: ProviderProcessSnapshot,
|
||||
): ProcessCapture => ({
|
||||
stdout: snapshot.stdout.text,
|
||||
stderr: snapshot.stderr.text,
|
||||
stdoutBytes: snapshot.stdout.bytes,
|
||||
stderrBytes: snapshot.stderr.bytes,
|
||||
exitCode: snapshot.exitCode ?? null,
|
||||
signal: snapshot.signal ?? null,
|
||||
});
|
||||
): ProcessCapture => {
|
||||
const captured = capturedProviderOutput(snapshot);
|
||||
return {
|
||||
stdout: captured.stdout,
|
||||
stderr: captured.stderr,
|
||||
stdoutBytes: snapshot.stdout.bytes,
|
||||
stderrBytes: snapshot.stderr.bytes,
|
||||
exitCode: captured.exit_code ?? null,
|
||||
signal: captured.signal ?? null,
|
||||
};
|
||||
};
|
||||
|
||||
const hashFile = (path: string, signal?: AbortSignal): Promise<string> =>
|
||||
new Promise((resolve, reject) => {
|
||||
|
||||
@@ -313,9 +313,9 @@ export class SigrokRecordingProvider implements SignalRecordingPort {
|
||||
operation,
|
||||
{
|
||||
diagnostics: {
|
||||
exit_code: output.exitCode ?? null,
|
||||
stdout: output.stdout.text,
|
||||
stderr: output.stderr.text,
|
||||
exit_code: capturedOutput.exit_code ?? null,
|
||||
stdout: capturedOutput.stdout,
|
||||
stderr: capturedOutput.stderr,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
@@ -531,7 +531,8 @@ export class WabtArtifactProvider implements WasmArtifactPort {
|
||||
)
|
||||
throw new WabtAdmissionError("incomplete_tool_profile");
|
||||
const validation = await execute(validate, validate.arguments, true);
|
||||
if (validation.exitCode !== 0)
|
||||
if (validation.exitCode !== 0) {
|
||||
const validationOutput = capturedProviderOutput(validation);
|
||||
throw new AnalysisInputError(
|
||||
OPERATION,
|
||||
{
|
||||
@@ -544,9 +545,9 @@ export class WabtArtifactProvider implements WasmArtifactPort {
|
||||
result: {
|
||||
...acquiredFacts(),
|
||||
validation: "rejected-by-selected-profile",
|
||||
exit_code: validation.exitCode ?? null,
|
||||
stdout: validation.stdout.text,
|
||||
stderr: validation.stderr.text,
|
||||
exit_code: validationOutput.exit_code ?? null,
|
||||
stdout: validationOutput.stdout,
|
||||
stderr: validationOutput.stderr,
|
||||
},
|
||||
confidence: "observed",
|
||||
locations: [{ kind: "artifact-path", path: input.path }],
|
||||
@@ -558,7 +559,7 @@ export class WabtArtifactProvider implements WasmArtifactPort {
|
||||
],
|
||||
},
|
||||
),
|
||||
capturedOutput: capturedProviderOutput(validation),
|
||||
capturedOutput: validationOutput,
|
||||
},
|
||||
[
|
||||
{
|
||||
@@ -569,6 +570,7 @@ export class WabtArtifactProvider implements WasmArtifactPort {
|
||||
},
|
||||
],
|
||||
);
|
||||
}
|
||||
validationState = "valid";
|
||||
const customSectionWarnings: {
|
||||
tool: (typeof commands)[number]["tool"];
|
||||
|
||||
Reference in new issue
Block a user