Skip to content

draft(ios-qa): SwiftUI a11y walker cleanup + GstackProbe + docs (iOS 26 NOT fixed) - #1755

Closed
sternryan wants to merge 1 commit into
garrytan:mainfrom
sternryan:fix/ios-qa-swiftui-a11y-walker
Closed

sternryan wants to merge 1 commit into
garrytan:mainfrom
sternryan:fix/ios-qa-swiftui-a11y-walker

Conversation

@sternryan

@sternryan sternryan commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

Draft — held back for honest scoping after live-device validation. Walker improvements verified to compile and not regress; the on-device SwiftUI tree-walking claim does NOT hold on iOS 26.3.1 (see validation comment). PR rewritten to reflect what's actually being proposed.

What this PR is now

Three low-risk, additive changes plus an honest docs page:

  1. Walker cleanup in ios-qa/templates/Bridges.swift.template — refactor that should be net-positive on every iOS version, no behavior regression observed:

    • Extract emitAXChild() helper (removes duplicated synthetic-element extraction).
    • Always run the indexed accessor path when accessibilityElements returns nil OR empty array (the existing template only fell through on nil — SwiftUI hosting views can return empty array with a non-zero accessibilityElementCount(), which was getting silently dropped).
    • Filter pure-container synthetic nodes (zero label/ident/value/traits) — reduces noise without dropping useful entries.
    • Tag synthetic entries with "source": "ax-synthetic" for downstream agent disambiguation.
    • Add UIAccessibility.post(notification: .layoutChanged, argument: nil) before walking. Documented public API. Note: likely a working trick on iOS 17-18 per related Swift-Forums + swift-agentation prior art, but does NOT trigger SwiftUI AX tree materialization on iOS 26.3.1 per device validation below.
  2. .gstackProbe(_:) SwiftUI ViewModifier (new public API in template) — opt-in escape hatch. Apps that need agent visibility on views the AX tree refuses to surface call .gstackProbe("dashboard.captureButton") and the walker merges (id, frame, label) into the /elements snapshot from GstackProbeRegistry. Uses GeometryReader { .global } + PreferenceKey to keep frames current without polling. Pure public API — no private selectors. Not validated on device in this PR — requires explicit per-view instrumentation that wasn't part of the validation app.

  3. New docs page ios-qa/docs/swiftui-accessibility.md — explains the underlying constraint (SwiftUI doesn't always create backing UIViews; AX tree is lazy + VoiceOver-gated), what this PR fixes, what it does NOT fix on iOS 26, and when to reach for .gstackProbe(_:) vs vision-based coordinate tapping.

What this PR is NOT

A general fix for the SwiftUI accessibility-walker problem on iOS 26. That problem appears to require either private XCTest APIs (XCAXClient_iOS, not available in an in-process DEBUG bridge), an actual VoiceOver-running session, or vision-based positioning. The docs page now says this plainly.

Validation

  • iPhone 12 Pro on iOS 26.3.1 (live device): ported the walker changes into a real SwiftUI app (Principal's Ear's Apps/iOS/DebugBridge/Bridges.swift), hit GET /elements against a Dashboard view with declared .accessibilityIdentifier(...) modifiers. Returns 3 elements (same as pre-PR). The walker cleanup is a no-op regression-wise; the SwiftUI tree-walking claim doesn't hold on this iOS version. Full data in comment thread.
  • Type-check pass: clean against iOS 16/17 SDKs (the Package.swift.template deployment floor) and Swift 6 strict concurrency.
  • .gstackProbe(_:) modifier: untested on device — requires app developer to instrument views with it before there's anything to validate.

Sources consulted

Suggested merge disposition

Three reasonable paths, in increasing order of conservatism:

  • A) Merge as-is. Walker cleanup + .gstackProbe(_:) modifier + docs are all useful additions; the docs page is explicit about iOS 26 limitations.
  • B) Merge walker cleanup + docs only, drop .gstackProbe(_:) until someone validates it on device.
  • C) Close as superseded by docs-only PR. I can spin a separate docs-only follow-up that just adds swiftui-accessibility.md + filters the noise-element cleanup, no API surface changes.

Author's recommendation: B — gets the cleanup + the honest docs in front of users, defers the new API until it has device evidence.

Tested against: iPhone 12 Pro, iOS 26.3.1, Xcode 26.0.1, Swift 6.2.

The /elements walker returned only top-level `_UIHostingView` /
`HostingView` shells on SwiftUI screens — three entries for a full
Dashboard, all with empty identifier/label and a 0,0,390,844 frame.
SwiftUI vends its AX leaves through the indexed accessor
(`accessibilityElementCount` + `accessibilityElement(at:)`) on the
hosting container, not through `accessibilityElements` (which returns
nil OR an empty array). The previous walker only fell through to the
indexed path on nil, not on empty — so SwiftUI leaves were silently
dropped.

