Skip to content

fix(wda): a first launch behind the privacy notice returns at once - #148

Merged
Derrors merged 3 commits into
Derrors:mainfrom
cosinec:fix/launch-first-run-sheet
Nov 17, 2026
Merged

Derrors merged 3 commits into
Derrors:mainfrom
cosinec:fix/launch-first-run-sheet

Conversation

@cosinec

@cosinec cosinec commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

What and why

The first time a system app such as Notes or Reminders is opened, iOS shows its privacy notice ("Welcome to Notes … Accept & Continue") in a separate process, com.apple.PDUIApp, on top of the app. /wda/apps/launch waits until XCTest sees the app in the foreground, so it waits the full 60 s and times out. The daemon then counts the stuck requests and restarts WDA. One iphone_launch_app costs 65 s, an error, and a WDA restart, and the agent is told to take a screenshot first. I hit it twice in one session (Reminders, Notes). It is reproduced below on v0.2.7.

Fix in WdaClient::launch_app:

  • Launch with /wda/apps/launchUnattached. It exists in the pinned WDA v16.15.3, goes through LSApplicationWorkspace without XCTest, and returns at once (0.05–0.3 s). Then the existing loop polls /wda/activeAppInfo as before.
  • First-launch failure: behind the privacy notice the route answers unknown error: LSApplicationWorkspace failed to launch app even though the notice is already up, so that answer is treated as launched and the foreground decides.
  • Foreground is com.apple.PDUIApp: the loop returns Launch::Blocked right away with a description of the notice. The daemon's existing wording for a blocking alert applies (已启动 …,但屏幕上有系统弹窗「第一次打开时的隐私说明页(…)」挡着;先用 iphone_tap_element 点弹窗上的按钮), and Outcome.blocked is set as for permission alerts.
  • Older WDA: when the route is missing (unknown command / unknown method / HTTP 404/405, the same test interface_rotation uses), it falls back to /wda/apps/launch. Any other error is still returned as an error.

