Skip to content

Run a virtual iPhone on an Apple Silicon Mac.

Swift

Clear the crash reports a template's own boots left before freezing it

Jacky9e2d69004124
diff --git a/Research/Host/machine_templates.md b/Research/Host/machine_templates.md
index 699d425e..584aa799 100644
--- a/Research/Host/machine_templates.md
+++ b/Research/Host/machine_templates.md
@@ -510,6 +510,7 @@ setup boot is the guest's first boot). It talks to vphoned through
| 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 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) |
| g stop | SIGINT to `vphone-vm` | 60 s | it exits without "turning it off" (the guest shut down within its 15 s) |
@@ -622,6 +623,44 @@ clone would show the template's name (its identifier, or the adopted
machine's name) until its own VM connects, and its first DHCP lease would
carry it (P1). The setup boot clears it last.
+The crash reports: every build's first boot after `cfw install` (the setup
+boot) writes a `panic-full-*.ips` of `initproc failed to start … Library not
+loaded: /usr/lib/libSystem.B.dylib … (no such file, no dyld cache)`. That
+panic is not the setup boot's. The restore reboots into the installed system
+before `cfw install` has copied the OS cryptex onto the System volume (vphone
+boots without the cryptex graft: every boot logs `cryptex1 sniff: ignition
+failed: 8`, then `dyld[1]: ignition disabled`), so launchd finds no dyld
+cache and the kernel panics; `vm create` and Launchpad wait for exactly that
+panic as the sign that the restore's reboot happened. iOS writes the report
+at the next boot, which is the setup boot, and the frozen template then gave
+every clone a kernel panic it never had, plus a dozen `duetexpertd` crashes
+(below). Matched by boot session UUID on 2026-10-09: `panic-full` reports in
+setup-boot and clone crash lists all name the session of the restore's
+post-restore boot in the `-dfu.log` (for example `A40A5DEA…` in
+`template-0fa581ca-dfu.log`, `AF2B2981…` in `template-9530cc5e-dfu.log`,
+written 2 s into that build's setup boot). A no-template machine gets the
+same report at its first boot. Console logs of installed guests showed no
+`panic(` in any boot: 0 in 35 boots of a trimmed, snapshot-deleted build, 19
+of a clone of a fixed template and 24 of a `--no-template` machine, by
+`system.reboot` and by `vm stop` + `vm start` (2026-10-09).
+
+After the verify step the setup boot lists the reports (`logs.crashes`) and
+deletes each one with `files.remove`; the report says `crash reports
+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.
+
+`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
+`ATXEnableMobileAssetDataVault` (AppPredictionInternal, from
+`_ATXInitializeInOwnerProcess`), "Failed to initialize datavault for
+DuetExpertCenterAsset". Neither the trim nor the slimming causes it; the
+trimmed profile turns `com.apple.duetexpertd` off, so it stops after the
+setup boot's reboot. The reports clones used to show were the template's
+first-boot ones; a clone of a template built with the cleanup had none after
+12 reboots and 6 cold starts. A machine without the profile keeps crashing.
+
Measured on iPhone17,3 27.0 (24A435), 2026-10-08: Launchpad created
`p4-src` (first boot at Setup), `vm template setup p4-src` took 2 min 16 s
(Setup's restart refused for 87 s, settle 25 s, reboot 10 s, stop 4 s), the
diff --git a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/VirtualMachine/VPhoneTemplateSetup.swift b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/VirtualMachine/VPhoneTemplateSetup.swift
index 4ccecf50..6217b585 100644
--- a/VPhoneExecutable/VPhoneCommand/VPhoneCommand/VirtualMachine/VPhoneTemplateSetup.swift
+++ b/VPhoneExecutable/VPhoneCommand/VPhoneCommand/VirtualMachine/VPhoneTemplateSetup.swift
@@ -189,6 +189,9 @@ enum VPhoneTemplateSetupRun {
}
print(" services: \(services)\(outcome.serviceProfile == "none" ? "" : " (\(outcome.servicesOwned) owned)")")
print(" apps removed: \(outcome.removedApps.isEmpty ? "none" : outcome.removedApps.joined(separator: ", "))")
+ if !outcome.clearedCrashReports.isEmpty {
+ print(" crash reports cleared: \(VPhoneTemplateSetupBoot.summarizeCrashReports(outcome.clearedCrashReports))")
+ }
let retried = outcome.retriedUnregistrations.sorted { $0.key < $1.key }
if !retried.isEmpty {
print(" unregistered after retries: \(retried.map { "\($0.key) (\($0.value) attempts)" }.joined(separator: ", "))")
diff --git a/VPhoneKit/VPhoneCoreKit/Bundle/VPhoneTemplateSetupBoot.swift b/VPhoneKit/VPhoneCoreKit/Bundle/VPhoneTemplateSetupBoot.swift
index 60f45369..94d9940f 100644
--- a/VPhoneKit/VPhoneCoreKit/Bundle/VPhoneTemplateSetupBoot.swift
+++ b/VPhoneKit/VPhoneCoreKit/Bundle/VPhoneTemplateSetupBoot.swift
@@ -112,6 +112,7 @@ public struct VPhoneTemplateSetupTimeouts: Equatable, Sendable {
/// From `system.reboot` until vphoned of the new boot answers (P1: 20 s).
public var reboot: TimeInterval = 300
public var verify: TimeInterval = 120
+ public var crashReports: TimeInterval = 60
public var deviceName: TimeInterval = 30
/// The VM gives the guest 15 s to shut down before turning it off.
public var stop: TimeInterval = 60
@@ -141,12 +142,17 @@ public struct VPhoneTemplateSetupPlan: Equatable, Sendable {
/// Clear the device name `vphone-vm` pinned during this boot, so a clone
/// does not show the template's name before its own VM pins its name.
public var clearsDeviceName: Bool
+ /// Delete the crash reports the template's own boots left (above all the
+ /// restore's pre-CFW `initproc failed` panic, written at the first boot
+ /// after CFW), so a clone does not start with reports of boots it never had.
+ public var clearsCrashReports: Bool
public var timeouts: VPhoneTemplateSetupTimeouts
public init(
slimming: VPhoneMachineTemplateSlimming,
requiresEveryApp: Bool,
clearsDeviceName: Bool = true,
+ clearsCrashReports: Bool = true,
timeouts: VPhoneTemplateSetupTimeouts = .standard,
) {
serviceProfile = slimming.serviceProfile
@@ -154,6 +160,7 @@ public struct VPhoneTemplateSetupPlan: Equatable, Sendable {
removedApps = slimming.removedApps
self.requiresEveryApp = requiresEveryApp
self.clearsDeviceName = clearsDeviceName
+ self.clearsCrashReports = clearsCrashReports
self.timeouts = timeouts
}
}
@@ -176,6 +183,7 @@ public enum VPhoneTemplateSetupStep: String, CaseIterable, Sendable, CustomStrin
case serviceProfile = "service-profile"
case reboot
case verify
+ case crashReports = "crash-reports"
case deviceName = "device-name"
case stop
@@ -190,6 +198,7 @@ public enum VPhoneTemplateSetupStep: String, CaseIterable, Sendable, CustomStrin
case .serviceProfile: "d/e. apply the service profile"
case .reboot: "f. reboot"
case .verify: "f. verify after the reboot"
+ case .crashReports: "clear the crash reports"
case .deviceName: "clear the pinned device name"
case .stop: "g. shut down"
}
@@ -232,6 +241,8 @@ public struct VPhoneTemplateSetupOutcome: Equatable, Sendable {
/// Labels the profile owns after it was applied.
public var servicesOwned = 0
public var verified = false
+ /// Names of the crash reports deleted before the shutdown.
+ public var clearedCrashReports: [String] = []
public var deviceNameCleared = false
public var stoppedCleanly = false
public var durations: [VPhoneTemplateSetupStep: TimeInterval] = [:]
@@ -378,6 +389,7 @@ public final class VPhoneTemplateSetupBoot {
}
try step(.reboot) { try reboot() }
try step(.verify) { try verify() }
+ try step(.crashReports) { clearCrashReports() }
try step(.deviceName) { clearDeviceName() }
try step(.stop) {
running = false
@@ -726,6 +738,65 @@ public final class VPhoneTemplateSetupBoot {
return problems
}
+ /// The crash reports this machine's boots left go before it is frozen:
+ /// every clone would otherwise list them as its own. The first is always
+ /// a `panic-full` report of `initproc failed to start … libSystem.B.dylib
+ /// … (no dyld cache)`: the restore reboots into the installed system
+ /// before `cfw install` has put the dyld cache on the System volume, the
+ /// kernel records that panic, and iOS writes the report at the next
+ /// boot, which is the setup boot. Nothing in the template panicked.
+ /// Best effort: a report left behind is a warning.
+ private func clearCrashReports() {
+ guard plan.clearsCrashReports else { return }
+ let end = deadline(timeouts.crashReports)
+ do {
+ let reports = try (call("logs.crashes", [:], deadline: end)["crashes"] as? [[String: Any]] ?? [])
+ .compactMap { $0["path"] as? String }
+ .filter(Self.isCrashReport)
+ var left: [String] = []
+ for path in reports {
+ do {
+ _ = try call("files.remove", ["path": path], deadline: end)
+ outcome.clearedCrashReports.append((path as NSString).lastPathComponent)
+ } catch {
+ left.append("\((path as NSString).lastPathComponent) (\(error))")
+ }
+ }
+ if !outcome.clearedCrashReports.isEmpty {
+ log(" cleared \(Self.summarizeCrashReports(outcome.clearedCrashReports))")
+ }
+ if !left.isEmpty {
+ let warning = "could not delete \(left.count) crash report(s): \(left.prefix(3).joined(separator: ", "))"
+ outcome.warnings.append(warning)
+ log(" warning: \(warning)")
+ }
+ } catch {
+ outcome.warnings.append("could not list the crash reports: \(error)")
+ log(" warning: could not list the crash reports: \(error)")
+ }
+ }
+
+ /// Only a report file in a CrashReporter folder: `logs.crashes` lists
+ /// nothing else; the check keeps `files.remove` off any other path it
+ /// might ever return.
+ public static func isCrashReport(_ path: String) -> Bool {
+ path.hasPrefix("/") && !path.contains("/../") && path.contains("/Logs/CrashReporter/")
+ && !path.hasSuffix("/")
+ }
+
+ /// `14 crash report(s): duetexpertd ×12, panic-full ×1, …`, by process.
+ public static func summarizeCrashReports(_ names: [String]) -> String {
+ var counts: [String: Int] = [:]
+ for name in names {
+ let stem = (name as NSString).deletingPathExtension
+ let process = stem.range(of: #"-\d{4}-\d{2}-\d{2}"#, options: .regularExpression)
+ .map { String(stem[..<$0.lowerBound]) } ?? stem
+ counts[process, default: 0] += 1
+ }
+ let parts = counts.sorted { ($0.value, $1.key) > ($1.value, $0.key) }.map { "\($0.key) ×\($0.value)" }
+ return "\(names.count) crash report(s): \(parts.joined(separator: ", "))"
+ }
+
/// `vphone-vm` pinned the device name to this machine's name on connect.
/// A clone would carry that pin until its own VM pins its name, so the
/// pin goes; the guest's own name (`iPhone`) shows in between.
diff --git a/VPhoneKit/VPhoneCoreKitTests/Bundle/TemplateSetupBootTests.swift b/VPhoneKit/VPhoneCoreKitTests/Bundle/TemplateSetupBootTests.swift
index 3cf0e7c0..52678fbb 100644
--- a/VPhoneKit/VPhoneCoreKitTests/Bundle/TemplateSetupBootTests.swift
+++ b/VPhoneKit/VPhoneCoreKitTests/Bundle/TemplateSetupBootTests.swift
@@ -61,6 +61,14 @@ private final class FakeGuest: VPhoneTemplateSetupMachine {
var bootTime = 1000.0
var downCalls = 0
var pinnedName: String? = "p4-src"
+ /// The restore's pre-CFW panic report, written at the first boot after
+ /// CFW, and one daemon crash of the setup boot.
+ var crashReports = [
+ "/var/mobile/Library/Logs/CrashReporter/panic-full-2026-10-09-155009.000.ips",
+ "/var/mobile/Library/Logs/CrashReporter/duetexpertd-2026-10-09-155011.ips",
+ ]
+ var undeletableReports: Set<String> = []
+ var crashListRefused = false
init(clock: FakeClock) {
self.clock = clock
@@ -183,6 +191,18 @@ private final class FakeGuest: VPhoneTemplateSetupMachine {
return ["setup_done": setupDone, "pending": !setupDone]
case "apps.list":
return ["apps": installed.map { ["bundle_id": $0] }]
+ case "logs.crashes":
+ if crashListRefused {
+ throw refused("unknown method logs.crashes", ["code": "unknown_method"])
+ }
+ return ["crashes": crashReports.map { ["path": $0, "name": ($0 as NSString).lastPathComponent] }, "count": crashReports.count]
+ case "files.remove":
+ let path = params["path"] as? String ?? ""
+ if undeletableReports.contains(path) {
+ throw refused("Operation not permitted", ["code": "failed"])
+ }
+ crashReports.removeAll { $0 == path }
+ return ["path": path, "removed": true]
case "device.name.set":
pinnedName = params["name"] as? String
return ["name": NSNull(), "changed": true]
@@ -247,7 +267,7 @@ struct TemplateSetupBootTests {
"apps.remove_system", "services.profile.apply", "services.profile",
"processes.list", "system.reboot", "processes.list",
"apfs.snapshots", "setup.status", "services.profile", "apps.list",
- "device.name.set",
+ "logs.crashes", "files.remove", "files.remove", "device.name.set",
]))
// Nothing slims before Setup is skipped and first-boot work settled.
let firstRemoval = try #require(guest.calls.firstIndex(of: "apps.remove_system"))
@@ -264,6 +284,8 @@ struct TemplateSetupBootTests {
#expect(outcome.serviceProfile == "trimmed")
#expect(outcome.deviceNameCleared)
#expect(guest.pinnedName == nil)
+ #expect(guest.crashReports.isEmpty)
+ #expect(outcome.clearedCrashReports.count == 2)
#expect(Set(outcome.durations.keys) == Set(VPhoneTemplateSetupStep.allCases))
// The offline trim records its tier before the setup boot, which
@@ -602,6 +624,72 @@ struct TemplateSetupBootTests {
#expect(VPhoneTemplateSetupBoot.bootMarker(["processes": [["pid": 2, "start_time": 12.5]]]) == nil)
#expect(VPhoneTemplateSetupBoot.bootMarker([:]) == nil)
}
+
+ @Test func `the restore's panic report and the setup boot's crashes are cleared after the reboot`() throws {
+ let guest = FakeGuest(clock: FakeClock())
+ let outcome = try run(guest).get()
+ #expect(guest.crashReports.isEmpty)
+ #expect(outcome.clearedCrashReports == [
+ "panic-full-2026-10-09-155009.000.ips", "duetexpertd-2026-10-09-155011.ips",
+ ])
+ // After the reboot, so the reports of both boots go; before the shutdown.
+ let reboot = try #require(guest.calls.firstIndex(of: "system.reboot"))
+ let listing = try #require(guest.calls.firstIndex(of: "logs.crashes"))
+ #expect(reboot < listing)
+ #expect(outcome.warnings.isEmpty)
+ }
+
+ @Test func `a crash report that cannot be cleared is a warning, not a failure`() throws {
+ let guest = FakeGuest(clock: FakeClock())
+ guest.undeletableReports = ["/var/mobile/Library/Logs/CrashReporter/duetexpertd-2026-10-09-155011.ips"]
+ let outcome = try run(guest).get()
+ #expect(outcome.isComplete)
+ #expect(outcome.clearedCrashReports == ["panic-full-2026-10-09-155009.000.ips"])
+ #expect(outcome.warnings.contains { $0.contains("could not delete 1 crash report(s)") })
+
+ let unlisted = FakeGuest(clock: FakeClock())
+ unlisted.crashListRefused = true
+ let second = try run(unlisted).get()
+ #expect(second.isComplete)
+ #expect(second.warnings.contains { $0.contains("could not list the crash reports") })
+ #expect(!unlisted.calls.contains("files.remove"))
+ }
+
+ @Test func `a setup boot told to keep the crash reports leaves them`() throws {
+ let guest = FakeGuest(clock: FakeClock())
+ let boot = VPhoneTemplateSetupBoot(
+ machine: guest,
+ plan: VPhoneTemplateSetupPlan(
+ slimming: VPhoneTemplateSlimmingRequest.defaultSlimming,
+ requiresEveryApp: true,
+ clearsCrashReports: false,
+ ),
+ clock: guest.clock,
+ log: { _ in },
+ )
+ let outcome = try boot.run()
+ #expect(outcome.isComplete)
+ #expect(guest.crashReports.count == 2)
+ #expect(!guest.calls.contains("logs.crashes"))
+ }
+
+ @Test func `only report files in a CrashReporter folder are deleted`() {
+ #expect(VPhoneTemplateSetupBoot.isCrashReport("/var/mobile/Library/Logs/CrashReporter/panic-full-2026-10-09-155009.000.ips"))
+ #expect(VPhoneTemplateSetupBoot.isCrashReport("/private/var/mobile/Library/Logs/CrashReporter/Retired/x.ips"))
+ #expect(!VPhoneTemplateSetupBoot.isCrashReport("/var/mobile/Library/Logs/CrashReporter/"))
+ #expect(!VPhoneTemplateSetupBoot.isCrashReport("/var/mobile/Library/Logs/CrashReporter/../../Preferences/x.plist"))
+ #expect(!VPhoneTemplateSetupBoot.isCrashReport("/var/mobile/Library/Preferences/com.apple.x.plist"))
+ #expect(!VPhoneTemplateSetupBoot.isCrashReport("Logs/CrashReporter/x.ips"))
+ }
+
+ @Test func `cleared reports are summarized by process, most first`() {
+ let names = [
+ "duetexpertd-2026-10-09-155011.ips", "duetexpertd-2026-10-09-155020.ips",
+ "panic-full-2026-10-09-155009.000.ips", "SiriSearchFeedback-2026-10-09-151008.ips",
+ ]
+ #expect(VPhoneTemplateSetupBoot.summarizeCrashReports(names)
+ == "4 crash report(s): duetexpertd ×2, SiriSearchFeedback ×1, panic-full ×1")
+ }
}
// MARK: - Recording