mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 11:43:20 +00:00
refactor(process): let Darwin helper cleanup errors read their owner's release (#10801)
* refactor(errors): read cleanup completion from dependencies instead of pushing it to dependents AnalysisError.cleanupIncomplete becomes a getter over the error's own unresolved state and its bound dependencies. The WeakRef dependents graph and resolveCleanup's push propagation are removed, and subclasses mark their initial state through markCleanupIncomplete instead of overriding a public mutable field. * fix(errors): settle bound dependencies before binding more A composite whose dependencies had released but whose status was never read stayed incomplete when a later dependency was bound. * refactor(errors): let errors read a lease group's release instead of resolving them (#10759) AnalysisCleanupLeaseGroup no longer calls resolveCleanup() on its error. The error holds the group as a release claim and reads cleanupReleased when asked, so completion follows the lease owner without a push. * chore(verify): count resolveCleanup and bindCleanupDependencies calls so they only shrink (#10763) * refactor(errors): let errors read a lease group's release instead of resolving them AnalysisCleanupLeaseGroup no longer calls resolveCleanup() on its error. The error holds the group as a release claim and reads cleanupReleased when asked, so completion follows the lease owner without a push. * chore(verify): count resolveCleanup and bindCleanupDependencies calls so they only shrink * refactor(process): let worker cleanup errors read their root epoch's release OwnedWorkerRuntime's root epoch is now an AnalysisCleanupReleaseClaim. Errors bound to it read its release when asked instead of the epoch pushing resolveCleanup() through weak references, and a runtime without a retained root binds an already-released owner. Removes the OwnedWorkerCleanupFailure structural type and four resolveCleanup() pushes; the counted baseline shrinks accordingly. * refactor(pcap): let pcap cleanup errors read command and snapshot release (#10792) Retained pcap commands, retained snapshot failures and snapshot completion descriptors now own their release and errors read it: commands and snapshot failures implement AnalysisCleanupReleaseClaim, and a failed completion-descriptor close is retried through an AnalysisCleanupLease bound to its error. Removes four resolveCleanup() pushes; the counted baseline shrinks accordingly. * refactor(process): let Darwin helper cleanup errors read their owner's release Darwin helper cache and run-token reader root cleanup now record an AnalysisCleanupRelease that every failure reports; a successful retry confirms it. Replaces the first-failure anchor that later failures depended on and the resolveCleanup() push. Removes two resolveCleanup() and two bindCleanupDependencies() calls; both counted baselines shrink. * refactor(ghidra): let Ghidra cleanup errors read the client's and checkpoint's release (#10802) GhidraClient and GhidraCheckpoint bind each cleanup failure to an AnalysisCleanupRelease and confirm it when a later close or retry releases everything, instead of keeping a set of failures and pushing resolveCleanup() to each. Removes two resolveCleanup() calls; the counted baseline shrinks.
This commit is contained in:
1 parent
3afd8a16ee
commit
df0bdd9f58
7 files changed
+84
-31
No files matched your search
@@ -366,15 +366,11 @@
|
||||
"src/desktop/AgentEnvSolveHelper.ts": 2,
|
||||
"src/desktop/BuildComputerLongRuns.ts": 1,
|
||||
"src/desktop/ScreenJudgeProcess.ts": 1,
|
||||
"src/ghidra/GhidraCheckpoint.ts": 1,
|
||||
"src/ghidra/GhidraClient.ts": 1,
|
||||
"src/ida/IdaSessionClient.ts": 1,
|
||||
"src/javascript/sourceMaps/SourceMapCommand.ts": 1,
|
||||
"src/kuna/KunaProjectCache.ts": 1,
|
||||
"src/native/CommandRunner.ts": 1,
|
||||
"src/native/LldbCallTracer.ts": 1,
|
||||
"src/process/DarwinHelperCache.ts": 1,
|
||||
"src/process/DarwinProcessRunTokenReader.ts": 1,
|
||||
"src/process/OwnedDebuggerSessionRegistry.ts": 1,
|
||||
"src/providers/AnalysisClientFailure.ts": 1,
|
||||
"src/server/environment/serveEnvironment.ts": 1,
|
||||
@@ -485,8 +481,7 @@
|
||||
"src/pcap/PcapProvider.ts": 7,
|
||||
"src/pcap/PcapSnapshot.ts": 1,
|
||||
"src/process/ArtifactAnalysisResources.ts": 4,
|
||||
"src/process/DarwinHelperCache.ts": 1,
|
||||
"src/process/DarwinProcessRunTokenReader.ts": 3,
|
||||
"src/process/DarwinProcessRunTokenReader.ts": 2,
|
||||
"src/process/capture/FilesystemSnapshot.ts": 1,
|
||||
"src/process/capture/ProcessCaptureError.ts": 3,
|
||||
"src/process/capture/ProcessCaptureLifecycle.ts": 1,
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { AnalysisCleanupRelease } from "./analysisCleanupRelease.js";
|
||||
import { ProviderCleanupError } from "./providerCleanupError.js";
|
||||
|
||||
const failure = () =>
|
||||
new ProviderCleanupError(
|
||||
"process-ownership",
|
||||
["/tmp/rea-owned"],
|
||||
{ reason: "removal failed" },
|
||||
{ operation: "prepare_owned_process" },
|
||||
);
|
||||
|
||||
it("lets every bound error read one owner's confirmed release", () => {
|
||||
const release = new AnalysisCleanupRelease();
|
||||
const first = release.bind(failure());
|
||||
const second = release.bind(failure());
|
||||
expect([first.cleanupIncomplete, second.cleanupIncomplete]).toEqual([
|
||||
true,
|
||||
true,
|
||||
]);
|
||||
|
||||
release.confirm();
|
||||
|
||||
expect([first.cleanupIncomplete, second.cleanupIncomplete]).toEqual([
|
||||
false,
|
||||
false,
|
||||
]);
|
||||
// An error bound after the release reads it immediately.
|
||||
expect(release.bind(failure()).cleanupIncomplete).toBe(false);
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
import type {
|
||||
AnalysisCleanupReleaseClaim,
|
||||
AnalysisError,
|
||||
} from "./analysisErrorBase.js";
|
||||
|
||||
/**
|
||||
* Release recorded by an owner that retries its cleanup in place instead of
|
||||
* through one `close()`. Errors bound to it read the release when asked; it is
|
||||
* never pushed to them. Start a new one for each unreleased cleanup.
|
||||
*/
|
||||
export class AnalysisCleanupRelease implements AnalysisCleanupReleaseClaim {
|
||||
#released = false;
|
||||
|
||||
get cleanupReleased(): boolean {
|
||||
return this.#released;
|
||||
}
|
||||
|
||||
/** Let `error` report this owner's release whenever it is asked. */
|
||||
bind<T extends AnalysisError>(error: T): T {
|
||||
return error.bindCleanupReleaseClaim(this);
|
||||
}
|
||||
|
||||
confirm(): void {
|
||||
this.#released = true;
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import { z } from "zod";
|
||||
import type { AnalysisProfileCommitment } from "../domain/analysisProfile.js";
|
||||
import { ConfigurationError } from "../domain/configurationErrors.js";
|
||||
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
|
||||
import { AnalysisCleanupRelease } from "../domain/analysisCleanupRelease.js";
|
||||
import { analysisErrorWithCleanupFailure } from "../domain/analysisErrorCleanup.js";
|
||||
import type { ArtifactResourceScope } from "../artifacts/ArtifactResourceScope.js";
|
||||
import {
|
||||
@@ -204,7 +205,8 @@ export class GhidraCheckpoint {
|
||||
#source: CheckpointSource | null | undefined;
|
||||
#state: GhidraCheckpointSelection["state"];
|
||||
readonly #pendingRemoval = new Set<string>();
|
||||
readonly #cleanupFailures = new Set<ProviderCleanupError>();
|
||||
/** Reported by every removal failure until a retry removes every file. */
|
||||
#cleanupRelease = new AnalysisCleanupRelease();
|
||||
#publishedInput: string | undefined;
|
||||
constructor(
|
||||
readonly selection: GhidraCheckpointSelection,
|
||||
@@ -406,12 +408,11 @@ export class GhidraCheckpoint {
|
||||
},
|
||||
{ cause },
|
||||
);
|
||||
this.#cleanupFailures.add(error);
|
||||
throw error;
|
||||
throw this.#cleanupRelease.bind(error);
|
||||
}
|
||||
}
|
||||
for (const failure of this.#cleanupFailures) failure.resolveCleanup();
|
||||
this.#cleanupFailures.clear();
|
||||
this.#cleanupRelease.confirm();
|
||||
this.#cleanupRelease = new AnalysisCleanupRelease();
|
||||
}
|
||||
async close(): Promise<void> {
|
||||
await this.retryCleanup();
|
||||
|
||||
@@ -17,6 +17,7 @@ import { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
import type { NativeValueFlowLimits } from "../domain/native/nativeValueFlow.js";
|
||||
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
|
||||
import { AnalysisCleanupRelease } from "../domain/analysisCleanupRelease.js";
|
||||
import {
|
||||
providerRetryAction,
|
||||
type ProviderOperationHealth,
|
||||
@@ -163,7 +164,8 @@ export class GhidraClient {
|
||||
| { readonly path: string; readonly disposition: "publish" | "discard" }
|
||||
| undefined;
|
||||
#checkpointRestore: GhidraPackedProgram | undefined;
|
||||
readonly #cleanupFailures = new Set<AnalysisError>();
|
||||
/** Reported by every cleanup failure until a close releases everything. */
|
||||
#cleanupRelease = new AnalysisCleanupRelease();
|
||||
#targetAdmission: JsonValue | undefined;
|
||||
#token: string | undefined;
|
||||
// Retain authentication identities for diagnostics from late request settlement.
|
||||
@@ -894,8 +896,7 @@ export class GhidraClient {
|
||||
];
|
||||
},
|
||||
});
|
||||
this.#cleanupFailures.add(failure);
|
||||
return failure;
|
||||
return this.#cleanupRelease.bind(failure);
|
||||
}
|
||||
|
||||
/** Observed failures that prevent a retained session from being reused. */
|
||||
@@ -1436,8 +1437,8 @@ export class GhidraClient {
|
||||
this.#runId = undefined;
|
||||
this.#responseLines.reset();
|
||||
if (forcedStopFailure !== undefined) throw forcedStopFailure.cause;
|
||||
for (const failure of this.#cleanupFailures) failure.resolveCleanup();
|
||||
this.#cleanupFailures.clear();
|
||||
this.#cleanupRelease.confirm();
|
||||
this.#cleanupRelease = new AnalysisCleanupRelease();
|
||||
} finally {
|
||||
this.#closing = false;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import { dirname, isAbsolute, join } from "node:path";
|
||||
import { z } from "zod";
|
||||
|
||||
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
|
||||
import { AnalysisCleanupRelease } from "../domain/analysisCleanupRelease.js";
|
||||
import { safeParseJson } from "../domain/safeJson.js";
|
||||
import { appendCallerPath } from "../filesystem/callerPath.js";
|
||||
import type { OwnedFileHandle } from "../filesystem/OwnedFileHandle.js";
|
||||
@@ -169,8 +170,8 @@ export const createDarwinHelperCache = (options: {
|
||||
const uid = process.getuid?.();
|
||||
// Failed closes and removals stay owned until close() retries them.
|
||||
const retained = new Map<string | OwnedFileHandle, () => Promise<void>>();
|
||||
// The first unresolved close failure; later ones depend on it.
|
||||
let cleanupAnchor: ProviderCleanupError | undefined;
|
||||
// Every close failure reports this release until a retry releases them all.
|
||||
let cleanupRelease: AnalysisCleanupRelease | undefined;
|
||||
let key: Promise<string> | undefined;
|
||||
|
||||
const xcrun = async (
|
||||
@@ -462,13 +463,10 @@ export const createDarwinHelperCache = (options: {
|
||||
operation: "prepare_owned_process",
|
||||
},
|
||||
);
|
||||
// Every returned failure clears once a later retry releases them all.
|
||||
if (cleanupAnchor === undefined) cleanupAnchor = failure;
|
||||
else failure.bindCleanupDependencies([cleanupAnchor]);
|
||||
throw failure;
|
||||
throw (cleanupRelease ??= new AnalysisCleanupRelease()).bind(failure);
|
||||
}
|
||||
cleanupAnchor?.resolveCleanup();
|
||||
cleanupAnchor = undefined;
|
||||
cleanupRelease?.confirm();
|
||||
cleanupRelease = undefined;
|
||||
};
|
||||
|
||||
return { lookup, publish, close };
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
import { MAX_NODE_TIMER_DELAY_MS } from "../domain/analysisResourceLimits.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
import { ProviderCleanupError } from "../domain/providerCleanupError.js";
|
||||
import { AnalysisCleanupRelease } from "../domain/analysisCleanupRelease.js";
|
||||
import type {
|
||||
AnalysisCapturedOutput,
|
||||
AnalysisError,
|
||||
@@ -370,7 +371,8 @@ const compilerInspectionError = (
|
||||
interface ProcessReaderRoot {
|
||||
readonly path: string;
|
||||
cleanupPromise?: Promise<void> | undefined;
|
||||
cleanupAnchor?: ProviderCleanupError | undefined;
|
||||
/** Reported by every removal failure until a retry removes the root. */
|
||||
cleanupRelease?: AnalysisCleanupRelease | undefined;
|
||||
}
|
||||
|
||||
interface ProcessReaderCompilation {
|
||||
@@ -508,13 +510,12 @@ export const createDarwinProcessRunTokenReader = (
|
||||
},
|
||||
{ cause, operation: "prepare_owned_process" },
|
||||
);
|
||||
if (target.cleanupAnchor === undefined)
|
||||
target.cleanupAnchor = failure;
|
||||
else failure.bindCleanupDependencies([target.cleanupAnchor]);
|
||||
throw failure;
|
||||
throw (target.cleanupRelease ??= new AnalysisCleanupRelease()).bind(
|
||||
failure,
|
||||
);
|
||||
}
|
||||
target.cleanupAnchor?.resolveCleanup();
|
||||
target.cleanupAnchor = undefined;
|
||||
target.cleanupRelease?.confirm();
|
||||
target.cleanupRelease = undefined;
|
||||
if (root !== target) return;
|
||||
root = undefined;
|
||||
executable = undefined;
|
||||
|
||||
Reference in new issue
Block a user