Skip to content

A text-locator find replaces the session snapshot with a scoped tree, so earlier @refs stop resolving #4686

Closed

Description

@xiatiandeairen

Purpose

help workflow says refs "stay valid until you press/click/fill/type/scroll/back/wait-for-async-UI, or otherwise change app state". A text-locator read with find does not change app state, yet afterwards the refs from the previous snapshot no longer resolve. A selector read with get keeps them.

Observed on 0.21.39, iOS 27.2 simulator:

$ agent-device snapshot -i --session c39            # "4 items" is @e4
$ agent-device find "speakers" get text --session c39
Speakers (4)
$ agent-device get text @e4 --session c39
Error (COMMAND_FAILED): Ref @e4 not found. Not dispatched. Next: Snapshot refs expire when the UI changes. Run snapshot -i and retry with a fresh @ref.

$ agent-device snapshot -i --session c39            # @e4 again
$ agent-device get text 'label="4 items"' --session c39
4 items
$ agent-device get text @e4 --session c39
4 items

The UI did not change between these commands.

The cause: findFirstLocatorMatch in selector-read.ts scopes the capture to the query (findSnapshotScope) and passes updateSession: true. captureSelectorSnapshot therefore stores the scoped, partial tree as the session snapshot, and the earlier full tree's refs disappear. Since #1093, nothing is misread, but the agent re-snapshots for nothing, and the error points it at a UI change that did not happen.

Required behavior

  • A read-only find (get text, get attrs, exists) leaves the refs from the last full snapshot resolvable, as the help says.
  • Any @ref printed by a read-only find resolves to the node that the find read.

Completion conditions

  • snapshot -i, then find "<text>" get text, then get text @eN on a ref from that snapshot returns the same text as before the find.
  • The ref printed by find "<text>" get attrs still resolves to that node afterwards.

Environment: agent-device 0.21.39, macOS 27.2, Xcode 27.2, Node 26.13.1, iOS 27.2 simulator.

Activity

  1. xiatiandeairen commented on Nov 18, 2026

    @xiatiandeairen
    ContributorAuthor

    #4698 fixes the wrong-node part. A plain ref outside a partial frame's issuance set is now refused with ref_not_issued, as ADR 0014 already requires.

    The first required behavior here, that earlier refs stay resolvable after a read-only find, conflicts with ADR 0014 "Partial issuance": publishing a partial frame intentionally supersedes the prior frame. Two ways to get it, both needing an ADR amendment:

    • B1: find … get text stops publishing a ref, so the frame is not superseded. The JSON ref and refsGeneration fields go away for get text.
    • B2: a read-only find's partial frame keeps the previous complete frame's tree for reads of refs outside its issuance set. That is one extra retained tree, which the ADR rejected for multiple trees.

    Should either be pursued, or is #4698 enough and the help wording ("or find/diff print refs") the intended contract?

  2. added
    bug
    on Nov 19, 2026
  3. xiatiandeairen commented on Nov 19, 2026

    @xiatiandeairen
    ContributorAuthor

    Decision: scope: #4698 fixed the part we need. A plain ref that the current frame did not issue is now refused instead of read from a newer tree.

    We withdraw the first required behavior here (earlier refs stay resolvable after a read-only find) and the B1/B2 question. The current contract, where refs printed by find or a settled diff supersede earlier ones, works for us. Feel free to close this issue.

  4. xiatiandeairen commented on Nov 19, 2026

    @xiatiandeairen
    ContributorAuthor

    Fixed by #4698.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions