fix(process): preserve observations after successful cleanup

This commit is contained in:
morluto
2026-10-08 23:29:43 +08:00
parent 5e1afe454f
commit 2af12a18a3
5 changed files with 252 additions and 59 deletions
+21 -10
View File
@@ -393,16 +393,27 @@ const lifecycleErrorDetails = (
),
}),
};
if (
error._tag === "ProcessCaptureError" &&
error.userCategory === "cancelled"
)
return { operation: "process_capture", cleanup: "complete" };
if (
error._tag === "ProcessCaptureError" &&
error.executionFailure !== undefined
)
return { execution_failure: error.executionFailure };
if (error._tag === "ProcessCaptureError") {
const details = {
...(error.userCategory === "cancelled"
? { operation: "process_capture", cleanup: "complete" }
: {}),
...(error.cleanupReport === undefined
? {}
: { cleanup_report: jsonValueSchema.parse(error.cleanupReport) }),
...(error.executionFailure === undefined
? {}
: { execution_failure: error.executionFailure }),
...(error.partialObservation === undefined
? {}
: {
partial_observation: jsonValueSchema.parse(
error.partialObservation,
),
}),
};
return Object.keys(details).length === 0 ? undefined : details;
}
if (error instanceof BinaryTargetError)
return {
path: error.path,
+8 -8
View File
@@ -578,7 +578,7 @@ const incompleteCaptureObservationSchema = z.strictObject({
observations: incompleteProcessCaptureObservationsSchema,
});
/** Validated, non-comparable process observations attached to cleanup errors. */
/** Validated, non-comparable process observations attached to execution or cleanup errors. */
export const partialProcessCaptureObservationSchema = z
.union([
completedCaptureObservationSchema.extend(
@@ -589,15 +589,15 @@ export const partialProcessCaptureObservationSchema = z
),
])
.superRefine((partial, context) => {
if (
!Object.values(partial.cleanup).some(
({ state }) => state === "failed" || state === "unverified",
)
)
const cleanupIncomplete = Object.values(partial.cleanup).some(
({ state }) => state === "failed" || state === "unverified",
);
if (!cleanupIncomplete && partial.execution_failure === null)
context.addIssue({
code: "custom",
path: ["cleanup"],
message: "partial observations require incomplete resource cleanup",
path: ["execution_failure"],
message:
"partial observations require incomplete cleanup or an execution failure",
});
if ("observations" in partial) {