Skip to content

feat: report truncated mobile trees as warnings - #141

Merged
cryptotavares merged 3 commits into
mainfrom
cryptotavares/p1-38-truncation-warnings
Dec 4, 2026
Merged

cryptotavares merged 3 commits into
mainfrom
cryptotavares/p1-38-truncation-warnings

Conversation

@cryptotavares

@cryptotavares cryptotavares commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

Part of the mm CLI v2 effort (P1-38, core part). The device-mcp part is 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.

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.

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
Loading

Yellow boxes are new.

What the agent sees

mm describe-screen on a truncated iOS tree (message from WARNING_ADVICE, details from device-mcp):

{"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, 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.
Testing
  • 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 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.

Docs changed
  • 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.

@cryptotavares
cryptotavares requested a review from a team as a code owner December 3, 2026 11:14
@cryptotavares
cryptotavares merged commit 7f83d07 into main Dec 4, 2026
27 checks passed
@cryptotavares
cryptotavares deleted the cryptotavares/p1-38-truncation-warnings branch December 4, 2026 14:37
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.

2 participants