Skip to content

fix(mcp): a tap by text that tapped nothing doesn't claim it had no effect - #149

Merged
Derrors merged 3 commits into
Derrors:mainfrom
cosinec:fix/missed-tap-no-change-note
Nov 17, 2026
Merged

Derrors merged 3 commits into
Derrors:mainfrom
cosinec:fix/missed-tap-no-change-note

Conversation

@cosinec

@cosinec cosinec commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What and why

When iphone_tap_element finds nothing, or the index is out of range, or the element is fully covered, it taps nothing and says why. With then, though, the answer goes on as if something had been tapped. It first waits 0.7–0.8 s for the screen to settle. Then it compares the screen with the tree the tap read beforehand and adds: ;但界面和操作前一样:操作可能没生效(点在了空白处、被别的东西挡住,或 App 还没反应过来),先截图看清再决定,不要原样再做一遍 ("the action may not have taken effect … don't repeat the same action"). That clause is wrong, because there was no action, and it points the agent at the wrong cause.

The fix has two parts:

  • daemon (core.rs): when a tap by text tapped nothing, drop before_action, so a following settle has nothing to compare and adds no clause. This also covers older MCP servers and the last step of a batch.
  • MCP (call_tool → finish): when the answer is a missed tap (tap_missed, i.e. Outcome.tapped_nothing or the old prefixes), skip the Settle call. The elements are listed right away from the tree the tap just read (it is in the elements cache), or the screenshot is taken right away. finish gets a settle flag; the batch paths pass true, so they are unchanged.

A tap that did happen settles and compares exactly as before.