Fix is three coordinated changes to ElementsBridgeImpl plus an opt-in
escape hatch:

1. Force materialization via `UIAccessibility.post(.layoutChanged, …)`
   before the walk. Public API, no-op when VoiceOver already populated
   the tree, doesn't speak.
2. Always run the indexed accessor when `accessibilityElements` is nil
   OR empty. This is the actual SwiftUI path.
3. Read identifier/label/value/traits/frame from synthetic AX elements
   via KVC over the documented `UIAccessibility` informal protocol
   property names — safe and version-independent across the private
   element classes (`_AXSnapshotElement`, `_UIAccessibilityElementMockView`, …).
4. New `.gstackProbe("identifier")` SwiftUI ViewModifier + thread-safe
   `GstackProbeRegistry` for views the AX tree refuses to surface
   (intentionally hidden, custom Canvas, decorative Shape stacks). Probe
   sets `.accessibilityIdentifier(_:)` AND registers (id, frame) in the
   registry; the walker merges these in as synthetic entries tagged
   `"source":"gstack-probe"`.

Also filters empty container synthetic nodes (no label/id/value/traits)
that were clogging the output before.

Docs in `ios-qa/docs/swiftui-accessibility.md` cover the root cause,
what the fix does/doesn't address, and when to reach for `.gstackProbe`
vs vision-based coordinate tapping.

Typechecks clean against iOS 16 + iOS 17 SDKs, Swift 6 strict
concurrency. Live-device validation pending — PR author will port to
downstream app + report new element count.
@sternryan

Copy link
Copy Markdown
Contributor Author

Downstream validation — iPhone 12 Pro on iOS 26.3.1

