fix(frida): drain admitted operations and honor queued cancellation (#2305)
* fix(frida): drain admitted operations and honor queued cancellation * fix(frida): settle cancelled loads before queued resume * test(frida): share lifecycle fixtures without duplicating assertions * fix(frida): preserve operation admission before session close * test(apple): bound cold archive fixture compilation * fix(frida): retain cancelled script creation evidence * test(release): scope preflight schema to selected jobs * fix(process): report no remaining time after a provider deadline fires Node timers can fire while performance.now() is still a fraction of a millisecond short of the monotonic deadline. ProviderStartupDeadline then reported interruption "timeout" and an aborted signal while remainingMs() returned ceil(0.x) = 1, so polling loops guarded by remainingMs() > 0 (Hopper and Ghidra startup) could run past an elapsed deadline, and the real-timer test "aborts a bounded wait when its real monotonic deadline expires" failed intermittently in CI (expected 1 to be 0). Once the deadline's own timer has classified a timeout, report zero remaining time. A deterministic regression test fires the timer with the monotonic clock 0.4 ms short of the deadline. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(comparison): recheck historical calls-only changes (#2223) * fix(comparison): preserve incomplete function call evidence Keep missing, unknown, partial and unresolved call relationships unknown in function comparisons and reconstruction claims. Aggregate IDA caller and callee coverage without overwriting uncertainty. Validate with 144 focused tests, typecheck/lint, docs checks and test discovery. Real providers were not verified; the full headless IDA session suite requires unavailable Windows native controls. * fix(comparison): recheck historical calls-only changes --------- Co-authored-by: morluto <76467478+morluto@users.noreply.github.com> (cherry picked from commit688defca0f) * fix(ci): isolate Linux Hopper process fixture inventory (cherry picked from commit 8cac51e12184d56a9ba80a4427b3e6082ddac1ec) * fix(android): make DEX descriptor pattern portable (cherry picked from commit 1335bcddc569a1cfb34b6efedcb6f2e3aaaa3357) * fix: repair the static-check failures on the default branch (#2895) * fix: repair the static-check failures on the default branch The default branch fails its own required `Static checks` job three ways, so every pull request reports that job as failed regardless of its own change. - `npm run format:check` reports `src/domain/functionComparison.test.ts` and `src/ida/IdaOperationRunner.ts`. - `npm run lint` reports a duplicate `import { join } from "node:path"` in `tests/boundary/mcp/ghidraInventoryMcp.test.ts` (lines 4 and 17). - `npm run typecheck` reports `format: "devin"` missing from the client format union in `src/application/SupportedClients.ts`, and an unchecked index in `tests/boundary/cli/clientProfileLifecycle.test.ts`, whose pair array is inferred as `string[][]`. Apply the pinned formatter, drop the duplicate import, list the `"devin"` format that its own definition already uses, and mark the pair array `as const`. Validation: `npm run check:fast` and `npm run format:check` pass. * fix(setup): keep Devin on the JSON configuration dialect --------- Co-authored-by: 吴佳浩 <wujiahao@supremind.com> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com> (cherry picked from commitdf3d96da80) --------- Co-authored-by: morluto <morluto@users.noreply.github.com> Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com> Co-authored-by: Lucien <164857476+dakjdakd@users.noreply.github.com> Co-authored-by: 吴佳浩Alben <35291372+XiaoBinGan@users.noreply.github.com> Co-authored-by: 吴佳浩 <wujiahao@supremind.com> Co-authored-by: OpenAI Codex <codex@openai.com>
This commit is contained in:
co-authored by
morluto
Kaoru0822
Claude Opus 5.5
morluto
Lucien
吴佳浩Alben
吴佳浩
OpenAI Codex
parent
72d5bbc96d
commit
4481f86188
@@ -1023,6 +1023,28 @@ it("serializes script loading against concurrent close and unloads the loaded sc
|
||||
expect(bindings.device.session.isDetached()).toBe(true);
|
||||
});
|
||||
|
||||
it("drains startup when the provider loader initiates shutdown", async () => {
|
||||
const bindings = new FakeDeviceManager();
|
||||
let closing: Promise<void> | undefined;
|
||||
const manager = new FridaInstrumentationManager({
|
||||
deviceManagerLoader: async () => {
|
||||
closing = manager.closeAll();
|
||||
return bindings;
|
||||
},
|
||||
});
|
||||
const started = await manager.startSession({
|
||||
mode: "spawn",
|
||||
deviceId: "local",
|
||||
program: "/tmp/fixture",
|
||||
});
|
||||
if (!started.ok) throw started.error;
|
||||
expect(closing).toBeDefined();
|
||||
await closing;
|
||||
expect(bindings.device.session.isDetached()).toBe(true);
|
||||
expect(bindings.device.resumed).toEqual([512]);
|
||||
expect(manager.status(started.value.sessionId)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("names the unknown session or script ID it rejects", async () => {
|
||||
const { manager, started } = await startLocalAttachedSession();
|
||||
if (!started.ok) throw started.error;
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import type {
|
||||
AnalysisError,
|
||||
AnalysisErrorOptions,
|
||||
} from "../../domain/analysisErrorBase.js";
|
||||
import { AnalysisCancelledError } from "../../domain/analysisErrorCore.js";
|
||||
import type { OptionalProviderLoadFailure } from "../OptionalObservationProviders.js";
|
||||
import type { JsonValue } from "../../domain/jsonValue.js";
|
||||
import type { Result } from "../../domain/result.js";
|
||||
@@ -60,6 +64,15 @@ export interface FridaScriptObservation {
|
||||
readonly messagesTruncated: boolean;
|
||||
}
|
||||
|
||||
export class FridaScriptLoadCancelledError extends AnalysisCancelledError {
|
||||
constructor(
|
||||
readonly script: FridaScriptObservation,
|
||||
options?: AnalysisErrorOptions,
|
||||
) {
|
||||
super("load_frida_script", options);
|
||||
}
|
||||
}
|
||||
|
||||
export interface FridaSessionStatus extends FridaSessionObservation {
|
||||
/** True only after REA has successfully resumed this spawned target. */
|
||||
readonly targetResumeObserved: boolean;
|
||||
@@ -100,14 +113,20 @@ export interface FridaInstrumentationPort {
|
||||
startSession(
|
||||
input: StartFridaSessionInput,
|
||||
): Promise<Result<FridaSessionObservation, AnalysisError>>;
|
||||
/** Own cancellation and new-script cleanup before returning a final load outcome. */
|
||||
loadScript(
|
||||
sessionId: string,
|
||||
source: FridaScriptSource,
|
||||
signal?: AbortSignal,
|
||||
): Promise<Result<FridaScriptObservation, AnalysisError>>;
|
||||
resumeSession(sessionId: string): Promise<Result<null, AnalysisError>>;
|
||||
resumeSession(
|
||||
sessionId: string,
|
||||
signal?: AbortSignal,
|
||||
): Promise<Result<null, AnalysisError>>;
|
||||
unloadScript(
|
||||
sessionId: string,
|
||||
scriptId: string,
|
||||
signal?: AbortSignal,
|
||||
): Promise<Result<null, AnalysisError>>;
|
||||
status(sessionId: string): FridaSessionStatus | undefined;
|
||||
closeSession(
|
||||
|
||||
@@ -3,6 +3,7 @@ import { join } from "node:path";
|
||||
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { FridaScriptLoadCancelledError } from "./FridaInstrumentationPort.js";
|
||||
import type { FridaInstrumentationPort } from "./FridaInstrumentationPort.js";
|
||||
import { FridaInstrumentationService } from "./FridaInstrumentationService.js";
|
||||
import {
|
||||
@@ -569,3 +570,74 @@ it("cleans up a session and returns typed cancellation after a pending start", a
|
||||
if (!result.ok) expect(result.error._tag).toBe("AnalysisCancelledError");
|
||||
expect(closed).toEqual(["00000000-0000-4000-8000-000000000001"]);
|
||||
});
|
||||
|
||||
it("retains a cancelled provider load's source and messages in one-shot Evidence", async () => {
|
||||
const controller = new AbortController();
|
||||
const script = {
|
||||
...createScriptObservation(),
|
||||
messages: [{ type: "send", payload: "cancelled-load" }],
|
||||
};
|
||||
const service = new FridaInstrumentationService(
|
||||
createProvider({
|
||||
async loadScript() {
|
||||
controller.abort(new Error("cancel during native load"));
|
||||
return {
|
||||
ok: false,
|
||||
error: new FridaScriptLoadCancelledError(script, {
|
||||
cause: controller.signal.reason,
|
||||
}),
|
||||
};
|
||||
},
|
||||
}),
|
||||
);
|
||||
const result = await service.instrument(
|
||||
{
|
||||
mode: "spawn",
|
||||
program: "/fixture",
|
||||
source: { sourceKind: "inline", source: "send('cancelled-load')" },
|
||||
durationMs: 0,
|
||||
},
|
||||
controller.signal,
|
||||
);
|
||||
if (result.ok) throw new Error("Cancelled instrumentation succeeded");
|
||||
expect(result.error.partialObservation).toMatchObject({
|
||||
normalized_result: {
|
||||
source_kind: "inline",
|
||||
source_sha256: script.sourceSha256,
|
||||
messages: script.messages,
|
||||
instrumentation_cleanup: "released",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves a provider-committed load when cancellation arrives during result delivery", async () => {
|
||||
const controller = new AbortController();
|
||||
let unloads = 0;
|
||||
const script = createScriptObservation();
|
||||
const service = new FridaInstrumentationService(
|
||||
createProvider({
|
||||
loadScript() {
|
||||
const completed = Promise.resolve({ ok: true as const, value: script });
|
||||
void completed.then(() =>
|
||||
controller.abort(new Error("late cancellation")),
|
||||
);
|
||||
return completed;
|
||||
},
|
||||
async unloadScript() {
|
||||
unloads += 1;
|
||||
return { ok: true, value: null };
|
||||
},
|
||||
}),
|
||||
);
|
||||
const loaded = await service.loadScript(
|
||||
createSession().sessionId,
|
||||
{ sourceKind: "inline", source: "send('ready')" },
|
||||
controller.signal,
|
||||
);
|
||||
expect(controller.signal.aborted).toBe(true);
|
||||
if (!loaded.ok) throw loaded.error;
|
||||
expect(loaded.value.normalized_result).toMatchObject({
|
||||
script_id: script.scriptId,
|
||||
});
|
||||
expect(unloads).toBe(0);
|
||||
});
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
AnalysisInputError,
|
||||
} from "../../domain/analysisErrorCore.js";
|
||||
import { err, ok, type Result } from "../../domain/result.js";
|
||||
import { FridaScriptLoadCancelledError } from "./FridaInstrumentationPort.js";
|
||||
import type {
|
||||
FridaDeviceSelector,
|
||||
FridaInstrumentationPort,
|
||||
@@ -181,8 +182,17 @@ export class FridaInstrumentationService {
|
||||
async loadScript(
|
||||
sessionId: string,
|
||||
source: FridaScriptSource,
|
||||
signal?: AbortSignal,
|
||||
): Promise<Result<Evidence, AnalysisError>> {
|
||||
const loaded = await this.#provider.loadScript(sessionId, source);
|
||||
if (signal?.aborted)
|
||||
return err(
|
||||
new AnalysisCancelledError("load_frida_script", {
|
||||
cause: signal.reason,
|
||||
}),
|
||||
);
|
||||
const loaded = await this.#provider.loadScript(sessionId, source, signal);
|
||||
if (!loaded.ok && loaded.error instanceof FridaScriptLoadCancelledError)
|
||||
return err(cancelledScriptEvidence(sessionId, loaded.error));
|
||||
return loaded.ok
|
||||
? ok(
|
||||
fridaEvidence("load_frida_script", scriptOutput(loaded.value), {
|
||||
@@ -192,12 +202,12 @@ export class FridaInstrumentationService {
|
||||
: loaded;
|
||||
}
|
||||
|
||||
resumeSession(sessionId: string) {
|
||||
return this.#provider.resumeSession(sessionId);
|
||||
resumeSession(sessionId: string, signal?: AbortSignal) {
|
||||
return this.#provider.resumeSession(sessionId, signal);
|
||||
}
|
||||
|
||||
unloadScript(sessionId: string, scriptId: string) {
|
||||
return this.#provider.unloadScript(sessionId, scriptId);
|
||||
unloadScript(sessionId: string, scriptId: string, signal?: AbortSignal) {
|
||||
return this.#provider.unloadScript(sessionId, scriptId, signal);
|
||||
}
|
||||
|
||||
status(sessionId: string): FridaSessionStatus | undefined {
|
||||
@@ -243,14 +253,19 @@ export class FridaInstrumentationService {
|
||||
const loaded = await this.#provider.loadScript(
|
||||
started.value.sessionId,
|
||||
input.source,
|
||||
signal,
|
||||
);
|
||||
let scriptObservation: FridaScriptObservation | undefined;
|
||||
if (loaded.ok) scriptObservation = loaded.value;
|
||||
else if (loaded.error instanceof FridaScriptLoadCancelledError)
|
||||
scriptObservation = loaded.error.script;
|
||||
if (signal?.aborted)
|
||||
return this.#cancelSession(
|
||||
"instrument_with_frida",
|
||||
started.value,
|
||||
input,
|
||||
signal.reason,
|
||||
loaded.ok ? loaded.value : undefined,
|
||||
scriptObservation,
|
||||
);
|
||||
if (!loaded.ok) {
|
||||
const closed = await this.#provider.closeSession(started.value.sessionId);
|
||||
@@ -267,6 +282,7 @@ export class FridaInstrumentationService {
|
||||
if (started.value.mode === "spawn") {
|
||||
const resumed = await this.#provider.resumeSession(
|
||||
started.value.sessionId,
|
||||
signal,
|
||||
);
|
||||
if (signal?.aborted)
|
||||
return this.#cancelSession(
|
||||
@@ -462,3 +478,23 @@ const sessionStatusOutput = (status: FridaSessionStatus) => ({
|
||||
messages: status.messages,
|
||||
messages_truncated: status.messagesTruncated,
|
||||
});
|
||||
|
||||
const cancelledScriptEvidence = (
|
||||
sessionId: string,
|
||||
error: FridaScriptLoadCancelledError,
|
||||
): AnalysisCancelledError =>
|
||||
new AnalysisCancelledError(error.operation, {
|
||||
cause: error.cause,
|
||||
cleanup: error.cleanup,
|
||||
partialObservation: fridaEvidence(
|
||||
error.operation,
|
||||
{
|
||||
...scriptOutput(error.script),
|
||||
cleanup_error: error.cleanup?.reason ?? null,
|
||||
script_cleanup: error.cleanupIncomplete
|
||||
? "incomplete_or_unknown"
|
||||
: "released",
|
||||
},
|
||||
{ session_id: sessionId },
|
||||
),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user