Skip to content

Commit 5f61be1

Browse files
committed
fix: shorten snapshot request timeout
1 parent 7c065bc commit 5f61be1

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

src/daemon-client.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ type EnsuredDaemon = {
116116
type ResolvedDaemonTransport = 'socket' | 'http';
117117

118118
const REQUEST_TIMEOUT_MS = 90_000;
119+
const SNAPSHOT_REQUEST_TIMEOUT_MS = 30_000;
119120
const DAEMON_STARTUP_TIMEOUT_MS = 15_000;
120121
const DAEMON_STARTUP_ATTEMPTS = 2;
121122
const DAEMON_TAKEOVER_TERM_TIMEOUT_MS = 3000;
@@ -192,14 +193,17 @@ export async function sendToDaemon(req: Omit<DaemonRequest, 'token'>): Promise<D
192193
}
193194
}
194195

195-
function resolveDaemonRequestTimeoutMs(req: Omit<DaemonRequest, 'token'>): number | undefined {
196+
export function resolveDaemonRequestTimeoutMs(
197+
req: Omit<DaemonRequest, 'token'>,
198+
): number | undefined {
196199
if (req.command === PUBLIC_COMMANDS.test) return undefined;
197200
if (
198201
(req.command === PUBLIC_COMMANDS.replay || req.command === PUBLIC_COMMANDS.prepare) &&
199202
typeof req.flags?.timeoutMs === 'number'
200203
) {
201204
return req.flags.timeoutMs;
202205
}
206+
if (req.command === PUBLIC_COMMANDS.snapshot) return SNAPSHOT_REQUEST_TIMEOUT_MS;
203207
return REQUEST_TIMEOUT_MS;
204208
}
205209

@@ -1146,7 +1150,11 @@ function resolveRequestTimeoutHint(params: {
11461150
return 'Retry with --debug and verify the remote daemon URL, auth token, and remote host logs.';
11471151
}
11481152
if (!resetDaemon) {
1149-
return `Retry with --debug and check daemon diagnostics logs. The timed-out ${command ?? 'request'} request was canceled and iOS runner work was aborted when detected; the daemon was kept alive so the session can still be closed or inspected.`;
1153+
const iosPrepareHint =
1154+
command === PUBLIC_COMMANDS.snapshot
1155+
? ' If this was the first iOS snapshot on the device, run agent-device prepare ios-runner --platform ios before snapshot/test so runner startup is handled explicitly.'
1156+
: '';
1157+
return `Retry with --debug and check daemon diagnostics logs. The timed-out ${command ?? 'request'} request was canceled and iOS runner work was aborted when detected; the daemon was kept alive so the session can still be closed or inspected.${iosPrepareHint}`;
11501158
}
11511159
return 'Retry with --debug and check daemon diagnostics logs. Timed-out iOS runner xcodebuild processes were terminated when detected.';
11521160
}

src/utils/__tests__/daemon-client.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
computeDaemonCodeSignature,
1919
downloadRemoteArtifact,
2020
openApp,
21+
resolveDaemonRequestTimeoutMs,
2122
resolveDaemonStartupHint,
2223
sendToDaemon,
2324
shouldResetDaemonAfterRequestTimeout,
@@ -165,6 +166,28 @@ test('snapshot request timeout preserves daemon metadata for follow-up evidence
165166
assert.equal(shouldResetDaemonAfterRequestTimeout(undefined), true);
166167
});
167168

169+
test('snapshot uses a shorter daemon request timeout than runner prepare', () => {
170+
const base = {
171+
session: 'default',
172+
positionals: [],
173+
flags: {},
174+
meta: {},
175+
};
176+
177+
assert.equal(resolveDaemonRequestTimeoutMs({ ...base, command: 'snapshot' }), 30_000);
178+
assert.equal(resolveDaemonRequestTimeoutMs({ ...base, command: 'screenshot' }), 90_000);
179+
assert.equal(
180+
resolveDaemonRequestTimeoutMs({
181+
...base,
182+
command: 'prepare',
183+
positionals: ['ios-runner'],
184+
flags: { timeoutMs: 240_000 },
185+
}),
186+
240_000,
187+
);
188+
assert.equal(resolveDaemonRequestTimeoutMs({ ...base, command: 'test' }), undefined);
189+
});
190+
168191
test('cleanupFailedDaemonStartupMetadata removes partial startup metadata', async () => {
169192
const stateDir = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-device-daemon-cleanup-'));
170193
const paths = resolveDaemonPaths(stateDir);

0 commit comments

Comments
 (0)