Skip to content

Commit 477508e

Browse files
committed
fix(daemon): fold #3199's record-stop retry into the liveness-gated hint
Rebase resolution against main@294dc7d (#3199), which rewrote the same hint formatter this PR restructures. Both changes are semantic and both survive here: - #3199 made `record` a preserve-daemon policy and generalized the keep-exporting retry to LOCAL timeouts, because a preserved daemon may still be exporting (and a stop queued for the device lock is dropped before any export starts, hence "may"). This PR's shape decides "preserved" from the probe verdict + declared policy instead of the old sweep/reset booleans, so the retry branch keys on `!resetDaemon` and `action === 'stop'` BEFORE the remote split, with the remote wording merely adding "remote ". The old remote-only "is still exporting" claim becomes the shared "may still be exporting" one at #3199's second commit. - The reset branch stays this PR's: a daemon the probe proved unresponsive was SIGKILLed, is no longer exporting, and gets the probe-verdict wording with no keep-exporting promise — the exact case #3199's note about a mid-export reset predates, where the probe now makes the reset rarer. Route coverage gains a local `record stop` row: the positional rides the real transport context into the hint, the preserve policy must skip the probe entirely (connections: 1), and no sweep call may fire — #3199's runner-survival requirement, which this PR satisfies by removing the sweep for every command instead of excluding `record` by name.
1 parent 46b30e8 commit 477508e

3 files changed

Lines changed: 53 additions & 15 deletions

File tree

‎src/daemon-client/__tests__/daemon-client-timeout-route.test.ts‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,16 @@ function seedProtocolLockDir(paths: DaemonPaths, owner: { pid: number; startTime
118118
);
119119
}
120120

121-
function buildRequest(command: string, platform: 'android' | 'ios' | undefined): DaemonRequest {
121+
function buildRequest(
122+
command: string,
123+
platform: 'android' | 'ios' | undefined,
124+
positionals: readonly string[] = [],
125+
): DaemonRequest {
122126
return {
123127
token: 'test-token',
124128
session: 'default',
125129
command,
126-
positionals: [],
130+
positionals: [...positionals],
127131
flags: platform ? { platform } : {},
128132
meta: { requestId: 'req-timeout-route' },
129133
};
@@ -229,6 +233,7 @@ type RouteRow = Readonly<{
229233
transport: 'http' | 'socket' | 'remote';
230234
command: string;
231235
platform: 'android' | 'ios' | undefined;
236+
positionals?: readonly string[];
232237
afterFirst: 'answer' | 'refuse';
233238
hintPattern: RegExp;
234239
// The connections the stand-in must observe: 1 = the RPC only (route never probed),
@@ -285,6 +290,22 @@ const ROUTE_ROWS: readonly RouteRow[] = [
285290
connections: 1,
286291
resets: false,
287292
},
293+
{
294+
// `record` declares preserve-daemon (#3199), so a LOCAL timed-out `record stop` reaches the
295+
// retry hint without the probe ever running: the export the surviving daemon may still be
296+
// finishing must not lose the runner to a sweep either (#3177 removed the sweep for all
297+
// commands; this row pins that it is gone for the recorder too, on the real action positional).
298+
name: 'names the record stop retry without probing a preserve-policy recorder',
299+
transport: 'socket',
300+
command: PUBLIC_COMMANDS.record,
301+
platform: 'ios',
302+
positionals: ['stop'],
303+
afterFirst: 'answer',
304+
hintPattern:
305+
/^The daemon may still be exporting the recording\. Run agent-device record stop --session default again/,
306+
connections: 1,
307+
resets: false,
308+
},
288309
{
289310
// A remote client cannot reset anything on the daemon's host: no probe window, no sweep.
290311
name: 'keeps a remote timeout declarative',
@@ -339,7 +360,7 @@ for (const row of ROUTE_ROWS) {
339360
await expectRouteError(
340361
sendRequest(
341362
info,
342-
buildRequest(row.command, row.platform),
363+
buildRequest(row.command, row.platform, row.positionals),
343364
row.transport === 'remote' ? 'http' : row.transport,
344365
statePaths,
345366
TIMEOUT_MS,

‎src/daemon-client/__tests__/daemon-client-timeout.test.ts‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ test('request timeout hint names an Apple runner only on a declared Apple platfo
6868
);
6969
});
7070

71-
test('a timed-out remote recording names the retry that returns the export', () => {
71+
test('a timed-out record stop on a surviving daemon names the retry that returns the export', () => {
72+
// A remote client never touches the daemon's host, so its daemon survives by construction.
7273
assert.equal(
7374
resolveRequestTimeoutHint({
7475
remote: true,
@@ -78,7 +79,7 @@ test('a timed-out remote recording names the retry that returns the export', ()
7879
action: 'stop',
7980
session: 'recording',
8081
}),
81-
'The remote daemon is still exporting the recording. Run agent-device record stop --session recording again to wait for that export and receive the completed recording.',
82+
'The remote daemon may still be exporting the recording. Run agent-device record stop --session recording again to wait for that export and receive the completed recording.',
8283
);
8384
assert.equal(
8485
resolveRequestTimeoutHint({
@@ -88,10 +89,23 @@ test('a timed-out remote recording names the retry that returns the export', ()
8889
applePlatformDeclared: false,
8990
action: 'stop',
9091
}),
91-
'The remote daemon is still exporting the recording. Run agent-device record stop again to wait for that export and receive the completed recording.',
92+
'The remote daemon may still be exporting the recording. Run agent-device record stop again to wait for that export and receive the completed recording.',
9293
);
93-
// A local timeout on an unreachable daemon resets it mid-export, so no keep-exporting promise
94-
// is made; the wording says what happened to the daemon instead.
94+
// A LOCAL daemon preserved across the timeout (#3199 declares `record` preserve-daemon) may
95+
// still be exporting too, so it gets the same retry instead of the generic kept-alive wording.
96+
assert.equal(
97+
resolveRequestTimeoutHint({
98+
remote: false,
99+
resetDaemon: false,
100+
command: 'record',
101+
applePlatformDeclared: false,
102+
action: 'stop',
103+
session: 'recording',
104+
}),
105+
'The daemon may still be exporting the recording. Run agent-device record stop --session recording again to wait for that export and receive the completed recording.',
106+
);
107+
// A daemon the probe proved unresponsive was reset, and a reset daemon is no longer exporting:
108+
// no keep-exporting promise is made, and the wording says what happened to it instead.
95109
assert.equal(
96110
resolveRequestTimeoutHint({
97111
remote: false,

‎src/daemon-client/daemon-client-timeout.ts‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,17 @@ export function resolveRequestTimeoutHint(params: {
133133
session?: string;
134134
}): string {
135135
const { remote, resetDaemon, command, applePlatformDeclared, session, action } = params;
136+
// A daemon that survives this client window may still be exporting a `record stop` that ran out
137+
// of time — a stop still queued for the device lock is dropped before any export starts, hence
138+
// "may" — and a finished file stays retrievable by asking again. This holds whether the daemon
139+
// survived because the request was remote or because `record` declares preserve-daemon (#3199).
140+
// A reset daemon makes no such promise.
141+
if (!resetDaemon && command === PUBLIC_COMMANDS.record && action === 'stop') {
142+
return `The ${remote ? 'remote ' : ''}daemon may still be exporting the recording. Run agent-device record stop${
143+
session ? ` --session ${session}` : ''
144+
} again to wait for that export and receive the completed recording.`;
145+
}
136146
if (remote) {
137-
// A remote daemon survives this client window, so a `record stop` that ran out of time is still
138-
// exporting there and its finished file stays retrievable by asking again.
139-
if (command === PUBLIC_COMMANDS.record && action === 'stop') {
140-
return `The remote daemon is still exporting the recording. Run agent-device record stop${
141-
session ? ` --session ${session}` : ''
142-
} again to wait for that export and receive the completed recording.`;
143-
}
144147
return 'Retry with --debug and verify the remote daemon URL, auth token, and remote host logs.';
145148
}
146149
if (resetDaemon) {

0 commit comments

Comments
 (0)