fix(providers): preserve artifact producer cancellation facts

Wire sigrok and tshark finalization to the effective signal. Services and file-failure adapters retain exact opaque reasons and completed Evidence instead of guessing from error names. Preserve typed primary outcomes through failed cleanup and recovery.

Validation: latest per-file coverage is 114 passing tests across nine selected files with 14 explicit Linux-only skips; core foundation passes independently. check:fast, docs and discovery pass. Four finalization controls failed before the signal ownership fix. Bounded completed authored-producer service workflows have identical Evidence with no performance improvement claim. Real sigrok/tshark and native Linux/Windows were not verified.

Closes #4858
This commit is contained in:
morluto committed 2026-10-18 02:38:30 +08:00
1 parent 147ae9718a
commit 8a247fc70f
7 files changed
+341 -18

No files matched your search

@@ -49,7 +49,9 @@ export class PacketCaptureService {
): Promise<Result<Evidence, AnalysisError>> {
const operation = "inspect_packet_capture";
if (options?.signal?.aborted)
return err(new AnalysisCancelledError(operation));
return err(
new AnalysisCancelledError(operation, { cause: options.signal.reason }),
);
const input = inspectPacketCaptureInputSchema.safeParse(raw);
if (!input.success)
return err(
@@ -92,7 +94,9 @@ export class PacketCaptureService {
): Promise<Result<Evidence, AnalysisError>> {
const operation = "inspect_packet_fields";
if (options?.signal?.aborted)
return err(new AnalysisCancelledError(operation));
return err(
new AnalysisCancelledError(operation, { cause: options.signal.reason }),
);
const input = inspectPacketFieldsInputSchema.safeParse(raw);
if (!input.success)
return err(
@@ -139,6 +143,7 @@ export class PacketCaptureService {
return options?.signal?.aborted
? err(
new AnalysisCancelledError(operation, {
cause: options.signal.reason,
partialObservation: evidence,
}),
)
@@ -49,7 +49,9 @@ export class SignalRecordingService {
): Promise<Result<Evidence, AnalysisError>> {
const operation = "decode_signal_recording";
if (options?.signal?.aborted)
return err(new AnalysisCancelledError(operation));
return err(
new AnalysisCancelledError(operation, { cause: options.signal.reason }),
);
const input = decodeSignalRecordingInputSchema.safeParse(raw);
if (!input.success)
return err(
@@ -92,7 +94,9 @@ export class SignalRecordingService {
): Promise<Result<Evidence, AnalysisError>> {
const operation = "inspect_signal_decoders";
if (options?.signal?.aborted)
return err(new AnalysisCancelledError(operation));
return err(
new AnalysisCancelledError(operation, { cause: options.signal.reason }),
);
const input = inspectSignalDecodersInputSchema.safeParse(raw);
if (!input.success)
return err(
@@ -139,6 +143,7 @@ export class SignalRecordingService {
return options?.signal?.aborted
? err(
new AnalysisCancelledError(operation, {
cause: options.signal.reason,
partialObservation: evidence,
}),
)
+13 -6
View File
@@ -1,3 +1,4 @@
import { artifactFileCancellationCause } from "../artifacts/ArtifactFileOperation.js";
import {
type InspectPacketFieldsInput,
packetFieldsCatalogSchema,
@@ -130,7 +131,10 @@ export class TsharkCaptureProvider implements PacketCapturePort {
let root: ArtifactAnalysisRuntime | undefined;
let result: Result<AnalysisExecution, AnalysisError>;
try {
if (options?.signal?.aborted) throw new AnalysisCancelledError(operation);
if (options?.signal?.aborted)
throw new AnalysisCancelledError(operation, {
cause: options.signal.reason,
});
await this.#resources.release();
if (this.platform !== "linux")
throw new Error(
@@ -419,6 +423,7 @@ export class TsharkCaptureProvider implements PacketCapturePort {
limitations: execution.limitations,
}),
operation,
options?.signal,
);
}
#failure(
@@ -447,11 +452,13 @@ export class TsharkCaptureProvider implements PacketCapturePort {
observedOutput,
operation,
);
if (
(cause instanceof Error && cause.name === "AbortError") ||
(cause instanceof ArtifactReaderFailure && cause.reason === "cancelled")
)
return new AnalysisCancelledError(operation, { cause });
if (cause instanceof ArtifactReaderFailure && cause.reason === "cancelled")
return new AnalysisCancelledError(operation, {
cause: artifactFileCancellationCause(cause),
...(observedOutput === undefined
? {}
: { capturedOutput: observedOutput }),
});
if (cause instanceof FieldDiscoveryBudgetError)
return new AnalysisResourceConstraintError(
operation,
+13 -6
View File
@@ -1,3 +1,4 @@
import { artifactFileCancellationCause } from "../artifacts/ArtifactFileOperation.js";
import {
type InspectSignalDecodersInput,
signalDecodersSchema,
@@ -126,7 +127,10 @@ export class SigrokRecordingProvider implements SignalRecordingPort {
let root: ArtifactAnalysisRuntime | undefined;
let result: Result<AnalysisExecution, AnalysisError>;
try {
if (options?.signal?.aborted) throw new AnalysisCancelledError(operation);
if (options?.signal?.aborted)
throw new AnalysisCancelledError(operation, {
cause: options.signal.reason,
});
await this.#resources.release();
if (this.platform !== "linux")
throw new Error(
@@ -383,6 +387,7 @@ export class SigrokRecordingProvider implements SignalRecordingPort {
limitations: execution.limitations,
}),
operation,
options?.signal,
);
}
#failure(
@@ -407,11 +412,13 @@ export class SigrokRecordingProvider implements SignalRecordingPort {
observedOutput,
operation,
);
if (
(cause instanceof Error && cause.name === "AbortError") ||
(cause instanceof ArtifactReaderFailure && cause.reason === "cancelled")
)
return new AnalysisCancelledError(operation, { cause });
if (cause instanceof ArtifactReaderFailure && cause.reason === "cancelled")
return new AnalysisCancelledError(operation, {
cause: artifactFileCancellationCause(cause),
...(observedOutput === undefined
? {}
: { capturedOutput: observedOutput }),
});
if (cause instanceof DecoderDiscoveryBudgetError)
return new AnalysisResourceConstraintError(
operation,