fix(interaction): a ref the stored tree lacks refuses with a typed reason

Merged
OK
2mo ago
+303-35

Summary

A stale or unknown @ref failed as COMMAND_FAILED with Ref @e12 not found or has no bounds and the stale-ref hint, on every route: press, click, fill, longpress, hover, get, wait, and snapshot --scope. A consumer that re-observes on a stale ref had to match the message. docs/agents/pull-requests.md says message matching must not replace a lost reason code, and the sibling producers already carry typed reasons (offscreen_ref, covered_by_interactive_descendants, selector_not_found).

Every ref miss now carries details.reason and details.ref (the bare ref body, as offscreen_ref does) beside the hint: a ref the stored tree does not list is ref_not_found (Ref @e9 not found); a listed ref whose node has no usable centre, or a selector target without one, is target_bounds_invalid (Ref @e1 has no usable bounds); a listed ref with no label to wait on or scope by is ref_unlabeled. The reasons live in INTERACTION_ERROR_REASONS beside the existing ones; ADR 0011's fixture list names them.

agent-device press @e999 --json
# {"ok":false,"error":{"code":"COMMAND_FAILED","message":"Ref @e999 not found or has no bounds",
#   "hint":"Snapshot refs expire when the UI changes. ...","details":{"reason":"ref_not_found","ref":"e999"}}}

11 files: 5 producers, 5 tests, the ADR. The wire shape is additive.

Validation

Tested at 275851f803 (third commit: tryResolveRefNode returns a discriminated outcome, resolved, unusable, or missing, and the refusal maps it with one lookup; get carries the stale-ref hint; pnpm check:affected --run --base c31cc49f6 passed on it):

  • pnpm check:affected --run --base c31cc49f6: all runnable checks passed.
  • Regression rows: resolution.test.ts, interaction-touch-runtime.test.ts, interaction-touch-fill.test.ts, and the runtime-ref contract test assert the reason and ref; selector-read.test.ts gains the get and wait misses (ref_not_found for a missing node, ref_unlabeled for one without text), and resolution.test.ts pins the three outcomes of tryResolveRefNode, the trailing-label recovery of an unusable node included; snapshot-scope-ref.test.ts covers --scope.
  • Live, dev daemon, dev.e2e.benchmark open with a stored snapshot -i: on an Android emulator (API 36.1, helper 0.21.14) and an iPhone 17 Pro Max simulator (iOS 26.5), press @e999, get text @e999, wait @e999 300, snapshot -s @e999, and fill @e999 hello each answered COMMAND_FAILED with details.reason: ref_not_found, details.ref: e999, the mutation, wait, and scope paths with the stale-ref hint.
  • Risk: consumers that deep-equal the error details of a ref miss now see two more keys, and the two messages that shared not found or has no bounds now say which it was.