Skip to content

Commit f02edea

Browse files
airoweclaude
andcommitted
refactor(android): track the dump budget with host-kit's Deadline
Matches the other platform-android modules that bound a sequence of steps, instead of computing the deadline and remainder by hand. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 3167664 commit f02edea

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

‎packages/platform-android/src/observation.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
import type { AppStateRuntimeResult } from '@agent-device/contracts/app-state-runtime';
77
import type { DeviceInfo } from '@agent-device/kernel/device';
88
import { isCommandTimeoutError } from '@agent-device/host-kit/command';
9+
import { Deadline } from '@agent-device/host-kit/retry';
910
import { deviceShellArgv } from '@agent-device/kernel/device-shell';
1011
import { AppError } from '@agent-device/kernel/errors';
1112
import {
@@ -90,18 +91,17 @@ export function createAndroidObservationAdapter(
9091
*/
9192
function createDumpReader(host: AndroidObservationHost, device: DeviceInfo): DumpReader {
9293
const dumps = new Map<string, Promise<string>>();
93-
let deadlineMs: number | undefined;
94+
let deadline: Deadline | undefined;
9495
return (words) => {
9596
const key = words.join(' ');
9697
const cached = dumps.get(key);
9798
if (cached) return cached;
98-
deadlineMs ??= Date.now() + DUMP_OBSERVATION_BUDGET_MS;
99-
const remainingMs = deadlineMs - Date.now();
100-
if (remainingMs <= 0) return Promise.resolve('');
99+
deadline ??= Deadline.fromTimeoutMs(DUMP_OBSERVATION_BUDGET_MS);
100+
if (deadline.isExpired()) return Promise.resolve('');
101101
const pending = host
102102
.runAdb(device, deviceShellArgv('adb', 'shell', words), {
103103
allowFailure: true,
104-
timeoutMs: remainingMs,
104+
timeoutMs: deadline.remainingMs(),
105105
})
106106
.then(
107107
(result) => {

0 commit comments

Comments
 (0)