feat(ios): expose AX custom actions on merged accessibility elements
The problem
SWM AppControlBench evidence: Bluesky's feed cards collapse into ONE accessibility element (feedItem-by-whiskers.test). The ellipsis/options button, reply button and inline hashtag links are not children in our snapshot, so models fall into coordinate-guessing loops — tap hits the image, media viewer opens, back, retry — and four tasks burned 330–720s each. A competing tool surfaced the options control on the same screen and finished in 3 calls / 19s.
The affordances are not missing, they are just not children. Apps that merge a card for VoiceOver publish its sub-actions as UIAccessibilityCustomActions — which is exactly what React Native's accessibilityActions prop compiles to. Bluesky's post-DETAIL screen exposes "Open post options menu" as a real labeled button; the feed card merges it away.
What ships
snapshot --actions names the actions a merged element hides:
@e8 [link] "feedItem-by-whiskers.test" actions: ["Reply", "Repost", "Open post options menu"]
Names only, one line, no extra nesting. An agent that reads this stops guessing that the card is a single opaque tap target.
Phase 1 — feasibility findings
Probed live inside the runner process against XCUIDevice.accessibilityInterface (XCAXClient_iOS) on iOS 26.2 / Xcode 26.2.
Reading: feasible. The AX server does expose them. XCTAutomationSupport declares XC_kAXXCAttributeCustomActions, and -[XCAXClient_iOS attributesForElement:attributes:error:] returns, per merged element, an array of dictionaries:
CustomActionIdentifier = "Name:Reply\nTarget:0x0\nSelector:(null)";
CustomActionName = Reply;
CustomActionActivationPoint = { X = 0; Y = 0; };
CustomActionSortPriority = 0;
CustomActionActivationPoint is (0,0) for actions created the ordinary way, so there is no position to expose — the names are the actionable part.
Reading in bulk: NOT feasible. Adding the attribute to the bulk requestSnapshotForElement:attributes:parameters:error: request does not merely slow it down, it breaks the reply:
BULK pass=0 (without) ok=1 ms=111
BULK pass=1 (with) ok=0 ms=65068 err=Timed out while fetching snapshot from testmanagerd..
[xpc.exceptions] Exception caught during decoding of reply to message
'_XCT_fetchSnapshotForElement:attributes:parameters:reply:', dropping incoming message
Exception: value for key 'NS.objects' was of unexpected class 'NSArray'
Allowed classes are: NSValue, NSDictionary, NSNumber, NSString
XCTest's reply decoder has an NSSecureCoding allowlist without NSArray, so a reply carrying custom actions is dropped and the request times out. This is why the implementation reads one element at a time (~100ms each, a different XPC message that decodes fine) rather than asking for the attribute in the tree request.
Invocation: NOT feasible from the runner. Five distinct routes, all closed:
| Route | Result |
|---|---|
XCUIElement public/private API | no custom-action method exists |
-[XCAXClient_iOS performAction:onElement:value:error:] | wants an XCUIAccessibilityAction (initWithAXAction: + actionNumber); every AX action number swept returned kAXErrorCannotComplete, with the action dict, its identifier string, and its name as value: |
-[XCAXClient_iOS setAttribute:value:element:outError:] on the custom-actions attribute | returns success for every value shape and does nothing (status label unchanged) |
-[XCAXClient_iOS parameterizedAttribute:forElement:parameter:error:] | kAXErrorNoValue ("copying parameterized attribute 2036") |
raw AXUIElementPerformAction / AXUIElementSetAttributeValue | reachable via dlsym, but unusable: a snapshot's XCAccessibilityElement is token-based and answers nil for AXUIElement, and an element rebuilt with _AXUIElementCreateWithPIDAndID(pid, elementID) answers kAXErrorInvalidUIElement (-25202) |
So this PR ships the read half. RunnerAXSnapshotBridge.h records the table above next to the code so the next person does not re-derive it. If invocation becomes possible, press @ref --action "<name>" is the natural follow-up and the names shipped here are already the matching key.
Fixture used. A 120-line UIKit app compiled with swiftc and installed with simctl (dev.agentdevice.axfixture): two cards that set isAccessibilityElement = true on a container holding real Reply/Repost/••• buttons, each card carrying three UIAccessibilityCustomActions, plus a status label that records the last invoked action. This is the same shape RN emits, it is deterministic, and it needs no Metro. The repo has no iOS fixture app with custom actions (the only Xcode project is the runner's own host app), and stock apps do not give a controllable oracle.
Before / after (live, iOS 26.2 simulator, repo CLI)
Same app, same screen, one session.
$ node bin/agent-device.mjs snapshot -i
Snapshot: 6 nodes
@e1 [application] "AXFixture"
@e2 [window]
@e3 [other] "last action: none"
@e4 [link] "feedItem-by-whiskers.test"
@e5 [link] "feedItem-by-otter.test"
@e6 [button] "Plain button"
The merged card is a dead end — three real controls inside it, none reachable.
$ node bin/agent-device.mjs snapshot -i --actions
Snapshot: 10 nodes (truncated)
@e1 [application] "AXFixture"
@e2 [window]
@e3 [other]
@e4 [other]
@e5 [other]
@e6 [other]
@e7 [text] "last action: none"
@e8 [link] "feedItem-by-whiskers.test" actions: ["Reply", "Repost", "Open post options menu"]
@e9 [link] "feedItem-by-otter.test" actions: ["Reply", "Repost", "Open post options menu"]
@e10 [button] "Plain button"
Verdict on that capture, showing the pin does not read as a degradation:
{"state":"recovered","backend":"private-ax",
"reason":"the private AX backend was selected because this capture asked for accessibility custom actions",
"reasonCode":"requested-backend"}
Runner log for the same capture — the bound is real and the read set is small:
AGENT_DEVICE_RUNNER_PRIVATE_AX_CUSTOM_ACTIONS reads=4 annotated=2 candidates=4
Cost, same screen, back to back: snapshot -i 0.24s / 0.66s, snapshot -i --actions 0.91s / 0.91s. The node-count and shape difference between the two outputs is the backend difference (private-AX presents the tree differently from the XCTest tree backend), not the actions read.
Disclosing a capped pass
The read budget (12 elements) is smaller than a long feed's card count, and an element the pass never reached renders byte-identically to one with no custom actions. Silence there would teach a reader that the rest of the feed has no affordances — precisely the mis-inference this feature exists to prevent. So the runner carries read/candidates into the quality verdict and the response renders one line when the pass was incomplete:
$ node bin/agent-device.mjs snapshot -i --actions # 16-card scrollable fixture
Snapshot: 13 nodes (truncated)
Custom actions were read for 12 of 18 merged elements, on-screen ones first; the remaining 6 were
not read, so an absent actions list on those is not evidence that they have none. Scroll them into
view and re-run to read them.
@e8 [link] "feedItem-by-whiskers.test" actions: ["Reply", "Repost", "Open post options menu"]
...
AGENT_DEVICE_RUNNER_PRIVATE_AX_CUSTOM_ACTIONS reads=12 annotated=11 candidates=18 onScreen=7
Response level, one line, no per-node bytes. A complete pass says nothing (read >= candidates), and "the capture never asked" stays distinguishable from "read none of them" — the bridge omits the key entirely rather than reporting (0, 0), which would otherwise warn on every default capture.
The scoped-re-run remedy does not work — measured, so it is not shipped
The obvious remedy for a capped pass is "re-run scoped". It does nothing: --scope is applied when the Swift walk builds nodes, long after the bridge's read pass, so it cannot redirect the budget. Measured on the 16-card fixture:
$ snapshot -i --actions → reads=12 candidates=18
$ snapshot -i --actions -s "feedItem-by-user9.test" → reads=12 candidates=18 (unchanged)
Making --scope narrow the read set would mean duplicating the scope predicate inside the ObjC bridge (scope inclusion is ancestry-dependent, decided during the Swift walk), which is exactly the kind of second, drifting implementation this repo keeps out.
Instead the read pass now orders candidates on-screen first. That does two things: the budget lands on the elements an agent can actually act on, and the disclosed remedy becomes true — scrolling changes the on-screen set, so a re-run reads elements the previous pass could not. Verified end to end on a scrollable fixture:
# top of feed: user12-14 are off-screen and unread
$ agent-device scroll down ; agent-device scroll down
$ agent-device snapshot -i --actions
@e11 [link] "feedItem-by-user12.test" actions: ["Reply", "Repost", "Open post options menu"]
@e12 [link] "feedItem-by-user13.test" actions: ["Reply", "Repost", "Open post options menu"]
@e13 [link] "feedItem-by-user14.test" actions: ["Reply", "Repost", "Open post options menu"]
An empty root frame (no viewport to judge against) treats every candidate as on-screen, so ordering degrades to document order rather than to "nothing is on screen".
Telling the reader what the names are for
Invocation is impossible, so a model that sees actions: ["Reply", …] will plausibly invent press @e8 --action "Reply" — the exact shape this PR deliberately does not ship. Both places a model reads now say so:
--actionsflag help: "name the affordances merged inside an element (iOS sim); not directly invokable — reach them via the detail screen, labeled children, or coordinates"- the MCP/SDK field description spells out the same three routes and says the names are for planning, not invocation.
Follow-up, not in this PR: one sentence belongs in the compact workflow help card's snapshot section, but that card is being rewritten by the in-flight help-diet PR #1663 (still open, not in this base — cli-help.ts line ~376 sits inside the workflow topic it rewrites). Touching it here would collide. Once #1663 lands, add: "Merged element (one node where the UI shows several controls): snapshot --actions names the affordances it hides — planning only, nothing invokes them." — into the card if it fits the <9000-byte budget, otherwise into help debugging.
Refusals: the request either gets actions or an error
A requested capability that silently returns nothing is worse than an error, because a node with no actions is indistinguishable from an element that genuinely has none. Every unserviceable combination fails closed:
| Request | Answer |
|---|---|
snapshot --actions --raw | INVALID_ARGS — raw does not use the private-AX path. Rejected at the shared request seam, so CLI, Node client and MCP answer alike before any device work |
diff --actions | INVALID_ARGS — snapshotCustomActions is deliberately not in the shared SNAPSHOT_FLAGS group |
--actions on android / macOS / linux / web / iOS physical device | UNSUPPORTED_OPERATION naming the resolved target. Checked before the session precondition, since it is pure flags+device — otherwise an iOS physical device costs a round trip ("run open first") before learning the flag is unserviceable there at all |
$ agent-device snapshot --actions --raw
Error (INVALID_ARGS): --actions and --raw are mutually exclusive: custom actions are only
readable through the private-AX snapshot path, which a raw capture does not use.
$ agent-device diff snapshot --actions
Error (INVALID_ARGS): Flag --actions is not supported for command diff.
Bounds, all three disclosed
The pass is bounded on four axes, and each bound reports itself through snapshotQuality.customActions {read, candidates, truncated, blocked}:
- 12 elements per capture, on-screen first, stopping at the capture deadline;
- 1s per element read — the AX call is a synchronous XPC round trip with no timeout of its own, so it runs off-thread behind a bounded wait. attempts is what the budget buys, reads is what completed, so a timed-out element stays in the undisclosed remainder rather than being reported as "read, and it has no actions";
- one read in flight at a time — the AX call is a synchronous XPC round trip that cannot be cancelled, so the deadline frees only the caller while the call keeps running. All reads share one serial queue, and while an abandoned read is outstanding the pass is skipped outright (
blocked) rather than queueing behind it, so a repeated capture adds no work.blockedgets its own disclosure line, deliberately not folded into the partial-pass line, because scrolling cannot clear a hang. Reads resume on their own once the hung call returns; - 8 names × 80 characters per element — the names are app-authored, so their count and length are the app's choice, and a long generated list is a plausible accident as well as a hostile case. Clipped elements are counted and disclosed on their own line, because a clipped list looks exactly as complete as a full one.
Live, against a fixture card publishing 12 actions including a 500-character name and a name containing a quote and a newline:
1 element(s) published more custom actions than are shown; those lists are clipped to the
first 8 names, and long names are shortened.
@e9 [link] "feedItem-by-whiskers.test" actions: ["long-long-…-long-…", "Say \"hi\" now", "Extra 3", … "Extra 8"]
AGENT_DEVICE_RUNNER_PRIVATE_AX_CUSTOM_ACTIONS reads=12 attempts=12 annotated=11 candidates=18 onScreen=7 truncated=1
Names get the same escaping as text previews plus control-character folding — visible above, Say "hi"\nnow renders as "Say \"hi\" now": quote escaped, newline folded, still exactly one line.
Actions count as identity
Three enumerations decide "same node", and all three now read actions:
snapshotNodeToComparableLine— the rendered line already carried actions while the diff key did not, so an action-only change diffed asunchangedwith silently different text;buildComparableSnapshotPresentation— the unchanged-comparison projection;buildSnapshotPresentationKey— the sharpest one:snapshotthensnapshot --actionson a still screen produced an identical presentation key, answeredunchanged, and never delivered the actions that were explicitly asked for.
Design notes
- Opt-in and bounded on three axes, every bound disclosed — see above. Default captures pay nothing:
customActionLimit: 0skips candidate collection entirely, the same waydeepExtensionCallLimit: 0already does. - Candidate rule. Labelled childless nodes only. That is the shape a merged card takes (container marked accessible, real controls invisible); unlabelled leaves are decoration and are not worth a round trip. Nodes that deep extension filled in since serialization are skipped — a node with real children is not merged.
- Backend pin.
--actionsimpliespreferredBackend: private-ax, because no other backend can read the attribute; returning a capture that structurally cannot carry actions would be a silent no-op. An explicit pin is never overwritten. - New
requested-backendreason code. The pin reuses the existing deferred-plan machinery, which reportsdeferred— "after recent slow accessibility work on this screen". For a user-requested pin nothing was slow, and the daemon's one-shot latch re-rendered that as a degradation warning on the first--actionscapture of a session. A request-pinned capture now reports its own cause, and bothrenderSnapshotQualityWarningsand the latch treat it as the non-event it is.
Scope / deferred
- Invocation (
press @ref --action) — infeasible today, evidence above. No interaction dispatch path was added, so ADR 0011's matrix is untouched. - Error/hint integration — a failed press inside a merged element does not yet mention available actions. It needs the runner to re-resolve one element from a ref on the failure path; worth doing as a follow-up now that the read primitive exists (
customActionNamesForElement:axClient:is the seam). - Non-simulator and non-private-AX backends — physical iOS devices have no private-AX backend, so
--actionsyields nothing there. diffdoes not take--actions; per-element reads on both sides of a comparison are not worth the cost.
Validation
- Runner XCTest unit lane (isolated derived path, own simulator):
testCustomActionsRequestPinsPrivateAXBackend,testPrivateAXNodesCarryAnnotatedCustomActions,testRequestPinnedBackendReportsItsOwnReason,testCustomActionCoverageParsesOnlyCompletePairs,testPartialCustomActionPassIsDisclosedAndCompleteOneIsNotpass, plus the pre-existing private-AX/deep-extension regressions (testDeepExtensionCountsMissedFrontiers,testPreferredPrivateAXBackendPlansAsPenalized,testPrivateAXDepthLimitedRequiresEveryFrontierResolved,testPrivateAXInteractiveFiltersLoginLikeHiddenDrawer) — 7/7. - New
src/snapshot/__tests__/snapshot-quality-custom-actions.test.ts(5 tests) covers the capped/complete/never-asked cases, half-a-pair parsing, and that the line is independent of degradation state. Newsrc/utils/__tests__/snapshot-lines-custom-actions.test.ts(4 tests) pins the rendered shape, ordering against bracketed metadata, the empty/whitespace cases, and hidden groups. src/commands/capture/runtime/snapshot.test.tsforwarding assertion extended to prove the flag reaches the backend;src/commands/capture/index.test.tsextended for the CLI reader.pnpm test:unitfully green: 633 files / 5617 tests. Three new TS test files cover the raw-pairing guard, the platform guard across six non-simulator targets, and action-aware identity/diff/presentation-key.pnpm typecheck,pnpm lint,pnpm check:layering,pnpm check:fallow,pnpm check:production-exports,pnpm check:command-docs,oxfmt --check .all clean. NoSessionStatefield added.- CI's public-CLI-flag completeness gate (
integration-progress-model.ts, the one ADR 0011 cites for catching the unclassified--verifyon #1064) flaggedsnapshotCustomActions. It is classified in its own bucket rather than the provider-scenario table: the values come from the private AX client inside the runner process, and the fake runner derives its behavior from fixture tables that cannot fabricate custom actions, so there is no provider-backed scenario to claim. The owning coverage is named instead. - Live validation ran on a purpose-created simulator with an isolated state dir; the simulator, its runner, the daemon and both derived-data trees were removed afterwards.