Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Stop a dying vphoned from holding the setup boot's reboot for 30 s

Jackye4a6ef484121
diff --git a/Research/Host/machine_templates.md b/Research/Host/machine_templates.md
index 584aa799..7a3c2bb5 100644
--- a/Research/Host/machine_templates.md
+++ b/Research/Host/machine_templates.md
@@ -508,7 +508,7 @@ setup boot is the guest's first boot). It talks to vphoned through
| b settle | `setup.settle {timeout_s ≤ 30}` repeated, a progress line after each | 600 s overall | `settled` (system apps expanded and data migration finished) |
| c apps | `apps.remove_system {bundle_ids, force}` | 300 s | every app `removed`, `absent` or `unregistered_stale` |
| d/e profile | `services.profile.apply {profile, groups, force}`, `services.profile` | 180 s | no `failed`; the record holds `signin_followup` and the extra groups; followupd and appleidsetupd disabled |
-| f reboot | `processes.list` (launchd's `start_time`), `system.reboot {force}` | 300 s | vphoned answers with another launchd start time |
+| f reboot | `processes.list` (launchd's `start_time`), `system.reboot {force}`, then `ping` and `processes.list` (10 s timeout) every 3 s | 300 s | vphoned answers with another launchd start time |
| f verify | `apfs.snapshots`, `setup.status`, `services.profile`, `apps.list`, `ping`, repeated | 120 s | no snapshot, Setup done, the profile recorded with `running` empty, no removed app listed |
| crash reports | `logs.crashes`, `files.remove {path}` for each report under `/Logs/CrashReporter/` | 60 s | (a warning on failure) |
| name | `device.name.set {}` | 30 s | (a warning on failure) |
@@ -650,6 +650,16 @@ cleared: 13 crash report(s): duetexpertd ×11, SiriSearchFeedback ×1,
panic-full ×1` (2026-10-09 build). A report it cannot delete is a warning, as
the device name is.
+The reboot step's 33 s: `system.reboot` is answered at once, and the first
+`ping` a moment later can still reach the old vphoned; the `processes.list`
+sent after it reaches vphoned as launchd stops it and is never answered, so
+`vphone.sock`'s read timeout runs out. With the 30 s it had, the step took
+33 s instead of 9–10 s in 4 of 6 builds (2026-10-09), and replaying the same
+polling against a running guest hit it in 3 of 8 reboots (33.3–33.5 s). The
+poll's `processes.list` now uses `VPhoneTemplateSetupTimeouts.rebootPoll`
+(10 s): the same replay took at most 13.3 s, and a fresh boot answers within
+a few seconds.
+
`duetexpertd` crashes about every 10 s from the first boot on every iOS 27.0
guest, template or not (13 reports on a `--no-template` machine with no trim,
no snapshot deletion and no service profile): `EXC_BREAKPOINT` in
diff --git a/VPhoneKit/VPhoneCoreKit/Bundle/VPhoneTemplateSetupBoot.swift b/VPhoneKit/VPhoneCoreKit/Bundle/VPhoneTemplateSetupBoot.swift
index 94d9940f..9ca57f9e 100644
--- a/VPhoneKit/VPhoneCoreKit/Bundle/VPhoneTemplateSetupBoot.swift
+++ b/VPhoneKit/VPhoneCoreKit/Bundle/VPhoneTemplateSetupBoot.swift
@@ -111,6 +111,12 @@ public struct VPhoneTemplateSetupTimeouts: Equatable, Sendable {
public var serviceProfile: TimeInterval = 180
/// From `system.reboot` until vphoned of the new boot answers (P1: 20 s).
public var reboot: TimeInterval = 300
+ /// One `processes.list` while waiting for the new boot. It answers within
+ /// a few seconds even right after a boot; one that reaches vphoned just
+ /// before the reboot stops it is never answered and holds the step for
+ /// this whole timeout (30 s made the step take 33 s instead of 10 s in
+ /// about a third of the setup boots).
+ public var rebootPoll: TimeInterval = 10
public var verify: TimeInterval = 120
public var crashReports: TimeInterval = 60
public var deviceName: TimeInterval = 30
@@ -646,7 +652,7 @@ public final class VPhoneTemplateSetupBoot {
}
while true {
try checkMachine()
- if machine.ping(), let after = try? machine.call("processes.list", params: [:], timeout: 30),
+ if machine.ping(), let after = try? machine.call("processes.list", params: [:], timeout: timeouts.rebootPoll),
let marker = Self.bootMarker(after), marker != before
{
return
diff --git a/VPhoneKit/VPhoneCoreKitTests/Bundle/TemplateSetupBootTests.swift b/VPhoneKit/VPhoneCoreKitTests/Bundle/TemplateSetupBootTests.swift
index 52678fbb..63bf0df6 100644
--- a/VPhoneKit/VPhoneCoreKitTests/Bundle/TemplateSetupBootTests.swift
+++ b/VPhoneKit/VPhoneCoreKitTests/Bundle/TemplateSetupBootTests.swift
@@ -47,6 +47,10 @@ private final class FakeGuest: VPhoneTemplateSetupMachine {
var servicesKeepRunning = false
var rebootNeverReturns = false
var stopsCleanly = true
+ /// vphoned still answers the first ping after `system.reboot`, then takes
+ /// the `processes.list` that follows down with it, unanswered.
+ var dyingVphonedTakesAList = false
+ private var dyingVphoned = false
// Guest state.
var snapshots = ["orig-fs.disabled.rn-4EC2"]
@@ -84,6 +88,9 @@ private final class FakeGuest: VPhoneTemplateSetupMachine {
func ping() -> Bool {
clock.sleep(0.1)
+ if dyingVphoned {
+ return true
+ }
if connectDelayPolls > 0 {
connectDelayPolls -= 1
return false
@@ -101,9 +108,14 @@ private final class FakeGuest: VPhoneTemplateSetupMachine {
VPhoneGuestCallError(kind: .refused, message: message, detail: detail)
}
- func call(_ method: String, params: [String: Any], timeout _: TimeInterval) throws -> [String: Any] {
+ func call(_ method: String, params: [String: Any], timeout: TimeInterval) throws -> [String: Any] {
calls.append(method)
clock.sleep(0.5)
+ if dyingVphoned, method == "processes.list" {
+ dyingVphoned = false
+ clock.sleep(timeout)
+ throw VPhoneGuestCallError(kind: .transport, message: "no answer from vphone.sock")
+ }
if downCalls > 0 {
throw VPhoneGuestCallError(kind: .transport, message: "guest not connected")
}
@@ -183,6 +195,7 @@ private final class FakeGuest: VPhoneTemplateSetupMachine {
case "system.reboot":
bootTime += 100
downCalls = 3
+ dyingVphoned = dyingVphonedTakesAList
if !servicesKeepRunning {
running = []
}
@@ -591,6 +604,21 @@ struct TemplateSetupBootTests {
#expect(guest.killed)
}
+ @Test func `a list the reboot leaves unanswered holds the step only for the poll timeout`() throws {
+ let quick = try run(FakeGuest(clock: FakeClock())).get()
+ let guest = FakeGuest(clock: FakeClock())
+ guest.dyingVphonedTakesAList = true
+ let outcome = try run(guest).get()
+ let base = try #require(quick.durations[.reboot])
+ let stalled = try #require(outcome.durations[.reboot])
+ // One poll timeout more than an undisturbed reboot, not the 30 s that
+ // made the live step take 33 s.
+ #expect(stalled - base >= VPhoneTemplateSetupTimeouts.standard.rebootPoll)
+ #expect(stalled - base < VPhoneTemplateSetupTimeouts.standard.rebootPoll + 5)
+ #expect(VPhoneTemplateSetupTimeouts.standard.rebootPoll <= 10)
+ #expect(outcome.isComplete)
+ }
+
@Test func `services still running after the reboot fail verification`() throws {
let guest = FakeGuest(clock: FakeClock())
guest.servicesKeepRunning = true