With scroll (#147) the search may have scrolled even when it finds nothing, so a missed tap with scroll still settles and compares as before; only a missed tap without scroll skips them. (Added when rebasing onto #147; the device runs below were made before that rebase and don't use scroll.)

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: not added. The daemon part sits in dispatch after tap_element, which needs a WDA to read a tree; the daemon tests have no WDA mock for that. The MCP part needs a daemon to call. The decision itself is tap_missed, already covered by tap_missed_* tests. It is covered by the device runs below. If you'd like a test seam here, tell me where you prefer it.
  • 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, 16.4s in all (this branch's daemon and MCP server). It includes a missed iphone_tap_element (no then) and iphone_tap_element with then: elements.
  • The same steps on the latest release, same device (run earlier the same day for fix(wda): a first launch behind the privacy notice returns at once #148): 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
run.py output (this branch)
### iPhone13,1, iOS 26.4.1, 375x812 pt, WDA, 00008101-00150D941AD8001E
=== iphone_status {} 0.16s
WDA 就绪: True
锁屏: 未锁屏
前台 App: com.apple.Preferences
屏幕: 375x812 点
守护进程: 就绪
=== iphone_tap_element {"text": "不存在的按钮xyz"} 0.49s
没找到包含 "不存在的按钮xyz" 的元素,先用 iphone_list_elements 或截图看看屏幕
=== iphone_press_button {"button": "home"} 1.69s
已按 home
=== iphone_launch_app {"app": "时钟"} 0.94s
已启动 com.apple.mobiletimer
=== iphone_list_elements {"limit": 40} 0.25s
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.66s
已点击 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.63s
已点击 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.14s
<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.79s
已按 home
=== iphone_swipe {"from_x": 188, "from_y": 349, "to_x": 188, "to_y": 609} 1.82s
已滑动 (188,349) → (188,609)
=== iphone_type_text {"text": "设置"} 2.41s
已输入 2 个字符
=== iphone_wait_for {"text": "设置", "timeout": 5} 0.27s
已出现 Cell "设置" id="Identifier:GridCell,Section:0,Row:0" @(188,143) 330x114(0.3 秒)
=== iphone_screenshot {} 0.34s
<image shots/shot3.jpg (375, 812)>
375x812 点,图像像素即点坐标(经 WDA)
=== iphone_press_button {"button": "home"} 1.54s
已按 home
=== iphone_status {} 0.19s
WDA 就绪: True
锁屏: 未锁屏
前台 App: com.apple.springboard
屏幕: 375x812 点
守护进程: 就绪
--- 16 calls, 0 failed, 16.4s 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: before/after on the same device through the MCP server
  • Untested conditions: native control (iOS 27)
Steps and results

Settings app; the elements were listed once first (so there is a "before" screen), then three calls: two by text that match nothing (with then: elements and then: screenshot) and one that does tap. The third call matched whatever "通用" was on the page Settings reopened on; that it navigates is all that matters here.

The last part runs the v0.2.7 MCP server against this branch's daemon, so it shows the daemon half alone: the screen still settles (the old MCP asks for it), but the wrong clause is gone.

### v0.2.7
## iphone_tap_element {"text":"不存在的项xyz","then":"elements","then_filter":"通用"}
[1.317s ok=True] 
没找到包含 "不存在的项xyz" 的元素,先用 iphone_list_elements 或截图看看屏幕
界面已稳定(0.8 秒);但界面和操作前一样:操作可能没生效(点在了空白处、被别的东西挡住,或 App 还没反应过来),先截图看清再决定,不要原样再做一遍
--- 操作后的界面 ---
NavigationBar "通用" @(188,77) 375x54
## iphone_tap_element {"text":"不存在的项xyz","then":"screenshot","then_region":[0,0,375,100]}
[1.454s ok=True] 
没找到包含 "不存在的项xyz" 的元素,先用 iphone_list_elements 或截图看看屏幕
界面已稳定(0.7 秒);但界面和操作前一样:操作可能没生效(点在了空白处、被别的东西挡住,或 App 还没反应过来),先截图看清再决定,不要原样再做一遍
区域 (0,0) 起 375x100 点,放大 3 倍;图中像素 (u,v) 对应屏幕点 (0+u/3, 0+v/3)(经 WDA)
## iphone_tap_element {"text":"通用","then":"elements","then_filter":"关于本机"}
[1.845s ok=True] 
已点击 NavigationBar "通用" @(188,77) 375x54(共匹配 3 个,点的是第 0 个)
界面已稳定(0.8 秒);但界面和操作前一样:操作可能没生效(点在了空白处、被别的东西挡住,或 App 还没反应过来),先截图看清再决定,不要原样再做一遍
--- 操作后的界面 ---
Cell "关于本机" id="About" @(188,384) 343x54
### branch daemon + branch MCP
daemon: /Users/Shared/phone-tool-bench/build/ic-rep/release/iphone-control
## iphone_tap_element {"text":"不存在的项xyz","then":"elements","then_filter":"通用"}
[0.909s ok=True] 
没找到包含 "不存在的项xyz" 的元素,先用 iphone_list_elements 或截图看看屏幕
--- 操作后的界面 ---
Button "通用" id="BackButton" @(38,72) 44x44
## iphone_tap_element {"text":"不存在的项xyz","then":"screenshot","then_region":[0,0,375,100]}
[0.643s ok=True] 
没找到包含 "不存在的项xyz" 的元素,先用 iphone_list_elements 或截图看看屏幕
区域 (0,0) 起 375x100 点,放大 3 倍;图中像素 (u,v) 对应屏幕点 (0+u/3, 0+v/3)(经 WDA)
## iphone_tap_element {"text":"通用","then":"elements","then_filter":"关于本机"}
[1.8s ok=True] 
已点击 Button "通用" id="BackButton" @(38,72) 44x44
界面已稳定(0.8 秒);和操作前相比界面有变化
--- 操作后的界面 ---
Cell "关于本机" id="About" @(188,384) 343x54
### branch daemon + v0.2.7 MCP (daemon half alone)
daemon: /Users/Shared/phone-tool-bench/build/ic-rep/release/iphone-control
## iphone_tap_element {"text":"不存在的项xyz","then":"elements","then_filter":"通用"}
[1.056s ok=True] 
没找到包含 "不存在的项xyz" 的元素,先用 iphone_list_elements 或截图看看屏幕
界面已稳定(0.6 秒)
--- 操作后的界面 ---
Button "通用" id="com.apple.settings.general" @(188,678) 343x53
## iphone_tap_element {"text":"不存在的项xyz","then":"screenshot","then_region":[0,0,375,100]}
[1.196s ok=True] 
没找到包含 "不存在的项xyz" 的元素,先用 iphone_list_elements 或截图看看屏幕
界面已稳定(0.6 秒)
区域 (0,0) 起 375x100 点,放大 3 倍;图中像素 (u,v) 对应屏幕点 (0+u/3, 0+v/3)(经 WDA)
## iphone_tap_element {"text":"通用","then":"elements","then_filter":"关于本机"}
[2.179s ok=True] 
已点击 Button "通用" id="com.apple.settings.general" @(188,678) 343x53
界面已稳定(1.3 秒);和操作前相比界面有变化
--- 操作后的界面 ---
Cell "关于本机" id="About" @(188,384) 343x54

Checklist

  • MCP tool names, parameters and default outputs stay compatible (docs/decisions.md D10): no change without then; with then, a missed tap drops the settle line and the wrong clause
  • New or changed dependencies are pinned to exact versions; vendor changes recorded in THIRD_PARTY.md: no dependency changes

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

🤖 Generated with Claude Code

…ffect

When iphone_tap_element finds nothing (or the index is out of range, or
the element is fully covered) it taps nothing. With then, the answer
still waited 0.7-0.8 s for the screen to settle and compared it with
the tree read before the (absent) tap, so it went on to say "the screen
is the same as before the action: it may not have taken effect … don't
repeat the same action", as if something had been tapped.

The daemon now drops the "before the action" screen when nothing was
tapped, and the MCP server skips the settle in that case and lists the
elements (or takes the screenshot) right away from the tree the tap
just read. A tap that did happen settles and compares as before.

On an iPhone 12 mini a missed tap with then=elements answers in 0.8 s
instead of 1.3 s, without the misleading clause.

Regression case Derrors#153.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cosinec
cosinec force-pushed the fix/missed-tap-no-change-note branch from 2bc21c2 to e7de4db Compare November 17, 2026 08:46
Derrors added a commit to cosinec/iphone-control that referenced this pull request Nov 17, 2026
Resolve the conflicts with Derrors#139, Derrors#141 and Derrors#143 by keeping both sides:
drag_steps next to tap_sequence_body, the exports of both, the protocol
helpers, the MCP tests, CHANGELOG lines and regression rows Derrors#146-Derrors#149 in
order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Derrors added a commit that referenced this pull request Nov 17, 2026
…144)

* feat(mcp): iphone_swipe holds before moving with hold, to drag icons

Home-screen icons, files and reorderable rows have to be long-pressed
before they can be dragged. iphone_swipe moves as soon as the finger is
down, so it only scrolls or pages. Holding with a W3C pause before the
move doesn't pick them up either; holding with a pointerMove in place
does. hold (seconds, default 0) adds that in-place move before the
stroke; over HID the finger is held, reporting its position every
100 ms like a long press, and then dragged without lifting.

On an iPhone 12 mini, moving the Settings icon to an empty slot worked
5/5 each with hold 0.5, 0.6 and 1 s, and 0/5 without it. A swipe
without hold is the same request as before, and seconds + hold is
bounded by the existing 10 s gesture limit.

Regression case #149.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(daemon): check a swipe's seconds on its own, then seconds plus hold

Only the sum was checked, so a negative seconds passed when the hold made
up for it (-0.5 + 1), and a sum over the limit said "seconds must be
between 0 and 10" although seconds alone was fine. Now seconds keeps its
own range, hold can't be negative, and a sum over the limit names both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Derrors <33656531+Derrors@users.noreply.github.com>
Derrors added a commit to cosinec/iphone-control that referenced this pull request Nov 17, 2026
Resolve the conflict in docs/dev/regression-cases.md: rows Derrors#146-Derrors#149 from
main, then this branch's Derrors#150. The repeat test's Request::Tap gains the
count field Derrors#141 added.

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#141, Derrors#143 and Derrors#144: keep both sides (Tap's
count and TapSequence next to TapElement's scroll, the protocol helpers,
the MCP tests, CHANGELOG lines, doc rows with iphone_tap's count and
iphone_tap_element's scroll, regression rows Derrors#146-Derrors#149 then Derrors#151).

The search scroll now builds the Stroke that Derrors#144's swipe takes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Derrors and others added 2 commits November 18, 2026 01:27
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>
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 merged commit 48b2c6e into Derrors:main Nov 17, 2026
19 of 21 checks passed
@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