mirror of
https://github.com/morluto/rea
synced 2026-10-28 06:46:47 -04:00
1b97b0f370
* fix(application): retain completed evidence through cancellation Validate completed provider reports before classifying cancellation and preserve Evidence and captured diagnostics. Share MCP recording and delivery across custom observation handlers. Add source-owned completion and public SDK recording controls. Refs #3923, #3927, #4261. * fix(wasm): retain final observations through cancellation Keep completed Evidence after finalization and through CLI/MCP delivery. Preserve output and cleanup failure precedence. Refs #4254. * fix(browser): retain final observations and forward cancellation Classify final CDP detach and completed scenario cleanup at the provider boundary. Translate completed partials into canonical Evidence for MCP recording, and forward CLI cancellation to passive Electron tools. Refs #4255, #4256, #4257. * fix(ghidra): isolate cancellation of shared startup waiters Keep startup group-owned while each caller has an independent abortable wait. Await final-owner cleanup and preserve cleanup facts before retrying. Reuse the shared abortable promise helper. Refs #3983. * fix(mcp): keep shutdown registrations until cleanup succeeds Retain repeated event requests while unresolved owners need cleanup, and unregister only after success. Verify coalescing and failed-owner retry. Refs #4253. * fix(adb): own transfer snapshots and stage screen publication Bind transfer digests to the exact private input bytes and preserve caller APK names. Retain failed descriptors and private-root owners with typed cleanup evidence; publish captures exclusively after the cancellation cutoff. Refs #4251, #4252. * fix(verification): report ADB cleanup failures Always close after attempted verification and keep unexpected primary failures and cleanup details visible. Exercise the production script with controlled imports, including null and undefined throws. Refs #4260. * fix(runner): stop owned Windows commands on cancellation Use the retained ChildProcess handle for IPC cancellation and parent disconnection. Keep the SQLite lock until observed child close, and include native Windows regressions in the curated CI lane. Native Windows results remain pending. Refs #4258. * fix(website): canonicalize link containment boundaries Compare resolved targets with resolved repository and site roots. Accept directory aliases while preserving escape checks and keep fixtures within their temporary owner. Refs #4264. * docs(testing): cover completion races and cleanup retry Clarify validation-before-cancellation, independent startup waiter controls, producer and adapter coverage, and repeated shutdown events. * fix(filesystem): retain file owners and completed reads after close failure * fix(session): report retained snapshot staging in cleanup status Fixes #4277. Include both snapshot and profile file-resource scopes in the owning status fact, preserving publication receipts and cleanup retry. * docs(mcp): clarify recovery of raw partial observations Document the observed SDK cancellation boundary and the open design decision in #4276 without promoting raw errors to Evidence. * fix(kuna): own the complete installation inspection lifetime * test(kuna): cover session cleanup of shared cache resources * fix(hopper): isolate publisher operation resource admission * fix(hopper): preserve launcher cleanup failure classification * fix(adb): retain ordered cleanup and screen publication outcomes * fix(runner): retain Windows job ownership through cleanup retries * docs: clarify inspection admission and ordered cleanup regressions * fix(ghidra): preserve startup cleanup and request deadlines * fix(runner): supervise stdin errors and bootstrap native controls * docs: require queued lifecycle controls to survive admission * fix(cli): leave cleanup resolution with resource owners * test(adb): verify owned install snapshots through CLI * fix(errors): exclude resolved primary cleanup resources * fix(adb): resolve publication cleanup after its handle closes * fix(android): resolve JADX hash cleanup after owned close * refactor(android): share hash failure cause options * fix(kuna): gate commands on retained descriptor cleanup * docs: cover cleanup admission and owner-confirmed recovery * refactor(artifacts): bind cleanup errors to confirmed release * fix(adb): resolve recovered cleanup at retained owners * fix(kuna): resolve installation cleanup after owned close * fix(kuna): gate cache reads on retained hash cleanup * fix(setup): preserve publisher cleanup admission failures * fix(android): resolve the reported retirement cleanup error * test(runner): scope post-spawn fault control to POSIX * test(adb): cover persistent snapshot owner retirement * fix(kuna): preserve file outcomes with explicit cleanup ownership * fix(artifacts): resolve errors through retained cleanup owners * docs(lifecycle): carry cleanup ownership in typed outcomes * fix(adb): bind staged screen errors to their cleanup lease * fix(kuna): bind profile cleanup through a close capability * fix(artifacts): retain descriptor resources in cleanup errors * fix(pcap): bind existing errors to snapshot retirement * fix(windows): load source owner through its file URL * test(build): copy the command runner helper into fixtures * fix(mcp): own shared observation providers in the transport * fix(jadx): resolve every retained cleanup retry error * fix(kuna): bind retry errors to every retained cleanup owner * fix(adb): bind admission and shutdown errors to exact cleanup leases * fix(windows): resolve command paths before native ownership * test(publisher): assert exact descriptor recovery without release metadata * docs(lifecycle): require every retry error to follow its owners * fix(kuna): keep hash cleanup state stable across concurrent retries * test(windows): exercise surviving descendants with scoped shutdown deadlines * fix(uninstall): preserve primary read errors through cleanup failure * test(publisher): assert cleanup Result and exact owner recovery * test(windows): observe supervisor resources through IPC disconnect * fix(browser): retain typed cancellation after interrupted actions * test(publisher): assert ownership phases without retry-count coupling * fix(lifecycle): preserve abort reasons through shared provider execution * fix(jadx): preserve execution and late hash cancellation causes * fix(adb): compose late cancellation with exact cleanup failures * test(mcp): use the shared budget for session workflows
224 lines
7.3 KiB
TypeScript
224 lines
7.3 KiB
TypeScript
import type { AnalysisProviderSelector } from "../../contracts/providerSelection.js";
|
|
import type { AnalysisProfileCommitment } from "../../domain/analysisProfile.js";
|
|
import type { BinaryTarget } from "../../domain/binaryTargetTypes.js";
|
|
import { AnalysisCapabilityUnavailableError } from "../../domain/analysisErrorCore.js";
|
|
import { ProviderSelectionError } from "../../domain/providerSelectionError.js";
|
|
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
|
import { err, ok, type Result } from "../../domain/result.js";
|
|
import type {
|
|
AnalysisClient,
|
|
AnalysisClientContext,
|
|
AnalysisProvider,
|
|
CapabilityDescriptor,
|
|
ProviderIdentity,
|
|
} from "../AnalysisProvider.js";
|
|
import type { FileCloseResourceOwner } from "../AnalysisProvider.js";
|
|
import {
|
|
AnalysisProviderRegistry,
|
|
type AnalysisProviderBinding,
|
|
type AnalysisProviderCandidateStatus,
|
|
type AnalysisProviderSelection,
|
|
} from "./AnalysisProviderRegistry.js";
|
|
import { CompositeProvider } from "./CompositeProvider.js";
|
|
|
|
/** Immutable operation routes and binding metadata for one target transition. */
|
|
export interface SessionProviderRoute {
|
|
readonly identity: ProviderIdentity;
|
|
readonly capabilities: ReadonlyMap<string, CapabilityDescriptor>;
|
|
readonly profile: AnalysisProfileCommitment | null;
|
|
readonly binding: AnalysisProviderBinding | null;
|
|
readonly selection: AnalysisProviderSelection | undefined;
|
|
createClient(
|
|
target: BinaryTarget,
|
|
context: AnalysisClientContext,
|
|
): AnalysisClient;
|
|
}
|
|
|
|
/** Resolve one registry-selected deep provider and disjoint auxiliary families. */
|
|
export class SessionProviderRouter {
|
|
private constructor(
|
|
private readonly registry: AnalysisProviderRegistry,
|
|
private readonly auxiliaryProviders: readonly AnalysisProvider[],
|
|
private readonly route: SessionProviderRoute,
|
|
) {}
|
|
|
|
/** Create selection-aware routing while keeping auxiliary families disjoint. */
|
|
static selectable(
|
|
registry: AnalysisProviderRegistry,
|
|
auxiliaryProviders: readonly AnalysisProvider[],
|
|
): SessionProviderRouter {
|
|
const identities = [
|
|
...registry.identities(),
|
|
...auxiliaryProviders.map((provider) => provider.identity()),
|
|
];
|
|
assertUniqueProviderIds(identities);
|
|
const auxiliaryOperations = assertDisjoint(auxiliaryProviders);
|
|
for (const operation of registry.declaredOperations())
|
|
if (auxiliaryOperations.has(operation))
|
|
throw new TypeError(
|
|
`Deep and auxiliary providers both declare operation ${operation}`,
|
|
);
|
|
const initialRoute = selectableRoute(auxiliaryProviders, undefined);
|
|
return new SessionProviderRouter(
|
|
registry,
|
|
[...auxiliaryProviders],
|
|
initialRoute,
|
|
);
|
|
}
|
|
|
|
/** Target-free routes and discovery metadata. */
|
|
initialRoute(): SessionProviderRoute {
|
|
return this.route;
|
|
}
|
|
|
|
/** Close provider owners not represented by the currently bound client. */
|
|
closeOwnedResources() {
|
|
return this.registry.closeOwnedResources();
|
|
}
|
|
|
|
/** Report retained candidate cleanup without performing cleanup work. */
|
|
hasPendingOwnedResources(): boolean {
|
|
return this.registry.hasPendingOwnedResources();
|
|
}
|
|
|
|
/** Resolve target routes before any provider client is created. */
|
|
async resolve(
|
|
target: BinaryTarget,
|
|
providerId?: AnalysisProviderSelector,
|
|
signal?: AbortSignal,
|
|
fileCloseResources?: FileCloseResourceOwner,
|
|
): Promise<Result<SessionProviderRoute, AnalysisError>> {
|
|
const resolutionOptions =
|
|
signal === undefined && fileCloseResources === undefined
|
|
? undefined
|
|
: {
|
|
...(signal === undefined ? {} : { signal }),
|
|
...(fileCloseResources === undefined ? {} : { fileCloseResources }),
|
|
};
|
|
const selected = await this.registry.select(
|
|
target,
|
|
providerId,
|
|
resolutionOptions,
|
|
);
|
|
return selected.ok
|
|
? ok(selectableRoute(this.auxiliaryProviders, selected.value))
|
|
: selected;
|
|
}
|
|
|
|
/** Candidate status authoritative for the active or target-free route. */
|
|
candidateStatuses(
|
|
route: SessionProviderRoute,
|
|
): readonly AnalysisProviderCandidateStatus[] {
|
|
return route.selection?.candidates ?? this.registry.candidates();
|
|
}
|
|
|
|
/** Produce exact candidate rejections for an intentionally unbound route. */
|
|
unboundOperationError(
|
|
operation: string,
|
|
route: SessionProviderRoute,
|
|
): ProviderSelectionError | undefined {
|
|
if (
|
|
route.binding !== null ||
|
|
route.selection === undefined ||
|
|
!this.registry.declaredOperations().includes(operation)
|
|
)
|
|
return undefined;
|
|
return this.registry.unboundOperationError(operation, route.selection);
|
|
}
|
|
}
|
|
|
|
const selectableRoute = (
|
|
auxiliaryProviders: readonly AnalysisProvider[],
|
|
selection: AnalysisProviderSelection | undefined,
|
|
): SessionProviderRoute => {
|
|
const binding = selection?.binding ?? null;
|
|
const providers = [
|
|
...auxiliaryProviders,
|
|
...(binding === null ? [] : [binding.provider]),
|
|
];
|
|
const provider =
|
|
binding === null && providers.length === 1
|
|
? providers[0]
|
|
: providers.length === 0
|
|
? undefined
|
|
: new CompositeProvider(providers);
|
|
const identity = provider?.identity() ?? emptyProviderIdentity();
|
|
// The binding attributes deep-provider capabilities to the resolved version.
|
|
const capabilities = capabilityMap([
|
|
...auxiliaryProviders.flatMap((auxiliary) => auxiliary.capabilities()),
|
|
...(binding?.capabilities ?? []),
|
|
]);
|
|
return {
|
|
identity,
|
|
capabilities,
|
|
profile: binding?.profile ?? null,
|
|
binding,
|
|
selection,
|
|
createClient: (target, context) =>
|
|
provider?.createClient(target, binding?.profile, context) ??
|
|
emptyClient(identity),
|
|
};
|
|
};
|
|
|
|
const emptyClient = (identity: ProviderIdentity): AnalysisClient => ({
|
|
execute: (operation) =>
|
|
operation === "health"
|
|
? Promise.resolve(
|
|
ok({
|
|
result: null,
|
|
rawResult: null,
|
|
provider: identity,
|
|
limitations: [],
|
|
locations: [],
|
|
subject: null,
|
|
}),
|
|
)
|
|
: Promise.resolve(
|
|
err(
|
|
new AnalysisCapabilityUnavailableError(
|
|
identity.id,
|
|
operation,
|
|
"operation is not declared by this provider set",
|
|
),
|
|
),
|
|
),
|
|
close: () => Promise.resolve(ok(null)),
|
|
});
|
|
|
|
const emptyProviderIdentity = (): ProviderIdentity => ({
|
|
id: "composite:none",
|
|
name: "REA composite analysis provider",
|
|
version: null,
|
|
});
|
|
|
|
const capabilityMap = (
|
|
capabilities: readonly CapabilityDescriptor[],
|
|
): ReadonlyMap<string, CapabilityDescriptor> =>
|
|
new Map(capabilities.map((descriptor) => [descriptor.operation, descriptor]));
|
|
|
|
const assertDisjoint = (
|
|
providers: readonly AnalysisProvider[],
|
|
): ReadonlySet<string> => {
|
|
const routes = new Set<string>();
|
|
for (const provider of providers)
|
|
for (const { operation } of provider.capabilities()) {
|
|
if (routes.has(operation))
|
|
throw new TypeError(
|
|
`Multiple auxiliary providers declare operation ${operation}`,
|
|
);
|
|
routes.add(operation);
|
|
}
|
|
return routes;
|
|
};
|
|
|
|
const assertUniqueProviderIds = (
|
|
identities: readonly ProviderIdentity[],
|
|
): void => {
|
|
const ids = new Set<string>();
|
|
for (const identity of identities) {
|
|
if (ids.has(identity.id))
|
|
throw new TypeError(`Duplicate configured provider ID: ${identity.id}`);
|
|
ids.add(identity.id);
|
|
}
|
|
};
|