Repository navigation
feat: warn when an iOS snapshot falls back from axbridge - #67
Merged
Merged
Conversation
pnarayanaswamy
approved these changes
Dec 4, 2026
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-53).
Problem
idb ui describe-all --api axbridgereads 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.#describeAllthen tries the other--apiand servesax.axreturns 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.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
axbridgein the same session.Solution
#describeAllreports the preferred backend's error when a later backend serves the read.snapshot()compares the serving backend withapis[0], the version preference, and adds:reasonisnot-respondingwhen the preferred error contains "did not respond to an accessibility request", otherwiseerror.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 stopYellow boxes are new. Red boxes stop the snapshot.
What changes
--api(singlenullattempt)axsupplementax-tree-fallback(...,reason=not-responding)ax-tree-fallback(...,reason=error)axis preferred andaxbridgeserves the readax-tree-fallback(from=ax,to=axbridge,reason=error)device_snapshotWarnings:line; no tool changeCore PR #141 passes
SnapshotResult.warningson to agents. This PR needs no core change.Decisions for reviewers
apis[0]snapshot()can readaxin parallel withaxbridgeand merge missing identified elements into theaxbridgetree. A successful merge is not a fallback.apis[0]instead of a fixedaxbridgepreferencechooseAxApiprefersaxbefore iOS 18 andaxbridgefrom iOS 18. The warning names the actual--apipair.nullattempt--apihas no alternative backend, so nothing fell back.reasoncomes from the error texterror.CHANGELOG.mdentryReview guide
Read the files in this order:
src/backends/idb-backend.tsfallbackWarning, and theapi !== apis[0]check insnapshot();preferredErrorin#describeAllsrc/backends/types.tsax-tree-fallbackformat onSnapshotResult.warningssrc/backends/idb-backend.test.tsREADME.md,src/tools/snapshot.test.tsWarnings:lineTesting
yarn buildexits 0.yarn lintexits 0.yarn testexits 0: 38 files, 986 passed, 6 skipped.origin/main: statements 82.97% → 83.02%, branches 80.31% → 80.39%, functions 77.97% → 78.00%, lines 83.24% → 83.29%.reason=not-responding,reason=error, theax→axbridgeorder, no warning for anaxbridgeread with theaxmerge, both warnings when the fallback read is truncated, and the existing rejection when every backend fails.