Skip to content

feat(daemon): say when the same action leaves the screen unchanged again - #145

Merged
Derrors merged 2 commits into
Derrors:mainfrom
cosinec:feat/repeat-unchanged
Nov 17, 2026
Merged

Derrors merged 2 commits into
Derrors:mainfrom
cosinec:feat/repeat-unchanged

Conversation

@cosinec

@cosinec cosinec commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

What and why

An agent that is stuck on a screen tends to repeat the same tap. With then (or after a screenshot), every answer ends with the same sentence, "but the screen is the same as before the action … don't repeat the same action", so nothing tells it that this is already the third or fourth identical try. Other phone agents add loop detection for this; here the daemon already compares the screen before and after each action, so it only needs to count.

  • PerDevice gets a small Repeats: the last action as sent (its Request JSON) and how many times in a row it left the screen unchanged. start is called where before_action is taken; settled is called by change_note with the comparison result.
  • From the second identical unchanged result on, the note continues: ;这已经是连续第 N 次原样做这个操作、界面都没变:别再重复了,换个做法(…),还不行就告诉用户卡在了哪一步 / ; this exact action has now left the screen unchanged N times in a row: stop repeating it and try something else (…), or tell the user where it is stuck.
  • Another action, other parameters (another point) or a changed screen start the count again. An action that couldn't be compared (nothing was looked at before it) neither counts nor resets. It is per device, like before_action, and cleared with it.

