Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix(frida): preserve non-timeout device lookup failures
getDeviceById is a lookup deadline only when Frida rejects with
"Device not found" after the wait. A device-manager or backend failure
stays a capability error. Align the assertions that still expected the
previous capacity and capture sentences.

Co-authored-by: morluto <morluto@users.noreply.github.com>
  • Loading branch information
cursoragent and morluto committed Oct 21, 2026
commit b0eca9fb48dcda98c8a6335cc29b356018818a29
26 changes: 24 additions & 2 deletions src/application/frida/FridaInstrumentationManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ const startLocalAttachedSession = async (

// eslint-disable-next-line max-lines-per-function -- related manager lifecycle cases share the same focused fake provider.
describe("FridaInstrumentationManager", () => {
it("reports a fixed device-lookup deadline when Frida cannot select the device", async () => {
it("reports a fixed device-lookup deadline when Frida's lookup times out", async () => {
const bindings = new FakeDeviceManager();
bindings.getDeviceById = async () => {
throw new Error("unable to find device with id 'local'");
throw new Error("Device not found");
};
const manager = new FridaInstrumentationManager({
deviceManager: bindings,
Expand All @@ -239,6 +239,28 @@ describe("FridaInstrumentationManager", () => {
expect(listed.error.remediationAction).toContain("no runtime override");
});

it("preserves a Frida device-manager failure instead of claiming the lookup deadline expired", async () => {
const bindings = new FakeDeviceManager();
bindings.getDeviceById = async () => {
throw new Error("Device manager is closed");
};
const manager = new FridaInstrumentationManager({
deviceManager: bindings,
});
const listed = await manager.listProcesses({ deviceId: "local" });
expect(listed.ok).toBe(false);
if (listed.ok) return;
expect(listed.error).toBeInstanceOf(AnalysisCapabilityUnavailableError);
expect(listed.error).not.toBeInstanceOf(AnalysisTimeoutError);
expect(listed.error).toMatchObject({
providerId: "frida",
operation: "list_frida_processes",
reason: "Device manager is closed",
});
expect(listed.error.message).toContain("Device manager is closed");
expect(listed.error.message).not.toContain("deadlineExpired");
});

it("names a capture cap only after that observation dropped data", () => {
expect(fridaCaptureLimitations({ messages_truncated: false })).toEqual([]);
expect(
Expand Down
12 changes: 12 additions & 0 deletions src/frida/FridaInstrumentationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ import {

const DEVICE_LOOKUP_TIMEOUT_MS = 1_000;

/**
* Frida Core 17.23.2 raises this from `getDeviceById` only after the supplied
* timeout elapses without a match. A closed manager or backend failure uses a
* different message and is not this deadline.
*/
const FRIDA_DEVICE_LOOKUP_TIMEOUT_MESSAGE = "Device not found";

const isFridaDeviceLookupTimeout = (cause: unknown): boolean =>
cause instanceof Error &&
cause.message === FRIDA_DEVICE_LOOKUP_TIMEOUT_MESSAGE;

export const FRIDA_PROVIDER_IDENTITY = {
id: "frida",
name: "Frida",
Expand Down Expand Up @@ -1139,6 +1150,7 @@ export class FridaInstrumentationManager implements FridaInstrumentationPort {
cause instanceof AnalysisTimeoutError
)
throw cause;
if (!isFridaDeviceLookupTimeout(cause)) throw cause;
throw new AnalysisTimeoutError(
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
"frida_device_lookup",
DEVICE_LOOKUP_TIMEOUT_MS,
Expand Down
4 changes: 2 additions & 2 deletions tests/boundary/mcp/fridaLifecycleMcp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ it.each([
response.structuredContent,
);
const result = evidence.normalized_result;
expect(result.messages_truncated).toBe(true);
expect(result.messages_truncated).toBe(false);
const retained = jsonObjectSchema.parse(result.messages[0]);
expect(retained.description_truncated).toBe(true);
expect(
Expand All @@ -492,7 +492,7 @@ it.each([
status.structuredContent,
),
).toMatchObject({
normalized_result: { messages: [retained], messages_truncated: true },
normalized_result: { messages: [retained], messages_truncated: false },
});
},
);
Expand Down
2 changes: 1 addition & 1 deletion tests/boundary/providers/GdbSessionManagerCoverage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2879,7 +2879,7 @@ process.stdin.on('data', (chunk) => {
});
expect(exited.error.partialObservation).toMatchObject({
limitations: expect.arrayContaining([
expect.stringContaining("truncated prefix"),
expect.stringContaining("16777216 byte or 16384 record cap"),
]),
});
}
Expand Down
2 changes: 1 addition & 1 deletion tests/composition/reverseEngineeringEdgeCases.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ it("rejects work after reaching the concurrent provider-operation limit", async
active_operations: 8,
});
expect(rejected.error.message).toContain(
"Concurrent reverse-engineering operation capacity reached.",
"Concurrent reverse-engineering operation capacity reached (8 operations).",
);
}
expect(providerCalls).toBe(0);
Expand Down
Loading