Skip to content

fix: allow typing empty text on iOS - #65

Merged
cryptotavares merged 1 commit into
mainfrom
cryptotavares/ios-type-empty
Nov 26, 2026
Merged

cryptotavares merged 1 commit into
mainfrom
cryptotavares/ios-type-empty

Conversation

@cryptotavares

@cryptotavares cryptotavares commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #64. Part of the mm CLI v2 effort. Ships in a device-mcp patch release (0.9.1).

Summary: On iOS, mm type <field> "" now succeeds and leaves the field empty. IdbBackend.typeText skips idb ui text for empty text, as the ADB backend already does.

Problem

On iOS, device_type clears the focused field with select-all and Backspace, then always runs idb 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 returns MM_TYPE_FAILED (exit 4). A script that clears a search field cannot tell this expected case from a real failure.

mm type --testid <search field> ""   (device-mcp 0.9.0, iOS)

idb ui key 4 --command --udid <udid>    select all
idb ui key 42 --udid <udid>             backspace
idb ui text  --udid <udid>              exit 1: ('Request was not sent',)
→ {"ok":false,"error":{"code":"MM_TYPE_FAILED", …}}   exit 4
  Field state: empty

Solution

IdbBackend.typeText returns after the clear when text is 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 new
Loading

Yellow boxes are new. The empty-text path returns before idb ui text.

Outcome

Call Before (0.9.0) After
typeText("abc") Select all, backspace, ui text abc No change
typeText("") Select all, backspace, ui text "" → exit 1 Select all, backspace, return
mm type --testid <field> "" (iOS) Field empty, MM_TYPE_FAILED, exit 4 Field empty, success
mm type --testid <field> "" (Android) Field empty, success (since 0.9.0) No change

Decisions for reviewers

Decision Reason
Keep select-all and Backspace for empty text The clear must run before the early return. typeText("") must empty a non-empty field, not only a focused empty one.
Do not change AppiumBackend.typeText Appium uses elementClear then elementSendKeys. It does not run idb ui text, so the reported failure cannot happen there.
Change the device_type description It said that empty text clears the field only on Android. The statement is now true on every backend.
No CHANGELOG.md or version change Release automation generates the changelog. This ships in 0.9.1.

Review guide

# File What to check
1 src/backends/idb-backend.ts The text.length === 0 return in typeText, after the Backspace
2 src/backends/idb-backend.test.ts only clears the field for an empty string checks the two key calls and no ui text
3 src/tools/type-text.ts The device_type description
Testing
  • yarn build exits 0.

  • yarn lint exits 0.

  • yarn test exits 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 === 0 return makes only clears the field for an empty string fail 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, type zz, then type "".

    Step npm 0.9.0 (before) 0.9.0+7b19697e (after)
    mm type --testid <field> "" exit 4, MM_TYPE_FAILED, 2373 ms exit 0, textLength: 0, 1887 ms
    Field after the call (describe-screen textContent) null (empty) null (empty)

    Before (npm 0.9.0):

    $ mm type --testid multichain-account-selector-search-input ""
    exit 4
    {"ok": false, "error": {"code": "MM_TYPE_FAILED", "message": "Operation failed: Command failed: idb ui text  --udid <udid>\nExit code: 1\nstderr: ('Request was not sent',)\n", "retryable": false}}
    

    After (this build):

    $ mm type --testid multichain-account-selector-search-input ""
    exit 0
    {"typed": true, "target": "testId:multichain-account-selector-search-input", "textLength": 0}
    

    get-text on this field returns the placeholder even when text is present, so the field state comes from describe-screen textContent: "zz" with width 260 before the clear, null with width 304 after it. The sheet was closed with back-arrow-button and no account row was tapped.

`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
cryptotavares marked this pull request as ready for review November 26, 2026 15:34
@cryptotavares
cryptotavares requested a review from a team as a code owner November 26, 2026 15:34
@cryptotavares
cryptotavares merged commit ed2cc13 into main Nov 26, 2026
35 checks passed
@cryptotavares
cryptotavares deleted the cryptotavares/ios-type-empty branch November 26, 2026 17:09
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>
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.

iOS: typeText("") clears the field but fails (idb ui text with empty text)

2 participants