Skip to content

Let an AI model use a real iPhone with a $7 ESP32: AirPlay eyes, USB HID hands, any OpenAI-compatible vision model. No Mac, no developer account, no jailbreak.

Explain failed runs and reconnect before retrying

Henry851a8c6110ca
diff --git a/docs/run-retry-2026-10-16.md b/docs/run-retry-2026-10-16.md
new file mode 100644
index 0000000..e46096c
--- /dev/null
+++ b/docs/run-retry-2026-10-16.md
@@ -0,0 +1,21 @@
+# Failed-run recovery
+
+Source HEAD: `32267d6`, with only untracked `ios/fastlane/` in the source checkout. Work was isolated on `codex/run-retry-feedback`.
+
+## Device evidence
+
+Read the connected phone's debug log and the two latest run step files without changing their contents:
+
+- `20261016-112552`: Live Activity creation succeeded at 11:25:52 China time. Startup waited for a screen capture; the board disconnected at 11:26:36, after the snap command had waited approximately 35 seconds.
+- `20261016-112625`: another startup began before the first finished. Both startup errors were consequently written to this newer trace: link lost during `snap`, then link lost during `stream on`. The first trace contains only its task entry.
+- Nearby RSSI readings ranged roughly from -83 to -95 dBm. Distance/interference may contribute, but the evidence establishes a lost BLE connection, not its physical cause. Neither startup reached a model call.
+
+## Changes
+
+Failed-run details now show the reason, a plain-language connection explanation where applicable, and expandable original error details. A labeled arrow-clockwise Retry button reconnects/reads board status first, then starts a new run with the original task. A failed reconnect stays in the review and displays its error. Old run records remain untouched.
+
+The startup guard spans the departure animation and asynchronous startup so repeated starts cannot replace the active trace. Live Activity creation moves ahead of stream setup; startup failures post a failure notification and open their review. The earlier unlabeled top refresh spinner is included.
+
+## Validation
+
+Signed device compilation succeeded; all 80 simulator tests passed. The final build was installed and launched on the connected iPhone (`com.onehumanbeing.esp32agent`). Device installation does not prove a complete physical task succeeds; BLE reliability and Dynamic Island rendering still require an actual run with the board connected.
diff --git a/ios/IPhoneAgent/App/AppModel.swift b/ios/IPhoneAgent/App/AppModel.swift
index 5ac9152..c4a26e6 100644
--- a/ios/IPhoneAgent/App/AppModel.swift
+++ b/ios/IPhoneAgent/App/AppModel.swift
@@ -49,6 +49,7 @@ import UIKit
var recoverySince = Date()
@Published var takingOver = false
@Published var departing = false // the character's take-off before a run
+ @Published var startingAgent = false
/// A banner on Home: the app could not leave by itself (swipe up), or the run waits while the app is in front.
@Published var homeHint: String?
var resumeAsked = 0.0 // when Continue was tapped in the app
diff --git a/ios/IPhoneAgent/App/RunSession.swift b/ios/IPhoneAgent/App/RunSession.swift
index 06df547..19c61e3 100644
--- a/ios/IPhoneAgent/App/RunSession.swift
+++ b/ios/IPhoneAgent/App/RunSession.swift
@@ -12,7 +12,9 @@ extension AppModel {
/// Start a task (or a saved intent: its checklist goes to the actor as hints).
func run(_ task: String, intent: SavedTask? = nil) async {
- guard !agent.running, !recorder.recording else { return }
+ guard !startingAgent, !agent.running, !recorder.recording else { return }
+ startingAgent = true
+ defer { startingAgent = false }
currentIntent = intent
lastTask = task
agent.hints = intent?.checklist ?? []
@@ -47,6 +49,8 @@ extension AppModel {
startVideo()
FrameMode.fallback = nil // each run starts in the chosen mode
let snapMode = FrameMode.current == .snap
+ live.start(task: task, runID: runID, limit: agent.maxSteps)
+ mark("Live Activity requested")
do {
if snapMode {
if feed.streamOn { try await feed.stream(false) }
@@ -59,8 +63,6 @@ extension AppModel {
self?.say("iOS is ending background time; BLE status keeps the run going")
self?.endBackgroundTask()
}
- live.start(task: task, runID: runID, limit: agent.maxSteps)
- mark("Live Activity started")
let left = now()
var away = await leaveApp()
if !away { away = await askUserToLeave() }
@@ -88,6 +90,10 @@ extension AppModel {
live.end((.failure, String(localized: "Could not start")))
endBackgroundTask()
runs.reload()
+ runMood = .failure
+ notifier.post(.failed, title: String(localized: "Could not start"),
+ body: error.localizedDescription, run: runID)
+ openReview(run: runID)
}
}
diff --git a/ios/IPhoneAgent/Localizable.xcstrings b/ios/IPhoneAgent/Localizable.xcstrings
index f568561..0bdeeb5 100644
--- a/ios/IPhoneAgent/Localizable.xcstrings
+++ b/ios/IPhoneAgent/Localizable.xcstrings
@@ -1,6 +1,46 @@
{
"sourceLanguage" : "en",
"strings" : {
+ "The board connection was lost. Move the board closer and keep it powered on, then tap Retry.": {
+ "localizations": {
+ "zh-Hans": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "与板子的连接已断开。请把板子移近并保持供电,然后点击重试。"
+ }
+ }
+ }
+ },
+ "The run ended before it could finish. Retry to start again.": {
+ "localizations": {
+ "zh-Hans": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "任务未完成便已结束。点击重试重新开始。"
+ }
+ }
+ }
+ },
+ "Error details": {
+ "localizations": {
+ "zh-Hans": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "错误详情"
+ }
+ }
+ }
+ },
+ "Could not finish": {
+ "localizations": {
+ "zh-Hans": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "未能完成"
+ }
+ }
+ }
+ },
"" : {
"shouldTranslate" : false
},
diff --git a/ios/IPhoneAgent/Review/ReviewView.swift b/ios/IPhoneAgent/Review/ReviewView.swift
index bc33bd0..a3a853d 100644
--- a/ios/IPhoneAgent/Review/ReviewView.swift
+++ b/ios/IPhoneAgent/Review/ReviewView.swift
@@ -20,6 +20,8 @@ struct ReviewView: View {
@State private var saving = false
@State private var optimizing = false
@State private var shareURL: URL?
+ @State private var retrying = false
+ @State private var retryError: String?
private var steps: [DraftStep] { draft.steps }
private var step: DraftStep? { steps.indices.contains(index) ? steps[index] : nil }
@@ -28,6 +30,23 @@ struct ReviewView: View {
var body: some View {
VStack(spacing: 0) {
topBar
+ if draft.outcome == .failed {
+ VStack(alignment: .leading, spacing: Space.s) {
+ Label("Could not finish", systemImage: "exclamationmark.triangle")
+ .font(.headline)
+ Text(verbatim: failureMessage).font(.subheadline)
+ if failureMessage != failureReason {
+ DisclosureGroup("Error details") {
+ Text(verbatim: failureReason).font(.caption).textSelection(.enabled)
+ }
+ }
+ if let retryError {
+ Text(verbatim: retryError).font(.subheadline).foregroundStyle(Palette.stop)
+ }
+ }
+ .frame(maxWidth: .infinity, alignment: .leading)
+ .padding(.horizontal, Space.xl).padding(.vertical, Space.s)
+ }
if steps.isEmpty {
IntentWordsView(draft: draft)
} else {
@@ -298,17 +317,56 @@ struct ReviewView: View {
private var bottomBar: some View {
BottomBar {
- HStack(spacing: Space.m) {
- Button { optimizing = true } label: { Label("Optimize with AI", systemImage: "sparkles") }
- .buttonStyle(BigButton(tint: Color(uiColor: .systemIndigo)))
- Button { saving = true } label: {
- Label(draft.intentID == nil ? "Save as Intent" : "Save Intent", systemImage: "bookmark.fill")
+ VStack(spacing: Space.s) {
+ if draft.runID != nil, draft.outcome == .failed {
+ Button("Retry", systemImage: "arrow.clockwise", action: retryRun)
+ .buttonStyle(BigButton())
+ .disabled(retrying || app.startingAgent || app.agent.running || app.recorder.recording)
+ if retrying { ProgressView("Reconnecting…") }
+ }
+ HStack(spacing: Space.m) {
+ Button { optimizing = true } label: { Label("Optimize with AI", systemImage: "sparkles") }
+ .buttonStyle(BigButton(tint: Color(uiColor: .systemIndigo)))
+ Button { saving = true } label: {
+ Label(draft.intentID == nil ? "Save as Intent" : "Save Intent", systemImage: "bookmark.fill")
+ }
+ .buttonStyle(BigButton())
}
- .buttonStyle(BigButton())
}
}
}
+ private func retryRun() {
+ guard !retrying, !app.startingAgent, !app.agent.running, !app.recorder.recording,
+ let id = draft.runID, let run = app.runs.run(id) else { return }
+ let intent = app.intents.item(draft.intentID)
+ playing = false
+ retrying = true
+ retryError = nil
+ Task {
+ defer { retrying = false }
+ do {
+ try await app.board.refreshStatus()
+ dismiss()
+ await app.run(run.task, intent: intent)
+ } catch {
+ retryError = error.localizedDescription
+ }
+ }
+ }
+
+ private var failureReason: String {
+ steps.last(where: { $0.name == "error" || $0.name == "fail" })?.action["reason"]?.str
+ ?? String(localized: "The run ended before it could finish. Retry to start again.")
+ }
+
+ private var failureMessage: String {
+ if failureReason.contains("board link lost") || failureReason.contains("board disconnected") {
+ return String(localized: "The board connection was lost. Move the board closer and keep it powered on, then tap Retry.")
+ }
+ return failureReason
+ }
+
private func rerun(from step: DraftStep) {
let intent = app.intents.item(draft.intentID)
let task = draft.prompt + "\n\n" + String(localized: "Start from this step: \(StepText.title(step.action)). The steps before it are already done.")
diff --git a/ios/IPhoneAgent/UI/HomeView.swift b/ios/IPhoneAgent/UI/HomeView.swift
index 0635a6f..c7b6242 100644
--- a/ios/IPhoneAgent/UI/HomeView.swift
+++ b/ios/IPhoneAgent/UI/HomeView.swift
@@ -270,7 +270,7 @@ struct HomeView: View {
Button { start(task) } label: { Label("Start", systemImage: "play.fill") }
.buttonStyle(BigButton())
.disabled(task.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty || blocker != nil
- || app.departing || recorder.recording)
+ || app.departing || app.startingAgent || recorder.recording)
if let blocker {
Button { app.setupPage = blocker.page } label: {
Label(blocker.text, systemImage: "exclamationmark.circle").font(.footnote)