Skip to content

Commit 4e88908

Browse files
committed
refactor(apple-runner): build every lost-reply failure in one place with one reason
Status recovery verdicts now carry either the runner's own answer or the facts of a lost reply. applyRunnerTransportRecovery turns a lost reply into one buildLostReplyError for a mutation, so runner_reply_lost is set on every lost-reply verdict (completed without a retained reply, still in flight, unknown or missing lifecycle, status probe failed, status unavailable) and the transport's reason stays under transportReason. A read keeps its transport error, which the read-only resend loop resends, so it never carries the reason. The four hand-built copies are gone.
1 parent 66ef675 commit 4e88908

4 files changed

Lines changed: 180 additions & 146 deletions

File tree

‎docs/adr/0011-interaction-guarantee-contract.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,11 @@ producer.
194194

195195
The Apple runner does not resend a mutating command whose first send may have
196196
run: a restart resends only a command the first attempt provably did not write,
197-
or a read-only one. A mutation whose runner dies mid-command fails with
198-
`reason: runner_reply_lost` and `dispatched: unknown` (row
199-
`ios-runner.transport.written-then-lost`).
197+
or a read-only one. A mutation whose reply stays lost (the runner dies
198+
mid-command, or status recovery finds neither a retained result nor a runner
199+
answer) fails with `reason: runner_reply_lost` and `dispatched: unknown` (row
200+
`ios-runner.transport.written-then-lost` and the lost-reply `ios-runner.status.*`
201+
rows). A read keeps its transport error and is resent.
200202

201203
Remaining gaps: a failure before the router's locked scope (session
202204
resolution, lock acquisition, lease and daemon-policy admission) never reaches

‎packages/platform-apple/src/runner/__tests__/runner-command-recovery.test.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,19 @@ test('a failing status probe retains the invalidation and names the lost reply',
158158
assert.equal(invalidate.mock.calls.length, 1);
159159
});
160160

161-
test('a command without an id cannot be probed: invalidate and rethrow', async () => {
161+
test('a command without an id cannot be probed: invalidate and name the lost reply', async () => {
162162
const { result, invalidate, transportError } = await runRecovery({
163163
script: [],
164164
command: { command: 'tap', x: 10, y: 10 } as RunnerCommand,
165165
});
166166

167-
await assert.rejects(result, (error: unknown) => error === transportError);
167+
await assert.rejects(result, (error: unknown) => {
168+
assert.ok(error instanceof AppError);
169+
assert.equal(error.cause, transportError);
170+
assert.equal(error.details?.reason, RUNNER_REPLY_LOST_REASON);
171+
assert.equal(error.details?.recovery, 'status_recovery_unavailable');
172+
return true;
173+
});
168174
assert.equal(invalidate.mock.calls.length, 1);
169175
assert.equal(server?.requests.length, 0);
170176
});

‎packages/platform-apple/src/runner/__tests__/runner-dispatch-disclosure.test.ts‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import {
99
dispatchDisclosureRowsOwnedBy,
1010
} from '@agent-device/contracts/dispatch-disclosure-fixtures';
1111
import { IOS_SIMULATOR } from './device-fixtures.ts';
12-
import { handleRunnerTransportErrorAfterCommandSend } from '../runner-command-recovery.ts';
12+
import {
13+
handleRunnerTransportErrorAfterCommandSend,
14+
RUNNER_REPLY_LOST_REASON,
15+
} from '../runner-command-recovery.ts';
1316
import { isReadOnlyRunnerCommand } from '../runner-command-traits.ts';
1417
import type { RunnerCommand } from '../runner-contract.ts';
1518
import {
@@ -206,6 +209,16 @@ const DRIVERS: Record<string, () => Promise<unknown>> = {
206209
lostResponse([], { command: 'tap', x: 10, y: 10 } as RunnerCommand),
207210
};
208211

212+
/** The rows whose mutation's reply stayed lost: each fails as runner_reply_lost and is not resent. */
213+
const REPLY_LOST_ROWS: ReadonlySet<string> = new Set([
214+
'ios-runner.status.completed-without-retained-reply',
215+
'ios-runner.status.accepted',
216+
'ios-runner.status.started',
217+
'ios-runner.status.notAccepted',
218+
'ios-runner.status.probe-failed',
219+
'ios-runner.status.unavailable',
220+
]);
221+
209222
const ROWS = dispatchDisclosureRowsOwnedBy(
210223
import.meta.url,
211224
fs.readFileSync(DISPATCH_DISCLOSURE_TABLE_PATH, 'utf8'),
@@ -222,7 +235,27 @@ for (const row of ROWS) {
222235
await assert.rejects(drive(), (error: unknown) => {
223236
assert.ok(error instanceof AppError);
224237
assert.equal(error.details?.dispatched, row.dispatched);
238+
assert.equal(error.details?.reason === RUNNER_REPLY_LOST_REASON, REPLY_LOST_ROWS.has(row.id));
225239
return true;
226240
});
227241
});
228242
}
243+
244+
const SNAPSHOT: RunnerCommand = { command: 'snapshot', commandId: 'cmd-1' };
245+
246+
test.each([
247+
['the status probe fails', [{ kind: 'runnerError', code: 'COMMAND_FAILED', message: 'down' }]],
248+
['status answers notAccepted', statusReply({ lifecycleState: 'notAccepted' })],
249+
['status answers started', statusReply({ lifecycleState: 'started' })],
250+
['status answers completed with no retained reply', statusReply({ lifecycleState: 'completed' })],
251+
] as const)(
252+
'a read whose reply is lost when %s keeps the transport error it is resent on',
253+
async (_, status) => {
254+
await assert.rejects(lostResponse([...status], SNAPSHOT), (error: unknown) => {
255+
assert.ok(error instanceof AppError);
256+
assert.notEqual(error.details?.reason, RUNNER_REPLY_LOST_REASON);
257+
assert.equal(isRetryableRunnerError(error), true);
258+
return true;
259+
});
260+
},
261+
);

0 commit comments

Comments
 (0)