Skip to content

feat: bound accessibility snapshot requests to avoid indefinite hangs - #1214

Open
mykola-mokhnach wants to merge 2 commits into
masterfrom
issue-1210-ax-timeout
Open

feat: bound accessibility snapshot requests to avoid indefinite hangs#1214
mykola-mokhnach wants to merge 2 commits into
masterfrom
issue-1210-ax-timeout

Conversation

@mykola-mokhnach

@mykola-mokhnach mykola-mokhnach commented Aug 18, 2026

Copy link
Copy Markdown

Summary

Fixes #1210: an app that stops answering accessibility requests could
previously block the whole WDA server forever, since XCTest offers no
bounded timeout for the underlying accessibility snapshot request that
backs most element/attribute lookups (including .identifier, active-app
detection, etc.).

  • Adds a new accessibilityDeadline setting/capability (NSTimeInterval,
    disabled by default). When set to a value > 0, a swizzle on
    -[XCAXClient_iOS requestSnapshotForElement:attributes:parameters:error:]
    first confirms the target app's main run loop is genuinely responsive
    (via the private notifyWhenEventLoopIsIdleForApplication: API, wrapped
    in FBXCAXClientProxy) before letting the real snapshot request proceed.
    If the app doesn't confirm responsiveness within the deadline, the
    request is aborted with a clear "illegal/unresponsive application state"
    error instead of risking an indefinite hang.
  • XCTest internally retries a failed snapshot request several times before
    giving up. To avoid multiplying the configured deadline by the retry
    count, a short-lived per-pid cache remembers "this app was just confirmed
    unresponsive," so those retries fail fast instead of each re-running the
    full wait.
  • handleActiveAppInfo: (GET /wda/activeAppInfo) is made resilient to
    .identifier returning nil (which can legitimately happen once the new
    deadline aborts the underlying fetch) - it now reports "unknown" for
    the app name instead of crashing.

Test plan

  • New integration test FBConfigurationTests.testAccessibilityDeadlineAbortsSnapshotRequestForDeadlockedApp
    freezes the IntegrationApp fixture's main thread (Deadlock app button,
    reworked to sleep instead of self-deadlock so it doesn't trip the OS
    watchdog) and asserts that a snapshot request against it aborts within
    bounds instead of hanging. Skipped on CI (CI env var) since it
    deliberately freezes the app for ~20s.
  • Verified manually end-to-end against a temporary freeze harness: with
    accessibilityDeadline set, a frozen app now fails gracefully in a few
    seconds; with it unset (default), original unbounded behavior is
    preserved unchanged.
  • WebDriverAgentLib and the new test target build and pass locally.

…#1210)

An app that stops answering accessibility requests could previously block
WDA forever, since XCTest offers no bounded timeout for the underlying
snapshot request. Adds a new accessibilityDeadline setting/capability that,
when set, aborts the request with a clear error instead of waiting
indefinitely, caching the unresponsive state briefly so XCTest's own
internal retries fail fast instead of each re-waiting the full timeout.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@Dan-Maor

Copy link
Copy Markdown
Collaborator

I will review it and run some tests tomorrow, very hectic day today.

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.

An app that stops answering accessibility requests blocks the whole agent forever, with no timeout left to bound it

2 participants