Repository navigation
feat: report truncated iOS accessibility trees as snapshot warnings - #59
Merged
Merged
Conversation
When the idb client supports `ui describe-all --format complete`, read the consolidated document instead of `--nested`. Its `elements` is the same nested tree, and it also reports `truncated` when the companion cut the tree at its size bound. A truncated read adds `ax-tree-truncated(backend=<name>,depth=<n>,nodes=<n>)` to the new optional `SnapshotResult.warnings`. An idb client without `--format complete` keeps today's arguments and output. A companion that ignores the format (answers with a flat tree) is read again with the previous format, once, and not asked again.
Match idb's own check: an object with a `backend` key is the complete document, even when `backend` is null or `elements` is missing. Before, such a document was read as a legacy tree, which built a one-element hierarchy from the root and stopped requesting `--format complete`. The warning names the backend only when it is a non-empty string. A JSON root that is neither an array nor an object (for example `null`) is now invalid output, as before this branch, and no longer turns `--format complete` off.
When a snapshot has warnings (for example ax-tree-truncated), the device_snapshot text adds a `Warnings: …` line before the elements, so an agent that uses the device-mcp MCP server sees that the tree is incomplete. Without warnings the output is unchanged.
cryptotavares
marked this pull request as ready for review
November 17, 2026 14:31
pnarayanaswamy
approved these changes
Nov 19, 2026
This was referenced Dec 3, 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>
cryptotavares
added a commit
to MetaMask/client-mcp-core
that referenced
this pull request
Dec 4, 2026
Part of the mm CLI v2 effort (P1-38, core part). The device-mcp part is [device-mcp#59](MetaMask/device-mcp#59), released in device-mcp 0.9.0. > **Summary:** A truncated iOS accessibility tree now shows up as a top-level `warnings` array in `describe_screen`, `accessibility_snapshot` and observations. Each warning says what to do. Output without warnings does not change. ## Problem The idb accessibility read stops at a size bound. On the 2026-10-28 run, iOS wallet home was 51 levels deep, so some visible controls were not in the tree. device-mcp reports this as `SnapshotResult.warnings`, but core reads only `hierarchy` and drops it. The agent sees a tree with no sign that it is incomplete, and concludes that the element is not on screen. ```text device-mcp snapshot: { hierarchy: [...], warnings: ["ax-tree-truncated(backend=axbridge-exclusive,depth=51,nodes=166)"] } mm describe-screen: { "state": ..., "testIds": ..., "a11y": ..., "screenshot": null } <- no warning ``` ## Solution The mobile driver keeps the snapshot warnings and adds advice for the codes it knows. The tools and the observation copy them to the top level of their output. ```mermaid flowchart TD A["backend.snapshot()"] --> B{"SnapshotResult.warnings<br/>non-empty?"} B -->|no| C["tree and testIds as before<br/>(no warnings key)"] B -->|yes| D["withAdvice: add what to do<br/>for a known code"] D --> E["AccessibilityTree.warnings /<br/>ScreenCapture.warnings"] E --> F["describe_screen and<br/>accessibility_snapshot: result.warnings"] E --> G["observation.warnings<br/>(kept in diff observations)"] classDef new fill:#fff3cd,stroke:#d39e00 class B,D,E,F,G new ``` Yellow boxes are new. ## What the agent sees `mm describe-screen` on a truncated iOS tree (message from `WARNING_ADVICE`, details from device-mcp): ```text {"warnings":["ax-tree-truncated(backend=axbridge-exclusive,depth=51,nodes=166): the tree hit the device read limit, so elements on screen can be missing from a11y and testIds. See them with `mm screenshot`; tap one with `mm tap-coordinates <x> <y>` (same units as `bounds`)."],"state":{...},"testIds":{...},"a11y":{...},"screenshot":null} ``` | Condition | Result | |---|---| | Snapshot has no `warnings`, or an empty array | No `warnings` key anywhere. Output is unchanged. | | `ax-tree-truncated(...)` | `warnings: ["ax-tree-truncated(...): the tree hit the device read limit, …"]` | | `ax-tree-fallback(...)` ([device-mcp#67](MetaMask/device-mcp#67), not released) | `warnings: ["ax-tree-fallback(...): the full read failed, …"]`: confirm the screen with a control that is present, tap a missing element by coordinates | | An unknown code | `warnings: ["<code>(...)"]`, passed through without advice | | `click` (or any call) with an observation | `observations.warnings`, also in a `diff` observation | | Browser | No change. Playwright has no `warnings` source. | ## Decisions for reviewers | Decision | Reason | |---|---| | No depth/node-count heuristic in core | The ticket asks for one only "until device-mcp ships it". Core depends on device-mcp `^0.10.0`, which reports the truncation from idb's own `truncated` flag. | | Advice: `mm screenshot` and `mm tap-coordinates` | These work today. `--root` (P1-39) is not on mobile. `--testid`, refs and `scroll-to-element` search the same snapshot as the tree, so they do not find an element that is missing from it. | | Warning first, then advice, in one string | The device-mcp code stays a stable prefix to match on. One `string[]` keeps the shape of `SnapshotResult.warnings`. | | `warnings` placed first in the output | An agent reads it before the tree. The browser has no warning field to reuse. | | Advice map keyed by code; unknown codes pass through | A new device-mcp code still reaches the agent without a core change. | ## Review guide Read the files in this order: | # | File | What to check | |---|---|---| | 1 | `src/platform/types.ts` | New `AccessibilityTree` type; `ScreenCapture` extends it. | | 2 | `src/platform/mobile-platform-driver.ts` | `#snapshotApp` keeps `warnings`; `WARNING_ADVICE` and `withAdvice`. | | 3 | `src/tools/discovery-tools.ts` | `describe_screen` and `accessibility_snapshot` add `warnings` only when present. | | 4 | `src/server/create-server.ts`, `observation-compaction.ts` | `snapshotMobile`, `collectObservation` and `diffObservation` carry `warnings`. | | 5 | `*.test.ts` | Driver, tools and HTTP tests (see Testing). | | 6 | `SKILL.md`, `README.md` | The warning and what to do about it. | <details> <summary>Testing</summary> - `yarn build`, `yarn lint` and `CI=1 yarn test` pass (76 files, 2975 tests). Coverage: statements 98.13, branches 95.54, functions 97.53, lines 98.23 (floors 97 / 94 / 96 / 97). - `mobile-platform-driver.test.ts`: the exact messages for `ax-tree-truncated` and `ax-tree-fallback`; advice on each warning when both are present; an unknown code passes through; no `warnings` key for an absent or empty array (`captureScreen` and `getAccessibilityTree`). - `discovery-tools.test.ts`: both tools return the driver warnings, and no key without them. - `create-server.test.ts` (real `MobilePlatformDriver`, fake backend): the warning reaches `describe_screen`, `accessibility_snapshot` and a `click` observation, also a `diff` observation. No `warnings` text in any of the three bodies without warnings. - Live, iOS sim (iPhone 17 Pro, dev client, Metro 8085, this branch via yalc, consumer device-mcp 0.10.0): | Screen | Result | |---|---| | Login | `describe-screen` and `accessibility-snapshot`: no `warnings` key. idb read: depth 34, 67 nodes, `truncated: false`. | | Wallet home | No `warnings` key. The full `axbridge` read fails ("did not respond to an accessibility request"), and device-mcp 0.10.0 falls back to the flat `ax` read (depth 2, 45 nodes) without a warning. | On the current app build, wallet home is 64 levels deep. iOS rejects the full read beyond about 62 levels, so device-mcp falls back to the flat read. [device-mcp#67](MetaMask/device-mcp#67) adds the `ax-tree-fallback` warning for that case. The truncation warning is covered by the unit and HTTP tests above, not by a live read. </details> <details> <summary>Docs changed</summary> - `SKILL.md`: the `warnings` array, an example, and what to do (screenshot, then `tap-coordinates`). - `README.md`: the response shape, the observation fields, and where device warnings appear. </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.
Part of the mm CLI v2 effort (ticket
P1-38, device-mcp part). Ships in device-mcp 0.9.0.Problem
The idb companion stops reading the accessibility tree at a size bound. MetaMask Mobile wallet home already reaches it (depth 51). device-mcp asks for
--nested, and that format does not report the cut. So the hierarchy silently misses elements, and the agent cannot find visible controls.Solution
When the installed idb client lists
completeunder--format, snapshots request--format completeinstead of--nested. That document has the same nested tree plustruncatedandbackend. A cut read adds a warning to the new optionalSnapshotResult.warnings.flowchart TD A[snapshot] --> B{"idb help lists --format complete?"} B -->|no| L["--nested, as in 0.8.0"] B -->|yes| C["--format complete"] C --> D{"answer is a complete document?"} D -->|"no: flat tree"| F["read again with --nested, stop requesting complete"] D -->|yes| E{"truncated?"} E -->|yes| W["warnings: ax-tree-truncated(…)"] E -->|no| N[no warnings field] classDef new fill:#fff3cd,stroke:#d39e00 class B,C,D,F,E,W newYellow boxes are new.
What changes
--format completewarningskey.warnings: ["ax-tree-truncated(backend=<name>,depth=<n>,nodes=<n>)"]completewith a flat tree--nested. This backend does not requestcompleteagain.device_snapshotMCP tool, with warningsWarnings: …line before the elementsDecisions for reviewers
ax-tree-truncated(backend=…,depth=…,nodes=…)instead of the ticket'sax-tree-truncated(depth>=50)completedocument does not report its limits. The warning gives what came back. The format is documented on the type and stays stable for core.axmergebackendkey is a complete document_warn_if_complete_downgraded. An odd document then does not switchcompleteoff for the session.SnapshotResult.rawis the complete document on clients withcompleterawhas no documented format. The only user in this repo (scroll.ts) compares it for equality only.Review guide
Read the files in this order:
src/utils/platform.tsidbSupportsCompleteDescribe: the help-text probesrc/backends/idb-backend.ts#describeAllArgs,#describeAllOnce(the flat-answer fallback),parseIdbDescribeAll,truncationWarningsrc/backends/types.tsSnapshotResult.warningsand its formatsrc/tools/snapshot.tsWarnings:lineaxfallbackTesting
yarn build,yarn lintandyarn testpass (36 files, 852 tests, 6 skipped). Coverage thresholds are unchanged.IdbBackend.snapshot()called directly. Before = npm 0.8.0, after = this branch. Run on the first commit; later commits change only edge-case parsing, the MCP tool text and docs.truncated/warningsfalse/ none (depth 34, 67 nodes)truncated/warningstrue/ warning on 20 of 20 readssnapshot()p50, 20 runsrawsizemm describe-screenon login (core 0.14.0)