fix(apple-runner): restart without resending a command written then lost

Merged
TH
2mo ago
+806-191

Summary

A mutating command whose reply stays lost now fails with details.reason: runner_reply_lost and dispatched: "unknown". This covers a runner that dies mid-command, and every status-recovery verdict that finds neither a retained result nor a runner answer: completed without a retained reply, still accepted or started, notAccepted, an unknown or missing lifecycle state, a failed status probe, and a command with no id to probe. The command is sent once and never replayed, and the next command starts a new runner. One builder makes this error. The transport's own reason stays under details.transportReason. A read keeps its transport error, so the read-only resend loop resends it, and the read never carries the reason.

The restart-and-resend rule after a connect failure is owned by shouldRestartRunnerBeforeCommandSend(error, command). The rule restarts only when no attempt could have written the command (resolveFirstAttemptDispatch(error) === 'no') or when the command is read-only. A simctl curl exit-28 POST carries dispatched: unknown, so it never restarts a mutation. The restart carries the first attempt's DispatchDisclosure, not a boolean.

agent-device longpress @e3 5000 --json   # runner killed mid-press: runner_reply_lost, sent once

Closes #3074. Part of #3069. Stacked on #3071. 14 files touched.

Validation

Tested commit: 4e88908fc322514cf25ddf27cad030351124f4d2.

pnpm check:affected --run (fail-open full set): every runnable check passed. In vitest-related, 1333 of 1334 files passed. The one failure was a 5 s timeout under host load in a file this PR does not touch (screenshot-density.test.ts, and press-target-readiness.test.ts on the run before). Each passes alone. The checks after vitest-related were then run on the same commit, and all passed. Also run: pnpm typecheck, pnpm lint, apple runner vitest (167 files, 1704 tests), check:layering, check:fallow, format:check, the eager-closure budget test, and the runner read-only parity test.

Live on f52f120b1d (iPhone 17 Pro simulator, iOS 26.2, Release test app): longpress @e3 5000 --debug, with the runner process killed 1.3 s after the runner accepted the command. The request log has one ios_runner_command_send for longPress, then a failed status probe, invalidation_decision status_probe_failed, and ios_runner_session_invalidated transport_error_after_command_send. The error has reason: runner_reply_lost, recovery: status_probe_failed, dispatched: unknown, and no runnerRestarted. snapshot -i then succeeded, and the next runner command started a new runner session (port 61516, was 61032). The structural changes after that commit do not change this path.