Skip to content

Commit be1b89f

Browse files
committed
fix(apple-runner): report the restart transport fact for a read, not no
The restart path disclosed `no` for a read-only command whose first send may have run, while the status-recovery path discloses `unknown` for the same read (read_only_completed_without_retained_response, and the notAccepted/unknown-state fallthrough). Both runner paths now report the transport fact: a first attempt that may have written the command is `unknown`, read or mutation. The read-only `no` has one owner, the daemon router seam (request-dispatch-disclosure.ts), which keys it on the registry's recordingEffect `observes-app` for every producer (daemon.read-only-command). A second copy keyed on the runner's own read-only trait reconstructed that rule from a different source of truth, and the two runner paths disagreed. The recycle-budget refusal on the restart path also stops deriving `no` from the read-only trait and uses only whether the first attempt was provably unwritten. The runner still resends a read on the restarted runner (canResendAfterRestart); only the disclosure changes. dispatch-disclosure.json: - ios-runner.transport.read-only-written-then-lost: now `unknown`; the trigger names the router rule that turns it into `no` for the caller. - ios-runner.status.read-only-completed-without-retained-reply: new, `unknown`, driven through the real connect loop and recovery module. It pins the status-recovery read to the same value as the restart read. Mutations: - put back `if (isReadOnlyRunnerCommand(evidence.command)) return discloseDispatch(error, 'no')` in discloseRestartDispatch -> read-only-written-then-lost fails. - set `dispatched: 'no'` on read_only_completed_without_retained_response -> status.read-only-completed-without-retained-reply fails.
1 parent 4708d4f commit be1b89f

3 files changed

Lines changed: 37 additions & 11 deletions

File tree

