Skip to content

Commit 50fc6fc

Browse files
committed
fix(apple-runner): name the lost reply when the status probe fails
A runner that dies mid-mutation drops the reply, and the status probe that follows fails. The error that reaches the caller was then a bare transport error (`fetch failed`, dispatched unknown), with no typed reason. #3074 requires a reason that names the lost reply, so this path now builds an error with reason runner_reply_lost (the name the restart arm already uses) and recovery status_probe_failed. The error keeps the transport message and details, and the transport error as cause. The session is still invalidated, and the command is still not resent. ADR 0011 gap list: the row ios-runner.transport.written-then-lost proves the rule behind canResendAfterRestart's mutating arm, not a production route. Over the real transport the arm cannot be reached, because mutations go through sendRunnerCommandOnce and only the connect loop raises the restart trigger. Tests: - runner-command-recovery: a failing status probe now asserts reason runner_reply_lost, recovery status_probe_failed, dispatched unknown, and the transport error as cause. - runner-recovery-wiring: press/fill whose runner dies mid-command (real fake-runner transport) now also asserts reason runner_reply_lost. Mutation: drop `reason: RUNNER_REPLY_LOST_REASON` from buildStatusProbeFailedError -> all three fail.
1 parent 4758d27 commit 50fc6fc

4 files changed

Lines changed: 46 additions & 4 deletions

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,12 @@ resolution, lock acquisition, lease and daemon-policy admission) never reaches
194194
the disclosure and carries no `dispatched`. It sends nothing, but a consumer
195195
must read the absent field as `unknown`. The public `agent-device/batch`
196196
`runBatch` has no ledger when a caller supplies its own `invoke`, so a batch run
197-
outside the daemon keeps the failing step's value.
197+
outside the daemon keeps the failing step's value. The row
198+
`ios-runner.transport.written-then-lost` proves the Apple runner's rule that a
199+
mutating command whose first send may have run is not resent after a restart,
200+
not a production route: over the real transport that arm is unreachable,
201+
because mutations go through `sendRunnerCommandOnce` and only the connect loop
202+
raises the restart trigger.
198203

199204
For `responseFields`, one `buildInteractionResponseData(...)` becomes the only
200205
construction site for interaction response payloads (this deletes the class of

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,20 @@ test('notAccepted from a restarted runner fails the lost command as unknown, nam
139139
assert.equal(invalidate.mock.calls.length, 1);
140140
});
141141

142-
test('a failing status probe retains the invalidation and rethrows the transport error', async () => {
142+
test('a failing status probe retains the invalidation and names the lost reply', async () => {
143143
const { result, invalidate, transportError } = await runRecovery({
144144
script: [{ kind: 'runnerError', code: 'COMMAND_FAILED', message: 'status probe exploded' }],
145145
});
146146

147-
await assert.rejects(result, (error: unknown) => error === transportError);
147+
await assert.rejects(result, (error: unknown) => {
148+
assert.ok(error instanceof AppError);
149+
assert.equal(error.message, transportError.message);
150+
assert.equal(error.cause, transportError);
151+
assert.equal(error.details?.reason, RUNNER_REPLY_LOST_REASON);
152+
assert.equal(error.details?.recovery, 'status_probe_failed');
153+
assert.equal(error.details?.dispatched, 'unknown');
154+
return true;
155+
});
148156
assert.equal(invalidate.mock.calls.length, 1);
149157
});
150158

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ test.each(Object.values(LOST_RESPONSE_MUTATION_ROWS))(
251251
await assert.rejects(runAppleRunnerCommand(IOS_SIMULATOR, { ...request }), (error: unknown) => {
252252
assert.ok(error instanceof AppError);
253253
assert.equal(error.details?.dispatched, 'unknown');
254+
assert.equal(error.details?.reason, RUNNER_REPLY_LOST_REASON);
254255
return true;
255256
});
256257
assert.equal(invalidateRunnerSessionMock.mock.calls.length, 1, 'the dead runner is dropped');

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,12 @@ async function tryRecoverRunnerCommandAfterTransportError(
204204
...readinessPreflight,
205205
},
206206
});
207-
return { type: 'retainInvalidation', reason: 'status_probe_failed', dispatched: 'unknown' };
207+
return {
208+
type: 'retainInvalidation',
209+
reason: 'status_probe_failed',
210+
dispatched: 'unknown',
211+
error: buildStatusProbeFailedError(command, transportError, options),
212+
};
208213
}
209214

210215
const lifecycleState = typeof status.lifecycleState === 'string' ? status.lifecycleState : '';
@@ -505,6 +510,29 @@ function readReadinessPreflightRecoveryDetails(
505510
return details;
506511
}
507512

513+
/** The lost reply could not be placed because the status probe itself failed. */
514+
function buildStatusProbeFailedError(
515+
command: RunnerCommand,
516+
transportError: AppError,
517+
options: AppleRunnerCommandOptions,
518+
): AppError {
519+
return new AppError(
520+
transportError.code,
521+
transportError.message,
522+
{
523+
...transportError.details,
524+
command: command.command,
525+
commandId: command.commandId,
526+
reason: RUNNER_REPLY_LOST_REASON,
527+
recovery: 'status_probe_failed',
528+
hint: unknownLifecycleStateHint(command.command),
529+
logPath: options.logPath ?? transportError.details?.logPath,
530+
transportError: transportError.message,
531+
},
532+
transportError,
533+
);
534+
}
535+
508536
function unknownLifecycleStateHint(command: string): string {
509537
return `The runner did not confirm that "${command}" reached a safe terminal state, so agent-device kept the conservative invalidation path. Run snapshot -i before retrying if the UI may have changed.`;
510538
}

0 commit comments

Comments
 (0)