The settle after reaching the foreground (settle_launched, LAUNCH_MIN, regression #13) is unchanged. The cold-start "tap right after launch" case is re-checked on the device below. Native control (iOS 27, native_launch) and open_url are not touched.

Tests

1. Unit tests

  • cargo test --workspace --all-features --locked, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings and cargo fmt --check (per package) pass (Rust 1.99.1, macOS)
  • New or changed behaviour has a unit test (ictl-wda):
    • a_first_launch_privacy_notice_is_reported_at_once: "failed to launch", then the privacy notice in front, gives Blocked within a second, with no /wda/apps/launch.
    • an_older_wda_without_unattached_launch_launches_as_before: a 404 unknown command falls back to the session launch.
    • other_launch_errors_are_errors
  • No existing test removed, ignored or loosened
  • #[ignore] tests of the changed area run by hand: none apply

2. Real-device regression

  • Device, iOS version, host (Linux / macOS): iPhone 12 mini (iPhone13,1), iOS 26.4.1, macOS (Apple silicon); WDA 16.14.0 launched in the background by the daemon
  • tests/device/run.py default steps pass on this branch (exit code 0): 16 calls, 0 failed, 15.0s in all, including iphone_launch_app 时钟 and the tap right after it
  • The same steps on the latest release, same device: v0.2.7 release binary, 16 calls, 0 failed, 16.8s in all. No step on the branch is clearly slower.
  • Steps exercising this change: see section 4
  • Longer run: not affected (it removes a WDA restart rather than adding any)
run.py output
this branch:

### iPhone13,1, iOS 26.4.1, 375x812 pt, WDA, 00008101-00150D941AD8001E
=== iphone_status {} 0.13s
WDA 就绪: True
锁屏: 未锁屏
前台 App: com.apple.Preferences
屏幕: 375x812 点
守护进程: 就绪
=== iphone_tap_element {"text": "不存在的按钮xyz"} 0.46s
没找到包含 "不存在的按钮xyz" 的元素,先用 iphone_list_elements 或截图看看屏幕
=== iphone_press_button {"button": "home"} 1.66s
已按 home
=== iphone_launch_app {"app": "时钟"} 0.89s
已启动 com.apple.mobiletimer
=== iphone_list_elements {"limit": 40} 0.24s
StaticText "0秒钟" id="stopwatch-time" @(188,235) 375x106
Button "分段" @(58,417) 84x84
Button "启动" @(317,417) 84x84
PageIndicator "第1页(共2页), 数码秒表" value="第1页(共2页), 数码秒表" @(188,420) 56x31
Table "空列表" @(188,644) 375x337
TabBar "标签页栏" @(188,770) 375x83
Button "世界时钟" @(72,760) 94x54
Button "闹钟" @(149,760) 94x54
Button "秒表" value="1" @(226,760) 94x54
Button "计时器" @(303,760) 94x54
=== iphone_tap_element {"text": "世界时钟", "then": "elements", "then_filter": "Button"} 1.62s
已点击 Button "世界时钟" @(72,760) 94x54
画面已静止(0.7 秒);但有一小块还在动(可能是加载圈或小动画),内容可能还没加载完,要等结果用 iphone_wait_for 或稍后再截图
--- 操作后的界面 ---
Button "编辑" @(49,72) 58x36
Button "添加" @(337,72) 36x36
Button "世界时钟" value="1" @(72,760) 94x54
Button "闹钟" @(149,760) 94x54
Button "秒表" @(226,760) 94x54
Button "计时器" @(303,760) 94x54
=== iphone_tap_element {"text": "秒表", "then": "elements", "then_filter": "Button"} 1.67s
已点击 Button "秒表" @(226,760) 94x54
画面已静止(0.7 秒)
--- 操作后的界面 ---
Button "分段" @(58,417) 84x84
Button "启动" @(317,417) 84x84
Button "世界时钟" @(72,760) 94x54
Button "闹钟" @(149,760) 94x54
Button "秒表" value="1" @(226,760) 94x54
Button "计时器" @(303,760) 94x54
=== iphone_screenshot {} 0.20s
<image shots/shot1.jpg (375, 812)>
375x812 点,图像像素即点坐标(经 WDA)
=== iphone_screenshot {"x": 0, "y": 0, "width": 375.0, "height": 60} 0.15s
<image shots/shot2.jpg (1124, 180)>
区域 (0,0) 起 375x60 点,放大 3 倍;图中像素 (u,v) 对应屏幕点 (0+u/3, 0+v/3)(经 WDA)
=== iphone_press_button {"button": "home"} 1.88s
已按 home
=== iphone_swipe {"from_x": 188, "from_y": 349, "to_x": 188, "to_y": 609} 1.85s
已滑动 (188,349) → (188,609)
=== iphone_type_text {"text": "设置"} 1.05s
已输入 2 个字符
=== iphone_wait_for {"text": "设置", "timeout": 5} 0.24s
已出现 Cell "设置" id="Identifier:GridCell,Section:0,Row:0" @(188,143) 330x114(0.2 秒)
=== iphone_screenshot {} 0.42s
<image shots/shot3.jpg (375, 812)>
375x812 点,图像像素即点坐标(经 WDA)
=== iphone_press_button {"button": "home"} 1.53s
已按 home
=== iphone_status {} 0.18s
WDA 就绪: True
锁屏: 未锁屏
前台 App: com.apple.springboard
屏幕: 375x812 点
守护进程: 就绪
--- 16 calls, 0 failed, 15.0s in all

latest release (v0.2.7):

### iPhone13,1, iOS 26.4.1, 375x812 pt, WDA, 00008101-00150D941AD8001E
=== iphone_status {} 0.23s
WDA 就绪: True
锁屏: 未锁屏
前台 App: com.apple.springboard
屏幕: 375x812 点
守护进程: 就绪
=== iphone_tap_element {"text": "不存在的按钮xyz"} 1.36s
没找到包含 "不存在的按钮xyz" 的元素,先用 iphone_list_elements 或截图看看屏幕
=== iphone_press_button {"button": "home"} 1.35s
已按 home
=== iphone_launch_app {"app": "时钟"} 0.97s
已启动 com.apple.mobiletimer
=== iphone_list_elements {"limit": 40} 0.26s
StaticText "0秒钟" id="stopwatch-time" @(188,235) 375x106
Button "分段" @(58,417) 84x84
Button "启动" @(317,417) 84x84
PageIndicator "第1页(共2页), 数码秒表" value="第1页(共2页), 数码秒表" @(188,420) 56x31
Table "空列表" @(188,644) 375x337
TabBar "标签页栏" @(188,770) 375x83
Button "世界时钟" @(72,760) 94x54
Button "闹钟" @(149,760) 94x54
Button "秒表" value="1" @(226,760) 94x54
Button "计时器" @(303,760) 94x54
=== iphone_tap_element {"text": "世界时钟", "then": "elements", "then_filter": "Button"} 1.65s
已点击 Button "世界时钟" @(72,760) 94x54
画面已静止(0.7 秒)
--- 操作后的界面 ---
Button "编辑" @(49,72) 58x36
Button "添加" @(337,72) 36x36
Button "世界时钟" value="1" @(72,760) 94x54
Button "闹钟" @(149,760) 94x54
Button "秒表" @(226,760) 94x54
Button "计时器" @(303,760) 94x54
=== iphone_tap_element {"text": "秒表", "then": "elements", "then_filter": "Button"} 1.58s
已点击 Button "秒表" @(226,760) 94x54
画面已静止(0.7 秒)
--- 操作后的界面 ---
Button "分段" @(58,417) 84x84
Button "启动" @(317,417) 84x84
Button "世界时钟" @(72,760) 94x54
Button "闹钟" @(149,760) 94x54
Button "秒表" value="1" @(226,760) 94x54
Button "计时器" @(303,760) 94x54
=== iphone_screenshot {} 0.19s
<image shots/shot1.jpg (375, 812)>
375x812 点,图像像素即点坐标(经 WDA)
=== iphone_screenshot {"x": 0, "y": 0, "width": 375.0, "height": 60} 0.16s
<image shots/shot2.jpg (1124, 180)>
区域 (0,0) 起 375x60 点,放大 3 倍;图中像素 (u,v) 对应屏幕点 (0+u/3, 0+v/3)(经 WDA)
=== iphone_press_button {"button": "home"} 1.85s
已按 home
=== iphone_swipe {"from_x": 188, "from_y": 349, "to_x": 188, "to_y": 609} 1.90s
已滑动 (188,349) → (188,609)
=== iphone_type_text {"text": "设置"} 1.17s
已输入 2 个字符
=== iphone_wait_for {"text": "设置", "timeout": 5} 0.25s
已出现 Cell "设置" id="Identifier:GridCell,Section:0,Row:0" @(188,143) 330x114(0.2 秒)
=== iphone_screenshot {} 0.38s
<image shots/shot3.jpg (375, 812)>
375x812 点,图像像素即点坐标(经 WDA)
=== iphone_press_button {"button": "home"} 1.56s
已按 home
=== iphone_status {} 0.18s
WDA 就绪: True
锁屏: 未锁屏
前台 App: com.apple.springboard
屏幕: 375x812 点
守护进程: 就绪
--- 16 calls, 0 failed, 16.8s in all

3. Regression cases (docs/dev/regression-cases.md)

4. Real-device proof of the fix or feature

  • Device, iOS version, host (Linux / macOS): iPhone 12 mini, iOS 26.4.1, macOS
  • Fix: reproduced on v0.2.7, then exercised end to end on this branch through the MCP server
  • Untested conditions: an older WDA without launchUnattached on a real device (covered by the unit test); iPad; native control (unchanged)
Steps and results

Notes had never been opened on this phone and was left on its privacy notice (not accepted) between runs.

v0.2.7:

=== iphone_press_button {"button": "home"} 1.38s
已按 home
=== iphone_launch_app {"app": "备忘录"} 65.02s ERROR
WDA 请求超时(请求已发出,手机可能仍在执行,先截图确认):请求超时(60 秒)
  FAILED: was refused
=== iphone_status {} 0.02s
WDA 不可用(正在启动 WDA),守护进程一般 1~2 分钟内会拉起;这台手机 iOS 低于 27,没有 HID 后备路线,WDA 恢复前截图、点击等操作都用不了
读界面元素、按名字点击、启动 App 要等 WDA 恢复;输入中文改经剪贴板粘贴,要点手机弹出的「允许粘贴」
daemon log: 07:23:32 WDA 卡死:/status 正常,但经 XCTest 的请求连续 3 次没有应答,重新启动 WDA

this branch:

## iphone_launch_app {"app":"备忘录"} (never opened: privacy notice)
[0.667s ok=True] 
已启动 com.apple.mobilenotes,但屏幕上有系统弹窗「第一次打开时的隐私说明页(点「继续」或「接受并继续」后才进入 App)」挡着;先用 iphone_tap_element 点弹窗上的按钮
## iphone_launch_app {"app":"备忘录"} (never opened: privacy notice)
[0.732s ok=True] 
已启动 com.apple.mobilenotes,但屏幕上有系统弹窗「第一次打开时的隐私说明页(点「继续」或「接受并继续」后才进入 App)」挡着;先用 iphone_tap_element 点弹窗上的按钮
## iphone_launch_app {"app":"时钟"} (cold start), then tap a tab right away
[0.881s ok=True] 
已启动 com.apple.mobiletimer
已点击 Button "秒表" value="1" @(226,760) 94x54
画面已静止(0.7 秒)
--- 操作后的界面 ---
Button "启动" @(317,417) 84x84
## iphone_launch_app {"app":"设置"} (already running in the background)
[1.408s ok=True] 
已启动 com.apple.Preferences
前台 App: com.apple.Preferences

No WDA restart in the daemon log during the branch runs.

Checklist

  • MCP tool names, parameters and default outputs stay compatible (docs/decisions.md D10): no tool changes; a launch blocked by the privacy notice now answers like one blocked by a permission alert instead of timing out
  • New or changed dependencies are pinned to exact versions; vendor changes recorded in THIRD_PARTY.md: no dependency changes (the route is in the pinned WDA)

Docs: CHANGELOG.md, CHANGELOG.zh-CN.md, regression row #152.

🤖 Generated with Claude Code

The first time a system app such as Notes or Reminders is opened, iOS
shows its privacy notice in a separate process (com.apple.PDUIApp) on
top of it. /wda/apps/launch waits until XCTest sees the app in the
foreground, so it waited the full 60 s, the call failed with a timeout,
and the daemon then judged WDA stalled and restarted it: 65 s and a WDA
restart for one iphone_launch_app.

Launch with /wda/apps/launchUnattached instead, which goes through
LSApplicationWorkspace and returns at once, and keep polling the
foreground as before. When the foreground is the privacy notice, report
it as blocking, like a permission alert. In this state the route
answers "failed to launch" although the notice is up, so that answer
is treated like a successful launch and the foreground decides. An
older WDA without the route falls back to /wda/apps/launch.

On an iPhone 12 mini (iOS 26.4.1) launching a never-opened Notes now
returns in 0.7 s without a WDA restart; 0.2.7 took 65 s and restarted
WDA.

Regression case Derrors#152.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Derrors added a commit to cosinec/iphone-control that referenced this pull request Nov 17, 2026
Resolve the conflicts with Derrors#139 and Derrors#141: keep both sides (TapSequence
next to Tap's new count, both constants, both client methods and their
tests, CHANGELOG lines, regression rows Derrors#146-Derrors#148 in order).

iphone_tap now carries count: a step with count under one_gesture is an
error instead of being tapped once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Derrors and others added 2 commits November 18, 2026 01:14
Resolve the conflicts with Derrors#141-Derrors#147: keep both sets of client tests, and
rows Derrors#146-Derrors#151 from main. This branch's row becomes Derrors#153 (Derrors#152 goes to the
native floating search bar fix, Derrors#150).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bring in Derrors#150: its CHANGELOG line and regression row Derrors#152 come before
this branch's line and row Derrors#153.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Derrors
Derrors merged commit 2b507a9 into Derrors:main Nov 17, 2026
7 checks passed
Derrors added a commit to cosinec/iphone-control that referenced this pull request Nov 17, 2026
Resolve the conflicts with Derrors#141-Derrors#150: TapElement's dispatch keeps main's
scroll search and this branch's clearing of before_action on a miss;
CHANGELOG lines after main's; this branch's regression row becomes Derrors#154
(Derrors#152 is Derrors#150's, Derrors#153 is Derrors#148's).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Derrors added a commit to cosinec/iphone-control that referenced this pull request Nov 17, 2026
Bring in Derrors#148: its CHANGELOG line and regression row Derrors#153 come before
this branch's line and row Derrors#154.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Derrors Derrors mentioned this pull request Nov 17, 2026
12 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants