Skip to content

fix(daemon): native Home waits out its animation even when the HID session had to be opened - #155

Merged
Derrors merged 1 commit into
mainfrom
fix/native-home-cold-hid
Nov 18, 2026
Merged

Derrors merged 1 commit into
mainfrom
fix/native-home-cold-hid

Conversation

@Derrors

@Derrors Derrors commented Nov 18, 2026

Copy link
Copy Markdown
Owner

What and why

With native control (iOS 27), an app launched right after Home on the home screen could be sent back to the home screen: iphone_launch_app said "Launched com.apple.mobiletimer", the app came to the front, and a moment later SpringBoard was in front again. It is why run.py's first run after a daemon start often failed with "Clock's tab bar isn't among the first 40 elements".

native_home answers no sooner than 0.6 s after Home was pressed when the home screen is already in front (HOME_ANIMATION, #130: what Home closes is still animating, and an app launched meanwhile is sent back when it ends). The time was taken before hid_do, which first opens the HID session when the daemon has closed it (idle for 30 s, supervise::HID_IDLE). Opening it (the screen stream, a fixed 300 ms, two services) takes about as long as the wait, so nothing was left to wait for.

The session is now opened first and the 0.6 s counted from the press. Home on the home screen with the session closed takes about 0.5 s longer for it (about 1.3 s instead of 0.8 s); with the session open nothing changes.

tests/device/scenarios.py has a new idle scenario (default, about 2 minutes): it lets the daemon close the idle session, presses Home on the home screen, launches Clock, and checks Clock is still in front 1.5 s later. Regression case #157.

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
  • New or changed behaviour / the fixed bug has a unit test: none; the fault is the order of opening the HID session and taking the time, which only shows on a device. Covered by scenarios.py idle
  • 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): iPhone19,7, iOS 27.2.1, native control, macOS 27.2 (Apple Silicon)
  • Builds: both started by hand, on 8770ef8 with fix(daemon): native unlocking keeps the HID session open until a key tap has landed #154's native.rs (now 121a498, so that the phone unlocks itself): "before" is that alone, "after" adds this change. The rebased branch's crates/ differs from "after" by nothing.
  • tests/device/run.py default steps pass on this branch (exit code 0)
  • tests/device/scenarios.py passes on this branch: all of them, --lock --url (tools, typing, fresh, batch, menu, idle, url, lock): 59 checks, 0 failed
  • The same steps before the change, same device, for comparison (run.py --repeat 5 --json, compare.py); no step clearly slower, or why: total median 15.23 s → 14.96 s. compare.py marks two steps: the last Home, 1.43 → 1.83 s, and the last status, 0.07 → 0.17 s. The last Home is Home from Spotlight to the home screen, where the 0.6 s now always passes in full: 1.79–1.90 s in all 5 runs here, 1.37–1.91 s before (1.74 and 1.91 in 2 of 5). Why it was sometimes shorter before isn't worked out. The status step is 0.04–0.18 s on both sides
  • Steps exercising this change: Home on the home screen, then Clock, 8 times with the session closed and 8 times open; scenarios.py idle; see part 4
  • Longer run (WDA start-up/recovery, reconnecting, unlocking, live picture, timers): not run; the change is a wait in Home only
run.py output
this branch:
### iPhone19,7, iOS 27.2.1, 440x956 pt, native, <udid>
=== iphone_status {} 0.24s
=== iphone_tap_element {"text": "不存在的按钮xyz"} 0.32s
=== iphone_press_button {"button": "home"} 0.74s
=== iphone_launch_app {"app": "时钟"} 0.94s
=== iphone_list_elements {"limit": 40} 0.48s
=== iphone_tap_element {"text": "闹钟", "then": "elements", "then_filter": "Button"} 0.90s
=== iphone_tap_element {"text": "世界时钟", "then": "elements", "then_filter": "Button"} 1.94s
=== iphone_screenshot {} 0.32s
=== iphone_screenshot {"x": 0, "y": 0, "width": 440.0, "height": 60} 0.26s
=== iphone_press_button {"button": "home"} 1.19s
=== iphone_swipe {"from_x": 220, "from_y": 411, "to_x": 220, "to_y": 717} 1.47s
=== iphone_type_text {"text": "设置"} 1.63s
=== iphone_wait_for {"text": "设置", "timeout": 5} 0.15s
=== iphone_screenshot {} 0.64s
=== iphone_press_button {"button": "home"} 1.59s
=== iphone_status {} 0.03s
--- 16 calls, 0 failed, 13.0s in all

before (run 1 of 5):
### iPhone19,7, iOS 27.2.1, 440x956 pt, native, <udid>
=== iphone_status {} 0.02s
=== iphone_tap_element {"text": "不存在的按钮xyz"} 0.34s
=== iphone_press_button {"button": "home"} 0.75s
=== iphone_launch_app {"app": "时钟"} 0.96s
=== iphone_list_elements {"limit": 40} 0.41s
=== iphone_tap_element {"text": "闹钟", "then": "elements", "then_filter": "Button"} 0.91s
=== iphone_tap_element {"text": "世界时钟", "then": "elements", "then_filter": "Button"} 1.12s
=== iphone_screenshot {} 0.87s
=== iphone_screenshot {"x": 0, "y": 0, "width": 440.0, "height": 60} 0.32s
=== iphone_press_button {"button": "home"} 1.17s
=== iphone_swipe {"from_x": 220, "from_y": 411, "to_x": 220, "to_y": 717} 1.44s
=== iphone_type_text {"text": "设置"} 1.86s
=== iphone_wait_for {"text": "设置", "timeout": 5} 0.18s
=== iphone_screenshot {} 0.68s
=== iphone_press_button {"button": "home"} 1.74s
=== iphone_status {} 0.04s
--- 80 calls, 0 failed, 74.1s in all

