diff --git a/packages/contracts/src/facades/command.ts b/packages/contracts/src/facades/command.ts index 7a32b9faef..a9f1db3ca8 100644 --- a/packages/contracts/src/facades/command.ts +++ b/packages/contracts/src/facades/command.ts @@ -14,9 +14,7 @@ export type { CommandFlags, MaestroRuntimeFlags } from '../command-flags.ts'; export type { DaemonWireRequest, DaemonWireRequestMeta } from '../daemon-wire-request.ts'; export type { DispatchedCommand } from '../dispatched-command.ts'; export { - ANDROID_IME_HELPER_DISPATCH_REJECTED_REASON, - ANDROID_IME_HELPER_NO_ACK_REASON, - ANDROID_SHELL_TEXT_UNSUPPORTED_REASON, + ANDROID_TEXT_CHANNEL_REASONS, normalizeBatchCommandName, readOptionalInteger, readOptionalNumber, diff --git a/packages/contracts/src/input-validation.ts b/packages/contracts/src/input-validation.ts index 3ab1dd67e3..a1f9ec17c8 100644 --- a/packages/contracts/src/input-validation.ts +++ b/packages/contracts/src/input-validation.ts @@ -1,4 +1,4 @@ -import { AppError } from '@agent-device/kernel/errors'; +import { AppError, type ReasonTable } from '@agent-device/kernel/errors'; export function readOptionalInteger( record: Record, @@ -40,23 +40,25 @@ export function readOptionalNumber( } /** - * The typed reason the Android adb-shell text channel reports when it cannot carry the - * requested text. Recovery routing keys on this constant, never on the message: the message - * states the channel limit; the reason names which recovery surfaces apply. It lives here - * because every producer and consumer of the reason already evaluates this module. + * Why an Android text channel refused to carry the text it was handed. Recovery routing keys on the + * reason, never on the message: the message states the channel limit, the reason names which + * recovery surfaces apply. The table lives here because every producer of these failures and the + * replay boundary that rewrites their hint already evaluate this module. */ -export const ANDROID_SHELL_TEXT_UNSUPPORTED_REASON = 'android_shell_text_unsupported' as const; - -/** - * Typed reasons for the Android test-IME broadcast channel's truthful-outcome failures (#4520). - * The channel's acknowledgement proves attempted dispatch only; these reasons distinguish "no - * acknowledgement evidence at all" (result=0 / unparseable — a pre-ack helper or no receiver, which - * are indistinguishable and therefore both refused) from a receiver-reported rejection. Result data - * carries codes and lengths only, never user text. - */ -export const ANDROID_IME_HELPER_NO_ACK_REASON = 'android_ime_helper_no_ack' as const; -export const ANDROID_IME_HELPER_DISPATCH_REJECTED_REASON = - 'android_ime_helper_dispatch_rejected' as const; +export const ANDROID_TEXT_CHANNEL_REASONS = { + // The adb-shell fallback carries ASCII text only; a helper or provider channel is needed. + shellTextUnsupported: { + reason: 'android_shell_text_unsupported', + commands: ['fill', 'type'], + }, + // The test IME helper gave no evidence it attempted the dispatch, so nothing is proven typed. + imeHelperNoAck: { reason: 'android_ime_helper_no_ack', commands: ['fill', 'type'] }, + // The test IME helper answered that it rejected the dispatch, so nothing was typed. + imeHelperDispatchRejected: { + reason: 'android_ime_helper_dispatch_rejected', + commands: ['fill', 'type'], + }, +} as const satisfies ReasonTable<'android text channel'>; /** Resolves a batch step command with the same whitespace and case rules on both peers. */ export function normalizeBatchCommandName(command: unknown): string { diff --git a/packages/contracts/src/settings.ts b/packages/contracts/src/settings.ts index ab472b4108..5ac568e7e6 100644 --- a/packages/contracts/src/settings.ts +++ b/packages/contracts/src/settings.ts @@ -160,12 +160,6 @@ export function settingsAppNotConsumedRefusal( const SETTINGS_APP_NOT_INSTALLED_HINT = 'Run apps --all for the exact bundle id or package name, or install the app, then retry with that id in --app.'; -/** - * The reason an Android app-scoped mutation refuses an app that resolves to an intent rather than a - * package: a permission or app-data change needs a package, so the recovery is naming one. - */ -export const SETTINGS_APP_NOT_PACKAGE_REASON = 'setting_app_not_package'; - /** * Resolves the app an app-scoped mutation lands on through the owner's own app resolution, ahead of * anything that reaches the device. A failed resolution therefore dispatched nothing, and an app that diff --git a/packages/platform-android/src/__tests__/device-input-state.test.ts b/packages/platform-android/src/__tests__/device-input-state.test.ts index 87347ed74d..02326c590c 100644 --- a/packages/platform-android/src/__tests__/device-input-state.test.ts +++ b/packages/platform-android/src/__tests__/device-input-state.test.ts @@ -10,7 +10,6 @@ import { readAndroidClipboardWithAdb, writeAndroidClipboardWithAdb, } from '../device-input-state.ts'; -import { ANDROID_CLIPBOARD_SHELL_COMMAND_UNAVAILABLE_REASON } from '../clipboard-shell-response.ts'; import { flushDiagnosticsToSessionFile, withDiagnosticsScope, @@ -399,7 +398,7 @@ test('readAndroidClipboardWithAdb refuses the exit-0 no-implementation answer in assert.equal(error.code, 'UNSUPPORTED_OPERATION'); assert.equal( (error.details as { reason?: unknown }).reason, - ANDROID_CLIPBOARD_SHELL_COMMAND_UNAVAILABLE_REASON, + 'android_clipboard_shell_command_unavailable', ); }); @@ -418,7 +417,7 @@ test('writeAndroidClipboardWithAdb refuses the exit-0 no-implementation answer i assert.equal(error.code, 'UNSUPPORTED_OPERATION'); assert.equal( (error.details as { reason?: unknown }).reason, - ANDROID_CLIPBOARD_SHELL_COMMAND_UNAVAILABLE_REASON, + 'android_clipboard_shell_command_unavailable', ); }); diff --git a/packages/platform-android/src/__tests__/settings-global-toggle.test.ts b/packages/platform-android/src/__tests__/settings-global-toggle.test.ts index 421c443bc2..628cc61b62 100644 --- a/packages/platform-android/src/__tests__/settings-global-toggle.test.ts +++ b/packages/platform-android/src/__tests__/settings-global-toggle.test.ts @@ -1,6 +1,10 @@ import { expect, test } from 'vitest'; import assert from 'node:assert/strict'; -import { setAndroidGlobalToggle, type AndroidGlobalToggle } from '../settings-global-toggle.ts'; +import { + ANDROID_GLOBAL_TOGGLE_REASONS, + setAndroidGlobalToggle, + type AndroidGlobalToggle, +} from '../settings-global-toggle.ts'; import { withFakeAdb } from './test-utils/fake-adb.ts'; import { underFakeTimers } from './test-utils/fake-timers.ts'; @@ -13,8 +17,8 @@ const TOGGLE: AndroidGlobalToggle<'example'> = { stateKey: 'example', parseRow: (storedValue) => storedValue === '1' ? 'enabled' : storedValue === '0' ? 'disabled' : undefined, - notAppliedReason: 'example-not-applied', - unreadableReason: 'example-unreadable', + notAppliedReason: ANDROID_GLOBAL_TOGGLE_REASONS.mobileDataNotApplied.reason, + unreadableReason: ANDROID_GLOBAL_TOGGLE_REASONS.mobileDataUnreadable.reason, sampleIntervalMs: 300, hint: 'Read example_on.', }; @@ -32,7 +36,7 @@ test('the sample taken after the settle window runs out still answers with the t ).rejects.toMatchObject({ code: 'COMMAND_FAILED', details: { - reason: 'example-not-applied', + reason: ANDROID_GLOBAL_TOGGLE_REASONS.mobileDataNotApplied.reason, example: 'disabled', storedValue: '0', dispatched: 'unknown', diff --git a/packages/platform-android/src/__tests__/settings.test.ts b/packages/platform-android/src/__tests__/settings.test.ts index 434ae6719d..35e24e23e4 100644 --- a/packages/platform-android/src/__tests__/settings.test.ts +++ b/packages/platform-android/src/__tests__/settings.test.ts @@ -1,6 +1,5 @@ import { test, vi } from 'vitest'; import assert from 'node:assert/strict'; -import { SETTINGS_APP_NOT_PACKAGE_REASON } from '@agent-device/contracts/settings'; import { TEXT_SIZE_CATEGORIES } from '@agent-device/contracts/settings-catalog'; import { AppError, PRE_DISPATCH_REFUSAL_REASONS } from '@agent-device/kernel/errors'; import { readAndroidSetting, setAndroidSetting } from '../settings.ts'; @@ -227,7 +226,7 @@ test('setAndroidSetting permission refuses an app alias that resolves to an inte setAndroidSetting(device, 'permission', 'grant', 'settings', { permissionTarget: 'camera', }), - { code: 'INVALID_ARGS', reason: SETTINGS_APP_NOT_PACKAGE_REASON, dispatched: 'no' }, + { code: 'INVALID_ARGS', reason: 'setting_app_not_package', dispatched: 'no' }, ); assert.deepEqual(calls, [CURRENT_USER]); }); diff --git a/packages/platform-android/src/__tests__/text-input.test.ts b/packages/platform-android/src/__tests__/text-input.test.ts index 77842533f2..d49026ce07 100644 --- a/packages/platform-android/src/__tests__/text-input.test.ts +++ b/packages/platform-android/src/__tests__/text-input.test.ts @@ -1,6 +1,5 @@ import { test } from 'vitest'; import assert from 'node:assert/strict'; -import { ANDROID_SHELL_TEXT_UNSUPPORTED_REASON } from '@agent-device/contracts/input-validation'; import { ANDROID_TEST_IME_OPEN_HINT, fillAndroid, typeAndroid } from '../text-input.ts'; import { assertRejectsAppError } from './test-utils/app-error.ts'; import { @@ -320,7 +319,7 @@ test('typeAndroid reports clear error when unicode input is unsupported', async await assertRejectsAppError(() => typeAndroid(device, '很'), { code: 'COMMAND_FAILED', message: /provider-native text injection/i, - reason: ANDROID_SHELL_TEXT_UNSUPPORTED_REASON, + reason: 'android_shell_text_unsupported', hint: ANDROID_TEST_IME_OPEN_HINT, }); }, diff --git a/packages/platform-android/src/adb-port-reverse.ts b/packages/platform-android/src/adb-port-reverse.ts index 23b9e26ef4..1ec7b13f0a 100644 --- a/packages/platform-android/src/adb-port-reverse.ts +++ b/packages/platform-android/src/adb-port-reverse.ts @@ -1,4 +1,4 @@ -import { AppError } from '@agent-device/kernel/errors'; +import { AppError, type ReasonTable } from '@agent-device/kernel/errors'; import { withKeyedLock } from '@agent-device/kernel/keyed-lock'; import { androidAdbResultError } from './adb-failure.ts'; import { normalizeAndroidAdbProvider } from './adb-provider-normalization.ts'; @@ -25,8 +25,11 @@ export type AndroidExecPortReverseOptions = Readonly<{ noRebind?: boolean; }>; -const ANDROID_PORT_REVERSE_REBIND_REFUSED_REASON = 'android_port_reverse_rebind_refused'; - +/** Why an owner-tracked port reverse refuses to touch the device's mapping table. */ +const PORT_REVERSE_REASONS = { + // The endpoint already has a device mapping, which a `--no-rebind` reverse never replaces. + rebindRefused: { reason: 'android_port_reverse_rebind_refused', commands: ['open'] }, +} as const satisfies ReasonTable<'android adb port reverse'>; const managedAndroidPortReverseProviders = new WeakSet(); export function createAndroidPortReverseManager( @@ -169,7 +172,7 @@ function rebindRefusedError( 'COMMAND_FAILED', `Android port reverse ${requested.local} is already mapped on the device`, { - reason: ANDROID_PORT_REVERSE_REBIND_REFUSED_REASON, + reason: PORT_REVERSE_REASONS.rebindRefused.reason, requested, existing, hint: `agent-device does not replace an existing reverse mapping on a shared device. Remove the mapping that holds device ${requested.local}, or use another device port.`, diff --git a/packages/platform-android/src/adb-transport.ts b/packages/platform-android/src/adb-transport.ts index a422665006..e09e32c4f5 100644 --- a/packages/platform-android/src/adb-transport.ts +++ b/packages/platform-android/src/adb-transport.ts @@ -2,7 +2,7 @@ import { relayDeviceShellArgvWithOptions, relayDeviceShellArgvWithoutOptions, } from '@agent-device/kernel/device-shell'; -import { AppError } from '@agent-device/kernel/errors'; +import { AppError, type ReasonTable } from '@agent-device/kernel/errors'; import type { Readable, Stream, Writable } from 'node:stream'; import type { Rect } from '@agent-device/kernel/snapshot'; import type { @@ -596,6 +596,12 @@ export function requireManagedAndroidAdbCommand(command: readonly string[]): voi if (isAndroidAdbManagedForbiddenCommand(head)) throw transportMismatch('target'); } +/** Why a managed adb transport refuses a call at all. */ +const MANAGED_TRANSPORT_REASONS = { + // The call aimed a managed adb transport at another device, target, or server. + transportMismatch: { reason: 'managed-device-transport-mismatch' }, +} as const satisfies ReasonTable<'android adb transport'>; + /** What a managed transport refuses to be pointed at: another device, target, or adb server. */ const TRANSPORT_MISMATCH_MESSAGES = { device: 'Managed ADB transport cannot address another device.', @@ -605,7 +611,7 @@ const TRANSPORT_MISMATCH_MESSAGES = { function transportMismatch(scope: keyof typeof TRANSPORT_MISMATCH_MESSAGES): never { throw new AppError('COMMAND_FAILED', TRANSPORT_MISMATCH_MESSAGES[scope], { - reason: 'managed-device-transport-mismatch', + reason: MANAGED_TRANSPORT_REASONS.transportMismatch.reason, }); } diff --git a/packages/platform-android/src/app-lifecycle.ts b/packages/platform-android/src/app-lifecycle.ts index 9976a09ef6..a9a74ff5e1 100644 --- a/packages/platform-android/src/app-lifecycle.ts +++ b/packages/platform-android/src/app-lifecycle.ts @@ -1,4 +1,4 @@ -import { AppError } from '@agent-device/kernel/errors'; +import { AppError, type ReasonTable } from '@agent-device/kernel/errors'; import type { AppStateRuntimeResult } from '@agent-device/contracts/app-state-runtime'; import { Deadline, sleep } from '@agent-device/host-kit/retry'; import { isCommandTimeoutError } from '@agent-device/host-kit/command'; @@ -27,6 +27,40 @@ import { import { androidLaunchCategory, androidLauncherCategories } from './launcher-categories.ts'; import { getAndroidAppState, getAndroidResumedActivity } from './window-state.ts'; +/** The `open` refusals this module states in `error.details.reason`. */ +const ANDROID_APP_OPEN_REASONS = { + // The `--activity` value is not an Android component name. + invalidActivityComponent: { reason: 'invalid-android-activity-component' }, + // The app the helper launched never reached the foreground before the launch budget ran out. + launchNotForeground: { reason: 'android-launch-not-foreground' }, +} as const satisfies ReasonTable<'open'>; + +/** + * The `close` refusals this module states in `error.details.reason`. `open --relaunch` stops the app + * through the same fences, so the timeout and the probe refusal name `open` too. A Maestro flow's + * `killApp` step guards its kill with the probe refusal too, so `replay` and `test` name it. + */ +const ANDROID_APP_CLOSE_REASONS = { + // A stop fence ended before the app left the foreground or its killed processes exited. + appCloseTimeout: { reason: 'android-app-close-timeout', commands: ['open'] }, + // `adb pidof` or the resumed-activity read did not answer, so process state is unknown. + processProbeUnavailable: { + reason: 'android-process-probe-unavailable', + commands: ['open', 'replay', 'test'], + }, +} as const satisfies ReasonTable<'close'>; + +/** The refusals only a Maestro flow's `killApp` step raises, through `killAndroidPackage`. */ +const ANDROID_APP_KILL_REASONS = { + // `am kill` returned and the process is still running; force-stop it instead. + killProcessSurvived: { reason: 'android-kill-process-survived', commands: ['test'] }, + // `am kill` only reaps background processes, so it refuses the foreground app. + killRequiresBackgroundApp: { + reason: 'android-kill-requires-background-app', + commands: ['test'], + }, +} as const satisfies ReasonTable<'replay'>; + const ANDROID_DEFAULT_CATEGORY = 'android.intent.category.DEFAULT'; const ANDROID_LOCALHOST_HOSTNAMES = new Set(['localhost', '127.0.0.1', '::1', '[::1]']); /** Owns localhost URL reverses, so a teardown that removes only owned mappings removes them too. */ @@ -169,7 +203,7 @@ const ANDROID_ACTIVITY_COMPONENT = new RegExp( function requireAndroidActivityComponent(activity: string): void { if (ANDROID_ACTIVITY_COMPONENT.test(activity)) return; throw new AppError('INVALID_ARGS', `Invalid Android activity component: ${activity}`, { - reason: 'invalid-android-activity-component', + reason: ANDROID_APP_OPEN_REASONS.invalidActivityComponent.reason, activity, hint: 'Pass --activity as /, ., or , using letters, digits, `_`, `.`, and `$`.', }); @@ -273,7 +307,7 @@ async function tryAndroidHelperLaunch( 'COMMAND_FAILED', 'Android helper launch timed out before the application reached the foreground', { - reason: 'android-launch-not-foreground', + reason: ANDROID_APP_OPEN_REASONS.launchNotForeground.reason, packageName, stdout, timeoutMs: ANDROID_HELPER_OPEN_TIMEOUT_MS, @@ -659,7 +693,7 @@ async function killAndroidPackage(device: DeviceInfo, packageName: string): Prom const resumed = await getAndroidResumedActivity(device); if (resumed.status === 'resumed' && resumed.package === packageName) { throw new AppError('COMMAND_FAILED', `Cannot kill foreground app ${packageName}`, { - reason: 'android-kill-requires-background-app', + reason: ANDROID_APP_KILL_REASONS.killRequiresBackgroundApp.reason, hint: 'Background the app before killApp (for example pressKey: Home): am kill only reaps background processes.', }); } @@ -668,7 +702,7 @@ async function killAndroidPackage(device: DeviceInfo, packageName: string): Prom 'COMMAND_FAILED', `Could not read resumed activity state before killing ${packageName}`, { - reason: 'android-process-probe-unavailable', + reason: ANDROID_APP_CLOSE_REASONS.processProbeUnavailable.reason, hint: 'adb dumpsys did not answer; retry once the device is reachable.', }, ); @@ -681,7 +715,7 @@ async function killAndroidPackage(device: DeviceInfo, packageName: string): Prom const process = await readAndroidPackageProcessState(device, packageName); if (process === 'running') { throw new AppError('COMMAND_FAILED', `am kill did not stop ${packageName}`, { - reason: 'android-kill-process-survived', + reason: ANDROID_APP_KILL_REASONS.killProcessSurvived.reason, hint: 'The process survived am kill (for example a foreground service keeps it alive): use stopApp (am force-stop) to terminate it.', }); } @@ -692,7 +726,7 @@ async function killAndroidPackage(device: DeviceInfo, packageName: string): Prom function androidPidofUnavailableError(packageName: string): AppError { return new AppError('COMMAND_FAILED', `Could not read process state for ${packageName}`, { - reason: 'android-process-probe-unavailable', + reason: ANDROID_APP_CLOSE_REASONS.processProbeUnavailable.reason, hint: 'adb pidof did not answer; retry once the device is reachable.', }); } @@ -734,7 +768,7 @@ const ANDROID_CLOSE_TIMEOUTS: Record< function androidCloseTimeoutError(packageName: string, phase: AndroidStopFencePhase): AppError { const { message, timeoutMs } = ANDROID_CLOSE_TIMEOUTS[phase]; return new AppError('COMMAND_FAILED', `Android app ${packageName} ${message}`, { - reason: 'android-app-close-timeout', + reason: ANDROID_APP_CLOSE_REASONS.appCloseTimeout.reason, phase, packageName, timeoutMs, diff --git a/packages/platform-android/src/automation-helper.ts b/packages/platform-android/src/automation-helper.ts index 3331fad5de..2eaa8fab45 100644 --- a/packages/platform-android/src/automation-helper.ts +++ b/packages/platform-android/src/automation-helper.ts @@ -1,4 +1,4 @@ -import { AppError } from '@agent-device/kernel/errors'; +import { AppError, type ReasonTable } from '@agent-device/kernel/errors'; import type { DeviceInfo } from '@agent-device/kernel/device'; import { getLiveAndroidSnapshotHelperSession, @@ -145,6 +145,11 @@ function decodeHelperIndex(value: string | undefined): number | undefined { return value !== undefined && /^\d+$/.test(value) ? Number(value) : undefined; } +const ANDROID_HELPER_INPUT_REASONS = { + // The request had no room left for one helper input attempt, so nothing was sent. + budgetExhausted: { reason: 'android-input-budget-exhausted' }, +} as const satisfies ReasonTable<'android input'>; + /** * The host waits for input up to its cap, or until the request's own deadline when that is sooner. * A request with no room for one attempt is refused before anything is sent. The refusal is thrown @@ -163,7 +168,7 @@ function admitInputTimeoutMs(): number { 'COMMAND_FAILED', 'Android input was not sent: the request has too little time left for one attempt', { - reason: 'android-input-budget-exhausted', + reason: ANDROID_HELPER_INPUT_REASONS.budgetExhausted.reason, remainingMs: timeoutMs, minimumMs: MIN_INPUT_ATTEMPT_MS, dispatched: 'no', diff --git a/packages/platform-android/src/clipboard-shell-response.test.ts b/packages/platform-android/src/clipboard-shell-response.test.ts index a909ea232f..d1c965dbc0 100644 --- a/packages/platform-android/src/clipboard-shell-response.test.ts +++ b/packages/platform-android/src/clipboard-shell-response.test.ts @@ -4,7 +4,6 @@ import { normalizeError } from '@agent-device/kernel/errors'; import { androidClipboardShellCommandUnavailableError, androidClipboardShellSupportForVerdict, - ANDROID_CLIPBOARD_SHELL_COMMAND_UNAVAILABLE_REASON, classifyAndroidClipboardShellResponse, } from './clipboard-shell-response.ts'; @@ -107,7 +106,7 @@ test('clipboard shell refusal is dispatchable and names the substitute', () => { assert.equal(error.code, 'UNSUPPORTED_OPERATION'); assert.equal( (error.details as { reason?: unknown }).reason, - ANDROID_CLIPBOARD_SHELL_COMMAND_UNAVAILABLE_REASON, + 'android_clipboard_shell_command_unavailable', ); assert.match(String(normalizeError(error).hint), /pasting into a focused field/); }); diff --git a/packages/platform-android/src/clipboard-shell-response.ts b/packages/platform-android/src/clipboard-shell-response.ts index 8e25d96fbf..424e951e9c 100644 --- a/packages/platform-android/src/clipboard-shell-response.ts +++ b/packages/platform-android/src/clipboard-shell-response.ts @@ -1,5 +1,5 @@ import type { AndroidClipboardShellSupport } from '@agent-device/contracts/android-clipboard-support'; -import { AppError } from '@agent-device/kernel/errors'; +import { AppError, type ReasonTable } from '@agent-device/kernel/errors'; import type { AndroidAdbExecutorResult } from './adb-executor.ts'; import { isAndroidShellCommandUnsupported, reportsAndroidNoShellCommand } from './adb.ts'; @@ -9,8 +9,11 @@ export type AndroidClipboardShellVerdict = 'executed' | 'no-shell-command' | 'ca /** Which clipboard subcommand was called, shared by the refusal wording and the reason. */ export type AndroidClipboardOperation = 'read' | 'write'; -export const ANDROID_CLIPBOARD_SHELL_COMMAND_UNAVAILABLE_REASON = - 'android_clipboard_shell_command_unavailable' as const; +/** Why an Android shell clipboard call refuses at all. */ +const ANDROID_CLIPBOARD_REASONS = { + // This Android build ships no shell command for the clipboard service. + shellCommandUnavailable: { reason: 'android_clipboard_shell_command_unavailable' }, +} as const satisfies ReasonTable<'clipboard'>; /** * What to do instead, carried by both the fact that refuses admission and the error that refuses @@ -80,7 +83,7 @@ export function androidClipboardShellCommandUnavailableError( 'UNSUPPORTED_OPERATION', `Android shell clipboard ${operation} is not supported on this device.`, { - reason: ANDROID_CLIPBOARD_SHELL_COMMAND_UNAVAILABLE_REASON, + reason: ANDROID_CLIPBOARD_REASONS.shellCommandUnavailable.reason, hint: ANDROID_CLIPBOARD_SHELL_COMMAND_UNAVAILABLE_HINT, }, ); diff --git a/packages/platform-android/src/helper-artifacts.ts b/packages/platform-android/src/helper-artifacts.ts index 8152e3af34..55a6ad8086 100644 --- a/packages/platform-android/src/helper-artifacts.ts +++ b/packages/platform-android/src/helper-artifacts.ts @@ -1,4 +1,4 @@ -import { AppError } from '@agent-device/kernel/errors'; +import { AppError, type ReasonTable } from '@agent-device/kernel/errors'; // Provider-boundary artifact vocabulary for the Android helper APKs. An adb provider may ship // its own helper artifacts (exactly as the SDK seam allows), so these shapes cross the @@ -49,17 +49,47 @@ export type AndroidHelperInstallDecision = { installedVersionCode?: number; installedSha256?: string; installed: boolean; - reason: 'missing' | 'outdated' | 'mismatched' | 'unverifiable' | 'current'; + reason: AndroidHelperInstallStateReason | 'current'; }; +/** + * Why the helper APK already on the device is not the bundled one. The install that follows the + * refusal publishes the state as `error.details.reason` when the push fails. `current` is a + * decision state that is never published, so it has no row. + */ +export const ANDROID_HELPER_INSTALL_STATE_REASONS = { + // The device has no package installed under the helper's name. + missing: { reason: 'missing' }, + // The installed helper's versionCode is below the bundled artifact's. + outdated: { reason: 'outdated' }, + // The installed helper matches the artifact's versionCode but not its APK checksum. + mismatched: { reason: 'mismatched' }, + // The installed helper's APK checksum could not be read, so its currency stays unproven. + unverifiable: { reason: 'unverifiable' }, +} as const satisfies ReasonTable<'android helper install'>; + +type AndroidHelperInstallStateRows = typeof ANDROID_HELPER_INSTALL_STATE_REASONS; +type AndroidHelperInstallStateReason = + AndroidHelperInstallStateRows[keyof AndroidHelperInstallStateRows]['reason']; + export type InstalledAndroidHelperState = - | { reason: 'missing'; installedVersionCode?: never; installedSha256?: never } | { - reason: 'outdated' | 'unverifiable'; + reason: AndroidHelperInstallStateRows['missing']['reason']; + installedVersionCode?: never; + installedSha256?: never; + } + | { + reason: + | AndroidHelperInstallStateRows['outdated']['reason'] + | AndroidHelperInstallStateRows['unverifiable']['reason']; installedVersionCode: number; installedSha256?: never; } - | { reason: 'mismatched'; installedVersionCode: number; installedSha256: string } + | { + reason: AndroidHelperInstallStateRows['mismatched']['reason']; + installedVersionCode: number; + installedSha256: string; + } | { reason: 'current'; installedVersionCode: number; installedSha256?: string }; // --- Manifest field validators, shared by every helper's manifest parser --------------------- diff --git a/packages/platform-android/src/helper-package-install.ts b/packages/platform-android/src/helper-package-install.ts index 7ff0c30170..af82ef01b1 100644 --- a/packages/platform-android/src/helper-package-install.ts +++ b/packages/platform-android/src/helper-package-install.ts @@ -13,9 +13,10 @@ import { import type { AndroidAdbPackageInstallOptions } from './adb-transfer.ts'; import { attachAndroidHelperInstallTimeoutHint } from './adb-failure.ts'; import { requireAndroidAdbHost } from './adb-host.ts'; -import type { - AndroidHelperInstallDecision, - InstalledAndroidHelperState, +import { + ANDROID_HELPER_INSTALL_STATE_REASONS, + type AndroidHelperInstallDecision, + type InstalledAndroidHelperState, } from './helper-artifacts.ts'; // Shared install/version-check/checksum lifecycle for the three Android helper APKs. @@ -134,8 +135,13 @@ export async function inspectInstalledAndroidHelper(options: { packageName, signal, ); - if (installedVersionCode === undefined) return { reason: 'missing' }; - if (installedVersionCode < versionCode) return { installedVersionCode, reason: 'outdated' }; + if (installedVersionCode === undefined) + return { reason: ANDROID_HELPER_INSTALL_STATE_REASONS.missing.reason }; + if (installedVersionCode < versionCode) + return { + installedVersionCode, + reason: ANDROID_HELPER_INSTALL_STATE_REASONS.outdated.reason, + }; if (installedVersionCode > versionCode) return { installedVersionCode, reason: 'current' }; try { @@ -148,11 +154,17 @@ export async function inspectInstalledAndroidHelper(options: { return { installedVersionCode, installedSha256, - reason: installedSha256 === sha256 ? 'current' : 'mismatched', + reason: + installedSha256 === sha256 + ? 'current' + : ANDROID_HELPER_INSTALL_STATE_REASONS.mismatched.reason, }; } catch { signal?.throwIfAborted(); - return { installedVersionCode, reason: 'unverifiable' }; + return { + installedVersionCode, + reason: ANDROID_HELPER_INSTALL_STATE_REASONS.unverifiable.reason, + }; } } diff --git a/packages/platform-android/src/ime-helper.ts b/packages/platform-android/src/ime-helper.ts index 92436758ae..97836fc16e 100644 --- a/packages/platform-android/src/ime-helper.ts +++ b/packages/platform-android/src/ime-helper.ts @@ -1,7 +1,4 @@ -import { - ANDROID_IME_HELPER_DISPATCH_REJECTED_REASON, - ANDROID_IME_HELPER_NO_ACK_REASON, -} from '@agent-device/contracts/command'; +import { ANDROID_TEXT_CHANNEL_REASONS } from '@agent-device/contracts/command'; import { AppError } from '@agent-device/kernel/errors'; import type { DeviceInfo } from '@agent-device/kernel/device'; import { isCommandTimeoutError } from '@agent-device/host-kit/command'; @@ -341,8 +338,8 @@ function assertCommittedOutcome( backend: 'test-ime', reason: outcome.kind === 'no-ack' - ? ANDROID_IME_HELPER_NO_ACK_REASON - : ANDROID_IME_HELPER_DISPATCH_REJECTED_REASON, + ? ANDROID_TEXT_CHANNEL_REASONS.imeHelperNoAck.reason + : ANDROID_TEXT_CHANNEL_REASONS.imeHelperDispatchRejected.reason, dispatchKind: outcome.kind, ...(outcome.kind === 'no-ack' ? { diff --git a/packages/platform-android/src/recording/start-reconciliation.ts b/packages/platform-android/src/recording/start-reconciliation.ts index 73108cf12e..9e9bc13c26 100644 --- a/packages/platform-android/src/recording/start-reconciliation.ts +++ b/packages/platform-android/src/recording/start-reconciliation.ts @@ -1,5 +1,5 @@ import type { DeviceInfo } from '@agent-device/kernel/device'; -import { AppError } from '@agent-device/kernel/errors'; +import { AppError, type ReasonTable } from '@agent-device/kernel/errors'; import type { PlatformRuntimeHost } from '@agent-device/contracts/platform-runtime-operations'; import { provesAndroidScreenRecordPathUnclaimed } from '@agent-device/contracts/screen-recording-runtime-host'; import { candidateRemotePaths, cleanupChunks } from './chunks.ts'; @@ -116,12 +116,35 @@ async function removePendingArtifact( if (!(await transport.remove(pendingPath))) throw artifactRemovalFailed(pendingPath); } +/** + * Why `record start` refuses over the native recovery evidence one Android screenrecord leaves on + * the device. + */ +const NATIVE_RECOVERY_EVIDENCE_REASONS = { + // The marker exists but the device could not be read, so it cannot be classified. + unavailable: { reason: 'native_recovery_evidence_unavailable' }, + // The marker exists but does not decode, so nothing about it can be verified. + unreadable: { reason: 'native_recovery_evidence_unreadable' }, + // The marker was written by the other adb transport, so this one must not retire it. + transportMismatch: { reason: 'native_recovery_evidence_transport_mismatch' }, + // An open recording still owns the marker; only its own session's stop or close retires it. + evidenceOpen: { reason: 'native_recovery_evidence_open' }, + // A recorder is still writing the pending artifact, so removing it would cut a clip short. + artifactClaimed: { reason: 'native_recording_artifact_claimed' }, + // The device refused to remove the pending artifact, so the marker has to stay. + artifactRemovalFailed: { reason: 'native_recording_artifact_removal_failed' }, + // The marker read back after removal, so its retirement is not proven. + retirementUnconfirmed: { reason: 'native_recovery_evidence_retirement_unconfirmed' }, + // The probe could not prove no recorder is writing the pending artifact. + recorderUnproven: { reason: 'native_recording_recorder_unproven' }, +} as const satisfies ReasonTable<'record'>; + function unavailableEvidence(manifestPath: string, probeMessage: string): AppError { return new AppError( 'COMMAND_FAILED', `Android screenrecord native recovery evidence is unavailable: ${manifestPath}`, { - reason: 'native_recovery_evidence_unavailable', + reason: NATIVE_RECOVERY_EVIDENCE_REASONS.unavailable.reason, manifestPath, hint: 'Confirm the device is online and its storage readable, then run record start again.', }, @@ -134,7 +157,7 @@ function corruptEvidence(manifestPath: string): AppError { 'COMMAND_FAILED', `Android screenrecord native recovery evidence is unreadable: ${manifestPath}`, { - reason: 'native_recovery_evidence_unreadable', + reason: NATIVE_RECOVERY_EVIDENCE_REASONS.unreadable.reason, manifestPath, hint: markerRemovalHint(manifestPath), }, @@ -150,7 +173,7 @@ function foreignTransportEvidence( 'COMMAND_FAILED', `Android screenrecord native recovery evidence was written by the ${evidence.transportMode} transport, not this ${transportMode} one: ${manifestPath}`, { - reason: 'native_recovery_evidence_transport_mismatch', + reason: NATIVE_RECOVERY_EVIDENCE_REASONS.transportMismatch.reason, manifestPath, evidenceTransportMode: evidence.transportMode, hint: markerRemovalHint(manifestPath), @@ -167,7 +190,7 @@ function openEvidenceOnDevice( 'DEVICE_IN_USE', `Android screenrecord native recovery evidence already exists: ${manifestPath} (open recording of session "${evidence.sessionId}" on ${device.id})`, { - reason: 'native_recovery_evidence_open', + reason: NATIVE_RECOVERY_EVIDENCE_REASONS.evidenceOpen.reason, manifestPath, sessionId: evidence.sessionId, // Retrying this start cannot free the marker; only the owning session's stop or close can. @@ -188,7 +211,7 @@ function artifactClaimed( named ? 'its recorder' : 'another recorder' } is writing ${remotePath}`, { - reason: 'native_recording_artifact_claimed', + reason: NATIVE_RECOVERY_EVIDENCE_REASONS.artifactClaimed.reason, remotePath, writer, // A recorder this marker names is a live recording: only its owner's stop frees it. An @@ -206,7 +229,7 @@ function artifactRemovalFailed(remotePath: string): AppError { 'COMMAND_FAILED', `Android screenrecord recovery evidence could not remove ${remotePath}`, { - reason: 'native_recording_artifact_removal_failed', + reason: NATIVE_RECOVERY_EVIDENCE_REASONS.artifactRemovalFailed.reason, remotePath, hint: 'Confirm the device is online and run record start again.', }, @@ -218,7 +241,7 @@ function retirementUnconfirmed(manifestPath: string): AppError { 'COMMAND_FAILED', `Android screenrecord recovery evidence removal could not be confirmed: ${manifestPath}`, { - reason: 'native_recovery_evidence_retirement_unconfirmed', + reason: NATIVE_RECOVERY_EVIDENCE_REASONS.retirementUnconfirmed.reason, manifestPath, hint: 'Run record start again; the marker is retired from the beginning.', }, @@ -230,7 +253,7 @@ function unprovenRecorder(remotePath: string): AppError { 'COMMAND_FAILED', `Android screenrecord recovery evidence cannot be safely retired: ${remotePath}`, { - reason: 'native_recording_recorder_unproven', + reason: NATIVE_RECOVERY_EVIDENCE_REASONS.recorderUnproven.reason, remotePath, hint: 'Confirm the device is online and run record start again.', }, diff --git a/packages/platform-android/src/settings-bluetooth.ts b/packages/platform-android/src/settings-bluetooth.ts index 5a37b04243..816f21e30f 100644 --- a/packages/platform-android/src/settings-bluetooth.ts +++ b/packages/platform-android/src/settings-bluetooth.ts @@ -5,13 +5,23 @@ import { androidAdbResultError } from './adb-failure.ts'; import { readAndroidSdkInt } from './device-sdk-int.ts'; import { androidFeatureListDeclares } from './inventory-parsers.ts'; import { + ANDROID_GLOBAL_TOGGLE_REASONS, setAndroidGlobalToggle, type AndroidGlobalToggle, type AndroidToggleState, } from './settings-global-toggle.ts'; +import type { ReasonTable } from '@agent-device/kernel/errors'; -const NO_BLUETOOTH_ADAPTER_REASON = 'android_bluetooth_adapter_missing'; -const BLUETOOTH_COMMAND_UNAVAILABLE_REASON = 'android_bluetooth_command_unavailable'; +/** + * The `error.details.reason` the Bluetooth adapter and API-level checks state before the write, both + * of which refuse with nothing changed. + */ +const BLUETOOTH_PREWRITE_REASONS = { + // The device declares no Bluetooth adapter, so there is nothing to turn on or off. + adapterMissing: { reason: 'android_bluetooth_adapter_missing' }, + // The build predates `svc bluetooth`, so the adapter cannot be switched from the shell. + commandUnavailable: { reason: 'android_bluetooth_command_unavailable' }, +} as const satisfies ReasonTable<'settings'>; /** Without this feature no Bluetooth service starts, and `svc bluetooth` exits 0 having done nothing. */ const BLUETOOTH_FEATURE = 'android.hardware.bluetooth'; @@ -36,8 +46,8 @@ const BLUETOOTH_TOGGLE: AndroidGlobalToggle<'bluetooth'> = { if (storedValue === '0' || storedValue === '2') return 'disabled'; return undefined; }, - notAppliedReason: 'bluetooth-not-applied', - unreadableReason: 'bluetooth-unreadable', + notAppliedReason: ANDROID_GLOBAL_TOGGLE_REASONS.bluetoothNotApplied.reason, + unreadableReason: ANDROID_GLOBAL_TOGGLE_REASONS.bluetoothUnreadable.reason, sampleIntervalMs: 200, hint: 'A device policy or user restriction can block Bluetooth changes. Run `adb shell settings get global bluetooth_on` to see what the device holds.', }; @@ -74,7 +84,7 @@ async function requireAndroidSvcBluetooth( 'UNSUPPORTED_OPERATION', 'This Android device has no Bluetooth adapter, so nothing was changed.', { - reason: NO_BLUETOOTH_ADAPTER_REASON, + reason: BLUETOOTH_PREWRITE_REASONS.adapterMissing.reason, deviceId: device.id, hint: `Some emulator images ship without Bluetooth. Use a device or emulator image whose pm list features includes ${BLUETOOTH_FEATURE}.`, }, @@ -93,7 +103,7 @@ async function requireAndroidSvcBluetooth( 'UNSUPPORTED_OPERATION', 'This Android build has no shell command for Bluetooth, so nothing was changed.', { - reason: BLUETOOTH_COMMAND_UNAVAILABLE_REASON, + reason: BLUETOOTH_PREWRITE_REASONS.commandUnavailable.reason, deviceId: device.id, sdkInt, hint: 'settings bluetooth needs svc bluetooth, which requires Android 8.1 (API 27) or newer. Use a newer device or emulator image.', diff --git a/packages/platform-android/src/settings-global-toggle.ts b/packages/platform-android/src/settings-global-toggle.ts index 3780bbd849..4801aa7ae3 100644 --- a/packages/platform-android/src/settings-global-toggle.ts +++ b/packages/platform-android/src/settings-global-toggle.ts @@ -7,6 +7,26 @@ import { import type { DeviceInfo } from '@agent-device/kernel/device'; import { runAndroidShell } from './adb.ts'; import { androidAdbResultError } from './adb-failure.ts'; +import type { ReasonTable } from '@agent-device/kernel/errors'; + +/** + * The `error.details.reason` pair a global-toggle read-back answers with, shared by every toggle + * `setAndroidGlobalToggle` runs. Each toggle names which two rows it hands over. + */ +export const ANDROID_GLOBAL_TOGGLE_REASONS = { + // The device kept Bluetooth in its prior state after `svc bluetooth` accepted the request. + bluetoothNotApplied: { reason: 'bluetooth-not-applied' }, + // The device answered the Bluetooth read-back with a value that is not a known state. + bluetoothUnreadable: { reason: 'bluetooth-unreadable' }, + // The device kept mobile data in its prior state after `svc data` accepted the request. + mobileDataNotApplied: { reason: 'mobile-data-not-applied' }, + // The device answered the mobile-data read-back with a value that is neither 0 nor 1. + mobileDataUnreadable: { reason: 'mobile-data-unreadable' }, +} as const satisfies ReasonTable<'settings'>; + +/** The reason spellings a global-toggle read-back publishes, as `error.details.reason`. */ +export type AndroidGlobalToggleReason = + (typeof ANDROID_GLOBAL_TOGGLE_REASONS)[keyof typeof ANDROID_GLOBAL_TOGGLE_REASONS]['reason']; export type AndroidToggleState = 'enabled' | 'disabled'; @@ -25,8 +45,10 @@ export type AndroidGlobalToggle = Readonly<{ /** The key the toggle's state is reported under, on success and in failure details. */ stateKey: Key; parseRow: (storedValue: string) => AndroidToggleState | undefined; - notAppliedReason: string; - unreadableReason: string; + /** Why to report when the row settled on the other state: a row of `ANDROID_GLOBAL_TOGGLE_REASONS`. */ + notAppliedReason: AndroidGlobalToggleReason; + /** Why to report when the final read is no known state: a row of `ANDROID_GLOBAL_TOGGLE_REASONS`. */ + unreadableReason: AndroidGlobalToggleReason; sampleIntervalMs: number; hint: string; }>; diff --git a/packages/platform-android/src/settings.ts b/packages/platform-android/src/settings.ts index cc69686d4a..4b0ad93361 100644 --- a/packages/platform-android/src/settings.ts +++ b/packages/platform-android/src/settings.ts @@ -3,6 +3,7 @@ import { sessionAppRequiredDetails, summarizeCommandAttemptFailures, type CommandAttemptFailure, + type ReasonTable, } from '@agent-device/kernel/errors'; import type { DeviceInfo } from '@agent-device/kernel/device'; import { deviceShellArgv } from '@agent-device/kernel/device-shell'; @@ -12,7 +13,6 @@ import { parseSettingState, parseTextSizeCategory, resolveSettingsApp, - SETTINGS_APP_NOT_PACKAGE_REASON, textSizeSettingPayload, type ReadSettingResult, type SettingOptions, @@ -25,7 +25,11 @@ import { } from '@agent-device/contracts/settings-catalog'; import { runAndroidAdb, runAndroidShell } from './adb.ts'; import { setAndroidAirplaneMode } from './settings-airplane.ts'; -import { setAndroidGlobalToggle, type AndroidGlobalToggle } from './settings-global-toggle.ts'; +import { + ANDROID_GLOBAL_TOGGLE_REASONS, + setAndroidGlobalToggle, + type AndroidGlobalToggle, +} from './settings-global-toggle.ts'; import { androidAdbResultError } from './adb-executor.ts'; import { resolveAndroidApp } from './app-deployment-resolution.ts'; import { @@ -34,6 +38,15 @@ import { setAndroidPermission, } from './settings-permission.ts'; +/** + * The `error.details.reason` an app-scoped `settings` change states when the name it was handed + * resolves to nothing it can grant or revoke. + */ +const ANDROID_SETTINGS_APP_REASONS = { + // The named app resolves to an intent such as `settings`, not to an installed package. + appNotPackage: { reason: 'setting_app_not_package' }, +} as const satisfies ReasonTable<'settings'>; + /** The settings {@link setAndroidSetting} applies over adb, wherever an owner runs it. */ export const ANDROID_SETTINGS = [ 'wifi', @@ -227,7 +240,7 @@ async function resolveAndroidSettingsPackage( 'INVALID_ARGS', `settings ${setting} requires a package name, not an intent.`, { - reason: SETTINGS_APP_NOT_PACKAGE_REASON, + reason: ANDROID_SETTINGS_APP_REASONS.appNotPackage.reason, dispatched: 'no', app, hint: 'Run apps --all for the exact package name, then retry with it in --app.', @@ -316,8 +329,8 @@ const MOBILE_DATA_TOGGLE: AndroidGlobalToggle<'mobileData'> = { if (storedValue === '0') return 'disabled'; return undefined; }, - notAppliedReason: 'mobile-data-not-applied', - unreadableReason: 'mobile-data-unreadable', + notAppliedReason: ANDROID_GLOBAL_TOGGLE_REASONS.mobileDataNotApplied.reason, + unreadableReason: ANDROID_GLOBAL_TOGGLE_REASONS.mobileDataUnreadable.reason, sampleIntervalMs: 100, hint: 'Run `adb shell settings get global mobile_data` to see what the device holds. A target without an active SIM, or with more than one, can accept svc data without changing that row.', }; diff --git a/packages/platform-android/src/shake/console-shake.ts b/packages/platform-android/src/shake/console-shake.ts index 92294edba9..14093b72a9 100644 --- a/packages/platform-android/src/shake/console-shake.ts +++ b/packages/platform-android/src/shake/console-shake.ts @@ -1,6 +1,6 @@ import { sleep } from '@agent-device/host-kit/retry'; import type { DeviceInfo } from '@agent-device/kernel/device'; -import { AppError } from '@agent-device/kernel/errors'; +import { AppError, type ReasonTable } from '@agent-device/kernel/errors'; import { runEmulatorConsole } from '../emulator-console.ts'; @@ -16,18 +16,16 @@ const SHAKE_SWING_MS = 80; const CONSOLE_REFUSED_HINT = 'The emulator console refused the accelerometer command. An emulator image without an acceleration sensor has nothing to shake.'; +const REST_UNREADABLE_MESSAGE = 'The emulator console returned no accelerometer reading'; +const CONSOLE_REFUSED_MESSAGE = 'The emulator console refused the shake'; /** The failures a shake publishes as `error.details.reason`; commands.md documents each one. */ -const SHAKE_FAILURES = { - restUnreadable: { - reason: 'shake-rest-acceleration-unreadable', - message: 'The emulator console returned no accelerometer reading', - }, - consoleRefused: { - reason: 'shake-console-refused', - message: 'The emulator console refused the shake', - }, -} as const satisfies Record>; +const SHAKE_REASONS = { + // The console gave no accelerometer reading to restore afterwards, so nothing was sent. + restUnreadable: { reason: 'shake-rest-acceleration-unreadable' }, + // The emulator console refused an accelerometer command; `details.consoleReason` is its reply. + consoleRefused: { reason: 'shake-console-refused' }, +} as const satisfies ReasonTable<'shake'>; type Acceleration = readonly [x: string, y: string, z: string]; @@ -64,9 +62,9 @@ async function readRestAcceleration( if (reply.refusal !== undefined) throw consoleRefused(device, reply, { dispatched: 'no' }); const reading = /^acceleration\s*=\s*([^:\s]+):([^:\s]+):([^:\s]+)\s*$/m.exec(reply.stdout); if (!reading || reading.slice(1).some((axis) => !Number.isFinite(Number(axis)))) { - throw new AppError('COMMAND_FAILED', SHAKE_FAILURES.restUnreadable.message, { + throw new AppError('COMMAND_FAILED', REST_UNREADABLE_MESSAGE, { deviceId: device.id, - reason: SHAKE_FAILURES.restUnreadable.reason, + reason: SHAKE_REASONS.restUnreadable.reason, dispatched: 'no', stdout: reply.stdout.trim(), }); @@ -92,9 +90,9 @@ function consoleRefused( reply: Readonly<{ stdout: string; refusal?: string }>, extra: Readonly<{ dispatched?: 'no' }> = {}, ): AppError { - return new AppError('COMMAND_FAILED', SHAKE_FAILURES.consoleRefused.message, { + return new AppError('COMMAND_FAILED', CONSOLE_REFUSED_MESSAGE, { deviceId: device.id, - reason: SHAKE_FAILURES.consoleRefused.reason, + reason: SHAKE_REASONS.consoleRefused.reason, ...extra, stdout: reply.stdout.trim(), ...(reply.refusal ? { consoleReason: reply.refusal } : {}), diff --git a/packages/platform-android/src/snapshot-helper-install.ts b/packages/platform-android/src/snapshot-helper-install.ts index c95ee7e953..d8ea262eae 100644 --- a/packages/platform-android/src/snapshot-helper-install.ts +++ b/packages/platform-android/src/snapshot-helper-install.ts @@ -1,4 +1,4 @@ -import { AppError, asAppError } from '@agent-device/kernel/errors'; +import { AppError, asAppError, type ReasonTable } from '@agent-device/kernel/errors'; import { inspectInstalledAndroidHelper, installAndroidHelperPackage, @@ -29,16 +29,20 @@ export function forgetAndroidSnapshotHelperInstall(options: { } } -/** - * @internal Test isolation hook for process-global snapshot helper install cache. - */ -const ANDROID_SNAPSHOT_HELPER_NOT_CURRENT = 'android-snapshot-helper-not-current'; +/** Why a snapshot capture refuses before it installs anything. */ +const SNAPSHOT_HELPER_INSTALL_REASONS = { + // A current-only check found no current helper: nothing ran, so there is nothing to recover. + notCurrent: { reason: 'android-snapshot-helper-not-current' }, +} as const satisfies ReasonTable<'android snapshot helper'>; /** A `current-only` check found no current helper: nothing ran, so there is nothing to recover. */ export function isAndroidSnapshotHelperNotCurrentError(error: unknown): boolean { - return asAppError(error).details?.reason === ANDROID_SNAPSHOT_HELPER_NOT_CURRENT; + return asAppError(error).details?.reason === SNAPSHOT_HELPER_INSTALL_REASONS.notCurrent.reason; } +/** + * @internal Test isolation hook for process-global snapshot helper install cache. + */ export function resetAndroidSnapshotHelperInstallCache(): void { installedSnapshotHelpers.clear(); } @@ -149,7 +153,7 @@ export async function ensureAndroidSnapshotHelper(options: { 'COMMAND_FAILED', 'Android snapshot helper is not installed at the current version', { - reason: ANDROID_SNAPSHOT_HELPER_NOT_CURRENT, + reason: SNAPSHOT_HELPER_INSTALL_REASONS.notCurrent.reason, packageName, versionCode, installedVersionCode, diff --git a/packages/platform-android/src/snapshot-helper-retirement.ts b/packages/platform-android/src/snapshot-helper-retirement.ts index 2a12f81f85..a851114173 100644 --- a/packages/platform-android/src/snapshot-helper-retirement.ts +++ b/packages/platform-android/src/snapshot-helper-retirement.ts @@ -1,5 +1,5 @@ import { runtimeSlot } from '@agent-device/host-kit/runtime-slots'; -import { AppError } from '@agent-device/kernel/errors'; +import { AppError, type ReasonTable } from '@agent-device/kernel/errors'; import type { DeviceInfo } from '@agent-device/kernel/device'; import { shellFragment } from '@agent-device/kernel/device-shell'; import { emitDiagnostic } from '@agent-device/host-kit/diagnostics'; @@ -18,7 +18,14 @@ const RUNTIME_OCCUPANCY_RECHECK_MS = 250; // time out before Android could confirm UiAutomation release. export const ANDROID_SNAPSHOT_HELPER_HOST_PROCESS_EXIT_GRACE_MS = 250; export const ANDROID_SNAPSHOT_HELPER_DEVICE_RETIREMENT_TIMEOUT_MS = 2_000; -const RUNTIME_OCCUPIED_REASON = 'android_snapshot_helper_runtime_occupied'; +/** + * Why a command cannot take the device automation runtime at all. The retirement runs for the + * snapshot capture and the helper-backed touch commands alike. + */ +const SNAPSHOT_HELPER_RUNTIME_REASONS = { + // Another helper process still holds UiAutomation, so nothing can take the runtime. + runtimeOccupied: { reason: 'android_snapshot_helper_runtime_occupied' }, +} as const satisfies ReasonTable<'android snapshot helper'>; /** * Printed by the device's own shell, and only by it, when the helper process is not running. * Exported so a fake device can answer with the real thing. @@ -152,7 +159,10 @@ export async function recordAndroidSnapshotHelperRelease(params: { } export function isAndroidSnapshotHelperRuntimeOccupiedError(error: unknown): boolean { - return error instanceof AppError && error.details?.reason === RUNTIME_OCCUPIED_REASON; + return ( + error instanceof AppError && + error.details?.reason === SNAPSHOT_HELPER_RUNTIME_REASONS.runtimeOccupied.reason + ); } function createAndroidSnapshotHelperRuntimeOccupiedError(params: { @@ -165,7 +175,7 @@ function createAndroidSnapshotHelperRuntimeOccupiedError(params: { 'COMMAND_FAILED', 'Android automation helper is still holding device automation ownership', { - reason: RUNTIME_OCCUPIED_REASON, + reason: SNAPSHOT_HELPER_RUNTIME_REASONS.runtimeOccupied.reason, deviceKey: params.deviceKey, packageName: params.packageName, cause: causeMessage, diff --git a/packages/platform-android/src/snapshot-helper-session-protocol.ts b/packages/platform-android/src/snapshot-helper-session-protocol.ts index 725241d334..076f516d3e 100644 --- a/packages/platform-android/src/snapshot-helper-session-protocol.ts +++ b/packages/platform-android/src/snapshot-helper-session-protocol.ts @@ -1,6 +1,6 @@ import { createHmac, randomBytes, timingSafeEqual } from 'node:crypto'; import net from 'node:net'; -import { AppError } from '@agent-device/kernel/errors'; +import { AppError, type ReasonTable } from '@agent-device/kernel/errors'; import { emitDiagnostic } from '@agent-device/host-kit/diagnostics'; import { androidCaptureFailureReasonDetail, @@ -62,11 +62,31 @@ export function androidSnapshotHelperSessionLaunchArgs( const socketName = `${ANDROID_SNAPSHOT_HELPER_SESSION_SOCKET_PREFIX}${port}`; return { socketName, forwardTarget: `localabstract:${socketName}` }; } -const SESSION_REQUEST_TIMEOUT_REASON = 'android_snapshot_helper_session_request_timeout'; +/** + * The `error.details.reason` the persistent snapshot-helper session protocol states: why a command + * never reached the helper, or why the helper that answers is not the one this session launched. The + * session serves the snapshot capture and the helper-backed touch commands, so the owner is the + * helper, not one command. + */ +const SNAPSHOT_HELPER_SESSION_REASONS = { + // The helper accepted the session request but sent no answer before the command deadline. + requestTimeout: { reason: 'android_snapshot_helper_session_request_timeout' }, + // The listener could not prove the session secret, so it is not the helper this session launched. + peerUnverified: { reason: 'android_snapshot_helper_session_peer_unverified' }, + // The helper process never reported readiness before the readiness budget ran out. + readyTimeout: { reason: 'android_snapshot_helper_session_ready_timeout' }, + // The readiness record the helper sent does not prove this session's protocol, socket, or secret. + readyMalformed: { reason: 'android_snapshot_helper_session_ready_malformed' }, + // The helper process ended before it reported readiness. + exitedBeforeReady: { reason: 'android_snapshot_helper_session_exited_before_ready' }, +} as const satisfies ReasonTable<'android snapshot helper'>; /** The helper accepted the session request but sent no answer before the command deadline. */ export function isAndroidSnapshotHelperSessionRequestTimeout(error: unknown): boolean { - return error instanceof AppError && error.details?.reason === SESSION_REQUEST_TIMEOUT_REASON; + return ( + error instanceof AppError && + error.details?.reason === SNAPSHOT_HELPER_SESSION_REASONS.requestTimeout.reason + ); } /** @@ -75,14 +95,15 @@ export function isAndroidSnapshotHelperSessionRequestTimeout(error: unknown): bo */ export type AndroidSnapshotHelperSessionEndpoint = { port: number; secret: Buffer }; -const SESSION_PEER_UNVERIFIED_REASON = 'android_snapshot_helper_session_peer_unverified'; - /** * The listener did not prove the session secret, so it is not the helper this session launched * (another process can bind a freed abstract name). No command byte was sent to it. */ export function isAndroidSnapshotHelperSessionPeerUnverified(error: unknown): boolean { - return error instanceof AppError && error.details?.reason === SESSION_PEER_UNVERIFIED_REASON; + return ( + error instanceof AppError && + error.details?.reason === SNAPSHOT_HELPER_SESSION_REASONS.peerUnverified.reason + ); } const SERVER_LABEL = 'agent-device-session-server|'; @@ -122,7 +143,7 @@ export function sendAndroidSnapshotHelperSessionCommand( command: command.split(' ', 1)[0], timeoutMs, port, - reason: SESSION_REQUEST_TIMEOUT_REASON, + reason: SNAPSHOT_HELPER_SESSION_REASONS.requestTimeout.reason, // Before a proven hello the command never left this process. ...(phase === 'proven' ? {} : { dispatched: 'no' }), }), @@ -144,13 +165,13 @@ export function sendAndroidSnapshotHelperSessionCommand( socket.destroy(); emitDiagnostic({ level: 'warn', - phase: SESSION_PEER_UNVERIFIED_REASON, + phase: SNAPSHOT_HELPER_SESSION_REASONS.peerUnverified.reason, data: { port, command: command.split(' ', 1)[0] }, }); reject( new AppError('COMMAND_FAILED', 'Android snapshot helper session peer is unverified', { port, - reason: SESSION_PEER_UNVERIFIED_REASON, + reason: SNAPSHOT_HELPER_SESSION_REASONS.peerUnverified.reason, dispatched: 'no', // How much of the unverified answer was kept: never more than one hello line. receivedBytes: hello.length, @@ -230,10 +251,6 @@ export async function requestAndroidSnapshotHelperSessionSnapshot(params: { return parseAndroidSnapshotHelperSessionSnapshotResponse(response, requestId); } -const SESSION_READY_TIMEOUT_REASON = 'android_snapshot_helper_session_ready_timeout'; -const SESSION_EXITED_BEFORE_READY_REASON = 'android_snapshot_helper_session_exited_before_ready'; -const SESSION_READY_MALFORMED_REASON = 'android_snapshot_helper_session_ready_malformed'; - type ReadinessOutcome = | { kind: 'ready'; commands: ReadonlySet; secret: Buffer } | { kind: 'failed'; error: AppError }; @@ -281,7 +298,7 @@ function classifyReadinessRecord( return { kind: 'failed', error: new AppError('COMMAND_FAILED', 'Android snapshot helper readiness is malformed', { - reason: SESSION_READY_MALFORMED_REASON, + reason: SNAPSHOT_HELPER_SESSION_REASONS.readyMalformed.reason, }), }; } @@ -323,7 +340,7 @@ export function waitForAndroidSnapshotHelperSessionReady( new AppError('COMMAND_FAILED', 'Android snapshot helper session did not become ready', { instrumentation: record.current(), timeoutMs, - reason: SESSION_READY_TIMEOUT_REASON, + reason: SNAPSHOT_HELPER_SESSION_REASONS.readyTimeout.reason, }), ); }, timeoutMs); @@ -380,7 +397,7 @@ export function waitForAndroidSnapshotHelperSessionReady( exitCode: code, signal: exitSignal, instrumentation: record.exitResult() ?? record.current(), - reason: SESSION_EXITED_BEFORE_READY_REASON, + reason: SNAPSHOT_HELPER_SESSION_REASONS.exitedBeforeReady.reason, }), ); }); diff --git a/packages/platform-android/src/telephony/console-event.ts b/packages/platform-android/src/telephony/console-event.ts index b1e8631ebe..9be35d5016 100644 --- a/packages/platform-android/src/telephony/console-event.ts +++ b/packages/platform-android/src/telephony/console-event.ts @@ -1,12 +1,18 @@ import type { TelephonyEventInput } from '@agent-device/contracts/device'; import type { DeviceInfo } from '@agent-device/kernel/device'; -import { AppError } from '@agent-device/kernel/errors'; +import { AppError, type ReasonTable } from '@agent-device/kernel/errors'; import { runEmulatorConsole } from '../emulator-console.ts'; const CONSOLE_REFUSED_HINT = 'The emulator console refused the event. accept needs a call from that same number (start one with telephony call ), and an emulator image without a modem has no telephony to simulate.'; +/** Why an emulator-console telephony event refuses. */ +const TELEPHONY_CONSOLE_REASONS = { + // The console answered the event with an error; `details.consoleReason` is its reply. + consoleRefused: { reason: 'telephony-console-refused' }, +} as const satisfies ReasonTable<'telephony'>; + /** Simulates one telephony event through the emulator console (`gsm …` / `sms send …`). */ export async function sendAndroidTelephonyEvent( device: DeviceInfo, @@ -17,7 +23,7 @@ export async function sendAndroidTelephonyEvent( if (reply.refusal !== undefined) { throw new AppError('COMMAND_FAILED', `The emulator console refused telephony ${input.action}`, { deviceId: device.id, - reason: 'telephony-console-refused', + reason: TELEPHONY_CONSOLE_REASONS.consoleRefused.reason, stdout: reply.stdout.trim(), ...(reply.refusal ? { consoleReason: reply.refusal } : {}), hint: CONSOLE_REFUSED_HINT, diff --git a/packages/platform-android/src/text-input.ts b/packages/platform-android/src/text-input.ts index e935d179cf..2055e4de4a 100644 --- a/packages/platform-android/src/text-input.ts +++ b/packages/platform-android/src/text-input.ts @@ -5,13 +5,14 @@ * `fill-verification.ts`. */ import type { FillUnconfirmedVerification } from '@agent-device/contracts/fill-evidence'; -import { - ANDROID_IME_HELPER_DISPATCH_REJECTED_REASON, - ANDROID_SHELL_TEXT_UNSUPPORTED_REASON, -} from '@agent-device/contracts/command'; +import { ANDROID_TEXT_CHANNEL_REASONS } from '@agent-device/contracts/command'; import type { DeviceInfo } from '@agent-device/kernel/device'; import type { ShellWord } from '@agent-device/kernel/device-shell'; -import { AppError, discloseDispatchAfterSteps } from '@agent-device/kernel/errors'; +import { + AppError, + discloseDispatchAfterSteps, + type ReasonTable, +} from '@agent-device/kernel/errors'; import { emitDiagnostic } from '@agent-device/host-kit/diagnostics'; import { @@ -259,6 +260,15 @@ async function admitAndroidTextChannel( return { backend: 'adb-shell' }; } +/** Why the Android text routes refuse before any text is sent. */ +const ANDROID_TEXT_ROUTE_REASONS = { + // The test IME rebind could not be confirmed, so the focused field may have no input session. + testImeRebindUnconfirmed: { + reason: 'android_test_ime_rebind_unconfirmed', + commands: ['type'], + }, +} as const satisfies ReasonTable<'fill'>; + /** * Rebinds the test IME so the focused field gets a fresh input session, or throws: a helper whose * rebind went unconfirmed may hold no session, so no text may reach it. @@ -271,7 +281,7 @@ async function confirmAndroidTestImeRebound(device: DeviceInfo): Promise { 'COMMAND_FAILED', `Could not confirm the Android test IME rebind on ${device.name ?? device.id}.`, { - reason: 'android_test_ime_rebind_unconfirmed', + reason: ANDROID_TEXT_ROUTE_REASONS.testImeRebindUnconfirmed.reason, rebindCause: outcome.kind === 'not-owned' ? 'not-owned' : outcome.cause, deviceId: device.id, hint: 'Close and reopen the session to restore the keyboard and reactivate the test IME.', @@ -382,7 +392,7 @@ function isImeDispatchRejection( ): error is AppError { return ( error instanceof AppError && - error.details?.reason === ANDROID_IME_HELPER_DISPATCH_REJECTED_REASON && + error.details?.reason === ANDROID_TEXT_CHANNEL_REASONS.imeHelperDispatchRejected.reason && error.details.dispatchKind === kind ); } @@ -630,7 +640,7 @@ function unsupportedAndroidShellTextError(text: string, cause?: unknown): AppErr 'Android text input requires provider-native text injection or the bundled test IME helper for non-ASCII/control characters; the adb-shell fallback supports ASCII text only.', { backend: 'adb-shell', - reason: ANDROID_SHELL_TEXT_UNSUPPORTED_REASON, + reason: ANDROID_TEXT_CHANNEL_REASONS.shellTextUnsupported.reason, textLength: Array.from(text).length, textPreview: text.slice(0, 32), // The direct-interaction route's recovery. The replay failure boundary rewrites it diff --git a/packages/replay-port/src/daemon-port/__tests__/session-replay-runtime-failure-response.test.ts b/packages/replay-port/src/daemon-port/__tests__/session-replay-runtime-failure-response.test.ts index 156e7960b7..f3a850b939 100644 --- a/packages/replay-port/src/daemon-port/__tests__/session-replay-runtime-failure-response.test.ts +++ b/packages/replay-port/src/daemon-port/__tests__/session-replay-runtime-failure-response.test.ts @@ -1,5 +1,5 @@ import { test, expect } from 'vitest'; -import { ANDROID_SHELL_TEXT_UNSUPPORTED_REASON } from '@agent-device/contracts/input-validation'; +import { ANDROID_TEXT_CHANNEL_REASONS } from '@agent-device/contracts/input-validation'; import { BOUNDED_COMPOSITE_RESOURCE_UNSUPPORTED_REASON } from '@agent-device/kernel/errors'; import { ANDROID_TEST_IME_FLOW_HINT, @@ -134,7 +134,10 @@ test('an Android shell-text cause gets the flow-owned --test-ime recovery', () = message: 'Android text input requires provider-native text injection or the bundled test IME helper for non-ASCII/control characters; the adb-shell fallback supports ASCII text only.', hint: openRouteHint, - details: { reason: ANDROID_SHELL_TEXT_UNSUPPORTED_REASON, hint: openRouteHint }, + details: { + reason: ANDROID_TEXT_CHANNEL_REASONS.shellTextUnsupported.reason, + hint: openRouteHint, + }, }); expect(cause.hint).toBe(ANDROID_TEST_IME_FLOW_HINT); diff --git a/packages/replay-port/src/daemon-port/session-replay-runtime-failure-response.ts b/packages/replay-port/src/daemon-port/session-replay-runtime-failure-response.ts index db5f5f56ca..f9a7f2744d 100644 --- a/packages/replay-port/src/daemon-port/session-replay-runtime-failure-response.ts +++ b/packages/replay-port/src/daemon-port/session-replay-runtime-failure-response.ts @@ -1,5 +1,5 @@ import type { SessionAction } from '@agent-device/contracts/session'; -import { ANDROID_SHELL_TEXT_UNSUPPORTED_REASON } from '@agent-device/contracts/input-validation'; +import { ANDROID_TEXT_CHANNEL_REASONS } from '@agent-device/contracts/input-validation'; import { BOUNDED_COMPOSITE_RESOURCE_UNSUPPORTED_REASON } from '@agent-device/kernel/errors'; import { scrubReplayVarValues, type ReplayVarScrubEntry } from '@agent-device/ad-replay/divergence'; import { formatDivergenceActionLabel } from '@agent-device/ad-script'; @@ -34,7 +34,8 @@ export function hoistReplayFailureCauseDiagnosticMeta( * recovery is the `test`/`replay` flag itself. Keyed on the typed reason only. */ function rewriteAndroidTestImeFlowHint(error: ReplayFailureCause): ReplayFailureCause { - if (error.details?.reason !== ANDROID_SHELL_TEXT_UNSUPPORTED_REASON) return error; + if (error.details?.reason !== ANDROID_TEXT_CHANNEL_REASONS.shellTextUnsupported.reason) + return error; return { ...error, hint: ANDROID_TEST_IME_FLOW_HINT }; } diff --git a/website/docs/docs/error-reasons.md b/website/docs/docs/error-reasons.md index 3fe47ed2a4..6a52f6a1f1 100644 --- a/website/docs/docs/error-reasons.md +++ b/website/docs/docs/error-reasons.md @@ -17,10 +17,18 @@ Treat a reason that this page does not list as unknown, not as an error in the r | --- | --- | | `native-audit-invalid-result` | The runner answered the native audit with a missing or malformed result. | +### `clipboard` + +| Reason | Meaning | +| --- | --- | +| `android_clipboard_shell_command_unavailable` | This Android build ships no shell command for the clipboard service. | + ### `close` | Reason | Meaning | | --- | --- | +| `android-app-close-timeout` | A stop fence ended before the app left the foreground or its killed processes exited. | +| `android-process-probe-unavailable` | `adb pidof` or the resumed-activity read did not answer, so process state is unknown. | | `MACOS_APP_TERMINATION_TIMEOUT` | The macOS app was still running after every termination attempt. | ### `events` @@ -30,6 +38,15 @@ Treat a reason that this page does not list as unknown, not as an error in the r | `EVENT_LOG_CURSOR_EXPIRED` | The cursor names a line that rotation has already removed from the retained window. | | `EVENT_LOG_WINDOW_UNVERIFIED` | The retained event log files or their window sidecar are malformed, incomplete, or disagree, so no cursor can be trusted. | +### `fill` + +| Reason | Meaning | +| --- | --- | +| `android_shell_text_unsupported` | The adb-shell fallback carries ASCII text only; a helper or provider channel is needed. | +| `android_ime_helper_no_ack` | The test IME helper gave no evidence it attempted the dispatch, so nothing is proven typed. | +| `android_ime_helper_dispatch_rejected` | The test IME helper answered that it rejected the dispatch, so nothing was typed. | +| `android_test_ime_rebind_unconfirmed` | The test IME rebind could not be confirmed, so the focused field may have no input session. | + ### `fold` | Reason | Meaning | @@ -65,6 +82,11 @@ Treat a reason that this page does not list as unknown, not as an error in the r | Reason | Meaning | | --- | --- | +| `android_port_reverse_rebind_refused` | The endpoint already has a device mapping, which a `--no-rebind` reverse never replaces. | +| `invalid-android-activity-component` | The `--activity` value is not an Android component name. | +| `android-launch-not-foreground` | The app the helper launched never reached the foreground before the launch budget ran out. | +| `android-app-close-timeout` | A stop fence ended before the app left the foreground or its killed processes exited. | +| `android-process-probe-unavailable` | `adb pidof` or the resumed-activity read did not answer, so process state is unknown. | | `ios-simulator-openurl-timeout` | CoreSimulator did not answer `simctl openurl` in time, so the URL open failed. | | `system-surface-host-not-openable` | The bundle hosts an iOS system surface, which `open` refuses to launch as an app. | | `launch_confirmation_foreign_app` | iOS asks to open another app's URL scheme instead of the session app's. | @@ -118,6 +140,14 @@ Treat a reason that this page does not list as unknown, not as an error in the r | Reason | Meaning | | --- | --- | | `android_screenrecord_startup_failed` | Android `screenrecord` exited before it began writing; its startup output says why. | +| `native_recovery_evidence_unavailable` | The marker exists but the device could not be read, so it cannot be classified. | +| `native_recovery_evidence_unreadable` | The marker exists but does not decode, so nothing about it can be verified. | +| `native_recovery_evidence_transport_mismatch` | The marker was written by the other adb transport, so this one must not retire it. | +| `native_recovery_evidence_open` | An open recording still owns the marker; only its own session's stop or close retires it. | +| `native_recording_artifact_claimed` | A recorder is still writing the pending artifact, so removing it would cut a clip short. | +| `native_recording_artifact_removal_failed` | The device refused to remove the pending artifact, so the marker has to stay. | +| `native_recovery_evidence_retirement_unconfirmed` | The marker read back after removal, so its retirement is not proven. | +| `native_recording_recorder_unproven` | The probe could not prove no recorder is writing the pending artifact. | | `recording_destination_not_requested` | A remote recording was saved to the current directory because the request named no destination; a warning. | ### `replay` @@ -125,6 +155,9 @@ Treat a reason that this page does not list as unknown, not as an error in the r | Reason | Meaning | | --- | --- | | `wait_landmark_identity_mismatch` | A replay destination guard refused the match because its identity differs from the recorded landmark. | +| `android-process-probe-unavailable` | `adb pidof` or the resumed-activity read did not answer, so process state is unknown. | +| `android-kill-process-survived` | `am kill` returned and the process is still running; force-stop it instead. | +| `android-kill-requires-background-app` | `am kill` only reaps background processes, so it refuses the foreground app. | ### `screenshot` @@ -164,8 +197,22 @@ Treat a reason that this page does not list as unknown, not as an error in the r | Reason | Meaning | | --- | --- | +| `android_bluetooth_adapter_missing` | The device declares no Bluetooth adapter, so there is nothing to turn on or off. | +| `android_bluetooth_command_unavailable` | The build predates `svc bluetooth`, so the adapter cannot be switched from the shell. | +| `bluetooth-not-applied` | The device kept Bluetooth in its prior state after `svc bluetooth` accepted the request. | +| `bluetooth-unreadable` | The device answered the Bluetooth read-back with a value that is not a known state. | +| `mobile-data-not-applied` | The device kept mobile data in its prior state after `svc data` accepted the request. | +| `mobile-data-unreadable` | The device answered the mobile-data read-back with a value that is neither 0 nor 1. | +| `setting_app_not_package` | The named app resolves to an intent such as `settings`, not to an installed package. | | `app-no-data-container` | `clear-app-state` was refused because the installed app owns no data container. | +### `shake` + +| Reason | Meaning | +| --- | --- | +| `shake-rest-acceleration-unreadable` | The console gave no accelerometer reading to restore afterwards, so nothing was sent. | +| `shake-console-refused` | The emulator console refused an accelerometer command; `details.consoleReason` is its reply. | + ### `snapshot` | Reason | Meaning | @@ -173,6 +220,29 @@ Treat a reason that this page does not list as unknown, not as an error in the r | `observation-unavailable` | The runner answered an observe-only snapshot request without an observe-only snapshot. | | `empty-snapshot` | XCTest returned a snapshot with no nodes on an iOS simulator. | +### `telephony` + +| Reason | Meaning | +| --- | --- | +| `telephony-console-refused` | The console answered the event with an error; `details.consoleReason` is its reply. | + +### `test` + +| Reason | Meaning | +| --- | --- | +| `android-process-probe-unavailable` | `adb pidof` or the resumed-activity read did not answer, so process state is unknown. | +| `android-kill-process-survived` | `am kill` returned and the process is still running; force-stop it instead. | +| `android-kill-requires-background-app` | `am kill` only reaps background processes, so it refuses the foreground app. | + +### `type` + +| Reason | Meaning | +| --- | --- | +| `android_shell_text_unsupported` | The adb-shell fallback carries ASCII text only; a helper or provider channel is needed. | +| `android_ime_helper_no_ack` | The test IME helper gave no evidence it attempted the dispatch, so nothing is proven typed. | +| `android_ime_helper_dispatch_rejected` | The test IME helper answered that it rejected the dispatch, so nothing was typed. | +| `android_test_ime_rebind_unconfirmed` | The test IME rebind could not be confirmed, so the focused field may have no input session. | + ### `wait` | Reason | Meaning | @@ -196,6 +266,53 @@ These reasons can come from more than one command. | --- | --- | | `swift_cache_untrusted` | The Swift helper cache, a helper compiled into it, or the selected `DEVELOPER_DIR` is not a trusted path that only this user or root can change. | +### Android adb port reverse + +| Reason | Meaning | +| --- | --- | +| `android_port_reverse_rebind_refused` | The endpoint already has a device mapping, which a `--no-rebind` reverse never replaces. | + +### Android adb transport + +| Reason | Meaning | +| --- | --- | +| `managed-device-transport-mismatch` | The call aimed a managed adb transport at another device, target, or server. | + +### Android helper install + +| Reason | Meaning | +| --- | --- | +| `missing` | The device has no package installed under the helper's name. | +| `outdated` | The installed helper's versionCode is below the bundled artifact's. | +| `mismatched` | The installed helper matches the artifact's versionCode but not its APK checksum. | +| `unverifiable` | The installed helper's APK checksum could not be read, so its currency stays unproven. | + +### Android input + +| Reason | Meaning | +| --- | --- | +| `android-input-budget-exhausted` | The request had no room left for one helper input attempt, so nothing was sent. | + +### Android snapshot helper + +| Reason | Meaning | +| --- | --- | +| `android-snapshot-helper-not-current` | A current-only check found no current helper: nothing ran, so there is nothing to recover. | +| `android_snapshot_helper_runtime_occupied` | Another helper process still holds UiAutomation, so nothing can take the runtime. | +| `android_snapshot_helper_session_request_timeout` | The helper accepted the session request but sent no answer before the command deadline. | +| `android_snapshot_helper_session_peer_unverified` | The listener could not prove the session secret, so it is not the helper this session launched. | +| `android_snapshot_helper_session_ready_timeout` | The helper process never reported readiness before the readiness budget ran out. | +| `android_snapshot_helper_session_ready_malformed` | The readiness record the helper sent does not prove this session's protocol, socket, or secret. | +| `android_snapshot_helper_session_exited_before_ready` | The helper process ended before it reported readiness. | + +### Android text channel + +| Reason | Meaning | +| --- | --- | +| `android_shell_text_unsupported` | The adb-shell fallback carries ASCII text only; a helper or provider channel is needed. | +| `android_ime_helper_no_ack` | The test IME helper gave no evidence it attempted the dispatch, so nothing is proven typed. | +| `android_ime_helper_dispatch_rejected` | The test IME helper answered that it rejected the dispatch, so nothing was typed. | + ### Apple app resolution | Reason | Meaning |