Skip to content

fix(device): an app that reads no elements restarts a stuck axauditd too - #156

Merged
Derrors merged 1 commit into
mainfrom
fix/native-ax-empty-app
Nov 18, 2026
Merged

Derrors merged 1 commit into
mainfrom
fix/native-ax-empty-app

Conversation

@Derrors

@Derrors Derrors commented Nov 18, 2026

Copy link
Copy Markdown
Owner

What and why

axauditd stuck without a timeout. With native control (iOS 27), axauditd also gets stuck in a way #152 doesn't catch: the frontmost app reads no elements at all, not even its own application element, and a new session reads the same, while SpringBoard reads as usual. Nothing times out, so it isn't DeviceError::AxUnanswered and axauditd isn't restarted. Reading the screen, tapping by text and launching apps all failed with "读界面失败:超时:没有读到界面元素" (Clock, then Settings after a relaunch). Terminating and relaunching the app didn't help, and neither did restarting the daemon. Ending axauditd by hand (the same Tunnel::restart_ax_daemon the daemon uses) brought the reads back at once: Settings read 15 elements. This was seen once, on an iPhone19,7 (iOS 27.2.1), and what puts axauditd in this state isn't known.

Tunnel::ax_screen now reports such a read (no elements after the reconnect it already does) as DeviceError::AxUnanswered, with the same text as before. The daemon restarts axauditd for it and reads again, at most once a minute (#152). The lock screen under the HID screen stream reads one element, the app's (#126), so it isn't taken for this.

scenarios.py url, #131. The check wanted the link in Safari. Natively a web link always opens in Safari (apps::app_for_url). Through WDA the system opens the default browser, so the check failed on a phone whose default browser is Chrome. It now also passes when the link opens in the app the answer names, that app is in front, and it isn't the home screen. The scenario's description says which browser each route uses. Test only, no product code.

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: an_app_read_with_no_elements_is_an_unanswered_accessibility_service (the error kind and that its text is unchanged; that the phone reads empty only shows on a device)
  • No existing test removed, ignored or loosened. The fix(setup): a key typed after an unfinished sequence isn't swallowed #131 device check is widened to accept the default browser through WDA, for the reason above
  • #[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, macOS 27.2 (Apple Silicon); this branch's daemon started by hand
  • tests/device/run.py default steps pass on this branch (exit code 0)
  • tests/device/scenarios.py passes on this branch: native, all scenarios with --lock --url, 59 checks, 0 failed; WDA, --url url, 3 checks, 0 failed
  • The same steps on main, same device, for comparison (run.py --repeat 5 --json, compare.py): not run. The change only matters when a read returns no elements, and over the runs below that never happened, so no other step takes a different path
  • Steps exercising this change: the native runs below, with the daemon's debug log checked for the new path and for axauditd restarts; url through WDA before and after
  • Longer run: not run
run.py output
this branch, native (the phone was locked at the start, the 2nd step unlocked it first):
### iPhone19,7, iOS 27.2.1, 440x956 pt, native, <udid>
=== iphone_status {} 0.02s
=== iphone_tap_element {"text": "不存在的按钮xyz"} 10.94s
=== iphone_press_button {"button": "home"} 0.70s
=== iphone_launch_app {"app": "时钟"} 1.02s
=== iphone_list_elements {"limit": 40} 0.08s
=== iphone_tap_element {"text": "世界时钟", "then": "elements", "then_filter": "Button"} 1.79s
=== iphone_tap_element {"text": "闹钟", "then": "elements", "then_filter": "Button"} 1.20s
=== iphone_screenshot {} 0.31s
=== iphone_screenshot {"x": 0, "y": 0, "width": 440.0, "height": 60} 0.25s
=== iphone_press_button {"button": "home"} 1.18s
=== iphone_swipe {"from_x": 220, "from_y": 411, "to_x": 220, "to_y": 717} 1.45s
=== iphone_type_text {"text": "设置"} 1.83s
=== iphone_wait_for {"text": "设置", "timeout": 5} 0.15s
=== iphone_screenshot {} 0.67s
=== iphone_press_button {"button": "home"} 1.76s
=== iphone_status {} 0.04s
--- 16 calls, 0 failed, 23.9s 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): iPhone19,7, iOS 27.2.1, macOS 27.2
  • Bug fix: reproduced on main, gone with this branch, same device and steps. Not done for the axauditd part: the stuck state can't be brought about on demand, and it hasn't come back since. What was shown on the device:
    • while it was stuck (on a build of main), ending axauditd through Tunnel::restart_ax_daemon fixed the reads at once. That is what the daemon now does on its own
    • with this branch the new path doesn't trigger on a healthy phone. Over run.py and every scenario (59 checks, three automatic unlocks) the daemon log has no "reads no elements on a new session either" and no "已重启手机上的 axauditd"
  • fix(setup): a key typed after an unfinished sequence isn't swallowed #131 check: fails with main's scenarios.py through WDA, passes with this branch's, same daemon, back to back
  • Untested conditions: iPad, landscape, other iOS 27 versions, a Linux host
