Skip to content

fix(daemon): restart a stuck axauditd instead of failing until the phone is replugged - #152

Merged
Derrors merged 2 commits into
mainfrom
fix/native-ax-wedged-restart
Nov 18, 2026
Merged

Derrors merged 2 commits into
mainfrom
fix/native-ax-wedged-restart

Conversation

@Derrors

@Derrors Derrors commented Nov 18, 2026

Copy link
Copy Markdown
Owner

What and why

Under native control (iOS 27) the phone's axauditd, the process behind remoteAXService, can get stuck. Every read of the screen then times out (remoteAXService: request, then deviceAPIVersion on each new handshake), the daemon stays at "准备手机失败,稍后重试", and a new session, a new tunnel or a daemon restart doesn't help. Only replugging the phone brought it back. It happened three times on 2026-11-17/18 on an iPhone 15 Pro Max (iOS 27.2.1): twice right after a deploy restarted the daemon, once during a regression run right after an automatic unlock.

Freezing axauditd with SIGSTOP (through CoreDevice AppService) reproduces it exactly. Ending it brings remoteAXService back at once: launchd starts it on the next connection, and the next read took 0.3 s.

  • ictl-device: remoteAXService not answering (a handshake, a request or the connection timing out) is now DeviceError::AxUnanswered, worded exactly like Timeout. Tunnel::restart_ax_daemon ends …/AccessibilityAudit.framework/Support/axauditd with SIGKILL and gives launchd a second.
  • ictl-daemon: reading the screen (ax_snapshot, so also preparing the phone) or the foreground app, on AxUnanswered, restarts axauditd and reads once more. At most once a minute per device (AX_RESTART_EVERY); if that doesn't help the error is reported as before. The event log says 无障碍服务没有应答(…),已重启手机上的 axauditd.

WDA and iOS below 27 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.89 in Docker, Debian 12; clippy with the two lints 1.89 reports and CI's 1.99 doesn't allowed). The one local failure, tasks::tests::the_agent_cant_control_its_own_task, fails on main the same way in this container (process parentage); CI runs it.
  • New behaviour has unit tests: ax::wedge_tests::an_unanswered_accessibility_service_is_told_apart_and_reads_as_a_timeout, ax::wedge_tests::only_axauditd_is_the_accessibility_daemon (process paths as the phone lists them). The restart itself needs a phone; see section 4.
  • 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: iPhone 15 Pro Max (iPhone16,2), iOS 27.2.1, native control, Debian 12
  • tests/device/run.py --repeat 5: 80 calls, 0 failed, 88.1 s (main 48b2c6e earlier the same day: 80 calls, 0 failed, 89.8 s)
  • tests/device/scenarios.py --lock --url: 57 checks, 0 failed
  • tests/device/run.py over the viewer's /mcp: 16 calls, 0 failed
  • tests/device/tasks.py: 71 checks, 0 failed; remote: 23 checks, 0 failed; restart: 4 checks, 0 failed
  • Longer run: the whole set above, about 5 minutes; the restart fired only for the induced stall

3. Regression cases

4. Real-device proof of the fix

  • Bug fix: reproduced on main, gone with this branch, same device and steps
Steps and results

axauditd frozen with SIGSTOP through CoreDevice AppService (a scratch example, not part of this PR), then iphone_list_elements:

main (035b7c6):
  iphone_list_elements  -> native: 读界面失败:超时:remoteAXService: request
  iphone_list_elements  -> native: 读界面失败:超时:remoteAXService: deviceAPIVersion
  (stays like this; SIGKILL to axauditd by hand -> the next read works)

this branch (929b37c):
  iphone_list_elements  -> StaticText "计时器" @(68,138) 97x41 …   (no error)
  event log: 无障碍服务没有应答(remoteAXService: request),已重启手机上的 axauditd
  axauditd pid 48336 -> 48420

Checklist

  • MCP tool names, parameters and default outputs stay compatible (D10): error texts unchanged
  • No dependency changes
  • User-visible change noted in CHANGELOG.md and CHANGELOG.zh-CN.md under Unreleased
  • No private data

🤖 Generated with Claude Code

Derrors and others added 2 commits November 18, 2026 08:49
…one is replugged

Under native control (iOS 27) the phone's axauditd, the process behind
remoteAXService, can get stuck: every read then times out on
`deviceAPIVersion`, a new session or tunnel doesn't help, and only
replugging the phone brought it back. Seen after automatic unlocks and
daemon restarts (iPhone 15 Pro Max, iOS 27.2.1); freezing axauditd with
SIGSTOP reproduces it, and ending it brings remoteAXService back at once.

remoteAXService not answering is now an error of its own
(DeviceError::AxUnanswered, worded as before). Reading the screen or the
foreground app then ends axauditd through CoreDevice (launchd starts it
on the next connection) and reads once more, at most once a minute per
device, and the event log says so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Derrors
Derrors merged commit e2afc62 into main Nov 18, 2026
13 of 14 checks passed
Derrors added a commit that referenced this pull request Nov 18, 2026
…y byte (#153)

* test(terminal): a busy runner gets more attempts to send a key byte by byte

The fragmented-key check throws away an attempt whose writes took longer
than 0.2 s (the script was held up, which proves nothing about the menu)
and tries again, five times at most. A busy macOS runner stretched every
sleep for longer than that: five attempts in a row took 0.21-0.33 s, and
macos-terminal failed twice on 2026-11-18 (#151, #152) with nothing wrong
in the menu.

It now tries up to 30 times within 20 s, says how many attempts a key
took when it needed more than one, and the failure names the count. The
budget, the gap between bytes and what is checked are unchanged.

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

* docs: what the axauditd stall in regression case #155 was traced to

Only right after the lock button with a read following; what was tried
and didn't reproduce it; the cause is inside axauditd.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Derrors added a commit that referenced this pull request Nov 18, 2026
…too (#156)

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 mentioned this pull request Nov 18, 2026
11 tasks done
@Derrors
Derrors deleted the fix/native-ax-wedged-restart 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