compare.py, medians of 5 runs (before → this branch):
iphone_status {}                                0.25    0.04   -0.21
iphone_tap_element {"text": "不存在的按钮xyz"}        0.69    0.57   -0.12
iphone_press_button {"button": "home"}          0.94    0.76   -0.18
iphone_launch_app {"app": "时钟"}                 0.97    0.96   -0.01
iphone_list_elements {"limit": 40}              0.40    0.38   -0.02
iphone_tap_element {"text": "闹钟", "then": "     0.94    0.90   -0.04
iphone_tap_element {"text": "世界时钟", "then":     1.86    1.84   -0.02
iphone_screenshot {}                            0.34    0.31   -0.03
iphone_screenshot {"height": 60, "width": 4     0.28    0.27   -0.01
iphone_press_button {"button": "home"}          1.20    1.20   -0.00
iphone_swipe {"from_x": 220, "from_y": 411,     1.34    1.36   +0.01
iphone_type_text {"text": "设置"}                 3.64    3.54   -0.09
iphone_wait_for {"text": "设置", "timeout": 5     0.21    0.20   -0.01
iphone_screenshot {}                            0.68    0.65   -0.03
iphone_press_button {"button": "home"}          1.43    1.83   +0.40  SLOWER
iphone_status {}                                0.07    0.17   +0.10  SLOWER
total                                          15.23   14.96   -0.27

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

4. Real-device proof of the fix or feature

  • Device, iOS version, host (Linux / macOS): iPhone19,7, iOS 27.2.1, macOS 27.2
  • Bug fix: reproduced before the change, gone with this branch, same device and steps
  • Untested conditions (device kind, iOS version, orientation, host OS), if any: iPad, landscape, other iOS 27 versions, a Linux host. WDA doesn't go through this code.
Steps and results (before / after, output, log lines, screenshots)
Home on the home screen, then iphone_launch_app Clock, then the foreground app read every 0.3 s for 3 s.
"cold": 35 s idle first, so the daemon has closed the HID session; "warm": right after another action.

before (main's Home code), 8 + 8 trials:
cold: 7 of 8 sent back to the home screen, e.g.
  2 cold home 0.82s launch 1.09s [已启动 com.apple.mobiletimer] BACK HOME  0.0:springboard 0.5:springboard 0.9:springboard …
warm: 0 of 8

after (this branch), 8 + 8 trials:
cold: 0 of 8 (Home 0.82–1.34 s)
warm: 0 of 8 (Home 0.82–0.89 s)

scenarios.py idle, before:
FAIL [idle] #157 Home with the HID session idle, then an app started: it stays in front, 1 of 2  ← … 前台 App: com.apple.springboard …
FAIL [idle] #157 Home with the HID session idle, then an app started: it stays in front, 2 of 2  ← … 前台 App: com.apple.springboard …
--- 2 checks, 2 failed, 94.9s in all

scenarios.py idle, after (within --lock --url, 59 checks, 0 failed):
PASS [idle] #157 Home with the HID session idle, then an app started: it stays in front, 1 of 2  ← … 前台 App: com.apple.mobiletimer …
PASS [idle] #157 Home with the HID session idle, then an app started: it stays in front, 2 of 2  ← … 前台 App: com.apple.mobiletimer …

Checklist

  • MCP tool names, parameters and default outputs stay compatible (docs/decisions.md D10)
  • New or changed dependencies are pinned to exact versions; vendor changes recorded in THIRD_PARTY.md (none)
  • User-visible changes noted in CHANGELOG.md (and CHANGELOG.zh-CN.md if you can) under Unreleased
  • No private data in fixtures, screenshots, logs or the outputs above

🤖 Generated with Claude Code

…ssion had to be opened

With native control (iOS 27), Home on the home screen is answered no sooner
than 0.6 s after it was pressed (#130), but the time was taken before the HID
session was opened. After the daemon had left the session idle (30 s), opening
it again (the screen stream) took about as long, so nothing was waited for, and
an app launched right after was sent back to the home screen when the
animation ended: 7 times in 8 on an iPhone19,7 (iOS 27.2.1), 0 in 8 with the
session already open. It is why run.py's first run after a daemon start failed
with "Clock's tab bar isn't among the first 40 elements".

The session is now opened first and the wait counted from the press.
scenarios.py has a new `idle` scenario for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Derrors
Derrors merged commit 5e43c01 into main Nov 18, 2026
7 checks passed
Derrors added a commit that referenced this pull request Nov 18, 2026
Version 0.2.9 in Cargo.toml and Cargo.lock (this workspace's crates
only), and the changelogs' Unreleased section dated. The entries of
#154, #155 and #156 end with their pull requests and say only what the
user sees, as CONTRIBUTING asks.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@Derrors
Derrors deleted the fix/native-home-cold-hid branch November 18, 2026 09:08
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.

1 participant