Skip to content

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

Merged
thymikee merged 5 commits into
callstack:mainfrom
strzhao:community-selector-platform-hints
Nov 21, 2026
Merged

thymikee merged 5 commits into
callstack:mainfrom
strzhao:community-selector-platform-hints

Conversation

@strzhao

@strzhao strzhao commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

With no explicit --platform, a --udid naming an attached Android/HarmonyOS/Vega serial answered "No Apple device with UDID X" with no hint. The failure now names the flag the value belongs to, read through deviceIdentityFlag: "Did you mean --serial X?", and --serial answers the reverse. Only an observed candidate earns a hint; a --device name one punctuation character from exactly one candidate gets that name; two candidates under the fold, or an unknown name, earn none.

Per the review, the footprint shrank to consolidation: the host-scoped id grammar returned to device.ts, device-identity.ts is back to its merge-base content, the ./device-identity export is gone, with the three test files back on @agent-device/kernel/device — one entry, no eager-closure growth. The three not-found answers share one helper, deviceNotFoundHint(candidates, value, flag?), with the quote fold as quoteFoldDeviceName; messages are unchanged. device.ts sits at 987 lines at head and 997 on the merge preview with main, under the 1000 cap.

Before / after

raven device open --udid emulator-5580            # only an Android emulator attached
# before: No Apple device with UDID emulator-5580
# after:  No Apple device with UDID emulator-5580
#         Next: emulator-5580 identifies "Pixel 7" here. Did you mean --serial emulator-5580?

raven device open --serial SIM-001                # only an iOS simulator attached
# before: No Android, HarmonyOS device, or Vega VVD with serial SIM-001
# after:  ... Next: SIM-001 identifies "iPhone 16" here. Did you mean --udid SIM-001?

raven device open --device 'iPhone "16"'          # simulator renamed to iPhone “16”
# before: No device named iPhone "16"
# after:  ... Next: A device is named "iPhone “16”", which differs only in punctuation. Did you mean --device "iPhone “16”"?

Validation

At 05bd92c: kernel 284 and daemon-side 260 unit tests, tsc -b exit 0. In an isolated clone at origin/main at 18c6c42cd (merge-base 357e0d4), every check:affected lane passes and eager-closure-budgets passes 919 tests — the Coverage blocker. The earlier layering and eager-closure failures were fork-base misreports (origin = a private mirror). upload-http-deadline.test.ts fails identically at the merge-base on this host, (not this diff). The merge preview with main passes oxlint; its earlier failure was the device.ts cap, now fixed. CI owns Coverage and Body rules.

🤖 Generated with Claude Code

strzhao and others added 2 commits November 21, 2026 04:34
… 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 callstack#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>
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>
@thymikee

Copy link
Copy Markdown
Member

Thanks for tightening these selector errors. The hint logic reads correct at 9449b7e, but the Coverage check fails because of this PR, so the change is not ready yet.

The new ./device-identity package export makes device-identity.ts an entry whose eager closure grows from 1 to 3 modules (it now pulls in errors.ts and redaction.ts), and eager-closure-budgets.test.ts fails on that. Please drop the move and the new export, or place the host id grammar in a module that is not a package entry, then push so Coverage runs again. The Runner Build (tvOS + visionOS + watchOS) failure looks unrelated: it stops on an actions/cache setup error before any build, and the diff touches no Swift or runner path.

Not blocking, and these can be taken or left: the a name two candidates share under the quote fold earns no hint test in device-selector-flags.test.ts requests iPhone 16, which folds to neither candidate, so close.length is 0 and changing === 1 to >= 1 keeps it green; deviceIdentityWrongFlagHint in device.ts repeats the shape of deviceIdentityMistakenForNameHint; the closestDeviceNameHint text at device.ts:664 says "punctuation or spacing" while only quote style is folded; and the one-entry reasons table and the long docblocks add more than the change needs.

Could one helper taking the candidates, the value and an optional requested flag serve all three not-found sites, with the quote fold kept as a short helper? That would keep device.ts under 1000 lines, so no move, no new export and no test import changes, at roughly +40 production lines instead of +220/-127.

Not verified here: a live open --udid <android serial> run on a host with mixed devices, since this is a pre-dispatch error-text change and the route was traced by reading the code. Also not verified here: the layering gates beyond the CI result, where only the eager-closure test failed in Coverage.

…able 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>
@thymikee

Copy link
Copy Markdown
Member

Thanks for the update.

The evidence the earlier review asked for is now in place at 0a424cc. One problem from that review remains: the new ./device-identity export in packages/kernel/package.json is imported only by three test files (device-claim-admission.test.ts, device-claims-app.test.ts and daemon request-router-open.test.ts). It makes device-identity.ts a package entry, so its eager closure grows (errors.ts plus the device.ts type edge). That is the growth flagged earlier, and the export has no production consumer. Please remove the ./device-identity export and re-export hostAppDeviceId and hostDeviceIdPrefix from device.ts next to the other identity re-exports, so device.ts stays the one entry.

The Coverage job log stops mid-run with no error line, so the failure cannot be attributed from the log alone. Not verified here: whether it comes from this export or is unrelated. Body rules was cancelled in a different run, not failed. After the export is removed, Coverage and Body rules need to pass before merge. Re-running Coverage once would show whether the failure reproduces.

strzhao and others added 2 commits November 21, 2026 11:58
… 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>
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

Copy link
Copy Markdown
Member

Thanks for the quick update. At 05bd92c the earlier findings (#4861 (comment)) are fixed, and this PR is ready. The earlier Coverage failure came from the ./device-identity export, which this head removes, and the diff now touches only device.ts and its kernel test. CI is green: 15 checks, none failing. There are no conflicts. Nothing else must happen before merge. Not blocking, and fine to take or leave: in https://github.com/callstack/agent-device/blob/05bd92c/packages/kernel/src/device.ts#L708 deviceNotFoundHint folds the name of every candidate even when flag is set (--udid/--serial) and then drops the result, so an early return after the identity branch would run the fold only for --device. Not verified here: the kernel tests and tsc were not run locally, and no live device run was made. The change only alters pre-dispatch error text on resolveDevice, and the route was traced by reading the code and the tests, which call the production resolver.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 21, 2026
@thymikee
thymikee merged commit c37bb95 into callstack:main Nov 21, 2026
15 checks passed
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