Ported this PR's Bridges.swift.template changes (force UIAccessibility.post(.layoutChanged) + always-run indexed AX accessor + dual-path emission + emitAXChild helper) into a real SwiftUI app's DebugBridge (Principal's Ear), redeployed to a physical iPhone 12 Pro on iOS 26.3.1, and ran GET /elements against a freshly-loaded Dashboard view with declared identifiers (dashboard.captureButton, dashboard.settingsButton, etc.).

Result: still 3 elements, identical to the pre-PR behavior.

TOTAL: 3 | with-identifier: 0 | with-label: 0 | ax-synthetic: 0

  _UIHostingView<ModifiedContent<AnyView, RootModifi...   ident=''  label=''  frame=(0,0,390x844)
  HostingView                                             ident=''  label=''  frame=(0,0,390x844)
  FloatingBarHostingView<FloatingBarContainer>            ident=''  label=''  frame=(0,0,390x844)

Tried with a screenshot-warmup pass before the elements query (in case drawHierarchy would trigger AX hookup) — no change. Tried with a tap delivered between two element queries — no change.

The walker emits these three only because they hit the className.contains("Hosting") || className.contains("SwiftUI") branch. Recursing through subviews of each hosting view continues to find only non-AX _UIGraphicsView-style internal shells, and accessibilityElementCount() returns 0 on all of them post-.layoutChanged-post.

Diagnosis: on iOS 26.x SDK, UIAccessibility.post(.layoutChanged) no longer triggers SwiftUI AX tree materialization for in-process queries — this was likely a working trick on iOS 17-18 (which is what the related Medium articles + swift-agentation referenced) but Apple appears to have made the AX subsystem stricter about VoiceOver-being-actually-running as the gate.

Recommendation:

  • The GstackProbe ViewModifier path in this PR is still useful — it's a documented, opt-in escape hatch, and apps that want full agent visibility on iOS 26 will need it for any view that doesn't expose AX naturally.
  • The walker improvements (always trying indexed accessor, filtering empty synthetic nodes, emitAXChild helper) are no-cost wins that benefit iOS 17/18 users and are sound code anyway — worth keeping.
  • The docs page should add an iOS 26 reality check: the AX-tree-walker path is degraded on this version; vision-based positioning (parse the screenshot, tap by coordinate) is the supported approach for unmodified SwiftUI apps. The .gstackProbe(_:) modifier is the path forward for apps where the developer can instrument views.
  • If you want to chase the iOS 26 regression, the next thing to try is the XCTest private-API path (XCAXClient_iOS) — but that requires running in a test target, not an in-process DEBUG bridge. Likely a non-starter for this skill.

Tested against: iPhone 12 Pro, iOS 26.3.1, Xcode 26.0.1, Swift 6.2, app target uses iOS 26 deployment min, daemon at sternryan/gstack@bea2468 with the patched 24h cache TTL applied locally (PR #1756).

@sternryan
sternryan marked this pull request as draft May 27, 2026 18:46
@sternryan sternryan changed the title fix(ios-qa): walker now surfaces SwiftUI elements, not just hosting shells draft(ios-qa): SwiftUI a11y walker cleanup + GstackProbe + docs (iOS 26 NOT fixed) May 27, 2026
@time-attack

Copy link
Copy Markdown
Contributor

Thanks for this. The supplied iOS 26 validation contradicts claims still present in the documentation, while the new probe and template changes lack matching fixture and release-build coverage. Split documentation from behavior changes, remove disproved claims, mirror fixtures, and provide live-version plus release-absence validation.

@capy-ai

capy-ai Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Thank you for the iOS 26 device data. The synthetic accessibility walker is already on main, and as you found it doesn't help DragGesture on iOS 26. That limitation is being documented in /ios-qa in the current fix wave. Closing.

@capy-ai capy-ai Bot closed this Oct 8, 2026
capy-ai Bot added a commit that referenced this pull request Oct 8, 2026
…hes the app, loud boot-token write (#3076)

* fix(ios-qa): allow physical iPad devices in tunnel bootstrap (#2743)

(cherry picked from commit d6d4393)

* fix(ios-qa): iPhone + iPad on USB names each UDID instead of picking one

With GSTACK_IOS_TARGET_UDID unset, tied default ranks used to pick the first
device devicectl listed, so a QA session could drive the wrong device. Tied
candidates now fail with multiple_devices, list each device and UDID, and
print a ready export line. Device selection moves into selectDevice() so the
route-drop recovery can re-resolve with the same rules.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(ios-qa): a dropped CoreDevice route no longer relaunches the app (#1975)

Rotation deletes the app's one-shot boot-token file, so the daemon's old
503/504 path (invalidate + full bootstrap) could only get a new token by
running devicectl launch --terminate-existing, wiping the in-app QA state at
every route blip.

A route failure now goes through recoverTunnel(): re-select the device with
the bootstrap rules, re-resolve the tunnel address for the pinned UDID, check
the unauthenticated /healthz owner, then probe /state/snapshot with the cached
bearer. Outcomes:
- bearer accepted: keep the session (new address if it moved)
- 401: full bootstrap from the fresh boot token (app was relaunched)
- app confirmed absent: bootstrap, which launches it normally once
- different device or an address devicectl cannot tie to the UDID:
  bootstrap; the old bearer is never sent there
- route still down with the app running: surface the error, keep the session

Concurrent failures on one tunnel share a single refresh. Mutations whose
response was lost are still never replayed. The CLI wiring moves into
deviceTunnelSource() so tests drive it against a simulated device.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(ios-qa): a failed boot-token write is loud instead of silent (#1837)

StateServer.start() wrote the boot-token file with try?, so a failed write
left nothing on disk and no trace anywhere, and the daemon then relaunched the
app trying to mint a token that could never be written. The write is now a
do/catch that logs the path and error (never the token), logs a NOT READY
bootstrap line, and reports boot_token_error on /healthz. bootstrapTunnel
reads that field and returns boot_token_unavailable naming the device-side
cause instead of running --terminate-existing.

Also drops the stale comments claiming the token was written to os_log.
Template and fixture stay byte-identical.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* test(ios-qa): type the iPad acceptance test's mDNS stub

ResolveImpl returns Promise<string[]>; resolving null tripped the test-code
typecheck ratchet. A rejected lookup exercises the same resolve_failed path.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs(ios-qa): iPad support, GSTACK_IOS_TARGET_UDID, route-drop recovery, known limits

- iPhone-only description, triggers, and prerequisites now cover iPads, and
  say how to pick one device with GSTACK_IOS_TARGET_UDID.
- Phase 2 no longer tells you to capture a boot token from os_log (it has
  not been logged for many releases); it describes the 0600 tmp/ file and
  the NOT READY signal (#1837, #1735).
- Source-control guidance for the generated DebugBridge/ package (#1735).
- Failure table: route drops keep the session, multiple_devices, unwritable
  token file, and the one relaunch a daemon restart still costs.
- Known limits: SwiftUI DragGesture and /swipe on iOS 26 (#1975), the
  iOS 26.3.1 /elements data from PR #1755, unverified iPad Stage Manager.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs: iOS QA how-to and skill index cover iPads and route-drop recovery

The how-to still said the boot token was readable from os_log and that a
route drop re-bootstraps; both are now accurate, with iPad selection,
GSTACK_IOS_TARGET_UDID, and three new failure rows.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* v1.91.37.0 fix(ios-qa): iPads work, a route drop no longer relaunches the app, loud boot-token write

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs(ios-qa): keep issue numbers out of model-read skill text

The archaeology lint rejects issue references in generated SKILL.md text;
the Known limits entry keeps the iOS version and drops the number.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* chore: re-slot to v1.91.38.0 (v1.91.37.0 claimed by #3075)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* test(ios-qa): device-change recovery test without an IPv4-mapped address

The Windows lane could not reach a fake StateServer through
::ffff:127.0.0.1, so the iPad half of the device-change test timed out. The
fake device now swaps identity on its one ::1 listener, which is also closer
to production: every StateServer answers on the same port.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

---------

Co-authored-by: loulanyue <[email protected]>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
levi85 pushed a commit to levi85/gstack that referenced this pull request Oct 14, 2026
…hes the app, loud boot-token write (garrytan#3076)

* fix(ios-qa): allow physical iPad devices in tunnel bootstrap (garrytan#2743)

(cherry picked from commit d6d4393)

* fix(ios-qa): iPhone + iPad on USB names each UDID instead of picking one

With GSTACK_IOS_TARGET_UDID unset, tied default ranks used to pick the first
device devicectl listed, so a QA session could drive the wrong device. Tied
candidates now fail with multiple_devices, list each device and UDID, and
print a ready export line. Device selection moves into selectDevice() so the
route-drop recovery can re-resolve with the same rules.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(ios-qa): a dropped CoreDevice route no longer relaunches the app (garrytan#1975)

Rotation deletes the app's one-shot boot-token file, so the daemon's old
503/504 path (invalidate + full bootstrap) could only get a new token by
running devicectl launch --terminate-existing, wiping the in-app QA state at
every route blip.

A route failure now goes through recoverTunnel(): re-select the device with
the bootstrap rules, re-resolve the tunnel address for the pinned UDID, check
the unauthenticated /healthz owner, then probe /state/snapshot with the cached
bearer. Outcomes:
- bearer accepted: keep the session (new address if it moved)
- 401: full bootstrap from the fresh boot token (app was relaunched)
- app confirmed absent: bootstrap, which launches it normally once
- different device or an address devicectl cannot tie to the UDID:
  bootstrap; the old bearer is never sent there
- route still down with the app running: surface the error, keep the session

Concurrent failures on one tunnel share a single refresh. Mutations whose
response was lost are still never replayed. The CLI wiring moves into
deviceTunnelSource() so tests drive it against a simulated device.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* fix(ios-qa): a failed boot-token write is loud instead of silent (garrytan#1837)

StateServer.start() wrote the boot-token file with try?, so a failed write
left nothing on disk and no trace anywhere, and the daemon then relaunched the
app trying to mint a token that could never be written. The write is now a
do/catch that logs the path and error (never the token), logs a NOT READY
bootstrap line, and reports boot_token_error on /healthz. bootstrapTunnel
reads that field and returns boot_token_unavailable naming the device-side
cause instead of running --terminate-existing.

Also drops the stale comments claiming the token was written to os_log.
Template and fixture stay byte-identical.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* test(ios-qa): type the iPad acceptance test's mDNS stub

ResolveImpl returns Promise<string[]>; resolving null tripped the test-code
typecheck ratchet. A rejected lookup exercises the same resolve_failed path.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs(ios-qa): iPad support, GSTACK_IOS_TARGET_UDID, route-drop recovery, known limits

- iPhone-only description, triggers, and prerequisites now cover iPads, and
  say how to pick one device with GSTACK_IOS_TARGET_UDID.
- Phase 2 no longer tells you to capture a boot token from os_log (it has
  not been logged for many releases); it describes the 0600 tmp/ file and
  the NOT READY signal (garrytan#1837, garrytan#1735).
- Source-control guidance for the generated DebugBridge/ package (garrytan#1735).
- Failure table: route drops keep the session, multiple_devices, unwritable
  token file, and the one relaunch a daemon restart still costs.
- Known limits: SwiftUI DragGesture and /swipe on iOS 26 (garrytan#1975), the
  iOS 26.3.1 /elements data from PR garrytan#1755, unverified iPad Stage Manager.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs: iOS QA how-to and skill index cover iPads and route-drop recovery

The how-to still said the boot token was readable from os_log and that a
route drop re-bootstraps; both are now accurate, with iPad selection,
GSTACK_IOS_TARGET_UDID, and three new failure rows.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* v1.91.37.0 fix(ios-qa): iPads work, a route drop no longer relaunches the app, loud boot-token write

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* docs(ios-qa): keep issue numbers out of model-read skill text

The archaeology lint rejects issue references in generated SKILL.md text;
the Known limits entry keeps the iOS version and drops the number.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* chore: re-slot to v1.91.38.0 (v1.91.37.0 claimed by garrytan#3075)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

* test(ios-qa): device-change recovery test without an IPv4-mapped address

The Windows lane could not reach a fake StateServer through
::ffff:127.0.0.1, so the iPad half of the device-change test timed out. The
fake device now swaps identity on its one ::1 listener, which is also closer
to production: every StateServer answers on the same port.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

---------

Co-authored-by: loulanyue <[email protected]>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
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