perf(ios): read keyboard status from one keyboard snapshot
Closes #4641
What
keyboard status on iOS read each keyboard key's label and frame as its own XCTest element query (two resolves per key, about 35 ms each across the keyboard's process boundary). On a 40-key English keyboard that made the runner command take about 1.3 s. The status read now takes one snapshot() of the keyboard element. That snapshot carries the keyboard's visibility, its frame, and every key's and button's wording and frame, so the whole read is one round trip.
The output contract (visible, returnKey, returnKeyLabel) and the return-key rule in RunnerKeyboardStatus are unchanged. The shared return-key lookup that keyboard enter and dismiss use (findKeyboardReturnControl, tapKeyboardDismissControl) is untouched. The diff is keyboardStatus and observedKeyboardKeys in RunnerTests+Keyboard.swift, one unit test, and one comment name in navigation/runtime.ts.
Where the time went
Before, one keyboard status --debug on main, from the request ndjson and the runner log:
| Stage | Before | After |
|---|---|---|
| daemon request total | 1652 ms | 291 ms |
resolve_target_device (explicit --udid, xcrun simctl list) | 328 ms | 256 ms |
runner keyboardStatus command | 1306 ms | 23 ms |
| XCTest queries inside the runner command | exists + frame, 2 bulk allElementsBoundByIndex, then about 80 per-element label / frame resolves | one Find the Keyboard snapshot |
No waitForIdle, settle or repeated tree read was involved. The command already ran with withBoundedInteractionIdleTimeoutIfSupported(.bothSkipped). The cost was only the per-element round trips.
Timings
iPhone 17e simulator, iOS 27.0, warm daemon, keyboard up on the Wallet sign-up email field (explore-example-wallet://auth/sign-up). Wall clock per CLI call including node start, n=8 each, ms. Each run used its own private AGENT_DEVICE_STATE_DIR.
| Call | Main (before), --udid | Branch, --udid | Branch, session only |
|---|---|---|---|
keyboard status median | 1612 (1498-2185) | 476 (430-624) | 232 (227-510) |
snapshot median | 309 (298-551) | 320 (288-408) | 300 (271-421) |
Raw samples, main --udid, status: 1606 1498 1845 1618 1514 2185 1884 1604. Snapshot: 551 378 309 309 304 298 309 530.
Branch --udid, status: 441 580 432 472 624 588 430 480. Snapshot: 302 295 330 310 357 408 376 288.
Branch session only, status: 510 233 240 227 228 230 231 242. Snapshot: 271 282 299 333 421 353 286 302.
The remaining gap to snapshot
With the session alone selecting the device, keyboard status costs about 0.23 s, at or below snapshot. With an explicit --udid on every call (as the T3 device wrapper passes), it is about 0.16 s over snapshot. The cause is outside the status path. resolveCommandDevice treats an explicit device selector as a fresh selection and re-reads the simulator inventory (resolve_target_device, 256 ms, cacheHit:false). snapshot goes through resolveSessionDevice and skips it. That cost applies to every command that resolves its device through resolveCommandDevice, so I left it for its own change and kept this PR on the status read path.
Output identical before and after
keyboard status --json on main and on this branch, for each state:
| State | Output (both) |
|---|---|
| name field | visible: true, returnKey: next, returnKeyLabel: next |
| email field | visible: true, returnKey: next, returnKeyLabel: next |
| password field | visible: true, returnKey: done, returnKeyLabel: done |
keyboard hidden (after keyboard enter on the password field) | visible: false |
Verification
- Device: iPhone 17e simulator, iOS 27.0,
F25C7515-D67E-4838-BEAC-0AD08DB056EC. - Measured source: main
1cb2f242ae(before) and this branch with the same runner change at the head before the unit test and formatting pass was added. The runner was rebuilt withpnpm build:xcuitest:ios. - New unit test:
testObservedKeyboardKeysReadsKeysThenButtonsFromOneKeyboardSnapshot(iOS only, nightly lane). It checks nested descendants, keys before buttons, the whitespace-only space bar kept, and label-less or non-key elements dropped. pnpm check:xctest-selectionpasses locally. Per the worktree rules, CI validates the rest.
š¤ Generated with Claude Code