Nothing else changes: the first unchanged result reads exactly as before, and actions without then or without an earlier look get no note at all, as before (D10).

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-daemon tools::tests::the_same_action_leaving_the_screen_unchanged_is_counted (same tap counted 1, 2, an uncomparable run in between counts nothing, 3; another point restarts; a changed screen resets; another action in between restarts; a settle without an action counts nothing; no text below 2)
  • 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.2s in all
  • The same steps on the latest release, same device (run earlier the same day for feat(mcp): iphone_swipe holds before moving with hold, to drag icons #144): v0.2.7 release binary, 16 calls, 0 failed, 16.7s 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.22s
WDA 就绪: True
锁屏: 未锁屏
前台 App: com.apple.springboard
屏幕: 375x812 点
守护进程: 就绪
=== iphone_tap_element {"text": "不存在的按钮xyz"} 1.33s
没找到包含 "不存在的按钮xyz" 的元素,先用 iphone_list_elements 或截图看看屏幕
=== iphone_press_button {"button": "home"} 1.24s
已按 home
=== iphone_launch_app {"app": "时钟"} 0.96s
已启动 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.60s
已点击 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.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.78s
已按 home
=== iphone_swipe {"from_x": 188, "from_y": 349, "to_x": 188, "to_y": 609} 1.80s
已滑动 (188,349) → (188,609)
=== iphone_type_text {"text": "设置"} 1.96s
已输入 2 个字符
=== iphone_wait_for {"text": "设置", "timeout": 5} 0.28s
已出现 Cell "设置" id="Identifier:GridCell,Section:0,Row:0" @(188,143) 330x114(0.3 秒)
=== iphone_screenshot {} 0.33s
<image shots/shot3.jpg (375, 812)>
375x812 点,图像像素即点坐标(经 WDA)
=== iphone_press_button {"button": "home"} 1.51s
已按 home
=== iphone_status {} 0.19s
WDA 就绪: True
锁屏: 未锁屏
前台 App: com.apple.springboard
屏幕: 375x812 点
守护进程: 就绪
--- 16 calls, 0 failed, 16.2s 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.27s
已按 home
=== iphone_launch_app {"app": "时钟"} 0.95s
已启动 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.63s
已点击 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.60s
已点击 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.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.76s
已按 home
=== iphone_swipe {"from_x": 188, "from_y": 349, "to_x": 188, "to_y": 609} 1.87s
已滑动 (188,349) → (188,609)
=== iphone_type_text {"text": "设置"} 1.69s
已输入 2 个字符
=== iphone_wait_for {"text": "设置", "timeout": 5} 0.30s
已出现 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.53s
已按 home
=== iphone_status {} 0.18s
WDA 就绪: True
锁屏: 未锁屏
前台 App: com.apple.springboard
屏幕: 375x812 点
守护进程: 就绪
--- 16 calls, 0 failed, 16.7s 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
  • Feature: exercised end to end through the MCP server
  • Untested conditions: native control (iOS 27); the screenshot comparison path (the home screen has an element tree)
Steps and results

Home screen, element list read once, then taps on an empty spot with then=elements (the filter matches nothing, so only the note lines are shown).

# empty spot tapped 4 times, then another spot, then the first again
## iphone_tap (232,640) then=elements, run 1
已点击 (232,640)
界面已稳定(0.9 秒);但界面和操作前一样:操作可能没生效(点在了空白处、被别的东西挡住,或 App 还没反应过来),先截图看清再决定,不要原样再做一遍
## iphone_tap (232,640) then=elements, run 2
已点击 (232,640)
界面已稳定(0.9 秒);但界面和操作前一样:操作可能没生效(点在了空白处、被别的东西挡住,或 App 还没反应过来),先截图看清再决定,不要原样再做一遍;这已经是连续第 2 次原样做这个操作、界面都没变:别再重复了,换个做法(截图看清目标在哪、换个位置或改用按名字点、先关掉挡住的东西),还不行就告诉用户卡在了哪一步
## iphone_tap (232,640) then=elements, run 3
已点击 (232,640)
界面已稳定(0.9 秒);但界面和操作前一样:操作可能没生效(点在了空白处、被别的东西挡住,或 App 还没反应过来),先截图看清再决定,不要原样再做一遍;这已经是连续第 3 次原样做这个操作、界面都没变:别再重复了,换个做法(截图看清目标在哪、换个位置或改用按名字点、先关掉挡住的东西),还不行就告诉用户卡在了哪一步
## iphone_tap (232,640) then=elements, run 4
已点击 (232,640)
界面已稳定(0.9 秒);但界面和操作前一样:操作可能没生效(点在了空白处、被别的东西挡住,或 App 还没反应过来),先截图看清再决定,不要原样再做一遍;这已经是连续第 4 次原样做这个操作、界面都没变:别再重复了,换个做法(截图看清目标在哪、换个位置或改用按名字点、先关掉挡住的东西),还不行就告诉用户卡在了哪一步
## iphone_tap (300,680)
已点击 (300,680)
界面已稳定(0.9 秒);但界面和操作前一样:操作可能没生效(点在了空白处、被别的东西挡住,或 App 还没反应过来),先截图看清再决定,不要原样再做一遍
## iphone_tap (232,640) again
已点击 (232,640)
界面已稳定(0.9 秒);但界面和操作前一样:操作可能没生效(点在了空白处、被别的东西挡住,或 App 还没反应过来),先截图看清再决定,不要原样再做一遍
## iphone_tap_element 设置 (opens Settings: screen changes)
已点击 Icon "设置" value="1个新项目" @(62,580) 80x102
界面已稳定(1.1 秒);和操作前相比界面有变化

Checklist

  • MCP tool names, parameters and default outputs stay compatible (docs/decisions.md D10): only an extra clause on the existing note, from the second identical unchanged result on
  • New or changed dependencies are pinned to exact versions; vendor changes recorded in THIRD_PARTY.md: no dependency changes

Docs: docs/tools.md (the then section), CHANGELOG.md, CHANGELOG.zh-CN.md.

🤖 Generated with Claude Code

An agent stuck on a screen tends to repeat the same tap. Each time the
answer is the same "the screen is the same as before the action, don't
repeat it", so nothing tells it that this is already the third try.

The daemon now remembers the last action as sent (its request JSON) and
how many times in a row it left the screen unchanged. When the same
request leaves it unchanged again, from the second time on the note
adds "this exact action has now left the screen unchanged N times in a
row: stop repeating it and try something else, or tell the user where
it is stuck". Another action, other parameters or a changed screen
start the count again; an action that couldn't be compared (nothing was
looked at before it) neither counts nor resets.

Regression case Derrors#150.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Derrors merged commit 5282ec5 into Derrors:main Nov 17, 2026
13 of 14 checks passed
Derrors added a commit to cosinec/iphone-control that referenced this pull request Nov 17, 2026
Bring in Derrors#145; keep both tests in tools/mod.rs and rows Derrors#150 then Derrors#151.

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