‎contracts/fixtures/dispatch-disclosure.json‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@
244244
{
245245
"id": "ios-runner.transport.read-only-written-then-lost",
246246
"producer": "ios-runner",
247-
"trigger": "a connect attempt posted a read-only command and then timed out (fetch deadline, simctl curl exit 28); the runner is restarted and the read is sent again, a read has no side effect, and the resend failed",
248-
"dispatched": "no"
247+
"trigger": "a connect attempt posted a read-only command and then timed out (fetch deadline, simctl curl exit 28); the runner is restarted and the read is sent again, and the resend failed; the first send may have run, so the runner reports unknown, and the daemon's read-only rule (daemon.read-only-command) reports no to the caller",
248+
"dispatched": "unknown"
249249
},
250250
{
251251
"id": "ios-runner.pre-send.readiness-preflight-after-restart",
@@ -277,6 +277,12 @@
277277
"trigger": "transport lost; status probe reports lifecycleState completed without a readable retained reply",
278278
"dispatched": "unknown"
279279
},
280+
{
281+
"id": "ios-runner.status.read-only-completed-without-retained-reply",
282+
"producer": "ios-runner",
283+
"trigger": "transport lost on a read-only command; status probe reports lifecycleState completed without a readable retained reply; the runner reports unknown, and the daemon's read-only rule (daemon.read-only-command) reports no to the caller",
284+
"dispatched": "unknown"
285+
},
280286
{
281287
"id": "ios-runner.status.accepted",
282288
"producer": "ios-runner",

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from '@agent-device/contracts/dispatch-disclosure-fixtures';
1111
import { IOS_SIMULATOR } from './device-fixtures.ts';
1212
import { handleRunnerTransportErrorAfterCommandSend } from '../runner-command-recovery.ts';
13+
import { isReadOnlyRunnerCommand } from '../runner-command-traits.ts';
1314
import type { RunnerCommand } from '../runner-contract.ts';
1415
import {
1516
isRetryableRunnerError,
@@ -18,6 +19,7 @@ import {
1819
import { runApplePressSeries } from '../runner-sequence.ts';
1920
import { executeRunnerCommandWithSession, type RunnerSession } from '../runner-session.ts';
2021
import { RunnerCommandAccounting } from '../runner-session-types.ts';
22+
import { appleRunnerTestHost } from '../test-host.ts';
2123
import {
2224
startFakeRunnerServer,
2325
type FakeRunnerCommandScript,
@@ -66,19 +68,32 @@ async function replyFailure(code: string): Promise<unknown> {
6668
);
6769
}
6870

69-
/** The runner hangs up on the command, then answers the status probe with `status`. */
71+
/**
72+
* The runner hangs up on the command, then answers the status probe with `status`. A read goes
73+
* through the connect loop, which posts again on each attempt, so the runner hangs up on every
74+
* attempt and the loop's simctl curl fallback times out after its POST.
75+
*/
7076
async function lostResponse(
7177
status: FakeRunnerResponse[],
7278
command: RunnerCommand = TAP,
7379
): Promise<unknown> {
74-
server = await startFakeRunnerServer({ tap: [{ kind: 'hangUp' }], status });
80+
const readOnly = isReadOnlyRunnerCommand(command);
81+
const hangUps: FakeRunnerResponse[] = Array.from({ length: readOnly ? 20 : 1 }, () => ({
82+
kind: 'hangUp',
83+
}));
84+
server = await startFakeRunnerServer({ [command.command]: hangUps, status });
85+
if (readOnly) {
86+
appleRunnerTestHost.update({
87+
runXcrun: vi.fn(async () => ({ exitCode: 28, stdout: '', stderr: 'curl exited 28' })),
88+
});
89+
}
7590
const session = runnerSession(server.port);
7691
const transportError = await executeRunnerCommandWithSession(
7792
IOS_SIMULATOR,
7893
session,
7994
command,
8095
undefined,
81-
5_000,
96+
readOnly ? 400 : 5_000,
8297
).then(
8398
() => assert.fail('the fake runner hangs up on the command'),
8499
(error: unknown) => asAppError(error, 'COMMAND_FAILED'),
@@ -175,6 +190,11 @@ const DRIVERS: Record<string, () => Promise<unknown>> = {
175190
lostResponse(statusReply({ lifecycleState: 'failed', lifecycleErrorCode: 'RUNNER_BUSY' })),
176191
'ios-runner.status.completed-without-retained-reply': () =>
177192
lostResponse(statusReply({ lifecycleState: 'completed' })),
193+
'ios-runner.status.read-only-completed-without-retained-reply': () =>
194+
lostResponse(statusReply({ lifecycleState: 'completed' }), {
195+
command: 'snapshot',
196+
commandId: 'cmd-1',
197+
}),
178198
'ios-runner.status.accepted': () => lostResponse(statusReply({ lifecycleState: 'accepted' })),
179199
'ios-runner.status.started': () => lostResponse(statusReply({ lifecycleState: 'started' })),
180200
'ios-runner.status.notAccepted': () =>

‎packages/platform-apple/src/runner/runner-lifecycle.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ async function restartSessionAndRunCommand(params: {
423423
if (!tryBeginRunnerRecycle(recycleKey)) {
424424
throw discloseDispatch(
425425
buildRunnerRecycleBudgetExhaustedError(command, options),
426-
canResendAfterRestart(params) ? 'no' : 'unknown',
426+
params.firstAttemptUnwritten ? 'no' : 'unknown',
427427
);
428428
}
429429
await invalidateRunnerSession(params.session, restartReason);
@@ -529,17 +529,17 @@ function markRunnerRestartError(
529529
}
530530

531531
/**
532-
* A read-only command has no side effect to repeat, so its failure is `no` however many sends it
533-
* took. A mutating command whose first attempt may have written it is `unknown`: it is never resent.
534-
* After an unwritten first attempt, a restart that never replayed is `no`, and a replay's own verdict
535-
* stands; without one, only a pre-send refusal is `no`.
532+
* The transport fact, for reads and mutations alike: a first attempt that may have written the
533+
* command is `unknown`, whether or not a read was resent. After an unwritten first attempt, a
534+
* restart that never replayed is `no`, and a replay's own verdict stands; without one, only a
535+
* pre-send refusal is `no`. That a read repeats no app-visible action is the daemon router's rule
536+
* over the registry's `recordingEffect`, not this producer's.
536537
*/
537538
function discloseRestartDispatch(
538539
error: AppError,
539540
evidence: RunnerRestartResendEvidence,
540541
restartedSession: RunnerSession | undefined,
541542
): AppError {
542-
if (isReadOnlyRunnerCommand(evidence.command)) return discloseDispatch(error, 'no');
543543
if (!evidence.firstAttemptUnwritten) return discloseDispatch(error, 'unknown');
544544
if (!restartedSession) return discloseDispatch(error, 'no');
545545
return discloseUnclassifiedDispatch(error, isRunnerPreSendRefusal(error) ? 'no' : 'unknown');

0 commit comments

Comments
 (0)