Steps and results (before / after, output, log lines, screenshots)
While axauditd was stuck (main's code; daemon debug log, Clock and then Settings in front):
DEBUG ictl_device::ax: remoteAXService: app 19544 reads empty, reconnecting
iphone_list_elements → 读界面失败:超时:没有读到界面元素
iphone_terminate_app Clock, iphone_launch_app Clock → 读界面失败:超时:没有读到界面元素 (new process 19572 reads empty too)
iphone_launch_app Settings → 读界面失败:超时:没有读到界面元素 (SpringBoard read 24 elements meanwhile)
daemon restarted → the same
axauditd ended (Tunnel::restart_ax_daemon: "ended axauditd: Ok(1)"), daemon started:
iphone_list_elements → Button "…Apple账户、iCloud+等" id="com.apple.settings.primaryAppleAccount" … (15 elements)

This branch, native: run.py 16/16; scenarios.py --lock --url 59 checks, 0 failed
daemon log: 0 × "reads no elements on a new session either", 0 × "已重启手机上的 axauditd"

#131 through WDA (default browser Chrome), the same daemon:
main's scenarios.py --url url:
FAIL [url] #131 a link opened right after Safari was terminated opens in Safari (2.36s)  ← 已打开 https://example.com(前台 com.google.chrome.ios) / … 前台 App: com.google.chrome.ios …
PASS [url] #133 text on the web page can be waited for (0.08s)
--- 3 checks, 1 failed, 8.7s in all
this branch's:
PASS [url] #131 a link opened right after Safari was terminated opens in a browser (com.google.chrome.ios, 2.12s)
PASS [url] #133 text on the web page can be waited for (0.15s)
--- 3 checks, 0 failed, 8.4s in all

natively the same check with this branch:
PASS [url] #131 a link opened right after Safari was terminated opens in a browser (com.apple.mobilesafari, 0.91s)

Checklist

  • MCP tool names, parameters and default outputs stay compatible (docs/decisions.md D10); the error text is unchanged
  • 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

With native control (iOS 27), axauditd also gets stuck without timing out:
the frontmost app reads no elements at all, not even its own application
element, on a new session too, while SpringBoard reads as usual. Reading the
screen, tapping by text and launching apps then failed with "no screen
elements read" until axauditd was ended by hand; restarting the daemon didn't
help. Seen once on an iPhone19,7 (iOS 27.2.1); ending axauditd brought the
reads back at once.

Such a read is now reported as the accessibility service not answering
(DeviceError::AxUnanswered, worded as before), which the daemon restarts
axauditd for (#152), at most once a minute. The lock screen under the HID
screen stream reads one element (#126) and is not taken for it.

scenarios.py `url`: #131 also passes when the link opens in the browser the
answer names. Natively a web link always opens in Safari; through WDA the
system opens the default browser, which failed the check on a phone whose
default browser is Chrome.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Derrors
Derrors merged commit 9a28c83 into main Nov 18, 2026
7 checks passed
@Derrors Derrors mentioned this pull request Nov 18, 2026
11 tasks done
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-ax-empty-app 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