fix(providers): preserve live cleanup ownership through retries

Share exact command/helper cleanup adoption across Java probes. Preserve complete live resource labels and explicit unknowns through inspection leases, and retain unresolved ownership when a cleanup capability is unavailable.

Validation: focused cleanup, provider/doctor and Kuna consumer checks; shared Ghidra lifecycle and public doctor regressions. Native Windows/Linux provider behavior remains unverified.
This commit is contained in:
morluto committed 2026-10-18 01:59:10 +08:00
1 parent 3ad1032b11
commit 964decd989
15 files changed
+288 -74

No files matched your search

@@ -111,3 +111,34 @@ it("resolves every live retry error bound to one lease", async () => {
expect(firstError.cause).toBe(firstCause);
expect(secondError.cause).toBe(secondCause);
});
it("keeps explicit unknown labels separate from an absent owner label", () => {
const unknown = AnalysisCleanupLease.forCloseOwner(
{
close: async () => {},
get cleanupResources() {
return undefined;
},
},
"display-only",
);
const absent = AnalysisCleanupLease.forCloseOwner(
{ close: async () => {} },
"owned-path",
);
expect(unknown.cleanupResources).toBeUndefined();
expect(absent.cleanupResources).toEqual(["owned-path"]);
});
it.each([false, true])(
"preserves unknown resource labels in pending lease groups (known peer: %s)",
(knownPeer) => {
const unknown = new AnalysisCleanupLease(async () => {});
const error = new ProviderCleanupError("fixture", [], {});
const peers = knownPeer
? [new AnalysisCleanupLease(async () => {}, ["known"]), unknown]
: [unknown];
const group = new AnalysisCleanupLeaseGroup(error, peers);
expect(group.cleanupResources).toBeUndefined();
},
);
+40 -5
View File
@@ -1,4 +1,7 @@
import type { AnalysisError } from "../domain/analysisErrorBase.js";
import type {
AnalysisError,
AnalysisCleanupResourceOwner,
} from "../domain/analysisErrorBase.js";
/** Link one resource's confirmed release to its originating analysis error. */
export class AnalysisCleanupLease {
@@ -11,14 +14,46 @@ export class AnalysisCleanupLease {
return this.#released;
}
readonly cleanupResources: readonly string[] | undefined;
readonly #resourceOwner: AnalysisCleanupResourceOwner | undefined;
readonly #resources: readonly string[] | undefined;
get cleanupResources(): readonly string[] | undefined {
return this.#resourceOwner === undefined
? this.#resources
: this.#resourceOwner.cleanupResources;
}
/** Adopt exact close authority while retaining its live labels across retries. */
static forCloseOwner(
owner: {
close(): Promise<void>;
readonly cleanupResources?: readonly string[] | undefined;
},
resource: string,
): AnalysisCleanupLease {
return new AnalysisCleanupLease(
() => owner.close(),
!("cleanupResources" in owner)
? [resource]
: {
get cleanupResources() {
return owner.cleanupResources;
},
},
);
}
constructor(
private readonly cleanup: () => Promise<void>,
resources?: readonly string[],
resources?: readonly string[] | AnalysisCleanupResourceOwner,
) {
this.cleanupResources =
resources === undefined ? undefined : [...resources];
if (resources !== undefined && "cleanupResources" in resources) {
this.#resourceOwner = resources;
this.#resources = undefined;
} else {
this.#resourceOwner = undefined;
this.#resources = resources === undefined ? undefined : [...resources];
}
}
async release(): Promise<void> {
+5 -2
View File
@@ -205,11 +205,14 @@ export class ArtifactReaderFailure extends Error {
/** Give otherwise opaque cleanup failures a concrete owned resource. */
static cleanupObservation(
cause: unknown,
resource: string,
resource: string | readonly string[],
): AnalysisCleanupObservation {
if (cause instanceof ArtifactReaderFailure && cause.cleanup !== undefined)
return cause.cleanup;
return { reason: errorMessage(cause), resources: [resource] };
return {
reason: errorMessage(cause),
resources: typeof resource === "string" ? [resource] : [...resource],
};
}
}
+6 -1
View File
@@ -179,7 +179,12 @@ export class ArtifactResourceScope {
}
if (failures.length === 0) return;
const observations = failures.map(({ owner, cause }) =>
ArtifactReaderFailure.cleanupObservation(cause, owner.resource),
ArtifactReaderFailure.cleanupObservation(
cause,
owner.kind === "lease" && owner.lease instanceof AnalysisCleanupLease
? (owner.lease.cleanupResources ?? owner.resource)
: owner.resource,
),
);
const resources = [
...new Set(observations.flatMap(({ resources }) => resources)),