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
Next Next commit
fix(adb): keep truncated mutations non-retryable
Only live observations opt into retrying a capture that exceeded the allowance. Push, install, uninstall, and other mutations stay non-retryable.
  • Loading branch information
cursoragent committed Oct 20, 2026
commit a7ccb97fe69f740e13e4436e5467de95b53de1d5
63 changes: 33 additions & 30 deletions src/adb/AdbCommand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,36 +184,39 @@ it("does not infer cancellation from a foreign ABORT_ERR code", async () => {
});
});

it("keeps a truncated live adb capture retryable", async () => {
vi.mocked(execFileBytes).mockRejectedValueOnce(
Object.assign(new Error("too much"), {
code: 1,
stdout: "",
stderr: "",
signal: null,
killed: false,
outputTruncated: true,
}),
);
const result = await runAdbCapture(
"read_adb_logcat",
{ device: "device" },
"/host/adb",
["logcat", "-d"],
{ timeoutMs: 100, maxOutputBytes: 1024 },
undefined,
);
expect(result.ok).toBe(false);
if (result.ok) throw new Error("Expected a capture allowance refusal");
const projected = projectAnalysisError(result.error);
expect(projected.retryable).toBe(true);
expect(projected.remediation.action).toContain(
"The adb output capture allowance",
);
expect(projected.remediation.action).toContain(
"live output may change between requests",
);
});
it.each([true, false])(
"projects a truncated adb capture as retryable only for volatile output (%s)",
async (volatileOutput) => {
vi.mocked(execFileBytes).mockRejectedValueOnce(
Object.assign(new Error("too much"), {
code: 1,
stdout: "",
stderr: "",
signal: null,
killed: false,
outputTruncated: true,
}),
);
const result = await runAdbCapture(
volatileOutput ? "read_adb_logcat" : "install_adb_package",
{ device: "device" },
"/host/adb",
volatileOutput ? ["logcat", "-d"] : ["install", "app.apk"],
{ timeoutMs: 100, maxOutputBytes: 1024, volatileOutput },
undefined,
);
expect(result.ok).toBe(false);
if (result.ok) throw new Error("Expected a capture allowance refusal");
const projected = projectAnalysisError(result.error);
expect(projected.retryable).toBe(volatileOutput);
expect(projected.remediation.action).toContain(
"The adb output capture allowance",
);
expect(projected.remediation.action).toContain(
"live output may change between requests",
);
},
);

it("keeps a physical failure even when the later abort reason is that same error", async () => {
const controller = new AbortController();
Expand Down
10 changes: 7 additions & 3 deletions src/adb/AdbCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ export const adbArguments = (
export interface AdbRunLimits {
readonly timeoutMs: number;
readonly maxOutputBytes: number;
/**
* Live device observations can shrink between calls. Mutation commands omit
* this so a truncated result stays non-retryable.
*/
readonly volatileOutput?: boolean;
}

/** Keep the selected device separate from the file addressed by the command. */
Expand Down Expand Up @@ -146,8 +151,7 @@ export const runAdbCapture = async (
"The adb output capture allowance",
"capture",
),
// Device output can shrink between calls. Version text stays non-retryable.
retryable: true,
...(limits.volatileOutput === true ? { retryable: true } : {}),
},
),
);
Expand Down Expand Up @@ -277,7 +281,7 @@ export const probeAdbPathExistence = async (
{ device: serial, path },
binary,
adbArguments(serial, ["shell", "test", "-e", path]),
limits,
{ ...limits, volatileOutput: true },
signal,
);
if (probed.ok) {
Expand Down
18 changes: 15 additions & 3 deletions src/adb/AdbProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ export class AdbProvider {
"serial" in request.input ? request.input.serial : undefined,
["shell", ...arguments_],
),
limits,
{ ...limits, volatileOutput: true },
signal,
);
switch (operation) {
Expand All @@ -1346,6 +1346,7 @@ export class AdbProvider {
{
timeoutMs: DEVICES_TIMEOUT_MS,
maxOutputBytes: DEVICES_MAX_OUTPUT_BYTES,
volatileOutput: true,
},
signal,
);
Expand Down Expand Up @@ -1382,6 +1383,7 @@ export class AdbProvider {
{
timeoutMs: SHELL_TIMEOUT_MS,
maxOutputBytes: GETPROP_MAX_OUTPUT_BYTES,
volatileOutput: true,
},
signal,
);
Expand Down Expand Up @@ -1631,6 +1633,7 @@ export class AdbProvider {
{
timeoutMs: LISTING_TIMEOUT_MS,
maxOutputBytes: LISTING_MAX_OUTPUT_BYTES,
volatileOutput: true,
},
signal,
);
Expand Down Expand Up @@ -1917,6 +1920,7 @@ export class AdbProvider {
{
timeoutMs: PM_PATH_TIMEOUT_MS,
maxOutputBytes: PM_PATH_MAX_OUTPUT_BYTES,
volatileOutput: true,
},
signal,
);
Expand Down Expand Up @@ -2704,7 +2708,11 @@ export class AdbProvider {
"android.intent.category.LAUNCHER",
input.package,
]),
{ timeoutMs: SHELL_TIMEOUT_MS, maxOutputBytes: PM_PATH_MAX_OUTPUT_BYTES },
{
timeoutMs: SHELL_TIMEOUT_MS,
maxOutputBytes: PM_PATH_MAX_OUTPUT_BYTES,
volatileOutput: true,
},
signal,
);
if (!resolved.ok) return resolved;
Expand Down Expand Up @@ -2918,7 +2926,11 @@ export class AdbProvider {
{ device: input.serial },
selection.binary,
adbArguments(input.serial, ["exec-out", "screencap", "-p"]),
{ timeoutMs: SCREEN_TIMEOUT_MS, maxOutputBytes: SCREEN_MAX_OUTPUT_BYTES },
{
timeoutMs: SCREEN_TIMEOUT_MS,
maxOutputBytes: SCREEN_MAX_OUTPUT_BYTES,
volatileOutput: true,
},
signal,
);
if (!captured.ok) return captured;
Expand Down
Loading