Skip to content

fix(refs): make ambiguity candidate refs paste-ready and carry device boot state - #4853

Merged
thymikee merged 2 commits into
callstack:mainfrom
strzhao:community-ambiguous-match-ux
Nov 20, 2026
Merged

thymikee merged 2 commits into
callstack:mainfrom
strzhao:community-ambiguous-match-ux

Conversation

@strzhao

@strzhao strzhao commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Two same-domain fixes for AMBIGUOUS_MATCH recoverability, continuing #1597/#1602 (element candidates), #4506 (tied device id+name), and #2870's printing-implies-issuing rule. Scope declared on #4571 before opening: it takes that issue's ref-error half, not the swipe/gesture --settle gap.

  • A drag whose target selector refused printed bare candidate refs minted from the capture the drag itself consumed — a tree the caller's frame did not authorize — so pasting a printed ref was refused as superseded. The gesture route now runs the same ambiguity-issuance rule as press/click/fill and the strict reads.
  • A tied-device refusal listed id and name only. A tie can span booted and shut-down devices, and an id picked without the state can aim at a device that cannot answer, so device candidates now carry their boot state.

Before / after

An ambiguous drag on a session whose frame predates the drag's own capture:

  • before: Candidates: @e2 [view] "Drag source" with no refsGeneration; pasting @e2 (or the earlier snapshot's @e2~s42) is refused (plain_ref_requires_complete_frame / ref_generation_mismatch).
  • after: the refusal carries refsGeneration and the frame scope holds exactly the printed bodies; the pasted @e2~s<refsGeneration> taps the listed node.

An ambiguous device request with a booted emulator and a shut-down simulator tied:

  • before: Devices: lists emulator-5554 Pixel / Pixel_9_Pro_XL Pixel 9 Pro XL with no state.
  • after: emulator-5554 Pixel booted=true / Pixel_9_Pro_XL Pixel 9 Pro XL booted=false.

Changes

  • interaction-gesture.ts: the drag/swipe dispatch carries the consumed-capture slot and routes failures through publishAmbiguousMatchCandidateRefs.
  • command-output/src/output/error.ts: the candidate-line pin helper re-pins born-stamped lines to the view's generation, so every printed line carries the epoch the caller will face (bare lines, the epoch additive once as refsGeneration, stay the wire shape; the helper stays private to this module — the eager-closure budget forbids an edge from this entry into the capture-kit renderer).
  • device.ts / device-selection-resolver.ts: one deviceCandidateSummary builder feeds both device refusal sites, adding booted to each entry; kernel/errors carries the field through the device candidate view, and the CLI Devices: block renders booted=true|false.

Validation

  • Head dc30a9d: unit tests across capture-kit, command-output, kernel, device-selection, and the daemon execution/session areas pass (4,035 at 59ec8f1; the renderer and capture-kit suites re-ran green after the fold-in). New tests beside each change: the render-chain re-pin, the boot-state render, the kernel and resolver refusal shapes, and the acceptance case — an ambiguous drag refusal's printed candidate ref, pinned as its refsGeneration directs, is admitted on the issued frame and taps the listed node.
  • The eager-closure budget that failed on 59ec8f1 (scripts/__tests__/eager-closure-budgets.test.ts, command-output entries) passes at dc30a9d.
  • Local check:affected at the pinned base: format, lint, and typecheck pass. The local layering stage fails on pre-existing baseline drift (untyped-reason/promise-race findings across files this PR does not touch; session-snapshot.ts is unchanged from the base and its finding is the pre-existing ref_not_issued literal; the staged diff adds no reason literal). CI owns the full gate run.
  • No device run: the changes alter refusal payloads and their rendering, not dispatch or native execution.

🤖 Generated with Claude Code

strzhao and others added 2 commits November 21, 2026 03:08
… boot state

Two same-domain ambiguity recoverability fixes:

- A drag whose target selector refused used to print bare candidate refs the
  caller's frame never authorized: the drag's own resolution capture advanced
  past the tree that minted them, so pasting a printed ref was refused as
  superseded. The gesture route now runs the same ambiguity-issuance rule as
  the touch routes and the strict reads (the consumed-capture slot, then
  publishAmbiguousMatchCandidateRefs), so printed candidates are issued on the
  frame that lists them or not printed at all. The CLI render chain re-pins
  every printed line to the epoch the caller will face through one shared
  grammar (pinElementMatchCandidateLine beside the snapshot-line renderer).
- A tied-device refusal listed id and name only. A tie can span booted and
  shut-down devices, and an id picked without the state can aim at a device
  that cannot answer, so both refusal sites (the kernel tie and the selection
  resolver) now print each candidate's boot state through one summary builder,
  and the Devices block renders booted=true/false.

Unit acceptance: an ambiguous drag refusal's printed candidate ref, pinned as
its refsGeneration directs, is admitted on the issued frame and taps the
listed node.

Co-Authored-By: Claude Code <noreply@anthropic.com>
…ror renderer

CI caught the eager-closure budget: a static edge from the command-output
error renderer into capture-kit's snapshot-line module pulled 12 new modules
into the command-output entry closure. The pin grammar's only consumer is this
renderer, so it folds back into the private helper — the render chain still
re-pins born-stamped candidate lines, and capture-kit's renderer keeps
emitting bare lines (the callstack#2870 wire shape).

Co-Authored-By: Claude Code <noreply@anthropic.com>
@thymikee

Copy link
Copy Markdown
Member

Thanks for the PR. It is ready at dc30a9d: CI is green (12 checks, none failing), and there are no conflicts. Not blocking, and fine to take or leave: the re-pin branch in pinCandidateLine (packages/command-output/src/output/error.ts#L241) cannot fire today because no producer emits stamped candidate lines, and re-pinning a stale stamp would point the ref at the wrong element, so the base regex and the re-pin test can go; the free-standing comment block in packages/capture-kit/src/snapshot/snapshot-lines.ts#L105 is orphaned, and MCP renders through the same formatHumanError, so it can be deleted; the drag test in interaction-gesture-drag.test.ts#L196 could use the default matcher over the existing two "Drag source" fixture so the real resolver produces the ambiguity; readDeviceList in packages/kernel/src/errors.ts#L219 should keep booted only when it is a boolean, since "false" as a string would render as booted=true; and commands.md#L107 could mention that device candidates show booted and that drag refusals now issue pinned candidates. Not verified here: tests were not run locally, a live device was not used to confirm that a real ambiguous drag reaches the pinned-candidate branch rather than the count-only one, and external consumers that parse details.devices strictly were not checked (the booted field is additive).

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 20, 2026
@thymikee
thymikee merged commit dd7d81c into callstack:main Nov 20, 2026
12 checks passed
strzhao added a commit to strzhao/agent-device-upstream that referenced this pull request Nov 21, 2026
The merge preview joins this branch with main, where dd7d81c (callstack#4853) grew
device.ts by ten lines, so the branch's own zero-growth accounting does not hold
on the tree CI actually checks: 994 head lines plus those ten crossed the 1000
limit and failed oxlint there. Compress the helper's one-line docblock, put its
signature back on one line, and pass an empty value for a serial-less selector
(an empty string matches no id, so that miss stays hint-free): 987 lines at
head, 997 on the merge preview.

Co-Authored-By: Claude Code <noreply@anthropic.com>
thymikee pushed a commit that referenced this pull request Nov 21, 2026
… in selector errors (#4861)

* fix(kernel): name the other identity flag and the closest device name in selector errors

A `--udid` that resolves nothing while the same value identifies an observed
Android/HarmonyOS/Vega device answered "No Apple device with UDID emulator-5580"
with no hint when the request carried no explicit --platform (the explicit case
was already rejected by assertSelectorFlagMatchesPlatform). The failure now
reads the flag the value belongs to through deviceIdentityFlag — no third
inline pairing — and says "Did you mean --serial <value>?"; --serial answers
the reverse the same way. Only an observed identity earns the hint, and a
platform with no identity flag (web, linux) earns none, matching the #2065
precedent for --device.

A --device name that survives the matcher but sits one punctuation character
away from exactly one candidate (curly quotes on renamed simulators) is now
answered with that candidate's name; more than one candidate under the quote
fold earns no hint. The id-mistaken-for-name answer still wins when it applies.

device.ts carried this work past the 1000-line lint cap, so the host-scoped id
grammar (app devices, web sessions) moved verbatim into device-identity.ts,
which every closure through device.ts already evaluates; @agent-device/kernel
/device re-exports keep every import path stable. The moved web-session
refusal now reads its wire reason from a declared table.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(kernel): point the id-grammar test imports at the owning module

The barrel re-export of hostAppDeviceId and hostDeviceIdPrefix had no
production consumer after the move, so the production-unused-exports gate
refused it; both are used only by tests. The barrel keeps the symbols with
production call sites, the tests import the two from
@agent-device/kernel/device-identity (new exports-map entry), and the gate
passes again.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(kernel): rebuild the ambiguous-close fixture and drop the unreachable spacing claim

The two-candidate quote-fold case requested a quote-less name, which folds
onto neither quoted candidate, so the close list stayed empty and the no-hint
assertion passed without exercising the branch. The request now keeps its
straight quotes while the two candidates spell theirs with U+2018 and U+2019,
so both land under the fold and the answer names neither; flipping the
single-candidate guard to >= 1 fails exactly this test.

The closest-name hint said "punctuation or spacing", but the shared name
matcher already folds whitespace, so a spacing-only difference resolves
before any hint and the spacing claim was unreachable copy.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(kernel): keep the selector hints in device.ts and serve all three not-found sites with one helper

The review asked for the smallest structural footprint: the ./device-identity
package export made device-identity.ts a package entry whose eager closure grew
from one module to three (errors.ts via the moved web-session refusal, plus
redaction.ts), which the eager-closure budget gate refuses on no-growth, and the
export had no production consumer. This drops the move and the export entirely:
the host-scoped id grammar returns to device.ts, device-identity.ts returns to
its merge-base content, and the three test files that had been pointed at the
new entry go back to @agent-device/kernel/device.

The two hints this branch added and the pre-existing mistaken-name answer now
collapse into one helper: deviceNotFoundHint(candidates, value, flag?) reads the
flag the request used, answers with the flag an observed device carries the value
under, and for --device names the single candidate one quote fold away
(quoteFoldDeviceName). device.ts absorbs the consolidation with no net line
growth (989 at base, 989 here) against the 1000-line oxlint cap, so no module
move and no new entry are needed.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(kernel): leave the merged device.ts under the 1000-line cap

The merge preview joins this branch with main, where dd7d81c (#4853) grew
device.ts by ten lines, so the branch's own zero-growth accounting does not hold
on the tree CI actually checks: 994 head lines plus those ten crossed the 1000
limit and failed oxlint there. Compress the helper's one-line docblock, put its
signature back on one line, and pass an empty value for a serial-less selector
(an empty string matches no id, so that miss stays hint-free): 987 lines at
head, 997 on the merge preview.

Co-Authored-By: Claude Code <noreply@anthropic.com>

---------

Co-authored-by: Claude Code <noreply@anthropic.com>
strzhao added a commit to strzhao/agent-device-upstream that referenced this pull request Nov 23, 2026
…ts replacement refs

After `fill @e3 … --settle; press @e4` with @E4 taken from the earlier full
snapshot, the plain-ref refusal offered nothing: the agent could not tell
that a settled diff replaced the frame and paid a full `snapshot -i` every
time (callstack#4571, the most common agent-blocking error in the dogfood data).

The frame value now records which publication minted it. `RefFrameOrigin`
(`complete` | `settle-diff` | `partial`) is set at issuance through the same
factories; every partial publication flows through one choke point
(`markSessionPartialRefsIssued`), and only the settle path
(`issueSettleRefs`) passes `settle-diff`, so find, audit, replay divergence,
and ambiguity issuances keep their refusal shape unchanged. Origin is
diagnostic only: no admission decision and no ref lifetime changes — whether
refs a diff left unchanged stay valid stays open for maintainers on callstack#4571.

When the refusing frame is settle-diff and the refused plain ref is not one
of its issued refs, the refusal:

- names the settled diff as the replacement in the message (and says when
  the diff issued no refs),
- carries `details.replacedBy: "settle-diff"` and
  `details.replacementRefs`, each issued ref pinned to the frame epoch in
  the ready-to-copy `@eN~s<epoch>` form (callstack#4853 paste-ready standard; the
  frame already authorized exactly these bodies, so printing them issues
  nothing new),
- offers the same refs in the hint with the fresh-snapshot escape.

The exact-emitted-ref suggestion keeps precedence when the refused body is
itself in scope. ADR 0014 amended (dated subsection beside the refusal
contract it extends).

Co-Authored-By: Claude Code <noreply@anthropic.com>
thymikee pushed a commit that referenced this pull request Nov 23, 2026
…ts replacement refs (#5037)

After `fill @e3 … --settle; press @e4` with @E4 taken from the earlier full
snapshot, the plain-ref refusal offered nothing: the agent could not tell
that a settled diff replaced the frame and paid a full `snapshot -i` every
time (#4571, the most common agent-blocking error in the dogfood data).

The frame value now records which publication minted it. `RefFrameOrigin`
(`complete` | `settle-diff` | `partial`) is set at issuance through the same
factories; every partial publication flows through one choke point
(`markSessionPartialRefsIssued`), and only the settle path
(`issueSettleRefs`) passes `settle-diff`, so find, audit, replay divergence,
and ambiguity issuances keep their refusal shape unchanged. Origin is
diagnostic only: no admission decision and no ref lifetime changes — whether
refs a diff left unchanged stay valid stays open for maintainers on #4571.

When the refusing frame is settle-diff and the refused plain ref is not one
of its issued refs, the refusal:

- names the settled diff as the replacement in the message (and says when
  the diff issued no refs),
- carries `details.replacedBy: "settle-diff"` and
  `details.replacementRefs`, each issued ref pinned to the frame epoch in
  the ready-to-copy `@eN~s<epoch>` form (#4853 paste-ready standard; the
  frame already authorized exactly these bodies, so printing them issues
  nothing new),
- offers the same refs in the hint with the fresh-snapshot escape.

The exact-emitted-ref suggestion keeps precedence when the refused body is
itself in scope. ADR 0014 amended (dated subsection beside the refusal
contract it extends).

Co-authored-by: Claude Code <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants