fix(providers): preserve observations and primary cleanup failures

This commit is contained in:
morluto
2026-10-09 21:01:52 +08:00
parent 88640f60fe
commit 0696bde266
18 changed files with 629 additions and 232 deletions
+17 -2
View File
@@ -208,7 +208,12 @@ export class SafeOutputTree {
/** Remove only this operation's unsealed tree and verify absence. */
async rollback(): Promise<SafeOutputCleanup> {
if (this.#published) return structuredClone(this.#cleanup);
await rm(this.#outputRoot, { recursive: true, force: true });
let removalFailure: unknown;
try {
await rm(this.#outputRoot, { recursive: true, force: true });
} catch (cause: unknown) {
removalFailure = cause;
}
const absent = await isAbsent(this.#outputRoot);
this.#cleanup = absent
? { status: "complete", residualPaths: [] }
@@ -219,7 +224,17 @@ export class SafeOutputTree {
if (!absent)
throw new ArtifactReaderFailure(
"integrity",
"Extraction output cleanup could not be verified",
`Extraction output cleanup could not be verified${removalFailure === undefined ? "" : `: ${removalFailure instanceof Error ? removalFailure.message : String(removalFailure)}`}`,
{
cause: removalFailure,
cleanup: {
reason:
removalFailure instanceof Error
? removalFailure.message
: "Extraction output root remains after rollback",
resources: [this.#outputRoot],
},
},
);
return structuredClone(this.#cleanup);
}