Repository navigation
fix: allow typing empty text on iOS - #65
Merged
Merged
Conversation
`IdbBackend.typeText` always ran `idb ui text <text>`. With an empty string idb exits 1 with "Request was not sent", so `mm type <field> ""` cleared the field but failed with MM_TYPE_FAILED. Skip the `ui text` step when the text is empty, after the select-all and Backspace clear, matching the ADB backend. The `device_type` description now says an empty string only clears the field on all backends. Fixes #64. Part of the mm CLI v2 effort. Ships in device-mcp 0.9.1.
cryptotavares
marked this pull request as ready for review
November 26, 2026 15:34
pnarayanaswamy
approved these changes
Nov 26, 2026
This was referenced Nov 27, 2026
cryptotavares
added a commit
that referenced
this pull request
Dec 4, 2026
Part of the mm CLI v2 effort (ticket P1-53).
> **Summary:** When the preferred iOS accessibility backend fails,
`IdbBackend.snapshot()` now adds an `ax-tree-fallback` warning with the
backend that served the read and the reason. An agent can tell a partial
fallback read from a complete one.
## Problem
`idb ui describe-all --api axbridge` reads the tree as one XCTest
snapshot. iOS rejects that snapshot when the tree is deeper than its
limit (about 62 levels), and idb reports "did not respond to an
accessibility request". The MetaMask Mobile wallet home reaches 64
levels, so the preferred read fails.
`IdbBackend.#describeAll` then tries the other `--api` and serves `ax`.
`ax` returns a flat tree. On the wallet home that is depth 2, 45 nodes
and 35 of the 97 test IDs. `snapshot()` returns it without a warning, so
an agent cannot tell this tree from a full read.
```text
idb ui describe-all --api axbridge → exit 1: did not respond to an accessibility request
IdbBackend.#describeAll → try the other --api
idb ui describe-all --api ax → flat tree: depth 2, 45 nodes
IdbBackend.snapshot() → hierarchy and no warnings
```
A recorded live investigation on an iOS 27 simulator confirmed the
cause: at depth 64, single-fetch fails at every depth limit while the
per-node walk of the same screen succeeds. Login (34 levels) and the
hamburger menu (49) read with `axbridge` in the same session.
## Solution
`#describeAll` reports the preferred backend's error when a later
backend serves the read. `snapshot()` compares the serving backend with
`apis[0]`, the version preference, and adds:
```text
ax-tree-fallback(from=<preferred>,to=<used>,reason=<not-responding|error>)
```
`reason` is `not-responding` when the preferred error contains "did not
respond to an accessibility request", otherwise `error`.
```mermaid
flowchart TD
A[snapshot] --> B["#describeAll: try apis[0]"]
B -->|ok| N[no fallback warning]
B -->|fails| C[try the other --api]
C -->|fails| X[Reject: every backend failed]
C -->|ok| D{"preferred error has<br/>'did not respond...'?"}
D -->|yes| E["ax-tree-fallback(...,reason=not-responding)"]
D -->|no| F["ax-tree-fallback(...,reason=error)"]
E --> G{"served read truncated?"}
F --> G
G -->|yes| H["also ax-tree-truncated(...)"]
G -->|no| I[only the fallback warning]
classDef new fill:#fff3cd,stroke:#d39e00
classDef stop fill:#f8d7da,stroke:#c82333
class D,E,F,G,H new
class X stop
```
Yellow boxes are new. Red boxes stop the snapshot.
## What changes
| Condition | Result |
|---|---|
| idb client without `--api` (single `null` attempt) | No fallback
warning |
| Preferred backend serves the read, with or without the `ax` supplement
| No fallback warning |
| Preferred fails with "did not respond to an accessibility request" |
`ax-tree-fallback(...,reason=not-responding)` |
| Preferred fails with another error |
`ax-tree-fallback(...,reason=error)` |
| `ax` is preferred and `axbridge` serves the read |
`ax-tree-fallback(from=ax,to=axbridge,reason=error)` |
| Fallback read is also truncated | Both warnings, fallback first |
| Every backend fails | Snapshot rejects, as today |
| `device_snapshot` | Prints the warning on the existing `Warnings:`
line; no tool change |
Core PR #141 passes `SnapshotResult.warnings` on to agents. This PR
needs no core change.
## Decisions for reviewers
| Decision | Reason |
|---|---|
| Warn only when the serving backend is not `apis[0]` | `snapshot()` can
read `ax` in parallel with `axbridge` and merge missing identified
elements into the `axbridge` tree. A successful merge is not a fallback.
|
| Compare with `apis[0]` instead of a fixed `axbridge` preference |
`chooseAxApi` prefers `ax` before iOS 18 and `axbridge` from iOS 18. The
warning names the actual `--api` pair. |
| No warning for the `null` attempt | An idb client without `--api` has
no alternative backend, so nothing fell back. |
| `reason` comes from the error text | idb maps the guest's snapshot
rejection to "did not respond to an accessibility request". Other
failures get `error`. |
| No `CHANGELOG.md` entry | Release automation generates the changelog,
as for #59 and #65. |
## Review guide
Read the files in this order:
| # | File | What to check |
|---|---|---|
| 1 | `src/backends/idb-backend.ts` | `fallbackWarning`, and the `api
!== apis[0]` check in `snapshot()`; `preferredError` in `#describeAll` |
| 2 | `src/backends/types.ts` | The `ax-tree-fallback` format on
`SnapshotResult.warnings` |
| 3 | `src/backends/idb-backend.test.ts` | The fallback conditions in
the table above |
| 4 | `README.md`, `src/tools/snapshot.test.ts` | The documented meaning
and the `Warnings:` line |
<details>
<summary>Testing</summary>
- `yarn build` exits 0.
- `yarn lint` exits 0.
- `yarn test` exits 0: 38 files, 986 passed, 6 skipped.
- Coverage does not drop. Compared with `origin/main`: statements 82.97%
→ 83.02%, branches 80.31% → 80.39%, functions 77.97% → 78.00%, lines
83.24% → 83.29%.
- Tests cover: `reason=not-responding`, `reason=error`, the `ax` →
`axbridge` order, no warning for an `axbridge` read with the `ax` merge,
both warnings when the fallback read is truncated, and the existing
rejection when every backend fails.
- No live iOS run: the simulator was in use by other agents. The tests
use the error text and the flat-tree shape from the recorded
investigation.
</details>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #64. Part of the mm CLI v2 effort. Ships in a device-mcp patch release (0.9.1).
Problem
On iOS,
device_typeclears the focused field with select-all and Backspace, then always runsidb ui text <text>.idb ui text ""exits 1 with "Request was not sent". The clear has already run, so the field is empty, but the call returnsMM_TYPE_FAILED(exit 4). A script that clears a search field cannot tell this expected case from a real failure.Solution
IdbBackend.typeTextreturns after the clear whentextis empty. Non-empty text takes the same path as before.flowchart TD A["typeText(text)"] --> B["ui key 4 --command (select all)"] B --> C["ui key 42 (backspace)"] C --> D{"text.length === 0?"} D -->|yes| E["return. Field is empty."] D -->|no| F["ui text text"] F --> G["return. Field has text."] classDef new fill:#fff3cd,stroke:#d39e00 class D,E newYellow boxes are new. The empty-text path returns before
idb ui text.Outcome
typeText("abc")ui text abctypeText("")ui text ""→ exit 1mm type --testid <field> ""(iOS)MM_TYPE_FAILED, exit 4mm type --testid <field> ""(Android)Decisions for reviewers
typeText("")must empty a non-empty field, not only a focused empty one.AppiumBackend.typeTextelementClearthenelementSendKeys. It does not runidb ui text, so the reported failure cannot happen there.device_typedescriptionCHANGELOG.mdor version changeReview guide
src/backends/idb-backend.tstext.length === 0return intypeText, after the Backspacesrc/backends/idb-backend.test.tsonly clears the field for an empty stringchecks the two key calls and noui textsrc/tools/type-text.tsdevice_typedescriptionTesting
yarn buildexits 0.yarn lintexits 0.yarn testexits 0: 38 files, 982 passed, 6 skipped. Coverage thresholds pass (statements 82.97%, branches 80.31%, functions 77.97%, lines 83.24%).Mutation check: removing the
text.length === 0return makesonly clears the field for an empty stringfail on an unexpected third call,ui text "".CI on this PR passes (run 45819115544).
Live proof on the iOS simulator, account list search field (
multichain-account-selector-search-input). Each run: launch, unlock once, open the account list sheet, typezz, then type"".mm type --testid <field> ""MM_TYPE_FAILED, 2373 mstextLength: 0, 1887 msdescribe-screentextContent)null(empty)null(empty)Before (npm 0.9.0):
After (this build):
get-texton this field returns the placeholder even when text is present, so the field state comes fromdescribe-screentextContent:"zz"with width 260 before the clear,nullwith width 304 after it. The sheet was closed withback-arrow-buttonand no account row was tapped.