Skip to content

Commit d0afa30

Browse files
committed
fix(timeouts): prove install request envelope
1 parent 112d291 commit d0afa30

13 files changed

Lines changed: 596 additions & 31 deletions

File tree

‎packages/command-registry/src/registry.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
DEFAULT_TIMEOUT_POLICY,
1818
FOLD_TIMEOUT_POLICY,
1919
INSTALL_REQUEST_TIMEOUT_MS,
20+
INSTALL_SOURCE_REQUEST_TIMEOUT_MS,
2021
LEASE_ALLOCATE_REQUEST_TIMEOUT_MS,
2122
PREPARE_REQUEST_TIMEOUT_MS,
2223
} from './timeout-policy.ts';
@@ -347,8 +348,6 @@ const PRESERVE_DAEMON_TIMEOUT_POLICY: CommandTimeoutPolicy = {
347348
onTimeout: 'preserve-daemon',
348349
};
349350

350-
// Installs run long device subprocesses; their envelope stays above the longest
351-
// platform install subprocess timeout (see INSTALL_REQUEST_TIMEOUT_MS).
352351
const INSTALL_TIMEOUT_POLICY: CommandTimeoutPolicy = {
353352
...DEFAULT_TIMEOUT_POLICY,
354353
envelopeMs: INSTALL_REQUEST_TIMEOUT_MS,
@@ -979,7 +978,7 @@ export const RAW_COMMAND_DESCRIPTORS = [
979978
recordingEffect: 'mutates-app',
980979
daemon: { route: 'session', refFrameEffect: 'may-invalidate' },
981980
platformExecution: { kind: 'device-runtime', use: readyMaterializeAndDeployAppUse },
982-
timeoutPolicy: INSTALL_TIMEOUT_POLICY,
981+
timeoutPolicy: { ...INSTALL_TIMEOUT_POLICY, envelopeMs: INSTALL_SOURCE_REQUEST_TIMEOUT_MS },
983982
batchable: false,
984983
},
985984
{
@@ -1649,7 +1648,7 @@ export const RAW_COMMAND_DESCRIPTORS = [
16491648
recordsSessionAction: true,
16501649
recordingEffect: 'mutates-app',
16511650
platformExecution: { kind: 'device-runtime', use: readyMaterializeAndDeployAppUse },
1652-
timeoutPolicy: DEFAULT_TIMEOUT_POLICY,
1651+
timeoutPolicy: { ...INSTALL_TIMEOUT_POLICY, envelopeMs: INSTALL_SOURCE_REQUEST_TIMEOUT_MS },
16531652
batchable: true,
16541653
},
16551654

‎packages/command-registry/src/timeout-policy.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ import type { CommandTimeoutBudget, CommandTimeoutPolicy } from './types.ts';
66

77
const DAEMON_REQUEST_TIMEOUT_MS = 90_000;
88

9-
// Keep this above the longest platform install subprocess timeout so the client
10-
// envelope does not abort a still-progressing device install first.
11-
export const INSTALL_REQUEST_TIMEOUT_MS = 180_000;
9+
// Covers the install/reinstall/uninstall route's worst-case ledger plus the daemon-result margin.
10+
// Proven by the ledger test: `test/integration/provider-scenarios/install-timeout-ledger.test.ts`.
11+
export const INSTALL_REQUEST_TIMEOUT_MS = 330_000;
12+
13+
// Adds room for install-from-source URL materialization before the same platform install ledgers.
14+
export const INSTALL_SOURCE_REQUEST_TIMEOUT_MS = 420_000;
1215

1316
// Margin over a daemon-side budget so the daemon's own timeout result (with
1417
// diagnostics) wins the race against the client envelope. Never shrinks the

‎packages/contracts/src/platform-runtime-host.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,15 @@ export type AndroidToolHost = Readonly<{
101101
installPackage(
102102
device: DeviceInfo,
103103
packagePath: string,
104-
options: Readonly<{ replace: boolean }>,
104+
options: Readonly<{ replace: boolean; timeoutMs?: number }>,
105105
signal?: AbortSignal,
106106
): Promise<HostCommandResult>;
107107
/** Returns false when the selected transport has no bundle installer. */
108108
installBundle(
109109
device: DeviceInfo,
110110
bundlePath: string,
111111
mode: string,
112+
options?: Readonly<{ timeoutMs?: number }>,
112113
signal?: AbortSignal,
113114
): Promise<boolean>;
114115
}>;

‎packages/platform-android/src/adb-transport.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export type AndroidAdbInstaller = (
133133

134134
export type AndroidBundleInstaller = (
135135
bundlePath: string,
136-
options: Readonly<{ mode: string; signal?: AbortSignal }>,
136+
options: Readonly<{ mode: string; signal?: AbortSignal; timeoutMs?: number }>,
137137
) => Promise<void>;
138138

139139
export type AndroidTextInputAction = 'type' | 'fill';

‎packages/platform-android/src/deployment/native.test.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function hostFixture(options: { bundletool?: boolean; bundletoolJar?: string } =
3939
executable: 'adb-install',
4040
args: [packagePath],
4141
replace: options.replace,
42+
timeoutMs: options.timeoutMs,
4243
},
4344
signal,
4445
),
@@ -73,6 +74,7 @@ test('constructs a signal-bound adb install in the Android package', async () =>
7374
executable: 'adb-install',
7475
args: ['/tmp/app.apk'],
7576
replace: true,
77+
timeoutMs: 120_000,
7678
}),
7779
signal,
7880
);
@@ -98,9 +100,14 @@ test('owns bundletool command construction and temporary output cleanup', async
98100

99101
await installAndroidArtifact(host, device, '/tmp/app.aab', 'com.example.app', signal);
100102

101-
expect(run.mock.calls.map(([request]) => request.args[0])).toEqual([
102-
'build-apks',
103-
'install-apks',
103+
expect(
104+
run.mock.calls.map(([request]) => ({
105+
command: request.args[0],
106+
timeoutMs: request.timeoutMs,
107+
})),
108+
).toEqual([
109+
{ command: 'build-apks', timeoutMs: 120_000 },
110+
{ command: 'install-apks', timeoutMs: 120_000 },
104111
]);
105112
expect(run.mock.calls.every(([, actualSignal]) => actualSignal === signal)).toBe(true);
106113
expect(dispose).toHaveBeenCalledOnce();

‎packages/platform-android/src/deployment/native.ts‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { deviceShellArgv, type ShellWord } from '@agent-device/kernel/device-she
55
import { AppError } from '@agent-device/kernel/errors';
66
import path from 'node:path';
77

8+
const ANDROID_APP_INSTALL_TIMEOUT_MS = 120_000;
9+
const ANDROID_APP_DEPLOYMENT_ADB_TIMEOUT_MS = 15_000;
10+
811
export async function installAndroidArtifact(
912
host: PlatformRuntimeHost,
1013
device: DeviceInfo,
@@ -19,7 +22,7 @@ export async function installAndroidArtifact(
1922
const result = await host.androidTools.installPackage(
2023
device,
2124
installablePath,
22-
{ replace: true },
25+
{ replace: true, timeoutMs: ANDROID_APP_INSTALL_TIMEOUT_MS },
2326
signal,
2427
);
2528
assertCommandSuccess(result, 'adb install failed');
@@ -36,7 +39,13 @@ export async function uninstallAndroidPackage(
3639
packageName: string,
3740
signal: AbortSignal,
3841
): Promise<void> {
39-
const result = await runAdb(host, device, ['uninstall', packageName], signal);
42+
const result = await runAdb(
43+
host,
44+
device,
45+
['uninstall', packageName],
46+
signal,
47+
ANDROID_APP_DEPLOYMENT_ADB_TIMEOUT_MS,
48+
);
4049
if (result.exitCode === 0) return;
4150
const output = `${result.stdout}\n${result.stderr}`.toLowerCase();
4251
if (output.includes('unknown package') || output.includes('not installed')) return;
@@ -100,7 +109,16 @@ async function installAndroidBundle(
100109
bundlePath: string,
101110
signal: AbortSignal,
102111
): Promise<void> {
103-
if (await host.androidTools.installBundle(device, bundlePath, 'universal', signal)) return;
112+
if (
113+
await host.androidTools.installBundle(
114+
device,
115+
bundlePath,
116+
'universal',
117+
{ timeoutMs: ANDROID_APP_INSTALL_TIMEOUT_MS },
118+
signal,
119+
)
120+
)
121+
return;
104122
const bundletool = await host.commands.which('bundletool');
105123
const jar = host.androidDeployment.bundletoolJar;
106124
if (!bundletool && !jar) {
@@ -131,6 +149,7 @@ async function installAndroidBundle(
131149
'--mode',
132150
'universal',
133151
],
152+
timeoutMs: ANDROID_APP_INSTALL_TIMEOUT_MS,
134153
},
135154
signal,
136155
),
@@ -141,6 +160,7 @@ async function installAndroidBundle(
141160
{
142161
executable,
143162
args: [...prefix, 'install-apks', '--apks', apksPath, '--device-id', device.id],
163+
timeoutMs: ANDROID_APP_INSTALL_TIMEOUT_MS,
144164
},
145165
signal,
146166
),
@@ -189,7 +209,7 @@ async function runAdb(
189209
device: DeviceInfo,
190210
args: readonly string[],
191211
signal: AbortSignal,
192-
timeoutMs = 15_000,
212+
timeoutMs = ANDROID_APP_DEPLOYMENT_ADB_TIMEOUT_MS,
193213
) {
194214
return await host.androidTools.runAdb(device, args, { timeoutMs, allowFailure: true }, signal);
195215
}

‎packages/platform-apple/src/core/config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const IOS_DEVICECTL_TIMEOUT_MS = 20_000;
99
export const IOS_DEVICECTL_MIN_TIMEOUT_SECONDS = 5;
1010

1111
export const IOS_DEVICE_INSTALL_TIMEOUT_MS = 120_000;
12+
export const IOS_APP_UNINSTALL_TIMEOUT_MS = 20_000;
1213

1314
export const IOS_SIMULATOR_SHOW_TIMEOUT_MS = 10_000;
1415

‎packages/platform-apple/src/deployment/runtime.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { isIosFamily, type DeviceInfo } from '@agent-device/kernel/device';
1818
import { AppError } from '@agent-device/kernel/errors';
1919
import { requireExecSuccess } from '@agent-device/host-kit/command';
2020
import { isMissingAppErrorOutput } from '../core/physical-device-apps.ts';
21-
import { IOS_DEVICE_INSTALL_TIMEOUT_MS } from '../core/config.ts';
21+
import { IOS_APP_UNINSTALL_TIMEOUT_MS, IOS_DEVICE_INSTALL_TIMEOUT_MS } from '../core/config.ts';
2222
import { IOS_DEVICECTL_DEFAULT_HINT, resolveIosDevicectlHint } from '../core/devicectl.ts';
2323
import { ensureAppleReady } from '../readiness/runtime.ts';
2424
import { scopeSimctlArgsForDevice } from '../core/simctl.ts';
@@ -178,6 +178,7 @@ async function installAppleApp(
178178
? {
179179
tool: 'simctl',
180180
args: scopeSimctlArgsForDevice(device, ['install', device.id, installablePath]),
181+
timeoutMs: IOS_DEVICE_INSTALL_TIMEOUT_MS,
181182
}
182183
: {
183184
tool: 'devicectl',
@@ -202,10 +203,12 @@ async function uninstallAppleApp(
202203
? {
203204
tool: 'simctl',
204205
args: scopeSimctlArgsForDevice(device, ['uninstall', device.id, bundleId]),
206+
timeoutMs: IOS_APP_UNINSTALL_TIMEOUT_MS,
205207
}
206208
: {
207209
tool: 'devicectl',
208210
args: ['device', 'uninstall', 'app', '--device', device.id, bundleId],
211+
timeoutMs: IOS_APP_UNINSTALL_TIMEOUT_MS,
209212
},
210213
signal,
211214
`Apple app uninstall failed for ${bundleId}`,

‎packages/provision-kit/src/install-source.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const INTERNAL_ARCHIVE_EXTENSIONS = ['.zip', '.tar', '.tar.gz', '.tgz'] as const
4545
* @public Archive extensions accepted by install-source resolution.
4646
*/
4747
export const ARCHIVE_EXTENSIONS = Object.freeze([...INTERNAL_ARCHIVE_EXTENSIONS] as const);
48-
const DEFAULT_SOURCE_DOWNLOAD_TIMEOUT_MS = 120_000;
48+
export const INSTALL_SOURCE_DOWNLOAD_TIMEOUT_MS = 120_000;
4949

5050
export async function materializeInstallablePath(
5151
options: MaterializeInstallableOptions,
@@ -124,7 +124,7 @@ async function downloadToTempFile(
124124
if (requestSignal?.aborted) {
125125
throw createRequestCanceledError();
126126
}
127-
const timeoutSignal = AbortSignal.timeout(DEFAULT_SOURCE_DOWNLOAD_TIMEOUT_MS);
127+
const timeoutSignal = AbortSignal.timeout(INSTALL_SOURCE_DOWNLOAD_TIMEOUT_MS);
128128
const signal = requestSignal ? AbortSignal.any([requestSignal, timeoutSignal]) : timeoutSignal;
129129
try {
130130
return await downloadInstallSource({
@@ -139,7 +139,7 @@ async function downloadToTempFile(
139139
error,
140140
requestSignal,
141141
timeoutSignal,
142-
DEFAULT_SOURCE_DOWNLOAD_TIMEOUT_MS,
142+
INSTALL_SOURCE_DOWNLOAD_TIMEOUT_MS,
143143
);
144144
}
145145
}

‎src/__tests__/command-descriptor-timeout-policy.test.ts‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,13 @@ test('request envelopes deviating from the default are bounded, reviewed sets',
145145
const EXPECTED_ENVELOPES: Record<string, number | 'unbounded'> = {
146146
// prepare: daemon-side runner budget (PREPARE_STARTUP_BUDGET_MS) plus the daemon-result margin.
147147
prepare: 270_000,
148-
install: 180_000,
149-
reinstall: 180_000,
150-
uninstall: 180_000,
151-
install_source: 180_000,
148+
// install family: proven by the worst-case ledger test in
149+
// test/integration/provider-scenarios/install-timeout-ledger.test.ts.
150+
install: 330_000,
151+
reinstall: 330_000,
152+
uninstall: 330_000,
153+
'install-from-source': 420_000,
154+
install_source: 420_000,
152155
longpress: 210_000,
153156
// fold: proven by the worst-case ledger test in
154157
// test/integration/provider-scenarios/ios-fold.test.ts.
@@ -309,15 +312,15 @@ test('snapshot uses the standard daemon request timeout with an explicit overrid
309312
);
310313
assert.equal(
311314
resolveCommandRequestTimeoutMs(resolveCommandTimeoutPolicy('install'), { ...base }),
312-
180_000,
315+
330_000,
313316
);
314317
assert.equal(
315318
resolveCommandRequestTimeoutMs(resolveCommandTimeoutPolicy('reinstall'), { ...base }),
316-
180_000,
319+
330_000,
317320
);
318321
assert.equal(
319322
resolveCommandRequestTimeoutMs(resolveCommandTimeoutPolicy('install_source'), { ...base }),
320-
180_000,
323+
420_000,
321324
);
322325
assert.equal(
323326
resolveCommandRequestTimeoutMs(resolveCommandTimeoutPolicy('prepare'), {

0 commit comments

Comments
 (0)