From f8530734c4fa78c5ede2b7cd0c8d49cd7d8b38b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 21 Nov 2026 21:10:05 +0100 Subject: [PATCH 1/9] refactor(reasons): declare the provider reasons in ReasonTable rows --- packages/contracts/src/lease-scope.ts | 9 +- packages/contracts/src/platform-runtime.ts | 12 +- packages/provider-limrun/src/android.ts | 3 +- .../provider-limrun/src/app-log-runtime.ts | 3 +- .../provider-limrun/src/app-state-read.ts | 3 +- packages/provider-limrun/src/device.ts | 26 +++ packages/provider-limrun/src/lease-release.ts | 11 +- packages/provider-limrun/src/runtime.ts | 9 +- packages/provider-limrun/src/sync-cache.ts | 5 +- packages/provider-revyl/src/connection.ts | 6 +- packages/provider-revyl/src/credentials.ts | 10 +- packages/provider-revyl/src/deployment.ts | 27 +++- packages/provider-revyl/src/interactor.ts | 14 +- .../provider-revyl/src/platform-runtime.ts | 5 +- packages/provider-revyl/src/revyl-client.ts | 151 ++++++++++++++---- packages/provider-revyl/src/revyl-session.ts | 15 +- packages/provider-revyl/src/runtime.ts | 11 +- .../provider-revyl/src/session-allocation.ts | 3 +- packages/provider-revyl/src/snapshot.ts | 3 +- .../provider-webdriver/src/runtime-session.ts | 14 +- .../src/webdriver-interactor.ts | 3 +- .../src/webdriver-transport.ts | 57 ++++--- .../provider-webdriver/src/webdriver-utils.ts | 45 +++++- website/docs/docs/error-reasons.md | 68 ++++++++ 24 files changed, 403 insertions(+), 110 deletions(-) diff --git a/packages/contracts/src/lease-scope.ts b/packages/contracts/src/lease-scope.ts index cd6a9862eb..7d7da6a3bb 100644 --- a/packages/contracts/src/lease-scope.ts +++ b/packages/contracts/src/lease-scope.ts @@ -516,6 +516,8 @@ export const LEASE_REASONS = { scopeMismatch: { reason: 'LEASE_SCOPE_MISMATCH' }, // The lease was allocated with an owner scope that the request does not repeat. scopeRequired: { reason: 'LEASE_SCOPE_REQUIRED' }, + // The device instance behind the lease ended outside the daemon, which ends the lease with it. + instanceEnded: { reason: 'provider-instance-ended' }, } as const satisfies ReasonTable<'leases'>; /** @@ -544,8 +546,11 @@ export function isInactiveLeaseError(error: unknown): boolean { ); } -/** The reason a provider gives when the device instance behind a lease ended outside the daemon. */ -export const PROVIDER_INSTANCE_ENDED = 'provider-instance-ended'; +/** + * The reason a provider gives when the device instance behind a lease ended outside the daemon, read + * from the table so the spelling has one owner. + */ +export const PROVIDER_INSTANCE_ENDED = LEASE_REASONS.instanceEnded.reason; /** Whether `error` says the provider's device instance ended, which ends its lease. */ export function isProviderInstanceEndedError(error: unknown): boolean { diff --git a/packages/contracts/src/platform-runtime.ts b/packages/contracts/src/platform-runtime.ts index dc18513ebd..b13c347e6d 100644 --- a/packages/contracts/src/platform-runtime.ts +++ b/packages/contracts/src/platform-runtime.ts @@ -7,7 +7,7 @@ import { type DeviceTarget, type Platform, } from '@agent-device/kernel/device'; -import { AppError } from '@agent-device/kernel/errors'; +import { AppError, type ReasonTable } from '@agent-device/kernel/errors'; import type { PlatformModuleMetadata } from './platform-module.ts'; import type { PlatformRequestScope } from './platform-runtime-host.ts'; import type { ApplicationLifecycleResourceLifecycle } from './application-lifecycle-runtime.ts'; @@ -163,6 +163,16 @@ export function sameRuntimeOwner(left: RuntimeOwnerRef, right: RuntimeOwnerRef): export type RuntimeProviderMode = 'local' | 'transport-composed' | 'provider-runtime'; +/** + * Every `details.reason` a hosted provider's runtime owner publishes when it refuses to serve a + * request. More than one provider raises these, so the row lives with the runtime contract the + * providers all bind through. + */ +export const PROVIDER_RUNTIME_REASONS = { + // The provider's session for the device ended, so the runtime has nothing left to serve. + sessionUnavailable: { reason: 'provider-session-unavailable' }, +} as const satisfies ReasonTable<'provider runtime'>; + export type RuntimeDeviceShape = Readonly<{ family: Platform; appleOs?: AppleOS; diff --git a/packages/provider-limrun/src/android.ts b/packages/provider-limrun/src/android.ts index f97d81f53a..53c3586cc4 100644 --- a/packages/provider-limrun/src/android.ts +++ b/packages/provider-limrun/src/android.ts @@ -23,6 +23,7 @@ import type { } from './runtime-dependencies.ts'; import type { AndroidAdbInvocation } from '@agent-device/platform-android/mechanics'; import type { LimrunInstanceOwnership } from './instance-access.ts'; +import { LIMRUN_PROVIDER_REASONS } from './device.ts'; import { normalizeOptionalString } from './strings.ts'; import { awaitLimrunDeploymentOperation, @@ -346,7 +347,7 @@ function alreadyCleanedUp(session: LimrunAndroidAdbSession): AppError { 'SESSION_NOT_FOUND', `Limrun ADB tunnel for instance '${session.instanceId}' was already cleaned up`, { - reason: 'limrun_adb_tunnel_cleaned_up', + reason: LIMRUN_PROVIDER_REASONS.adbTunnelCleanedUp.reason, // The tunnel is gone whether the instance's delete confirmed or is still held for retry, so the hint // sends the caller to a new lease, and to Limrun only for the state where a release would refuse again. hint: `This interactor's ADB tunnel is closed for lease '${session.lease.leaseId}'. Open a new lease. If this lease's release was refused as an unconfirmed delete, ask Limrun to delete the instance first.`, diff --git a/packages/provider-limrun/src/app-log-runtime.ts b/packages/provider-limrun/src/app-log-runtime.ts index f608a5241c..434ece95c5 100644 --- a/packages/provider-limrun/src/app-log-runtime.ts +++ b/packages/provider-limrun/src/app-log-runtime.ts @@ -13,6 +13,7 @@ import type { AppStateRuntimeResult } from '@agent-device/contracts/app-state-ru import { type DeviceBinding, providerRuntimeOwner, + PROVIDER_RUNTIME_REASONS, sameRuntimeOwner, whenAdmitted, } from '@agent-device/contracts/platform-runtime'; @@ -121,7 +122,7 @@ export function createLimrunPlatformRuntimeOwner( throw new AppError( 'UNSUPPORTED_OPERATION', 'Limrun provider session is no longer live for the selected device', - { reason: 'provider-session-unavailable' }, + { reason: PROVIDER_RUNTIME_REASONS.sessionUnavailable.reason }, ); } return bindLimrunAppLogs( diff --git a/packages/provider-limrun/src/app-state-read.ts b/packages/provider-limrun/src/app-state-read.ts index ce85bb9311..3682eba9ab 100644 --- a/packages/provider-limrun/src/app-state-read.ts +++ b/packages/provider-limrun/src/app-state-read.ts @@ -1,5 +1,6 @@ import type { AppStateRuntimeResult } from '@agent-device/contracts/app-state-runtime'; import { AppError } from '@agent-device/kernel/errors'; +import { LIMRUN_PROVIDER_REASONS } from './device.ts'; import type { LimrunDeviceSession } from './device-session.ts'; import { awaitWithSignal } from '@agent-device/kernel/await-with-signal'; @@ -41,7 +42,7 @@ async function confirmLimrunIosInstanceAnswers( 'COMMAND_FAILED', 'Could not confirm that the Limrun iOS instance is running, so its app state is unknown.', { - reason: 'limrun_instance_unreachable', + reason: LIMRUN_PROVIDER_REASONS.instanceUnreachable.reason, hint: 'Retry appstate. If it keeps failing, the instance may have been terminated: run connect limrun and open again.', }, error, diff --git a/packages/provider-limrun/src/device.ts b/packages/provider-limrun/src/device.ts index b1afd85119..7d584997cf 100644 --- a/packages/provider-limrun/src/device.ts +++ b/packages/provider-limrun/src/device.ts @@ -1,8 +1,34 @@ import { createHash } from 'node:crypto'; import type { DeviceLease } from '@agent-device/contracts/device'; import type { DeviceInfo } from '@agent-device/kernel/device'; +import type { ReasonTable } from '@agent-device/kernel/errors'; import type { ProviderProfileFieldDeclaration } from '@agent-device/contracts/provider-profile-fields'; +/** + * Every `details.reason` the Limrun provider publishes, keyed by what the failure means. Each + * refusal site reads a row here, so the plugin's wire vocabulary has one owner; the modules that + * classify those failures all load this one. `provider-instance-ended` is the lease vocabulary and + * stays with the lease table in `@agent-device/contracts/lease-scope`. + */ +export const LIMRUN_PROVIDER_REASONS = { + // A release could not confirm Limrun deleted the instance, so it may still be billed. + instanceDeleteUnconfirmed: { reason: 'limrun_instance_delete_unconfirmed' }, + // The lease was released while its instance was still being prepared for the allocation. + leaseReleasedMidAllocation: { reason: 'limrun_lease_released_mid_allocation' }, + // The lease holds no live session, so the command that addresses it has nothing to act on. + leaseNotLive: { reason: 'limrun_lease_not_live' }, + // This runtime is shut down, so it refuses to allocate a lease into it. + runtimeShutDown: { reason: 'limrun_runtime_shut_down' }, + // The instance stopped answering, so its app state cannot be read. + instanceUnreachable: { reason: 'limrun_instance_unreachable' }, + // The ADB tunnel of this lease was already cleaned up, so nothing can be typed over it. + adbTunnelCleanedUp: { reason: 'limrun_adb_tunnel_cleaned_up' }, + // The app-sync session of this lease has ended, so no further sync runs on it. + appSyncRetired: { reason: 'limrun_app_sync_retired' }, + // Syncing the app to the instance stopped with nothing installed. + appSyncFailed: { reason: 'limrun_app_sync_failed' }, +} as const satisfies ReasonTable<'limrun provider'>; + export type LimrunPlatform = 'ios' | 'android'; export const LIMRUN_PROVIDER = 'limrun'; diff --git a/packages/provider-limrun/src/lease-release.ts b/packages/provider-limrun/src/lease-release.ts index 0f8652fade..c79b811487 100644 --- a/packages/provider-limrun/src/lease-release.ts +++ b/packages/provider-limrun/src/lease-release.ts @@ -5,7 +5,12 @@ import { cleanupLimrunAndroidAdbTunnel } from './android.ts'; import { CAPTURE_OPEN_BUDGET_MS } from './capture-lifecycle.ts'; import { deleteLimrunInstance } from './client-options.ts'; import type { LimrunBudgetOutcome } from './lifecycle-budget.ts'; -import { LIMRUN_PROVIDER, platformForLimrunLeaseBackend, type LimrunPlatform } from './device.ts'; +import { + LIMRUN_PROVIDER, + LIMRUN_PROVIDER_REASONS, + platformForLimrunLeaseBackend, + type LimrunPlatform, +} from './device.ts'; import type { LimrunDeleteResult, LimrunDisposalOutcome, @@ -498,7 +503,7 @@ export function allocationRefusedForTake( 'DEVICE_IN_USE', `Limrun lease '${lease.leaseId}' was released while its instance was being prepared`, { - reason: 'limrun_lease_released_mid_allocation', + reason: LIMRUN_PROVIDER_REASONS.leaseReleasedMidAllocation.reason, ...(instanceId === undefined ? { hint: `Instance create for lease '${lease.leaseId}' may still rent one. Check Limrun.` } : { limrunInstanceId: instanceId, ...(ended === undefined ? {} : { hint: ended }) }), @@ -562,7 +567,7 @@ function throwUnconfirmedDelete( 'COMMAND_FAILED', message, { - reason: 'limrun_instance_delete_unconfirmed', + reason: LIMRUN_PROVIDER_REASONS.instanceDeleteUnconfirmed.reason, retriable: true, ...instanceDetails, ...(failure === undefined ? {} : { cause: failure }), diff --git a/packages/provider-limrun/src/runtime.ts b/packages/provider-limrun/src/runtime.ts index 63d2fe8db2..7649f87b17 100644 --- a/packages/provider-limrun/src/runtime.ts +++ b/packages/provider-limrun/src/runtime.ts @@ -26,6 +26,7 @@ import { attachedLimrunInstanceId, buildLimrunDevice, LIMRUN_PROVIDER, + LIMRUN_PROVIDER_REASONS, parseLimrunDeviceId, platformForLimrunLeaseBackend, type LimrunPlatform, @@ -777,9 +778,9 @@ class LimrunRuntimeImplementation implements ProviderDeviceRuntime { terminationReason = 'Unknown'; } if (terminationReason === undefined) return undefined; - const { PROVIDER_INSTANCE_ENDED } = await import('@agent-device/contracts/lease-scope'); + const { LEASE_REASONS } = await import('@agent-device/contracts/lease-scope'); throw new AppError('COMMAND_FAILED', `The Limrun instance ended (${terminationReason}).`, { - reason: PROVIDER_INSTANCE_ENDED, + reason: LEASE_REASONS.instanceEnded.reason, terminationReason, instanceId: session.instanceId, }); @@ -810,7 +811,7 @@ class LimrunRuntimeImplementation implements ProviderDeviceRuntime { throw new AppError( 'COMMAND_FAILED', `Limrun lease '${owner.lease.leaseId}' has no live session`, - { reason: 'limrun_lease_not_live' }, + { reason: LIMRUN_PROVIDER_REASONS.leaseNotLive.reason }, ); } return session; @@ -939,7 +940,7 @@ function allocationRefusedAfterShutdown(lease: DeviceLease): never { 'SESSION_NOT_FOUND', `Cannot allocate Limrun lease '${lease.leaseId}': this runtime is shut down`, { - reason: 'limrun_runtime_shut_down', + reason: LIMRUN_PROVIDER_REASONS.runtimeShutDown.reason, hint: 'Start the daemon again to allocate a Limrun lease.', }, ); diff --git a/packages/provider-limrun/src/sync-cache.ts b/packages/provider-limrun/src/sync-cache.ts index bf1981660e..c398fad40a 100644 --- a/packages/provider-limrun/src/sync-cache.ts +++ b/packages/provider-limrun/src/sync-cache.ts @@ -2,6 +2,7 @@ import fs from 'node:fs/promises'; import os from 'node:os'; import path from 'node:path'; import { AppError } from '@agent-device/kernel/errors'; +import { LIMRUN_PROVIDER_REASONS } from './device.ts'; /** One lease retains only its latest artifact's basis, even when materialization paths change. */ export class LimrunSyncCache { @@ -17,7 +18,7 @@ export class LimrunSyncCache { ): Promise { if (this.retired) { throw new AppError('COMMAND_FAILED', 'Limrun app sync session has ended.', { - reason: 'limrun_app_sync_retired', + reason: LIMRUN_PROVIDER_REASONS.appSyncRetired.reason, }); } const operation = this.pending.then(async () => { @@ -43,7 +44,7 @@ export class LimrunSyncCache { 'COMMAND_FAILED', 'Limrun app sync failed.', { - reason: 'limrun_app_sync_failed', + reason: LIMRUN_PROVIDER_REASONS.appSyncFailed.reason, platform, installablePath, }, diff --git a/packages/provider-revyl/src/connection.ts b/packages/provider-revyl/src/connection.ts index 3b0a6566c3..628f05255e 100644 --- a/packages/provider-revyl/src/connection.ts +++ b/packages/provider-revyl/src/connection.ts @@ -8,7 +8,7 @@ import type { ProviderConnectionVerification } from '@agent-device/contracts/rem import { AppError } from '@agent-device/kernel/errors'; import { REVYL_PROVIDER, REVYL_SERVICE, type RevylPlatform } from './device.ts'; import { requireRevylCredentials, type RevylCredentials } from './credentials.ts'; -import { createRevylClient } from './revyl-client.ts'; +import { createRevylClient, REVYL_PROVIDER_REASONS } from './revyl-client.ts'; import { REVYL_PROFILE_FIELDS } from './profile-fields.ts'; import { revylTextFlag } from './session-allocation.ts'; @@ -87,7 +87,7 @@ export async function verifyRevylProfile( 'INVALID_ARGS', `${REVYL_SERVICE} installs the app from a URL, so --provider-app must be an https URL.`, { - reason: 'invalid_provider_app', + reason: REVYL_PROVIDER_REASONS.invalidApp.reason, hint: `Pass the URL ${REVYL_SERVICE} can read the build from; a local path cannot.`, }, ); @@ -140,7 +140,7 @@ function isRevylAppUrl(value: string | undefined): boolean { function requireConnectPlatform(flags: CliFlags): RevylPlatform { if (flags.platform === 'ios' || flags.platform === 'android') return flags.platform; throw new AppError('INVALID_ARGS', `connect ${REVYL_PROVIDER} requires --platform ios|android.`, { - reason: 'unsupported_platform', + reason: REVYL_PROVIDER_REASONS.unsupportedPlatform.reason, }); } diff --git a/packages/provider-revyl/src/credentials.ts b/packages/provider-revyl/src/credentials.ts index b8d93c123c..94f016efb6 100644 --- a/packages/provider-revyl/src/credentials.ts +++ b/packages/provider-revyl/src/credentials.ts @@ -1,4 +1,10 @@ -import { AppError } from '@agent-device/kernel/errors'; +import { AppError, type ReasonTable } from '@agent-device/kernel/errors'; + +/** Every `details.reason` this module raises when it reads the Revyl credentials. */ +const REVYL_CREDENTIAL_REASONS = { + // No Revyl API key is set, so the provider cannot authenticate the request. + missingCredentials: { reason: 'missing_provider_credentials' }, +} as const satisfies ReasonTable<'revyl provider'>; export const REVYL_API_KEY_VARIABLE = 'REVYL_API_KEY'; export const REVYL_API_URL_VARIABLE = 'REVYL_API_URL'; @@ -22,7 +28,7 @@ export function requireRevylCredentials( return { apiKey, apiUrl: env[REVYL_API_URL_VARIABLE]?.trim() || undefined }; } throw new AppError('INVALID_ARGS', `${command} requires a Revyl API key.`, { - reason: 'missing_provider_credentials', + reason: REVYL_CREDENTIAL_REASONS.missingCredentials.reason, hint: `Set ${REVYL_API_KEY_VARIABLE} to a Revyl API key. Revyl issues keys to its customers; a partner integration gets one through Revyl's partner program.`, variables: [REVYL_API_KEY_VARIABLE], }); diff --git a/packages/provider-revyl/src/deployment.ts b/packages/provider-revyl/src/deployment.ts index bd66ae3b35..421ca3e201 100644 --- a/packages/provider-revyl/src/deployment.ts +++ b/packages/provider-revyl/src/deployment.ts @@ -7,7 +7,11 @@ import { packGzipTar } from '@agent-device/host-kit/gzip-tar'; import { Deadline, type DeadlineClock, pollUntilSettled } from '@agent-device/host-kit/retry'; import { AppError } from '@agent-device/kernel/errors'; import type { EnvMap } from '@agent-device/kernel/source-value'; -import type { RevylClient } from './revyl-client.ts'; +import { + REVYL_PROVIDER_REASONS, + type RevylClient, + type RevylProviderReason, +} from './revyl-client.ts'; import type { RevylWorkerActionResponse } from './revyl-types.ts'; /** @@ -50,7 +54,7 @@ export async function deployRevylApp( const scoped = AbortSignal.any([signal, budget]); const timedOut = (cause?: unknown) => installStopped( - 'provider-unconfirmed', + REVYL_PROVIDER_REASONS.unconfirmed.reason, `Revyl did not finish the install within ${budgetMs / 1000} s.`, cause, ); @@ -96,7 +100,14 @@ async function uploadAndInstall( } } -function installStopped(reason: string, message: string, cause: unknown): AppError { +/** + * Why an install stopped short of a confirmed result: the provider's own verdicts, or the caller's + * cancellation. `request_canceled` is the kernel's cancellation vocabulary, which no provider table + * re-declares, so it is named here as the one spelling this wrapper also takes. + */ +type RevylInstallStopReason = RevylProviderReason | 'request_canceled'; + +function installStopped(reason: RevylInstallStopReason, message: string, cause: unknown): AppError { return new AppError( 'COMMAND_FAILED', message, @@ -148,13 +159,13 @@ function unsupportedBuild(platform: 'ios' | 'android', appPath: string): AppErro 'INVALID_ARGS', 'Revyl installs an iOS simulator build: a .app directory, or a .zip, .tar.gz, or .tgz of one.', { - reason: 'unsupported_app_artifact', + reason: REVYL_PROVIDER_REASONS.unsupportedAppArtifact.reason, appPath, hint: 'Build for the iOS simulator; a device .ipa does not run on a simulator.', }, ) : new AppError('INVALID_ARGS', 'Revyl installs an Android build from an .apk file.', { - reason: 'unsupported_app_artifact', + reason: REVYL_PROVIDER_REASONS.unsupportedAppArtifact.reason, appPath, hint: 'Pass the .apk the build produced.', }); @@ -179,7 +190,7 @@ async function installAndWait( const installId = accepted.install_id?.trim(); if (accepted.status !== 'accepted' || !installId) { throw new AppError('COMMAND_FAILED', 'Revyl did not accept the app install.', { - reason: 'provider-refused', + reason: REVYL_PROVIDER_REASONS.refused.reason, ...(accepted.status === undefined ? {} : { providerDetail: accepted.status }), }); } @@ -195,7 +206,7 @@ async function installAndWait( return requireInstalled(value.status, value.result ?? undefined); } throw new AppError('COMMAND_FAILED', `Revyl reported install status "${value.status}".`, { - reason: 'provider-refused', + reason: REVYL_PROVIDER_REASONS.refused.reason, installId, }); } @@ -212,7 +223,7 @@ function requireInstalled( 'COMMAND_FAILED', `Revyl could not install the app${error === undefined ? '' : `: ${error}`}`, { - reason: 'provider-refused', + reason: REVYL_PROVIDER_REASONS.refused.reason, installStatus: status, ...(error === undefined ? {} : { providerDetail: error }), }, diff --git a/packages/provider-revyl/src/interactor.ts b/packages/provider-revyl/src/interactor.ts index c4cf42c890..59975b61b8 100644 --- a/packages/provider-revyl/src/interactor.ts +++ b/packages/provider-revyl/src/interactor.ts @@ -31,6 +31,7 @@ import { discloseDispatchAfterSteps, } from '@agent-device/kernel/errors'; import { setTimeout as sleep } from 'node:timers/promises'; +import { REVYL_PROVIDER_REASONS } from './revyl-client.ts'; import type { RevylSession } from './revyl-session.ts'; import { captureRevylSnapshot, createRevylSnapshotReader } from './snapshot.ts'; @@ -155,7 +156,7 @@ class RevylInteractor implements Interactor { 'UNSUPPORTED_OPERATION', `This Revyl session has not launched ${target}, so it has no app to end.`, { - reason: 'provider-app-not-launched', + reason: REVYL_PROVIDER_REASONS.appNotLaunched.reason, command: 'close', requestedApp: target, hint: 'Close without an app name to end the app this session runs, or open the app first.', @@ -283,7 +284,10 @@ class RevylInteractor implements Interactor { throw new AppError( 'COMMAND_FAILED', 'Revyl reported no screen size for this session, so the scroll distance cannot be planned.', - { reason: 'provider-viewport-unavailable', runId: this.session.runId }, + { + reason: REVYL_PROVIDER_REASONS.viewportUnavailable.reason, + runId: this.session.runId, + }, ); } const plan = buildScrollGesturePlan({ @@ -451,7 +455,7 @@ class RevylInteractor implements Interactor { const current = await this.workerAction('appearance'); if (current.appearance !== 'light' && current.appearance !== 'dark') { throw new AppError('COMMAND_FAILED', 'Revyl did not report the current appearance.', { - reason: 'provider-invalid-response', + reason: REVYL_PROVIDER_REASONS.invalidResponse.reason, runId: this.session.runId, }); } @@ -518,7 +522,7 @@ class RevylInteractor implements Interactor { const app = appId?.trim() || this.session.launchedApp.bundleId; if (app) return app; throw new AppError('INVALID_ARGS', `The ${setting} setting needs an app.`, { - reason: 'provider-app-not-launched', + reason: REVYL_PROVIDER_REASONS.appNotLaunched.reason, command: 'settings', hint: 'Pass --app, or open the app first.', }); @@ -569,7 +573,7 @@ async function normalizeRevylIosDensity( throw new AppError( 'COMMAND_FAILED', 'Revyl reported no screen size for this session, so the screenshot density cannot be known.', - { reason: 'provider-viewport-unavailable' }, + { reason: REVYL_PROVIDER_REASONS.viewportUnavailable.reason }, ); } const [{ readPngSize }, { resizePngFile }, { computeDensityScaledScreenshotSize }] = diff --git a/packages/provider-revyl/src/platform-runtime.ts b/packages/provider-revyl/src/platform-runtime.ts index ae918f9110..48349248b9 100644 --- a/packages/provider-revyl/src/platform-runtime.ts +++ b/packages/provider-revyl/src/platform-runtime.ts @@ -2,6 +2,7 @@ import { AppError } from '@agent-device/kernel/errors'; import { REVYL_PROVIDER, isSupportedRevylRuntimeDevice } from './device.ts'; import { providerRuntimeOwner, + PROVIDER_RUNTIME_REASONS, sameRuntimeOwner, type DeviceBinding, type RuntimeFacts, @@ -69,7 +70,7 @@ export function createRevylPlatformRuntimeOwner( throw new AppError( 'UNSUPPORTED_OPERATION', 'Revyl provider session is no longer live for the selected device', - { reason: 'provider-session-unavailable' }, + { reason: PROVIDER_RUNTIME_REASONS.sessionUnavailable.reason }, ); } return bindRevylRuntime(options, owner, request.device, request.scope.signal, live); @@ -152,7 +153,7 @@ function bindRevylDeployment( const live = options.getDeploymentSession(device); if (live) return live; throw new AppError('UNSUPPORTED_OPERATION', 'Revyl provider session is no longer live.', { - reason: 'provider-session-unavailable', + reason: PROVIDER_RUNTIME_REASONS.sessionUnavailable.reason, }); }; return { diff --git a/packages/provider-revyl/src/revyl-client.ts b/packages/provider-revyl/src/revyl-client.ts index 4404bb6181..79273fc7f4 100644 --- a/packages/provider-revyl/src/revyl-client.ts +++ b/packages/provider-revyl/src/revyl-client.ts @@ -1,4 +1,4 @@ -import { AppError, type AppErrorCode } from '@agent-device/kernel/errors'; +import { AppError, type AppErrorCode, type ReasonTable } from '@agent-device/kernel/errors'; import { isRecord } from '@agent-device/kernel/record'; import fs from 'node:fs'; import net from 'node:net'; @@ -45,6 +45,67 @@ export type RevylClientOptions = Readonly<{ fetch?: typeof fetch; }>; +/** + * Every `details.reason` the Revyl provider publishes, keyed by what the failure means. The status + * table below and every Revyl refusal site read these rows, so the plugin's wire vocabulary has one + * owner beside the code that classifies it. `missing_provider_credentials` sits with the credential + * reader instead, which the plugin's eager entry loads before this module exists. + */ +export const REVYL_PROVIDER_REASONS = { + // Revyl refused the request or the action it carries. + refused: { reason: 'provider-refused' }, + // Revyl never answered the request, or the connection to its backend failed. + unreachable: { reason: 'provider-unreachable' }, + // Revyl answered in a way agent-device cannot read, such as a body that is not JSON. + responseInvalid: { reason: 'provider-response-invalid' }, + // Revyl rejected the credentials on the request. + authRejected: { reason: 'provider-auth-rejected' }, + // The session the request addresses no longer exists at Revyl. + sessionGone: { reason: 'provider-session-gone' }, + // Revyl rejected the request because its state conflicts with what it asks for. + conflict: { reason: 'provider-conflict' }, + // Revyl took the request but left its outcome unconfirmed; check the session before retrying. + unconfirmed: { reason: 'provider-unconfirmed' }, + // Revyl refused a request it never routed, with a status that settles the failure. + requestFailed: { reason: 'provider-request-failed' }, + // Revyl gave no response before the request's own deadline passed. + requestTimeout: { reason: 'request_timeout' }, + // `REVYL_API_URL` is not an origin Revyl's API can be addressed at. + invalidProviderUrl: { reason: 'invalid_provider_url' }, + // Revyl installs the app from a URL, so `--provider-app` cannot name a local file. + invalidApp: { reason: 'invalid_provider_app' }, + // Revyl rents an iOS simulator or an Android emulator, and the request names neither. + unsupportedPlatform: { reason: 'unsupported_platform' }, + // Revyl installs an iOS simulator build or an Android .apk, and the build is neither. + unsupportedAppArtifact: { reason: 'unsupported_app_artifact' }, + // The session runs no app, so a close or setting that names one has nothing to act on. + appNotLaunched: { reason: 'provider-app-not-launched' }, + // The session reports no viewport, so a scroll distance or screenshot density has nothing to scale by. + viewportUnavailable: { reason: 'provider-viewport-unavailable' }, + // Revyl answered a worker action with a value outside the field's own range. + invalidResponse: { reason: 'provider-invalid-response' }, + // Revyl started a session under an identity agent-device did not issue for the lease. + sessionIdentityMismatch: { reason: 'provider-session-identity-mismatch' }, + // Revyl refused to start the device and named why in its start answer. + startRefused: { reason: 'provider-start-refused' }, + // Revyl's worker connection ended in a state that never serves the device. + startFailed: { reason: 'provider-start-failed' }, + // Revyl never reported a ready device within the wait the caller could spend. + notReady: { reason: 'provider-not-ready' }, + // Revyl did not confirm it released the session, which stays rented and billed until it does. + cleanupPending: { reason: 'provider-cleanup-pending' }, + // The lease is being released, so it cannot serve another allocation. + leaseReleasing: { reason: 'provider-lease-releasing' }, + // An allocation joins a lease whose device was started for another app or device. + leaseRequestMismatch: { reason: 'provider-lease-request-mismatch' }, + // The provider runtime is ending the sessions it holds, so it takes no new work. + runtimeShuttingDown: { reason: 'runtime-shutting-down' }, +} as const satisfies ReasonTable<'revyl provider'>; + +/** The `details.reason` spellings {@link REVYL_PROVIDER_REASONS} declares. */ +export type RevylProviderReason = + (typeof REVYL_PROVIDER_REASONS)[keyof typeof REVYL_PROVIDER_REASONS]['reason']; + /** * Which half of the API one request belongs to, which is what a 404 or 410 means. A route that * addresses one session or run reports a session Revyl no longer has; a route that starts or @@ -274,7 +335,7 @@ export function createRevylClient(options: RevylClientOptions): RevylClient { throw new AppError( 'COMMAND_FAILED', 'Revyl storage did not accept the app upload.', - { reason: 'provider-unreachable' }, + { reason: REVYL_PROVIDER_REASONS.unreachable.reason }, error, ); } @@ -282,7 +343,10 @@ export function createRevylClient(options: RevylClientOptions): RevylClient { throw new AppError( 'COMMAND_FAILED', `Revyl storage refused the app upload with HTTP ${response.status}.`, - { reason: 'provider-refused', status: response.status }, + { + reason: REVYL_PROVIDER_REASONS.refused.reason, + status: response.status, + }, ); } }, @@ -341,7 +405,7 @@ async function sendOnce( return new AppError( 'COMMAND_FAILED', `Revyl did not answer ${request.method} ${request.path}.`, - { reason: 'provider-unreachable', path: request.path }, + { reason: REVYL_PROVIDER_REASONS.unreachable.reason, path: request.path }, error, ); } @@ -354,7 +418,10 @@ async function sendOnce( */ function isRetryable(request: RevylRequest, outcome: RevylResponse | Error): boolean { if (outcome instanceof Error) { - return outcome instanceof AppError && outcome.details?.reason === 'provider-unreachable'; + return ( + outcome instanceof AppError && + outcome.details?.reason === REVYL_PROVIDER_REASONS.unreachable.reason + ); } if (request.retryServerError === true && outcome.status === 500) return true; return revylFailure(request.route ?? 'general', outcome.status).retryable; @@ -376,7 +443,7 @@ function requestTimedOut(request: RevylRequest, cause: unknown): AppError { request.timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS } ms.`, { - reason: 'request_timeout', + reason: REVYL_PROVIDER_REASONS.requestTimeout.reason, path: request.path, hint: 'Revyl may have carried out the request. Check the session before retrying it.', }, @@ -422,7 +489,7 @@ function assertLifecycleAccepted( 'COMMAND_FAILED', `Revyl did not stop the session${message === undefined ? '' : `: ${message}`}`, { - reason: 'provider-refused', + reason: REVYL_PROVIDER_REASONS.refused.reason, operation, ...(message === undefined ? {} : { providerDetail: message }), hint: 'The Revyl session may still be rented. End it from Revyl if it stays listed.', @@ -453,7 +520,10 @@ function assertWorkerActionSuccess( error === undefined ? '' : `: ${error}` }`, { - reason: response.execution_uncertain === true ? 'provider-unconfirmed' : 'provider-refused', + reason: + response.execution_uncertain === true + ? REVYL_PROVIDER_REASONS.unconfirmed.reason + : REVYL_PROVIDER_REASONS.refused.reason, path: request.path, ...(error === undefined ? {} : { providerDetail: error }), }, @@ -493,7 +563,7 @@ function parseJson(request: RevylRequest, response: RevylResponse): T { throw new AppError( 'COMMAND_FAILED', `Revyl returned a response to ${request.method} ${request.path} that is not JSON (HTTP ${response.status}).`, - { reason: 'provider-response-invalid', path: request.path }, + { reason: REVYL_PROVIDER_REASONS.responseInvalid.reason, path: request.path }, error, ); } @@ -506,7 +576,7 @@ function parseJson(request: RevylRequest, response: RevylResponse): T { */ type RevylStatusVerdict = Readonly<{ code: AppErrorCode; - reason: string; + reason: RevylProviderReason; /** Revyl left it unknown whether the request landed, which is what a hint has to say. */ uncertain: boolean; /** Replaying the request is safe and may succeed, which is what the retry budget is for. */ @@ -515,7 +585,7 @@ type RevylStatusVerdict = Readonly<{ const REVYL_REQUEST_FAILED: RevylStatusVerdict = { code: 'COMMAND_FAILED', - reason: 'provider-request-failed', + reason: REVYL_PROVIDER_REASONS.requestFailed.reason, uncertain: false, retryable: false, }; @@ -523,7 +593,7 @@ const REVYL_REQUEST_FAILED: RevylStatusVerdict = { /** A server error Revyl has no rule for: the request went in, the verdict did not come back. */ const REVYL_SERVER_ERROR: RevylStatusVerdict = { code: 'COMMAND_FAILED', - reason: 'provider-unconfirmed', + reason: REVYL_PROVIDER_REASONS.unconfirmed.reason, uncertain: true, retryable: false, }; @@ -533,48 +603,68 @@ const REVYL_STATUS_VERDICTS: Readonly> = { 400: REVYL_REQUEST_FAILED, 401: { code: 'UNAUTHORIZED', - reason: 'provider-auth-rejected', + reason: REVYL_PROVIDER_REASONS.authRejected.reason, uncertain: false, retryable: false, }, 403: { code: 'UNAUTHORIZED', - reason: 'provider-auth-rejected', + reason: REVYL_PROVIDER_REASONS.authRejected.reason, uncertain: false, retryable: false, }, 404: { code: 'SESSION_NOT_FOUND', - reason: 'provider-session-gone', + reason: REVYL_PROVIDER_REASONS.sessionGone.reason, uncertain: false, retryable: false, }, 408: { code: 'COMMAND_FAILED', - reason: 'provider-unconfirmed', + reason: REVYL_PROVIDER_REASONS.unconfirmed.reason, uncertain: true, retryable: false, }, - 409: { code: 'COMMAND_FAILED', reason: 'provider-conflict', uncertain: false, retryable: false }, + 409: { + code: 'COMMAND_FAILED', + reason: REVYL_PROVIDER_REASONS.conflict.reason, + uncertain: false, + retryable: false, + }, 410: { code: 'SESSION_NOT_FOUND', - reason: 'provider-session-gone', + reason: REVYL_PROVIDER_REASONS.sessionGone.reason, uncertain: false, retryable: false, }, 500: { code: 'COMMAND_FAILED', - reason: 'provider-unconfirmed', + reason: REVYL_PROVIDER_REASONS.unconfirmed.reason, uncertain: true, retryable: false, }, - 502: { code: 'COMMAND_FAILED', reason: 'provider-unconfirmed', uncertain: true, retryable: true }, - 503: { code: 'COMMAND_FAILED', reason: 'provider-unconfirmed', uncertain: true, retryable: true }, - 504: { code: 'COMMAND_FAILED', reason: 'provider-unconfirmed', uncertain: true, retryable: true }, + 502: { + code: 'COMMAND_FAILED', + reason: REVYL_PROVIDER_REASONS.unconfirmed.reason, + uncertain: true, + retryable: true, + }, + 503: { + code: 'COMMAND_FAILED', + reason: REVYL_PROVIDER_REASONS.unconfirmed.reason, + uncertain: true, + retryable: true, + }, + 504: { + code: 'COMMAND_FAILED', + reason: REVYL_PROVIDER_REASONS.unconfirmed.reason, + uncertain: true, + retryable: true, + }, }; /** - * The verdict one status carries, read together with the route that answered. `session-gone` is only + * The verdict one status carries, read together with the route that answered. `sessionGone` is only * ever a session route's answer: a 404 from `start_device` or the credential check is a request the * backend did not route, not a session that ended, and reading it as one sends the user to run `open` * on a session they already have. @@ -582,7 +672,7 @@ const REVYL_STATUS_VERDICTS: Readonly> = { function revylFailure(route: RevylRoute, status: number): RevylStatusVerdict { const verdict = REVYL_STATUS_VERDICTS[status] ?? (status >= 500 ? REVYL_SERVER_ERROR : REVYL_REQUEST_FAILED); - if (verdict.reason === 'provider-session-gone' && route !== 'session') + if (verdict.reason === REVYL_PROVIDER_REASONS.sessionGone.reason && route !== 'session') return REVYL_REQUEST_FAILED; return verdict; } @@ -605,7 +695,9 @@ export function revylFailureRefusedTheRequest(error: unknown): boolean { * the same way. */ export function isRevylSessionGone(error: unknown): boolean { - return error instanceof AppError && error.details?.reason === 'provider-session-gone'; + return ( + error instanceof AppError && error.details?.reason === REVYL_PROVIDER_REASONS.sessionGone.reason + ); } /** The loopback ranges, the same set the daemon client trusts for a local daemon. */ @@ -629,7 +721,7 @@ export function resolveRevylBackendUrl(raw: string): string { url = new URL(raw); } catch { throw new AppError('INVALID_ARGS', 'REVYL_API_URL is not a valid URL.', { - reason: 'invalid_provider_url', + reason: REVYL_PROVIDER_REASONS.invalidProviderUrl.reason, }); } const loopback = isLoopbackHostname(url.hostname); @@ -637,14 +729,17 @@ export function resolveRevylBackendUrl(raw: string): string { throw new AppError( 'INVALID_ARGS', 'REVYL_API_URL must use HTTPS; plain HTTP is allowed only on loopback.', - { reason: 'invalid_provider_url', hint: 'Example: https://backend.revyl.ai' }, + { + reason: REVYL_PROVIDER_REASONS.invalidProviderUrl.reason, + hint: 'Example: https://backend.revyl.ai', + }, ); } if (url.username || url.password || url.search || url.hash) { throw new AppError( 'INVALID_ARGS', 'REVYL_API_URL must be an origin without credentials, query, or fragment.', - { reason: 'invalid_provider_url' }, + { reason: REVYL_PROVIDER_REASONS.invalidProviderUrl.reason }, ); } return url.origin; diff --git a/packages/provider-revyl/src/revyl-session.ts b/packages/provider-revyl/src/revyl-session.ts index c46a64d1b3..d31ff9f126 100644 --- a/packages/provider-revyl/src/revyl-session.ts +++ b/packages/provider-revyl/src/revyl-session.ts @@ -4,6 +4,7 @@ import type { DeviceLease } from '@agent-device/contracts/device'; import type { DeviceInfo } from '@agent-device/kernel/device'; import { buildRevylDevice, revylSessionIdForLease, type RevylPlatform } from './device.ts'; import { + REVYL_PROVIDER_REASONS, REVYL_START_DEVICE_TIMEOUT_MS, isRevylSessionGone, revylFailureRefusedTheRequest, @@ -148,7 +149,7 @@ export async function startRevylSession( 'COMMAND_FAILED', `Revyl started the device as session ${echoed} instead of ${sessionId}.`, { - reason: 'provider-session-identity-mismatch', + reason: REVYL_PROVIDER_REASONS.sessionIdentityMismatch.reason, runId, providerSessionId: echoed, hint: 'Retry the command; agent-device ends a Revyl session by the identity it issued.', @@ -166,7 +167,7 @@ export async function startRevylSession( 'COMMAND_FAILED', `Revyl did not start a ${input.platform} device: ${started.error ?? started.message ?? 'no workflow run was returned'}`, { - reason: 'provider-start-refused', + reason: REVYL_PROVIDER_REASONS.startRefused.reason, platform: input.platform, ...(started.trace_id === undefined ? {} : { traceId: started.trace_id }), }, @@ -267,7 +268,7 @@ export function revylCallerGaveUp( 'COMMAND_FAILED', `Revyl did not report a ready device within ${budgetMs} ms.`, { - reason: 'provider-not-ready', + reason: REVYL_PROVIDER_REASONS.notReady.reason, timeoutMs: budgetMs, providerSessionId, ...(budget.deadline === undefined ? {} : { deadline: budget.deadline }), @@ -305,7 +306,7 @@ export function revylCleanupPending( 'COMMAND_FAILED', `Revyl did not release session${one ? '' : 's'} ${ids}.`, { - reason: 'provider-cleanup-pending', + reason: REVYL_PROVIDER_REASONS.cleanupPending.reason, ...details, providerSessionIds: unconfirmed.map((stop) => stop.sessionId), causes: unconfirmed.map((stop) => stop.failure), @@ -431,7 +432,11 @@ async function untilRevylWorkerReady( ? '' : ` (${connection.message})` }`, - { reason: 'provider-start-failed', runId, status: connection.status }, + { + reason: REVYL_PROVIDER_REASONS.startFailed.reason, + runId, + status: connection.status, + }, ); } await sleepBefore(deadline, input.signal); diff --git a/packages/provider-revyl/src/runtime.ts b/packages/provider-revyl/src/runtime.ts index b154d1efdc..b344137f1c 100644 --- a/packages/provider-revyl/src/runtime.ts +++ b/packages/provider-revyl/src/runtime.ts @@ -22,7 +22,12 @@ import { revylSessionIdForLease, type RevylPlatform, } from './device.ts'; -import { createRevylClient, isRevylSessionGone, type RevylClient } from './revyl-client.ts'; +import { + createRevylClient, + isRevylSessionGone, + REVYL_PROVIDER_REASONS, + type RevylClient, +} from './revyl-client.ts'; import { keepRevylSessionAlive, REVYL_ALLOCATION_TIMEOUT_MS, @@ -268,7 +273,7 @@ function createRevylLeaseDriver( shuttingDown: (lease) => shuttingDownDuring(lease.leaseId, 'allocate'), releasing: (lease) => new AppError('COMMAND_FAILED', `Revyl lease ${lease.leaseId} is being released.`, { - reason: 'provider-lease-releasing', + reason: REVYL_PROVIDER_REASONS.leaseReleasing.reason, leaseId: lease.leaseId, hint: 'Run open again; it allocates a new lease and rents a fresh device.', }), @@ -340,7 +345,7 @@ function requireRevylLease(lease: DeviceLease, operation: 'recover' | 'release') function shuttingDownDuring(leaseId: string, operation: string): AppError { return new AppError('COMMAND_FAILED', `The Revyl runtime is shutting down.`, { - reason: 'runtime-shutting-down', + reason: REVYL_PROVIDER_REASONS.runtimeShuttingDown.reason, operation, leaseId, hint: 'Retry the command; the daemon is ending the sessions it holds.', diff --git a/packages/provider-revyl/src/session-allocation.ts b/packages/provider-revyl/src/session-allocation.ts index b5c76af7a1..b941e75b0b 100644 --- a/packages/provider-revyl/src/session-allocation.ts +++ b/packages/provider-revyl/src/session-allocation.ts @@ -2,6 +2,7 @@ import type { LeaseLifecycleContext } from '@agent-device/contracts/device'; import { AppError } from '@agent-device/kernel/errors'; import { rejectRefusedProviderProfileFields } from '@agent-device/contracts/provider-profile-fields'; import { REVYL_PROFILE_FIELDS } from './profile-fields.ts'; +import { REVYL_PROVIDER_REASONS } from './revyl-client.ts'; /** * Refuses the connect flags Revyl has no field for, so a flag that would be ignored is reported @@ -78,7 +79,7 @@ export function requireSameRevylStartRequest( 'INVALID_ARGS', `Revyl lease ${leaseId} already has a device started for a different ${differing.join(', ')}.`, { - reason: 'provider-lease-request-mismatch', + reason: REVYL_PROVIDER_REASONS.leaseRequestMismatch.reason, leaseId, fields: differing, hint: 'Disconnect and connect again to rent a device for the new app or device selection.', diff --git a/packages/provider-revyl/src/snapshot.ts b/packages/provider-revyl/src/snapshot.ts index 1a746f8a0c..6e85b0bf7d 100644 --- a/packages/provider-revyl/src/snapshot.ts +++ b/packages/provider-revyl/src/snapshot.ts @@ -6,6 +6,7 @@ import { acquireProviderKeyboard } from '@agent-device/contracts/tap-keyboard-oc import type { IosTreeNode } from '@agent-device/capture-kit/ios-ax-tree'; import type { RevylPlatform } from './device.ts'; import type { RevylSession } from './revyl-session.ts'; +import { REVYL_PROVIDER_REASONS } from './revyl-client.ts'; /** Reads one Revyl worker's accessibility tree and the box its actions measure. */ export type RevylSnapshotReader = Readonly<{ @@ -102,7 +103,7 @@ function invalidIosHierarchy(cause?: unknown): AppError { return new AppError( 'COMMAND_FAILED', 'Revyl returned an iOS hierarchy that is not an accessibility node tree.', - { reason: 'provider-response-invalid' }, + { reason: REVYL_PROVIDER_REASONS.responseInvalid.reason }, cause, ); } diff --git a/packages/provider-webdriver/src/runtime-session.ts b/packages/provider-webdriver/src/runtime-session.ts index 26c92db152..ffa317c5fb 100644 --- a/packages/provider-webdriver/src/runtime-session.ts +++ b/packages/provider-webdriver/src/runtime-session.ts @@ -15,7 +15,7 @@ import { WebDriverClient, type WebDriverSession } from './webdriver-client.ts'; import { isWebDriverRequestTimeout } from './webdriver-transport.ts'; import { createWebDriverInteractor } from './webdriver-interactor.ts'; import { snapshotBackendForPlatform } from './runtime-helpers.ts'; -import { releaseOnFailure } from './webdriver-utils.ts'; +import { releaseOnFailure, WEBDRIVER_PROVIDER_REASONS } from './webdriver-utils.ts'; import type { CloudWebDriverBaseSession, CloudWebDriverPreparedSession, @@ -653,7 +653,7 @@ function sessionCreateTimeoutError( 'COMMAND_FAILED', `${provider} did not create the WebDriver session within ${String(timeoutMs)}ms.`, { - reason: 'provider_session_create_timeout', + reason: WEBDRIVER_PROVIDER_REASONS.sessionCreateTimeout.reason, provider, leaseId: lease.leaseId, runId: lease.runId, @@ -688,8 +688,8 @@ function refusalForTeardown( { reason: by === 'release' - ? 'provider_session_released_during_allocation' - : 'provider_session_shutdown_during_allocation', + ? WEBDRIVER_PROVIDER_REASONS.sessionReleasedDuringAllocation.reason + : WEBDRIVER_PROVIDER_REASONS.sessionShutdownDuringAllocation.reason, provider, leaseId: lease.leaseId, runId: lease.runId, @@ -730,7 +730,7 @@ function refusalForTeardownInProgress( 'DEVICE_IN_USE', `${provider} is releasing lease ${lease.leaseId} and allocated no WebDriver session for it.`, { - reason: 'provider_session_release_in_progress', + reason: WEBDRIVER_PROVIDER_REASONS.sessionReleaseInProgress.reason, provider, leaseId: lease.leaseId, runId: lease.runId, @@ -752,7 +752,7 @@ function allocationRefusedAfterShutdown(provider: string, lease: DeviceLease): A 'COMMAND_FAILED', `${provider} is shut down and created no WebDriver session for lease ${lease.leaseId}.`, { - reason: 'provider_session_shutdown_during_allocation', + reason: WEBDRIVER_PROVIDER_REASONS.sessionShutdownDuringAllocation.reason, provider, leaseId: lease.leaseId, runId: lease.runId, @@ -797,7 +797,7 @@ function shutdownLeftSessionsRunning( 'COMMAND_FAILED', `${provider} left ${String(outcomes.length)} WebDriver session(s) running after shutdown: ${providerSessionIds.join(', ')}.`, { - reason: 'provider_session_cleanup_incomplete', + reason: WEBDRIVER_PROVIDER_REASONS.sessionCleanupIncomplete.reason, provider, providerSessionIds, cleanup: 'uncertain', diff --git a/packages/provider-webdriver/src/webdriver-interactor.ts b/packages/provider-webdriver/src/webdriver-interactor.ts index 966234c37e..e2ffd32052 100644 --- a/packages/provider-webdriver/src/webdriver-interactor.ts +++ b/packages/provider-webdriver/src/webdriver-interactor.ts @@ -26,6 +26,7 @@ import { } from './capabilities.ts'; import type { W3CPointerAction, WebDriverClient, WebDriverWindowRect } from './webdriver-client.ts'; import { isWebDriverRequestTimeout } from './webdriver-transport.ts'; +import { WEBDRIVER_PROVIDER_REASONS } from './webdriver-utils.ts'; import { touchPointer } from './webdriver-gestures.ts'; import { scrollFrameFromAndroidWebDriverSource, @@ -80,7 +81,7 @@ function textEntryClearTargetUnavailableError(): AppError { return new AppError( 'UNSUPPORTED_OPERATION', 'fill requires a focused element reference to clear and replace the field', - { reason: 'text_entry_clear_target_unavailable' }, + { reason: WEBDRIVER_PROVIDER_REASONS.textEntryClearTargetUnavailable.reason }, ); } diff --git a/packages/provider-webdriver/src/webdriver-transport.ts b/packages/provider-webdriver/src/webdriver-transport.ts index 404bc9df14..36d50f95d6 100644 --- a/packages/provider-webdriver/src/webdriver-transport.ts +++ b/packages/provider-webdriver/src/webdriver-transport.ts @@ -1,7 +1,12 @@ import { setTimeout as sleep } from 'node:timers/promises'; import { AppError, type DispatchDisclosure } from '@agent-device/kernel/errors'; import { agentDeviceRequestHeaders } from './request-headers.ts'; -import { basicAuthHeader, trimLeadingSlash, withTrailingSlash } from './webdriver-utils.ts'; +import { + basicAuthHeader, + trimLeadingSlash, + WEBDRIVER_PROVIDER_REASONS, + withTrailingSlash, +} from './webdriver-utils.ts'; export type WebDriverAuth = { username: string; @@ -21,12 +26,12 @@ export type WebDriverRequestPolicy = { sessionCreateTimeoutMs?: number; }; -/** Machine-readable `details.reason` of a request the transport gave up waiting on. */ -const WEBDRIVER_REQUEST_TIMEOUT_REASON = 'webdriver_request_timeout'; - /** A request the transport stopped waiting on; the server may still complete it. */ export function isWebDriverRequestTimeout(error: unknown): error is AppError { - return error instanceof AppError && error.details?.reason === WEBDRIVER_REQUEST_TIMEOUT_REASON; + return ( + error instanceof AppError && + error.details?.reason === WEBDRIVER_PROVIDER_REASONS.requestTimeout.reason + ); } /** @@ -38,15 +43,6 @@ function dispatchDisclosure(dispatched: DispatchDisclosure): { dispatched: Dispa return { dispatched }; } -/** Machine-readable `details.reason` of a request that never reached the driver. */ -const WEBDRIVER_CONNECT_REFUSED_REASON = 'webdriver_connect_refused'; - -/** - * Machine-readable `details.reason` of a request whose connection failed after it may have - * reached the driver: a socket reset, or a response body cut off after the status line. - */ -const WEBDRIVER_REQUEST_INTERRUPTED_REASON = 'webdriver_request_interrupted'; - /** * Socket error codes that prove the connection was never established, so no byte of the request * reached the driver. @@ -65,7 +61,10 @@ const ERROR_CAUSE_DEPTH_LIMIT = 4; /** A request whose connection failed before it was established (refused or unreachable host). */ export function isWebDriverConnectRefused(error: unknown): error is AppError { - return error instanceof AppError && error.details?.reason === WEBDRIVER_CONNECT_REFUSED_REASON; + return ( + error instanceof AppError && + error.details?.reason === WEBDRIVER_PROVIDER_REASONS.connectRefused.reason + ); } export type WebDriverRequestOverrides = { @@ -217,7 +216,7 @@ export class WebDriverTransport { const payload = parsed.json; const error = webdriverError(status, payload); if (isWebDriverRouteUnsupported(error)) { - emitWebDriverDiagnostic(WEBDRIVER_ROUTE_UNSUPPORTED_REASON, { + emitWebDriverDiagnostic(WEBDRIVER_PROVIDER_REASONS.routeUnsupported.reason, { method, path, status, @@ -398,9 +397,6 @@ function nonJsonAnswerError(status: number, text: string): AppError { }); } -/** Machine-readable `details.reason` of a driver answer that it does not implement the route. */ -const WEBDRIVER_ROUTE_UNSUPPORTED_REASON = 'webdriver_route_unsupported'; - /** * The driver answered with the W3C `invalid session id` error: the session it was asked about does * not exist (never did, was deleted, or timed out on the driver). @@ -418,10 +414,13 @@ export function isWebDriverInvalidSession(error: unknown): error is AppError { * the route. A command that tried every route it has and was refused by each carries the same. */ export function unsupportedRouteRefusal(): { - reason: typeof WEBDRIVER_ROUTE_UNSUPPORTED_REASON; + reason: typeof WEBDRIVER_PROVIDER_REASONS.routeUnsupported.reason; dispatched: DispatchDisclosure; } { - return { reason: WEBDRIVER_ROUTE_UNSUPPORTED_REASON, ...dispatchDisclosure('no') }; + return { + reason: WEBDRIVER_PROVIDER_REASONS.routeUnsupported.reason, + ...dispatchDisclosure('no'), + }; } /** W3C `error` codes a driver answers with when it does not implement the route. */ @@ -472,7 +471,10 @@ export function emitWebDriverDiagnostic(phase: string, data: Record; + /** Best-effort release after a failure; a failed release rides along as `cleanupError`, never masks the primary. */ export async function releaseOnFailure( primaryError: unknown, @@ -137,7 +171,9 @@ export async function postHubAppUpload( 'COMMAND_FAILED', `${options.service} app upload failed.`, { - reason: timedOut ? 'hub_app_upload_timeout' : 'hub_app_upload_transport_failed', + reason: timedOut + ? WEBDRIVER_PROVIDER_REASONS.hubAppUploadTimeout.reason + : WEBDRIVER_PROVIDER_REASONS.hubAppUploadTransportFailed.reason, ...(timedOut ? { timeoutMs: HUB_APP_UPLOAD_TIMEOUT_MS } : {}), hint: `Check network access to the ${options.service} upload API, then retry.`, }, @@ -217,7 +253,10 @@ function requireAppCwd(options: { service: string; app: string; cwd?: string }): throw new AppError( 'INVALID_ARGS', `${options.service} --provider-app ${options.app} is a relative path and the request names no working directory; pass an absolute path.`, - { providerApp: options.app, reason: 'provider_app_cwd_missing' }, + { + providerApp: options.app, + reason: WEBDRIVER_PROVIDER_REASONS.providerAppCwdMissing.reason, + }, ); } diff --git a/website/docs/docs/error-reasons.md b/website/docs/docs/error-reasons.md index 030b59b874..0df7ceca29 100644 --- a/website/docs/docs/error-reasons.md +++ b/website/docs/docs/error-reasons.md @@ -197,11 +197,25 @@ These reasons can come from more than one command. | `LEASE_NOT_FOUND` | The lease that the request names is not active. | | `LEASE_SCOPE_MISMATCH` | The lease does not match the tenant, run, backend, provider, device, or client of the request. | | `LEASE_SCOPE_REQUIRED` | The lease was allocated with an owner scope that the request does not repeat. | +| `provider-instance-ended` | The device instance behind the lease ended outside the daemon, which ends the lease with it. | | `LEASE_ID_IN_USE` | The requested lease id already names a lease that this daemon issued. | | `LEASE_CAPACITY_EXCEEDED` | Every iOS simulator lease slot is taken; retry after another lease is released. | | `LEASE_SESSION_MISMATCH` | The lease scope of the request differs from the lease of its session; `details.field` names the field. | | `LEASE_LEDGER_OVERWRITE` | The CLI already tracks an allocated lease and must release or transfer it before it allocates another. | +### Limrun provider + +| Reason | Meaning | +| --- | --- | +| `limrun_instance_delete_unconfirmed` | A release could not confirm Limrun deleted the instance, so it may still be billed. | +| `limrun_lease_released_mid_allocation` | The lease was released while its instance was still being prepared for the allocation. | +| `limrun_lease_not_live` | The lease holds no live session, so the command that addresses it has nothing to act on. | +| `limrun_runtime_shut_down` | This runtime is shut down, so it refuses to allocate a lease into it. | +| `limrun_instance_unreachable` | The instance stopped answering, so its app state cannot be read. | +| `limrun_adb_tunnel_cleaned_up` | The ADB tunnel of this lease was already cleaned up, so nothing can be typed over it. | +| `limrun_app_sync_retired` | The app-sync session of this lease has ended, so no further sync runs on it. | +| `limrun_app_sync_failed` | Syncing the app to the instance stopped with nothing installed. | + ### Macos helper | Reason | Meaning | @@ -219,6 +233,12 @@ These reasons can come from more than one command. | `event_creation_failed` | macOS could not create the keyboard or mouse event to post. | | `missing_button` | No button on the alert fits the requested accept or dismiss. | +### Provider runtime + +| Reason | Meaning | +| --- | --- | +| `provider-session-unavailable` | The provider's session for the device ended, so the runtime has nothing left to serve. | + ### Request admission | Reason | Meaning | @@ -229,6 +249,36 @@ These reasons can come from more than one command. | `app_not_installed` | The named app resolves to no installed app on the target. | | `malformed_request` | The transport refused the request envelope before any handler read it. | +### Revyl provider + +| Reason | Meaning | +| --- | --- | +| `missing_provider_credentials` | No Revyl API key is set, so the provider cannot authenticate the request. | +| `provider-refused` | Revyl refused the request or the action it carries. | +| `provider-unreachable` | Revyl never answered the request, or the connection to its backend failed. | +| `provider-response-invalid` | Revyl answered in a way agent-device cannot read, such as a body that is not JSON. | +| `provider-auth-rejected` | Revyl rejected the credentials on the request. | +| `provider-session-gone` | The session the request addresses no longer exists at Revyl. | +| `provider-conflict` | Revyl rejected the request because its state conflicts with what it asks for. | +| `provider-unconfirmed` | Revyl took the request but left its outcome unconfirmed; check the session before retrying. | +| `provider-request-failed` | Revyl refused a request it never routed, with a status that settles the failure. | +| `request_timeout` | Revyl gave no response before the request's own deadline passed. | +| `invalid_provider_url` | `REVYL_API_URL` is not an origin Revyl's API can be addressed at. | +| `invalid_provider_app` | Revyl installs the app from a URL, so `--provider-app` cannot name a local file. | +| `unsupported_platform` | Revyl rents an iOS simulator or an Android emulator, and the request names neither. | +| `unsupported_app_artifact` | Revyl installs an iOS simulator build or an Android .apk, and the build is neither. | +| `provider-app-not-launched` | The session runs no app, so a close or setting that names one has nothing to act on. | +| `provider-viewport-unavailable` | The session reports no viewport, so a scroll distance or screenshot density has nothing to scale by. | +| `provider-invalid-response` | Revyl answered a worker action with a value outside the field's own range. | +| `provider-session-identity-mismatch` | Revyl started a session under an identity agent-device did not issue for the lease. | +| `provider-start-refused` | Revyl refused to start the device and named why in its start answer. | +| `provider-start-failed` | Revyl's worker connection ended in a state that never serves the device. | +| `provider-not-ready` | Revyl never reported a ready device within the wait the caller could spend. | +| `provider-cleanup-pending` | Revyl did not confirm it released the session, which stays rented and billed until it does. | +| `provider-lease-releasing` | The lease is being released, so it cannot serve another allocation. | +| `provider-lease-request-mismatch` | An allocation joins a lease whose device was started for another app or device. | +| `runtime-shutting-down` | The provider runtime is ending the sessions it holds, so it takes no new work. | + ### Snapshot capture | Reason | Meaning | @@ -240,3 +290,21 @@ These reasons can come from more than one command. | `simulator-target-identity-unavailable` | The app's simulator process was found, but its identity could not be read. | | `simulator-runtime-probe-failed` | The simulator could not be asked for its runtime. | | `simulator-runtime-unavailable` | The simulator reported no runtime. | + +### Webdriver provider + +| Reason | Meaning | +| --- | --- | +| `hub_app_upload_timeout` | The app upload to the provider's storage did not answer within its own deadline. | +| `hub_app_upload_transport_failed` | The app upload to the provider's storage never completed its transport. | +| `provider_app_cwd_missing` | `--provider-app` is a relative path and the request names no working directory to resolve it in. | +| `webdriver_request_timeout` | The transport stopped waiting on a WebDriver request the driver may still be carrying out. | +| `webdriver_connect_refused` | The request never reached the driver: the connection was refused or the host is unreachable. | +| `webdriver_request_interrupted` | The connection to the driver failed after the request may have reached it. | +| `webdriver_route_unsupported` | The driver answered that it does not implement the route. | +| `provider_session_create_timeout` | The provider did not create the WebDriver session within the session-creation budget. | +| `provider_session_released_during_allocation` | The provider ended the session an allocation was waiting on by releasing its lease. | +| `provider_session_shutdown_during_allocation` | The provider ended the session an allocation was waiting on while shutting down. | +| `provider_session_release_in_progress` | The lease is still releasing its previous session, so a new allocation gets no session. | +| `provider_session_cleanup_incomplete` | Shutdown left WebDriver sessions running, so they may still be billed. | +| `text_entry_clear_target_unavailable` | `fill` has no focused element reference to clear before it types the replacement text. | From a0497dc2a177780391affd7543df758b58342796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 21 Nov 2026 22:10:37 +0100 Subject: [PATCH 2/9] refactor(reasons): read the provider-instance-ended reason from LEASE_REASONS Drops the PROVIDER_INSTANCE_ENDED alias, so the value has one spelling. Co-Authored-By: Claude Opus 5.5 --- packages/contracts/src/lease-scope.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/packages/contracts/src/lease-scope.ts b/packages/contracts/src/lease-scope.ts index 7d7da6a3bb..c46e1ee042 100644 --- a/packages/contracts/src/lease-scope.ts +++ b/packages/contracts/src/lease-scope.ts @@ -546,12 +546,6 @@ export function isInactiveLeaseError(error: unknown): boolean { ); } -/** - * The reason a provider gives when the device instance behind a lease ended outside the daemon, read - * from the table so the spelling has one owner. - */ -export const PROVIDER_INSTANCE_ENDED = LEASE_REASONS.instanceEnded.reason; - /** Whether `error` says the provider's device instance ended, which ends its lease. */ export function isProviderInstanceEndedError(error: unknown): boolean { return ( @@ -559,7 +553,7 @@ export function isProviderInstanceEndedError(error: unknown): boolean { error !== null && (error as Readonly<{ code?: unknown }>).code === 'COMMAND_FAILED' && (error as Readonly<{ details?: Readonly<{ reason?: unknown }> }>).details?.reason === - PROVIDER_INSTANCE_ENDED + LEASE_REASONS.instanceEnded.reason ); } From 17493539881cc028a3fcbd51bac1618aa5fcdece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sat, 21 Nov 2026 23:07:04 +0100 Subject: [PATCH 3/9] refactor(reasons): split the WebDriver reasons into a table per raising module; fix the app-sync summary Each WebDriver module (app upload, transport, session, text entry) now owns the rows it raises, all under the 'webdriver provider' owner. limrun_app_sync_failed now says sync or local cache maintenance failed and to check the device for the app. Co-Authored-By: Claude Opus 5.5 --- packages/provider-limrun/src/device.ts | 2 +- .../provider-webdriver/src/runtime-session.ts | 30 ++++++++++---- .../src/webdriver-interactor.ts | 11 +++-- .../src/webdriver-transport.ts | 41 +++++++++++-------- .../provider-webdriver/src/webdriver-utils.ts | 34 +++------------ website/docs/docs/error-reasons.md | 16 ++++---- 6 files changed, 68 insertions(+), 66 deletions(-) diff --git a/packages/provider-limrun/src/device.ts b/packages/provider-limrun/src/device.ts index 7d584997cf..85d0b087d8 100644 --- a/packages/provider-limrun/src/device.ts +++ b/packages/provider-limrun/src/device.ts @@ -25,7 +25,7 @@ export const LIMRUN_PROVIDER_REASONS = { adbTunnelCleanedUp: { reason: 'limrun_adb_tunnel_cleaned_up' }, // The app-sync session of this lease has ended, so no further sync runs on it. appSyncRetired: { reason: 'limrun_app_sync_retired' }, - // Syncing the app to the instance stopped with nothing installed. + // App sync or local cache maintenance failed; check the device for the app before retrying. appSyncFailed: { reason: 'limrun_app_sync_failed' }, } as const satisfies ReasonTable<'limrun provider'>; diff --git a/packages/provider-webdriver/src/runtime-session.ts b/packages/provider-webdriver/src/runtime-session.ts index ffa317c5fb..fc0cb96b18 100644 --- a/packages/provider-webdriver/src/runtime-session.ts +++ b/packages/provider-webdriver/src/runtime-session.ts @@ -4,7 +4,7 @@ import type { } from '@agent-device/contracts/observability'; import type { DeviceLease, LeaseLifecycleContext } from '@agent-device/contracts/device'; import { deviceFieldsFromPublicPlatform, type DeviceInfo } from '@agent-device/kernel/device'; -import { AppError, errorMessage } from '@agent-device/kernel/errors'; +import { AppError, errorMessage, type ReasonTable } from '@agent-device/kernel/errors'; import { unavailableCloudArtifactsResult } from './artifact-results.ts'; import { createCloudWebDriverCapabilities, @@ -15,7 +15,7 @@ import { WebDriverClient, type WebDriverSession } from './webdriver-client.ts'; import { isWebDriverRequestTimeout } from './webdriver-transport.ts'; import { createWebDriverInteractor } from './webdriver-interactor.ts'; import { snapshotBackendForPlatform } from './runtime-helpers.ts'; -import { releaseOnFailure, WEBDRIVER_PROVIDER_REASONS } from './webdriver-utils.ts'; +import { releaseOnFailure } from './webdriver-utils.ts'; import type { CloudWebDriverBaseSession, CloudWebDriverPreparedSession, @@ -23,6 +23,20 @@ import type { } from './runtime.ts'; import type { Interactor } from '@agent-device/contracts/interactor-types'; +/** Why a provider WebDriver session could not be allocated or cleaned up. */ +const WEBDRIVER_SESSION_REASONS = { + // The provider did not create the WebDriver session within the session-creation budget. + sessionCreateTimeout: { reason: 'provider_session_create_timeout' }, + // The provider ended the session an allocation was waiting on by releasing its lease. + sessionReleasedDuringAllocation: { reason: 'provider_session_released_during_allocation' }, + // The provider ended the session an allocation was waiting on while shutting down. + sessionShutdownDuringAllocation: { reason: 'provider_session_shutdown_during_allocation' }, + // The lease is still releasing its previous session, so a new allocation gets no session. + sessionReleaseInProgress: { reason: 'provider_session_release_in_progress' }, + // Shutdown left WebDriver sessions running, so they may still be billed. + sessionCleanupIncomplete: { reason: 'provider_session_cleanup_incomplete' }, +} as const satisfies ReasonTable<'webdriver provider'>; + export type WebDriverProviderSession = Readonly<{ lease: DeviceLease; device: DeviceInfo; @@ -653,7 +667,7 @@ function sessionCreateTimeoutError( 'COMMAND_FAILED', `${provider} did not create the WebDriver session within ${String(timeoutMs)}ms.`, { - reason: WEBDRIVER_PROVIDER_REASONS.sessionCreateTimeout.reason, + reason: WEBDRIVER_SESSION_REASONS.sessionCreateTimeout.reason, provider, leaseId: lease.leaseId, runId: lease.runId, @@ -688,8 +702,8 @@ function refusalForTeardown( { reason: by === 'release' - ? WEBDRIVER_PROVIDER_REASONS.sessionReleasedDuringAllocation.reason - : WEBDRIVER_PROVIDER_REASONS.sessionShutdownDuringAllocation.reason, + ? WEBDRIVER_SESSION_REASONS.sessionReleasedDuringAllocation.reason + : WEBDRIVER_SESSION_REASONS.sessionShutdownDuringAllocation.reason, provider, leaseId: lease.leaseId, runId: lease.runId, @@ -730,7 +744,7 @@ function refusalForTeardownInProgress( 'DEVICE_IN_USE', `${provider} is releasing lease ${lease.leaseId} and allocated no WebDriver session for it.`, { - reason: WEBDRIVER_PROVIDER_REASONS.sessionReleaseInProgress.reason, + reason: WEBDRIVER_SESSION_REASONS.sessionReleaseInProgress.reason, provider, leaseId: lease.leaseId, runId: lease.runId, @@ -752,7 +766,7 @@ function allocationRefusedAfterShutdown(provider: string, lease: DeviceLease): A 'COMMAND_FAILED', `${provider} is shut down and created no WebDriver session for lease ${lease.leaseId}.`, { - reason: WEBDRIVER_PROVIDER_REASONS.sessionShutdownDuringAllocation.reason, + reason: WEBDRIVER_SESSION_REASONS.sessionShutdownDuringAllocation.reason, provider, leaseId: lease.leaseId, runId: lease.runId, @@ -797,7 +811,7 @@ function shutdownLeftSessionsRunning( 'COMMAND_FAILED', `${provider} left ${String(outcomes.length)} WebDriver session(s) running after shutdown: ${providerSessionIds.join(', ')}.`, { - reason: WEBDRIVER_PROVIDER_REASONS.sessionCleanupIncomplete.reason, + reason: WEBDRIVER_SESSION_REASONS.sessionCleanupIncomplete.reason, provider, providerSessionIds, cleanup: 'uncertain', diff --git a/packages/provider-webdriver/src/webdriver-interactor.ts b/packages/provider-webdriver/src/webdriver-interactor.ts index e2ffd32052..e6df251b47 100644 --- a/packages/provider-webdriver/src/webdriver-interactor.ts +++ b/packages/provider-webdriver/src/webdriver-interactor.ts @@ -17,7 +17,7 @@ import { import type { TvRemoteButton } from '@agent-device/contracts/tv-remote'; import type { SettingOptions } from '@agent-device/contracts/settings'; import { snapshotViewportSizeFrom } from '@agent-device/kernel/rect'; -import { AppError } from '@agent-device/kernel/errors'; +import { AppError, type ReasonTable } from '@agent-device/kernel/errors'; import { capabilitySupported, unsupportedCapabilityMessage, @@ -26,7 +26,6 @@ import { } from './capabilities.ts'; import type { W3CPointerAction, WebDriverClient, WebDriverWindowRect } from './webdriver-client.ts'; import { isWebDriverRequestTimeout } from './webdriver-transport.ts'; -import { WEBDRIVER_PROVIDER_REASONS } from './webdriver-utils.ts'; import { touchPointer } from './webdriver-gestures.ts'; import { scrollFrameFromAndroidWebDriverSource, @@ -34,6 +33,12 @@ import { } from './webdriver-scroll-frame.ts'; import { setWebDriverOrientation } from './webdriver-orientation.ts'; +/** Why WebDriver text entry refused. */ +const WEBDRIVER_TEXT_ENTRY_REASONS = { + // `fill` has no focused element reference to clear before it types the replacement text. + textEntryClearTargetUnavailable: { reason: 'text_entry_clear_target_unavailable' }, +} as const satisfies ReasonTable<'webdriver provider'>; + /** * How long a tapped field gets to take text entry focus before `fill` gives up. * Mirrors the Apple runner's `TextEntryTiming.readinessTimeout` @@ -81,7 +86,7 @@ function textEntryClearTargetUnavailableError(): AppError { return new AppError( 'UNSUPPORTED_OPERATION', 'fill requires a focused element reference to clear and replace the field', - { reason: WEBDRIVER_PROVIDER_REASONS.textEntryClearTargetUnavailable.reason }, + { reason: WEBDRIVER_TEXT_ENTRY_REASONS.textEntryClearTargetUnavailable.reason }, ); } diff --git a/packages/provider-webdriver/src/webdriver-transport.ts b/packages/provider-webdriver/src/webdriver-transport.ts index 36d50f95d6..717aa9e355 100644 --- a/packages/provider-webdriver/src/webdriver-transport.ts +++ b/packages/provider-webdriver/src/webdriver-transport.ts @@ -1,12 +1,19 @@ import { setTimeout as sleep } from 'node:timers/promises'; -import { AppError, type DispatchDisclosure } from '@agent-device/kernel/errors'; +import { AppError, type DispatchDisclosure, type ReasonTable } from '@agent-device/kernel/errors'; import { agentDeviceRequestHeaders } from './request-headers.ts'; -import { - basicAuthHeader, - trimLeadingSlash, - WEBDRIVER_PROVIDER_REASONS, - withTrailingSlash, -} from './webdriver-utils.ts'; +import { basicAuthHeader, trimLeadingSlash, withTrailingSlash } from './webdriver-utils.ts'; + +/** Why a WebDriver request failed at the transport. */ +const WEBDRIVER_TRANSPORT_REASONS = { + // The transport stopped waiting on a WebDriver request the driver may still be carrying out. + requestTimeout: { reason: 'webdriver_request_timeout' }, + // The request never reached the driver: the connection was refused or the host is unreachable. + connectRefused: { reason: 'webdriver_connect_refused' }, + // The connection to the driver failed after the request may have reached it. + requestInterrupted: { reason: 'webdriver_request_interrupted' }, + // The driver answered that it does not implement the route. + routeUnsupported: { reason: 'webdriver_route_unsupported' }, +} as const satisfies ReasonTable<'webdriver provider'>; export type WebDriverAuth = { username: string; @@ -30,7 +37,7 @@ export type WebDriverRequestPolicy = { export function isWebDriverRequestTimeout(error: unknown): error is AppError { return ( error instanceof AppError && - error.details?.reason === WEBDRIVER_PROVIDER_REASONS.requestTimeout.reason + error.details?.reason === WEBDRIVER_TRANSPORT_REASONS.requestTimeout.reason ); } @@ -63,7 +70,7 @@ const ERROR_CAUSE_DEPTH_LIMIT = 4; export function isWebDriverConnectRefused(error: unknown): error is AppError { return ( error instanceof AppError && - error.details?.reason === WEBDRIVER_PROVIDER_REASONS.connectRefused.reason + error.details?.reason === WEBDRIVER_TRANSPORT_REASONS.connectRefused.reason ); } @@ -216,7 +223,7 @@ export class WebDriverTransport { const payload = parsed.json; const error = webdriverError(status, payload); if (isWebDriverRouteUnsupported(error)) { - emitWebDriverDiagnostic(WEBDRIVER_PROVIDER_REASONS.routeUnsupported.reason, { + emitWebDriverDiagnostic(WEBDRIVER_TRANSPORT_REASONS.routeUnsupported.reason, { method, path, status, @@ -414,11 +421,11 @@ export function isWebDriverInvalidSession(error: unknown): error is AppError { * the route. A command that tried every route it has and was refused by each carries the same. */ export function unsupportedRouteRefusal(): { - reason: typeof WEBDRIVER_PROVIDER_REASONS.routeUnsupported.reason; + reason: typeof WEBDRIVER_TRANSPORT_REASONS.routeUnsupported.reason; dispatched: DispatchDisclosure; } { return { - reason: WEBDRIVER_PROVIDER_REASONS.routeUnsupported.reason, + reason: WEBDRIVER_TRANSPORT_REASONS.routeUnsupported.reason, ...dispatchDisclosure('no'), }; } @@ -473,7 +480,7 @@ export function emitWebDriverDiagnostic(phase: string, data: Record; /** Best-effort release after a failure; a failed release rides along as `cleanupError`, never masks the primary. */ @@ -172,8 +148,8 @@ export async function postHubAppUpload( `${options.service} app upload failed.`, { reason: timedOut - ? WEBDRIVER_PROVIDER_REASONS.hubAppUploadTimeout.reason - : WEBDRIVER_PROVIDER_REASONS.hubAppUploadTransportFailed.reason, + ? WEBDRIVER_APP_UPLOAD_REASONS.hubAppUploadTimeout.reason + : WEBDRIVER_APP_UPLOAD_REASONS.hubAppUploadTransportFailed.reason, ...(timedOut ? { timeoutMs: HUB_APP_UPLOAD_TIMEOUT_MS } : {}), hint: `Check network access to the ${options.service} upload API, then retry.`, }, @@ -255,7 +231,7 @@ function requireAppCwd(options: { service: string; app: string; cwd?: string }): `${options.service} --provider-app ${options.app} is a relative path and the request names no working directory; pass an absolute path.`, { providerApp: options.app, - reason: WEBDRIVER_PROVIDER_REASONS.providerAppCwdMissing.reason, + reason: WEBDRIVER_APP_UPLOAD_REASONS.providerAppCwdMissing.reason, }, ); } diff --git a/website/docs/docs/error-reasons.md b/website/docs/docs/error-reasons.md index 0df7ceca29..1ec5453473 100644 --- a/website/docs/docs/error-reasons.md +++ b/website/docs/docs/error-reasons.md @@ -214,7 +214,7 @@ These reasons can come from more than one command. | `limrun_instance_unreachable` | The instance stopped answering, so its app state cannot be read. | | `limrun_adb_tunnel_cleaned_up` | The ADB tunnel of this lease was already cleaned up, so nothing can be typed over it. | | `limrun_app_sync_retired` | The app-sync session of this lease has ended, so no further sync runs on it. | -| `limrun_app_sync_failed` | Syncing the app to the instance stopped with nothing installed. | +| `limrun_app_sync_failed` | App sync or local cache maintenance failed; check the device for the app before retrying. | ### Macos helper @@ -295,16 +295,16 @@ These reasons can come from more than one command. | Reason | Meaning | | --- | --- | -| `hub_app_upload_timeout` | The app upload to the provider's storage did not answer within its own deadline. | -| `hub_app_upload_transport_failed` | The app upload to the provider's storage never completed its transport. | -| `provider_app_cwd_missing` | `--provider-app` is a relative path and the request names no working directory to resolve it in. | -| `webdriver_request_timeout` | The transport stopped waiting on a WebDriver request the driver may still be carrying out. | -| `webdriver_connect_refused` | The request never reached the driver: the connection was refused or the host is unreachable. | -| `webdriver_request_interrupted` | The connection to the driver failed after the request may have reached it. | -| `webdriver_route_unsupported` | The driver answered that it does not implement the route. | | `provider_session_create_timeout` | The provider did not create the WebDriver session within the session-creation budget. | | `provider_session_released_during_allocation` | The provider ended the session an allocation was waiting on by releasing its lease. | | `provider_session_shutdown_during_allocation` | The provider ended the session an allocation was waiting on while shutting down. | | `provider_session_release_in_progress` | The lease is still releasing its previous session, so a new allocation gets no session. | | `provider_session_cleanup_incomplete` | Shutdown left WebDriver sessions running, so they may still be billed. | | `text_entry_clear_target_unavailable` | `fill` has no focused element reference to clear before it types the replacement text. | +| `webdriver_request_timeout` | The transport stopped waiting on a WebDriver request the driver may still be carrying out. | +| `webdriver_connect_refused` | The request never reached the driver: the connection was refused or the host is unreachable. | +| `webdriver_request_interrupted` | The connection to the driver failed after the request may have reached it. | +| `webdriver_route_unsupported` | The driver answered that it does not implement the route. | +| `hub_app_upload_timeout` | The app upload to the provider's storage did not answer within its own deadline. | +| `hub_app_upload_transport_failed` | The app upload to the provider's storage never completed its transport. | +| `provider_app_cwd_missing` | `--provider-app` is a relative path and the request names no working directory to resolve it in. | From c84adb27d098f4ccb47baebe3e8f727ab104ab00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sun, 22 Nov 2026 00:02:03 +0100 Subject: [PATCH 4/9] refactor(reasons): give each Revyl module its own reason table; fix the shutdown-during-allocation summary Rows used by one Revyl module move into that module (connection, deployment, interactor, session, runtime, allocation); the HTTP classification rows several modules share stay in revyl-client.ts. Co-Authored-By: Claude Opus 5.5 --- packages/provider-revyl/src/connection.ts | 16 ++++++++--- packages/provider-revyl/src/deployment.ts | 12 ++++++-- packages/provider-revyl/src/interactor.ts | 22 +++++++++++---- packages/provider-revyl/src/revyl-client.ts | 28 ------------------- packages/provider-revyl/src/revyl-session.ts | 27 +++++++++++++----- packages/provider-revyl/src/runtime.ts | 21 ++++++++------ .../provider-revyl/src/session-allocation.ts | 11 ++++++-- .../provider-webdriver/src/runtime-session.ts | 2 +- website/docs/docs/error-reasons.md | 16 +++++------ 9 files changed, 86 insertions(+), 69 deletions(-) diff --git a/packages/provider-revyl/src/connection.ts b/packages/provider-revyl/src/connection.ts index 628f05255e..a9bb0f3453 100644 --- a/packages/provider-revyl/src/connection.ts +++ b/packages/provider-revyl/src/connection.ts @@ -5,13 +5,21 @@ import { requireResolvedProfilePlatform, } from '@agent-device/contracts/provider-profile-fields'; import type { ProviderConnectionVerification } from '@agent-device/contracts/remote'; -import { AppError } from '@agent-device/kernel/errors'; +import { AppError, type ReasonTable } from '@agent-device/kernel/errors'; import { REVYL_PROVIDER, REVYL_SERVICE, type RevylPlatform } from './device.ts'; import { requireRevylCredentials, type RevylCredentials } from './credentials.ts'; -import { createRevylClient, REVYL_PROVIDER_REASONS } from './revyl-client.ts'; +import { createRevylClient } from './revyl-client.ts'; import { REVYL_PROFILE_FIELDS } from './profile-fields.ts'; import { revylTextFlag } from './session-allocation.ts'; +/** Why a Revyl connection request is refused. */ +const REVYL_CONNECTION_REASONS = { + // Revyl installs the app from a URL, so `--provider-app` cannot name a local file. + invalidApp: { reason: 'invalid_provider_app' }, + // Revyl rents an iOS simulator or an Android emulator, and the request names neither. + unsupportedPlatform: { reason: 'unsupported_platform' }, +} as const satisfies ReasonTable<'revyl provider'>; + /** The connect half of the plugin, bound to one host's environment. */ export type RevylConnection = ReturnType; @@ -87,7 +95,7 @@ export async function verifyRevylProfile( 'INVALID_ARGS', `${REVYL_SERVICE} installs the app from a URL, so --provider-app must be an https URL.`, { - reason: REVYL_PROVIDER_REASONS.invalidApp.reason, + reason: REVYL_CONNECTION_REASONS.invalidApp.reason, hint: `Pass the URL ${REVYL_SERVICE} can read the build from; a local path cannot.`, }, ); @@ -140,7 +148,7 @@ function isRevylAppUrl(value: string | undefined): boolean { function requireConnectPlatform(flags: CliFlags): RevylPlatform { if (flags.platform === 'ios' || flags.platform === 'android') return flags.platform; throw new AppError('INVALID_ARGS', `connect ${REVYL_PROVIDER} requires --platform ios|android.`, { - reason: REVYL_PROVIDER_REASONS.unsupportedPlatform.reason, + reason: REVYL_CONNECTION_REASONS.unsupportedPlatform.reason, }); } diff --git a/packages/provider-revyl/src/deployment.ts b/packages/provider-revyl/src/deployment.ts index 421ca3e201..eb17fe67e2 100644 --- a/packages/provider-revyl/src/deployment.ts +++ b/packages/provider-revyl/src/deployment.ts @@ -5,7 +5,7 @@ import type { } from '@agent-device/contracts/app-deployment-runtime'; import { packGzipTar } from '@agent-device/host-kit/gzip-tar'; import { Deadline, type DeadlineClock, pollUntilSettled } from '@agent-device/host-kit/retry'; -import { AppError } from '@agent-device/kernel/errors'; +import { AppError, type ReasonTable } from '@agent-device/kernel/errors'; import type { EnvMap } from '@agent-device/kernel/source-value'; import { REVYL_PROVIDER_REASONS, @@ -14,6 +14,12 @@ import { } from './revyl-client.ts'; import type { RevylWorkerActionResponse } from './revyl-types.ts'; +/** Why a Revyl app deployment is refused. */ +const REVYL_DEPLOYMENT_REASONS = { + // Revyl installs an iOS simulator build or an Android .apk, and the build is neither. + unsupportedAppArtifact: { reason: 'unsupported_app_artifact' }, +} as const satisfies ReasonTable<'revyl provider'>; + /** * The whole install's budget: packing, upload, and Revyl's install. It stays inside the daemon's * share of the install command's 480 s envelope, so the plugin reports its own timeout before the @@ -159,13 +165,13 @@ function unsupportedBuild(platform: 'ios' | 'android', appPath: string): AppErro 'INVALID_ARGS', 'Revyl installs an iOS simulator build: a .app directory, or a .zip, .tar.gz, or .tgz of one.', { - reason: REVYL_PROVIDER_REASONS.unsupportedAppArtifact.reason, + reason: REVYL_DEPLOYMENT_REASONS.unsupportedAppArtifact.reason, appPath, hint: 'Build for the iOS simulator; a device .ipa does not run on a simulator.', }, ) : new AppError('INVALID_ARGS', 'Revyl installs an Android build from an .apk file.', { - reason: REVYL_PROVIDER_REASONS.unsupportedAppArtifact.reason, + reason: REVYL_DEPLOYMENT_REASONS.unsupportedAppArtifact.reason, appPath, hint: 'Pass the .apk the build produced.', }); diff --git a/packages/provider-revyl/src/interactor.ts b/packages/provider-revyl/src/interactor.ts index 59975b61b8..6e4085134a 100644 --- a/packages/provider-revyl/src/interactor.ts +++ b/packages/provider-revyl/src/interactor.ts @@ -29,12 +29,22 @@ import { AppError, discloseDispatch, discloseDispatchAfterSteps, + type ReasonTable, } from '@agent-device/kernel/errors'; import { setTimeout as sleep } from 'node:timers/promises'; -import { REVYL_PROVIDER_REASONS } from './revyl-client.ts'; import type { RevylSession } from './revyl-session.ts'; import { captureRevylSnapshot, createRevylSnapshotReader } from './snapshot.ts'; +/** Why a Revyl interaction cannot run or be trusted. */ +const REVYL_INTERACTOR_REASONS = { + // The session runs no app, so a close or setting that names one has nothing to act on. + appNotLaunched: { reason: 'provider-app-not-launched' }, + // The session reports no viewport, so a scroll distance or screenshot density has nothing to scale by. + viewportUnavailable: { reason: 'provider-viewport-unavailable' }, + // Revyl answered a worker action with a value outside the field's own range. + invalidResponse: { reason: 'provider-invalid-response' }, +} as const satisfies ReasonTable<'revyl provider'>; + /** Revyl's worker holds the touch this long when the caller names no hold. */ const DEFAULT_LONG_PRESS_DURATION_MS = 1_500; @@ -156,7 +166,7 @@ class RevylInteractor implements Interactor { 'UNSUPPORTED_OPERATION', `This Revyl session has not launched ${target}, so it has no app to end.`, { - reason: REVYL_PROVIDER_REASONS.appNotLaunched.reason, + reason: REVYL_INTERACTOR_REASONS.appNotLaunched.reason, command: 'close', requestedApp: target, hint: 'Close without an app name to end the app this session runs, or open the app first.', @@ -285,7 +295,7 @@ class RevylInteractor implements Interactor { 'COMMAND_FAILED', 'Revyl reported no screen size for this session, so the scroll distance cannot be planned.', { - reason: REVYL_PROVIDER_REASONS.viewportUnavailable.reason, + reason: REVYL_INTERACTOR_REASONS.viewportUnavailable.reason, runId: this.session.runId, }, ); @@ -455,7 +465,7 @@ class RevylInteractor implements Interactor { const current = await this.workerAction('appearance'); if (current.appearance !== 'light' && current.appearance !== 'dark') { throw new AppError('COMMAND_FAILED', 'Revyl did not report the current appearance.', { - reason: REVYL_PROVIDER_REASONS.invalidResponse.reason, + reason: REVYL_INTERACTOR_REASONS.invalidResponse.reason, runId: this.session.runId, }); } @@ -522,7 +532,7 @@ class RevylInteractor implements Interactor { const app = appId?.trim() || this.session.launchedApp.bundleId; if (app) return app; throw new AppError('INVALID_ARGS', `The ${setting} setting needs an app.`, { - reason: REVYL_PROVIDER_REASONS.appNotLaunched.reason, + reason: REVYL_INTERACTOR_REASONS.appNotLaunched.reason, command: 'settings', hint: 'Pass --app, or open the app first.', }); @@ -573,7 +583,7 @@ async function normalizeRevylIosDensity( throw new AppError( 'COMMAND_FAILED', 'Revyl reported no screen size for this session, so the screenshot density cannot be known.', - { reason: REVYL_PROVIDER_REASONS.viewportUnavailable.reason }, + { reason: REVYL_INTERACTOR_REASONS.viewportUnavailable.reason }, ); } const [{ readPngSize }, { resizePngFile }, { computeDensityScaledScreenshotSize }] = diff --git a/packages/provider-revyl/src/revyl-client.ts b/packages/provider-revyl/src/revyl-client.ts index 79273fc7f4..f7c7226848 100644 --- a/packages/provider-revyl/src/revyl-client.ts +++ b/packages/provider-revyl/src/revyl-client.ts @@ -72,34 +72,6 @@ export const REVYL_PROVIDER_REASONS = { requestTimeout: { reason: 'request_timeout' }, // `REVYL_API_URL` is not an origin Revyl's API can be addressed at. invalidProviderUrl: { reason: 'invalid_provider_url' }, - // Revyl installs the app from a URL, so `--provider-app` cannot name a local file. - invalidApp: { reason: 'invalid_provider_app' }, - // Revyl rents an iOS simulator or an Android emulator, and the request names neither. - unsupportedPlatform: { reason: 'unsupported_platform' }, - // Revyl installs an iOS simulator build or an Android .apk, and the build is neither. - unsupportedAppArtifact: { reason: 'unsupported_app_artifact' }, - // The session runs no app, so a close or setting that names one has nothing to act on. - appNotLaunched: { reason: 'provider-app-not-launched' }, - // The session reports no viewport, so a scroll distance or screenshot density has nothing to scale by. - viewportUnavailable: { reason: 'provider-viewport-unavailable' }, - // Revyl answered a worker action with a value outside the field's own range. - invalidResponse: { reason: 'provider-invalid-response' }, - // Revyl started a session under an identity agent-device did not issue for the lease. - sessionIdentityMismatch: { reason: 'provider-session-identity-mismatch' }, - // Revyl refused to start the device and named why in its start answer. - startRefused: { reason: 'provider-start-refused' }, - // Revyl's worker connection ended in a state that never serves the device. - startFailed: { reason: 'provider-start-failed' }, - // Revyl never reported a ready device within the wait the caller could spend. - notReady: { reason: 'provider-not-ready' }, - // Revyl did not confirm it released the session, which stays rented and billed until it does. - cleanupPending: { reason: 'provider-cleanup-pending' }, - // The lease is being released, so it cannot serve another allocation. - leaseReleasing: { reason: 'provider-lease-releasing' }, - // An allocation joins a lease whose device was started for another app or device. - leaseRequestMismatch: { reason: 'provider-lease-request-mismatch' }, - // The provider runtime is ending the sessions it holds, so it takes no new work. - runtimeShuttingDown: { reason: 'runtime-shutting-down' }, } as const satisfies ReasonTable<'revyl provider'>; /** The `details.reason` spellings {@link REVYL_PROVIDER_REASONS} declares. */ diff --git a/packages/provider-revyl/src/revyl-session.ts b/packages/provider-revyl/src/revyl-session.ts index d31ff9f126..e8f09a7bf7 100644 --- a/packages/provider-revyl/src/revyl-session.ts +++ b/packages/provider-revyl/src/revyl-session.ts @@ -1,10 +1,9 @@ -import { AppError } from '@agent-device/kernel/errors'; +import { AppError, type ReasonTable } from '@agent-device/kernel/errors'; import { setTimeout as sleep } from 'node:timers/promises'; import type { DeviceLease } from '@agent-device/contracts/device'; import type { DeviceInfo } from '@agent-device/kernel/device'; import { buildRevylDevice, revylSessionIdForLease, type RevylPlatform } from './device.ts'; import { - REVYL_PROVIDER_REASONS, REVYL_START_DEVICE_TIMEOUT_MS, isRevylSessionGone, revylFailureRefusedTheRequest, @@ -17,6 +16,20 @@ import type { RevylWorkerHealth, } from './revyl-types.ts'; +/** Why a Revyl session could not start, be confirmed, or be cleaned up. */ +const REVYL_SESSION_REASONS = { + // Revyl started a session under an identity agent-device did not issue for the lease. + sessionIdentityMismatch: { reason: 'provider-session-identity-mismatch' }, + // Revyl refused to start the device and named why in its start answer. + startRefused: { reason: 'provider-start-refused' }, + // Revyl's worker connection ended in a state that never serves the device. + startFailed: { reason: 'provider-start-failed' }, + // Revyl never reported a ready device within the wait the caller could spend. + notReady: { reason: 'provider-not-ready' }, + // Revyl did not confirm it released the session, which stays rented and billed until it does. + cleanupPending: { reason: 'provider-cleanup-pending' }, +} as const satisfies ReasonTable<'revyl provider'>; + /** How long Revyl may take to assign a worker and connect the device before the start is given up on. */ const READY_TIMEOUT_MS = 240_000; /** @@ -149,7 +162,7 @@ export async function startRevylSession( 'COMMAND_FAILED', `Revyl started the device as session ${echoed} instead of ${sessionId}.`, { - reason: REVYL_PROVIDER_REASONS.sessionIdentityMismatch.reason, + reason: REVYL_SESSION_REASONS.sessionIdentityMismatch.reason, runId, providerSessionId: echoed, hint: 'Retry the command; agent-device ends a Revyl session by the identity it issued.', @@ -167,7 +180,7 @@ export async function startRevylSession( 'COMMAND_FAILED', `Revyl did not start a ${input.platform} device: ${started.error ?? started.message ?? 'no workflow run was returned'}`, { - reason: REVYL_PROVIDER_REASONS.startRefused.reason, + reason: REVYL_SESSION_REASONS.startRefused.reason, platform: input.platform, ...(started.trace_id === undefined ? {} : { traceId: started.trace_id }), }, @@ -268,7 +281,7 @@ export function revylCallerGaveUp( 'COMMAND_FAILED', `Revyl did not report a ready device within ${budgetMs} ms.`, { - reason: REVYL_PROVIDER_REASONS.notReady.reason, + reason: REVYL_SESSION_REASONS.notReady.reason, timeoutMs: budgetMs, providerSessionId, ...(budget.deadline === undefined ? {} : { deadline: budget.deadline }), @@ -306,7 +319,7 @@ export function revylCleanupPending( 'COMMAND_FAILED', `Revyl did not release session${one ? '' : 's'} ${ids}.`, { - reason: REVYL_PROVIDER_REASONS.cleanupPending.reason, + reason: REVYL_SESSION_REASONS.cleanupPending.reason, ...details, providerSessionIds: unconfirmed.map((stop) => stop.sessionId), causes: unconfirmed.map((stop) => stop.failure), @@ -433,7 +446,7 @@ async function untilRevylWorkerReady( : ` (${connection.message})` }`, { - reason: REVYL_PROVIDER_REASONS.startFailed.reason, + reason: REVYL_SESSION_REASONS.startFailed.reason, runId, status: connection.status, }, diff --git a/packages/provider-revyl/src/runtime.ts b/packages/provider-revyl/src/runtime.ts index b344137f1c..5875ab1312 100644 --- a/packages/provider-revyl/src/runtime.ts +++ b/packages/provider-revyl/src/runtime.ts @@ -14,7 +14,7 @@ import type { import type { Interactor, RunnerContext } from '@agent-device/contracts/interactor-types'; import type { DeviceInfo } from '@agent-device/kernel/device'; import { matchesPlatformSelector } from '@agent-device/kernel/device'; -import { AppError, errorMessage } from '@agent-device/kernel/errors'; +import { AppError, errorMessage, type ReasonTable } from '@agent-device/kernel/errors'; import { parseRevylDeviceId, platformForRevylLeaseBackend, @@ -22,12 +22,7 @@ import { revylSessionIdForLease, type RevylPlatform, } from './device.ts'; -import { - createRevylClient, - isRevylSessionGone, - REVYL_PROVIDER_REASONS, - type RevylClient, -} from './revyl-client.ts'; +import { createRevylClient, isRevylSessionGone, type RevylClient } from './revyl-client.ts'; import { keepRevylSessionAlive, REVYL_ALLOCATION_TIMEOUT_MS, @@ -51,6 +46,14 @@ import { resolveRevylRuntimeInstance } from './runtime-instance.ts'; import type { RevylStartRequest } from './session-allocation.ts'; import type { RevylDeploymentSession } from './deployment.ts'; +/** Why the Revyl runtime refuses a lease request. */ +const REVYL_RUNTIME_REASONS = { + // The lease is being released, so it cannot serve another allocation. + leaseReleasing: { reason: 'provider-lease-releasing' }, + // The provider runtime is ending the sessions it holds, so it takes no new work. + runtimeShuttingDown: { reason: 'runtime-shutting-down' }, +} as const satisfies ReasonTable<'revyl provider'>; + /** What one lease's start asks Revyl for, with the platform the lease was admitted for. */ type RevylLeaseRequest = RevylStartRequest & Readonly<{ platform: RevylPlatform }>; @@ -273,7 +276,7 @@ function createRevylLeaseDriver( shuttingDown: (lease) => shuttingDownDuring(lease.leaseId, 'allocate'), releasing: (lease) => new AppError('COMMAND_FAILED', `Revyl lease ${lease.leaseId} is being released.`, { - reason: REVYL_PROVIDER_REASONS.leaseReleasing.reason, + reason: REVYL_RUNTIME_REASONS.leaseReleasing.reason, leaseId: lease.leaseId, hint: 'Run open again; it allocates a new lease and rents a fresh device.', }), @@ -345,7 +348,7 @@ function requireRevylLease(lease: DeviceLease, operation: 'recover' | 'release') function shuttingDownDuring(leaseId: string, operation: string): AppError { return new AppError('COMMAND_FAILED', `The Revyl runtime is shutting down.`, { - reason: REVYL_PROVIDER_REASONS.runtimeShuttingDown.reason, + reason: REVYL_RUNTIME_REASONS.runtimeShuttingDown.reason, operation, leaseId, hint: 'Retry the command; the daemon is ending the sessions it holds.', diff --git a/packages/provider-revyl/src/session-allocation.ts b/packages/provider-revyl/src/session-allocation.ts index b941e75b0b..a3a7e5c12b 100644 --- a/packages/provider-revyl/src/session-allocation.ts +++ b/packages/provider-revyl/src/session-allocation.ts @@ -1,8 +1,13 @@ import type { LeaseLifecycleContext } from '@agent-device/contracts/device'; -import { AppError } from '@agent-device/kernel/errors'; +import { AppError, type ReasonTable } from '@agent-device/kernel/errors'; import { rejectRefusedProviderProfileFields } from '@agent-device/contracts/provider-profile-fields'; import { REVYL_PROFILE_FIELDS } from './profile-fields.ts'; -import { REVYL_PROVIDER_REASONS } from './revyl-client.ts'; + +/** Why a Revyl lease allocation is refused. */ +const REVYL_ALLOCATION_REASONS = { + // An allocation joins a lease whose device was started for another app or device. + leaseRequestMismatch: { reason: 'provider-lease-request-mismatch' }, +} as const satisfies ReasonTable<'revyl provider'>; /** * Refuses the connect flags Revyl has no field for, so a flag that would be ignored is reported @@ -79,7 +84,7 @@ export function requireSameRevylStartRequest( 'INVALID_ARGS', `Revyl lease ${leaseId} already has a device started for a different ${differing.join(', ')}.`, { - reason: REVYL_PROVIDER_REASONS.leaseRequestMismatch.reason, + reason: REVYL_ALLOCATION_REASONS.leaseRequestMismatch.reason, leaseId, fields: differing, hint: 'Disconnect and connect again to rent a device for the new app or device selection.', diff --git a/packages/provider-webdriver/src/runtime-session.ts b/packages/provider-webdriver/src/runtime-session.ts index fc0cb96b18..131b1401ab 100644 --- a/packages/provider-webdriver/src/runtime-session.ts +++ b/packages/provider-webdriver/src/runtime-session.ts @@ -29,7 +29,7 @@ const WEBDRIVER_SESSION_REASONS = { sessionCreateTimeout: { reason: 'provider_session_create_timeout' }, // The provider ended the session an allocation was waiting on by releasing its lease. sessionReleasedDuringAllocation: { reason: 'provider_session_released_during_allocation' }, - // The provider ended the session an allocation was waiting on while shutting down. + // The WebDriver runtime could not finish the allocation: shutdown was in progress or done. sessionShutdownDuringAllocation: { reason: 'provider_session_shutdown_during_allocation' }, // The lease is still releasing its previous session, so a new allocation gets no session. sessionReleaseInProgress: { reason: 'provider_session_release_in_progress' }, diff --git a/website/docs/docs/error-reasons.md b/website/docs/docs/error-reasons.md index 1ec5453473..7f54f84ed8 100644 --- a/website/docs/docs/error-reasons.md +++ b/website/docs/docs/error-reasons.md @@ -253,7 +253,13 @@ These reasons can come from more than one command. | Reason | Meaning | | --- | --- | +| `invalid_provider_app` | Revyl installs the app from a URL, so `--provider-app` cannot name a local file. | +| `unsupported_platform` | Revyl rents an iOS simulator or an Android emulator, and the request names neither. | | `missing_provider_credentials` | No Revyl API key is set, so the provider cannot authenticate the request. | +| `unsupported_app_artifact` | Revyl installs an iOS simulator build or an Android .apk, and the build is neither. | +| `provider-app-not-launched` | The session runs no app, so a close or setting that names one has nothing to act on. | +| `provider-viewport-unavailable` | The session reports no viewport, so a scroll distance or screenshot density has nothing to scale by. | +| `provider-invalid-response` | Revyl answered a worker action with a value outside the field's own range. | | `provider-refused` | Revyl refused the request or the action it carries. | | `provider-unreachable` | Revyl never answered the request, or the connection to its backend failed. | | `provider-response-invalid` | Revyl answered in a way agent-device cannot read, such as a body that is not JSON. | @@ -264,20 +270,14 @@ These reasons can come from more than one command. | `provider-request-failed` | Revyl refused a request it never routed, with a status that settles the failure. | | `request_timeout` | Revyl gave no response before the request's own deadline passed. | | `invalid_provider_url` | `REVYL_API_URL` is not an origin Revyl's API can be addressed at. | -| `invalid_provider_app` | Revyl installs the app from a URL, so `--provider-app` cannot name a local file. | -| `unsupported_platform` | Revyl rents an iOS simulator or an Android emulator, and the request names neither. | -| `unsupported_app_artifact` | Revyl installs an iOS simulator build or an Android .apk, and the build is neither. | -| `provider-app-not-launched` | The session runs no app, so a close or setting that names one has nothing to act on. | -| `provider-viewport-unavailable` | The session reports no viewport, so a scroll distance or screenshot density has nothing to scale by. | -| `provider-invalid-response` | Revyl answered a worker action with a value outside the field's own range. | | `provider-session-identity-mismatch` | Revyl started a session under an identity agent-device did not issue for the lease. | | `provider-start-refused` | Revyl refused to start the device and named why in its start answer. | | `provider-start-failed` | Revyl's worker connection ended in a state that never serves the device. | | `provider-not-ready` | Revyl never reported a ready device within the wait the caller could spend. | | `provider-cleanup-pending` | Revyl did not confirm it released the session, which stays rented and billed until it does. | | `provider-lease-releasing` | The lease is being released, so it cannot serve another allocation. | -| `provider-lease-request-mismatch` | An allocation joins a lease whose device was started for another app or device. | | `runtime-shutting-down` | The provider runtime is ending the sessions it holds, so it takes no new work. | +| `provider-lease-request-mismatch` | An allocation joins a lease whose device was started for another app or device. | ### Snapshot capture @@ -297,7 +297,7 @@ These reasons can come from more than one command. | --- | --- | | `provider_session_create_timeout` | The provider did not create the WebDriver session within the session-creation budget. | | `provider_session_released_during_allocation` | The provider ended the session an allocation was waiting on by releasing its lease. | -| `provider_session_shutdown_during_allocation` | The provider ended the session an allocation was waiting on while shutting down. | +| `provider_session_shutdown_during_allocation` | The WebDriver runtime could not finish the allocation: shutdown was in progress or done. | | `provider_session_release_in_progress` | The lease is still releasing its previous session, so a new allocation gets no session. | | `provider_session_cleanup_incomplete` | Shutdown left WebDriver sessions running, so they may still be billed. | | `text_entry_clear_target_unavailable` | `fill` has no focused element reference to clear before it types the replacement text. | From 1f28fe0bf350ede7f39c567650b132491e6bb3f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sun, 22 Nov 2026 01:00:38 +0100 Subject: [PATCH 5/9] refactor(reasons): give each Limrun module its own reason table; fix the released-during-allocation summary Co-Authored-By: Claude Opus 5.5 --- packages/provider-limrun/src/android.ts | 11 +++++--- .../provider-limrun/src/app-state-read.ts | 11 +++++--- packages/provider-limrun/src/device.ts | 26 ------------------- packages/provider-limrun/src/lease-release.ts | 21 ++++++++------- packages/provider-limrun/src/runtime.ts | 15 ++++++++--- packages/provider-limrun/src/sync-cache.ts | 15 ++++++++--- .../provider-webdriver/src/runtime-session.ts | 2 +- website/docs/docs/error-reasons.md | 6 ++--- 8 files changed, 54 insertions(+), 53 deletions(-) diff --git a/packages/provider-limrun/src/android.ts b/packages/provider-limrun/src/android.ts index 53c3586cc4..a66145d5f5 100644 --- a/packages/provider-limrun/src/android.ts +++ b/packages/provider-limrun/src/android.ts @@ -11,7 +11,7 @@ import type { ProviderDeviceInstallResult, ProviderPortReverseOptions, } from '@agent-device/contracts/device'; -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 type { LimrunAdbCommandOptions, @@ -23,13 +23,18 @@ import type { } from './runtime-dependencies.ts'; import type { AndroidAdbInvocation } from '@agent-device/platform-android/mechanics'; import type { LimrunInstanceOwnership } from './instance-access.ts'; -import { LIMRUN_PROVIDER_REASONS } from './device.ts'; import { normalizeOptionalString } from './strings.ts'; import { awaitLimrunDeploymentOperation, type LimrunRequestOperationDrain, } from './request-cancellation.ts'; +/** Why a Limrun Android operation refused. */ +const LIMRUN_ANDROID_REASONS = { + // The ADB tunnel of this lease was already cleaned up, so nothing can be typed over it. + adbTunnelCleanedUp: { reason: 'limrun_adb_tunnel_cleaned_up' }, +} as const satisfies ReasonTable<'limrun provider'>; + type LimrunAdbTunnel = Awaited>; type LimrunAndroidAdbSession = { @@ -347,7 +352,7 @@ function alreadyCleanedUp(session: LimrunAndroidAdbSession): AppError { 'SESSION_NOT_FOUND', `Limrun ADB tunnel for instance '${session.instanceId}' was already cleaned up`, { - reason: LIMRUN_PROVIDER_REASONS.adbTunnelCleanedUp.reason, + reason: LIMRUN_ANDROID_REASONS.adbTunnelCleanedUp.reason, // The tunnel is gone whether the instance's delete confirmed or is still held for retry, so the hint // sends the caller to a new lease, and to Limrun only for the state where a release would refuse again. hint: `This interactor's ADB tunnel is closed for lease '${session.lease.leaseId}'. Open a new lease. If this lease's release was refused as an unconfirmed delete, ask Limrun to delete the instance first.`, diff --git a/packages/provider-limrun/src/app-state-read.ts b/packages/provider-limrun/src/app-state-read.ts index 3682eba9ab..282d4278a8 100644 --- a/packages/provider-limrun/src/app-state-read.ts +++ b/packages/provider-limrun/src/app-state-read.ts @@ -1,9 +1,14 @@ import type { AppStateRuntimeResult } from '@agent-device/contracts/app-state-runtime'; -import { AppError } from '@agent-device/kernel/errors'; -import { LIMRUN_PROVIDER_REASONS } from './device.ts'; +import { AppError, type ReasonTable } from '@agent-device/kernel/errors'; import type { LimrunDeviceSession } from './device-session.ts'; import { awaitWithSignal } from '@agent-device/kernel/await-with-signal'; +/** Why reading app state from a Limrun instance failed. */ +const LIMRUN_APP_STATE_REASONS = { + // The instance stopped answering, so its app state cannot be read. + instanceUnreachable: { reason: 'limrun_instance_unreachable' }, +} as const satisfies ReasonTable<'limrun provider'>; + /** * Android reads the foreground app. Limrun exposes no foreground bundle id on iOS, so an iOS read * only proves the instance still answers: its empty result leaves the session record to name the @@ -42,7 +47,7 @@ async function confirmLimrunIosInstanceAnswers( 'COMMAND_FAILED', 'Could not confirm that the Limrun iOS instance is running, so its app state is unknown.', { - reason: LIMRUN_PROVIDER_REASONS.instanceUnreachable.reason, + reason: LIMRUN_APP_STATE_REASONS.instanceUnreachable.reason, hint: 'Retry appstate. If it keeps failing, the instance may have been terminated: run connect limrun and open again.', }, error, diff --git a/packages/provider-limrun/src/device.ts b/packages/provider-limrun/src/device.ts index 85d0b087d8..b1afd85119 100644 --- a/packages/provider-limrun/src/device.ts +++ b/packages/provider-limrun/src/device.ts @@ -1,34 +1,8 @@ import { createHash } from 'node:crypto'; import type { DeviceLease } from '@agent-device/contracts/device'; import type { DeviceInfo } from '@agent-device/kernel/device'; -import type { ReasonTable } from '@agent-device/kernel/errors'; import type { ProviderProfileFieldDeclaration } from '@agent-device/contracts/provider-profile-fields'; -/** - * Every `details.reason` the Limrun provider publishes, keyed by what the failure means. Each - * refusal site reads a row here, so the plugin's wire vocabulary has one owner; the modules that - * classify those failures all load this one. `provider-instance-ended` is the lease vocabulary and - * stays with the lease table in `@agent-device/contracts/lease-scope`. - */ -export const LIMRUN_PROVIDER_REASONS = { - // A release could not confirm Limrun deleted the instance, so it may still be billed. - instanceDeleteUnconfirmed: { reason: 'limrun_instance_delete_unconfirmed' }, - // The lease was released while its instance was still being prepared for the allocation. - leaseReleasedMidAllocation: { reason: 'limrun_lease_released_mid_allocation' }, - // The lease holds no live session, so the command that addresses it has nothing to act on. - leaseNotLive: { reason: 'limrun_lease_not_live' }, - // This runtime is shut down, so it refuses to allocate a lease into it. - runtimeShutDown: { reason: 'limrun_runtime_shut_down' }, - // The instance stopped answering, so its app state cannot be read. - instanceUnreachable: { reason: 'limrun_instance_unreachable' }, - // The ADB tunnel of this lease was already cleaned up, so nothing can be typed over it. - adbTunnelCleanedUp: { reason: 'limrun_adb_tunnel_cleaned_up' }, - // The app-sync session of this lease has ended, so no further sync runs on it. - appSyncRetired: { reason: 'limrun_app_sync_retired' }, - // App sync or local cache maintenance failed; check the device for the app before retrying. - appSyncFailed: { reason: 'limrun_app_sync_failed' }, -} as const satisfies ReasonTable<'limrun provider'>; - export type LimrunPlatform = 'ios' | 'android'; export const LIMRUN_PROVIDER = 'limrun'; diff --git a/packages/provider-limrun/src/lease-release.ts b/packages/provider-limrun/src/lease-release.ts index c79b811487..8ee88e8921 100644 --- a/packages/provider-limrun/src/lease-release.ts +++ b/packages/provider-limrun/src/lease-release.ts @@ -1,16 +1,11 @@ import type Limrun from '@limrun/api'; import type { DeviceLease } from '@agent-device/contracts/device'; -import { AppError, errorMessage } from '@agent-device/kernel/errors'; +import { AppError, errorMessage, type ReasonTable } from '@agent-device/kernel/errors'; import { cleanupLimrunAndroidAdbTunnel } from './android.ts'; import { CAPTURE_OPEN_BUDGET_MS } from './capture-lifecycle.ts'; import { deleteLimrunInstance } from './client-options.ts'; import type { LimrunBudgetOutcome } from './lifecycle-budget.ts'; -import { - LIMRUN_PROVIDER, - LIMRUN_PROVIDER_REASONS, - platformForLimrunLeaseBackend, - type LimrunPlatform, -} from './device.ts'; +import { LIMRUN_PROVIDER, platformForLimrunLeaseBackend, type LimrunPlatform } from './device.ts'; import type { LimrunDeleteResult, LimrunDisposalOutcome, @@ -20,6 +15,14 @@ import type { } from './lease-ownership.ts'; import type { SettledNetworkCapture } from './network-har.ts'; +/** Why a Limrun lease release could not be confirmed. */ +const LIMRUN_LEASE_RELEASE_REASONS = { + // A release could not confirm Limrun deleted the instance, so it may still be billed. + instanceDeleteUnconfirmed: { reason: 'limrun_instance_delete_unconfirmed' }, + // The lease was released while its instance was still being prepared for the allocation. + leaseReleasedMidAllocation: { reason: 'limrun_lease_released_mid_allocation' }, +} as const satisfies ReasonTable<'limrun provider'>; + /** * Everything this runtime does once a lease has been taken for good: end what its owner holds, and answer with * what came of it. One lease's disposal runs here, and every route that ends a lease — release, daemon close, @@ -503,7 +506,7 @@ export function allocationRefusedForTake( 'DEVICE_IN_USE', `Limrun lease '${lease.leaseId}' was released while its instance was being prepared`, { - reason: LIMRUN_PROVIDER_REASONS.leaseReleasedMidAllocation.reason, + reason: LIMRUN_LEASE_RELEASE_REASONS.leaseReleasedMidAllocation.reason, ...(instanceId === undefined ? { hint: `Instance create for lease '${lease.leaseId}' may still rent one. Check Limrun.` } : { limrunInstanceId: instanceId, ...(ended === undefined ? {} : { hint: ended }) }), @@ -567,7 +570,7 @@ function throwUnconfirmedDelete( 'COMMAND_FAILED', message, { - reason: LIMRUN_PROVIDER_REASONS.instanceDeleteUnconfirmed.reason, + reason: LIMRUN_LEASE_RELEASE_REASONS.instanceDeleteUnconfirmed.reason, retriable: true, ...instanceDetails, ...(failure === undefined ? {} : { cause: failure }), diff --git a/packages/provider-limrun/src/runtime.ts b/packages/provider-limrun/src/runtime.ts index 7649f87b17..a95b39b796 100644 --- a/packages/provider-limrun/src/runtime.ts +++ b/packages/provider-limrun/src/runtime.ts @@ -14,7 +14,7 @@ import type { ProviderPortReverseOptions, } from '@agent-device/contracts/device'; import type { DeviceInfo } from '@agent-device/kernel/device'; -import { AppError, errorMessage } from '@agent-device/kernel/errors'; +import { AppError, errorMessage, type ReasonTable } from '@agent-device/kernel/errors'; import { configureLimrunAndroidPortReverse, createLimrunAndroidInteractor, @@ -26,7 +26,6 @@ import { attachedLimrunInstanceId, buildLimrunDevice, LIMRUN_PROVIDER, - LIMRUN_PROVIDER_REASONS, parseLimrunDeviceId, platformForLimrunLeaseBackend, type LimrunPlatform, @@ -68,6 +67,14 @@ import type { import type { LimrunCaptureLifecycle } from './capture-lifecycle.ts'; import type { LimrunDisposalHost } from './lease-release.ts'; +/** Why the Limrun runtime refuses a lease request. */ +const LIMRUN_RUNTIME_REASONS = { + // The lease holds no live session, so the command that addresses it has nothing to act on. + leaseNotLive: { reason: 'limrun_lease_not_live' }, + // This runtime is shut down, so it refuses to allocate a lease into it. + runtimeShutDown: { reason: 'limrun_runtime_shut_down' }, +} as const satisfies ReasonTable<'limrun provider'>; + const HEARTBEAT_PROBE_BUDGET_MS = 2_000; const KEEP_ALIVE_INTERVAL_MS = 30_000; @@ -811,7 +818,7 @@ class LimrunRuntimeImplementation implements ProviderDeviceRuntime { throw new AppError( 'COMMAND_FAILED', `Limrun lease '${owner.lease.leaseId}' has no live session`, - { reason: LIMRUN_PROVIDER_REASONS.leaseNotLive.reason }, + { reason: LIMRUN_RUNTIME_REASONS.leaseNotLive.reason }, ); } return session; @@ -940,7 +947,7 @@ function allocationRefusedAfterShutdown(lease: DeviceLease): never { 'SESSION_NOT_FOUND', `Cannot allocate Limrun lease '${lease.leaseId}': this runtime is shut down`, { - reason: LIMRUN_PROVIDER_REASONS.runtimeShutDown.reason, + reason: LIMRUN_RUNTIME_REASONS.runtimeShutDown.reason, hint: 'Start the daemon again to allocate a Limrun lease.', }, ); diff --git a/packages/provider-limrun/src/sync-cache.ts b/packages/provider-limrun/src/sync-cache.ts index c398fad40a..c2497b4146 100644 --- a/packages/provider-limrun/src/sync-cache.ts +++ b/packages/provider-limrun/src/sync-cache.ts @@ -1,8 +1,15 @@ import fs from 'node:fs/promises'; import os from 'node:os'; import path from 'node:path'; -import { AppError } from '@agent-device/kernel/errors'; -import { LIMRUN_PROVIDER_REASONS } from './device.ts'; +import { AppError, type ReasonTable } from '@agent-device/kernel/errors'; + +/** Why a Limrun app sync failed. */ +const LIMRUN_APP_SYNC_REASONS = { + // The app-sync session of this lease has ended, so no further sync runs on it. + appSyncRetired: { reason: 'limrun_app_sync_retired' }, + // App sync or local cache maintenance failed; check the device for the app before retrying. + appSyncFailed: { reason: 'limrun_app_sync_failed' }, +} as const satisfies ReasonTable<'limrun provider'>; /** One lease retains only its latest artifact's basis, even when materialization paths change. */ export class LimrunSyncCache { @@ -18,7 +25,7 @@ export class LimrunSyncCache { ): Promise { if (this.retired) { throw new AppError('COMMAND_FAILED', 'Limrun app sync session has ended.', { - reason: LIMRUN_PROVIDER_REASONS.appSyncRetired.reason, + reason: LIMRUN_APP_SYNC_REASONS.appSyncRetired.reason, }); } const operation = this.pending.then(async () => { @@ -44,7 +51,7 @@ export class LimrunSyncCache { 'COMMAND_FAILED', 'Limrun app sync failed.', { - reason: LIMRUN_PROVIDER_REASONS.appSyncFailed.reason, + reason: LIMRUN_APP_SYNC_REASONS.appSyncFailed.reason, platform, installablePath, }, diff --git a/packages/provider-webdriver/src/runtime-session.ts b/packages/provider-webdriver/src/runtime-session.ts index 131b1401ab..0bd1ad0387 100644 --- a/packages/provider-webdriver/src/runtime-session.ts +++ b/packages/provider-webdriver/src/runtime-session.ts @@ -27,7 +27,7 @@ import type { Interactor } from '@agent-device/contracts/interactor-types'; const WEBDRIVER_SESSION_REASONS = { // The provider did not create the WebDriver session within the session-creation budget. sessionCreateTimeout: { reason: 'provider_session_create_timeout' }, - // The provider ended the session an allocation was waiting on by releasing its lease. + // Releasing the lease interrupted the allocation; `details.cleanup` reports how cleanup ended. sessionReleasedDuringAllocation: { reason: 'provider_session_released_during_allocation' }, // The WebDriver runtime could not finish the allocation: shutdown was in progress or done. sessionShutdownDuringAllocation: { reason: 'provider_session_shutdown_during_allocation' }, diff --git a/website/docs/docs/error-reasons.md b/website/docs/docs/error-reasons.md index 7f54f84ed8..dc4110364e 100644 --- a/website/docs/docs/error-reasons.md +++ b/website/docs/docs/error-reasons.md @@ -207,12 +207,12 @@ These reasons can come from more than one command. | Reason | Meaning | | --- | --- | +| `limrun_adb_tunnel_cleaned_up` | The ADB tunnel of this lease was already cleaned up, so nothing can be typed over it. | +| `limrun_instance_unreachable` | The instance stopped answering, so its app state cannot be read. | | `limrun_instance_delete_unconfirmed` | A release could not confirm Limrun deleted the instance, so it may still be billed. | | `limrun_lease_released_mid_allocation` | The lease was released while its instance was still being prepared for the allocation. | | `limrun_lease_not_live` | The lease holds no live session, so the command that addresses it has nothing to act on. | | `limrun_runtime_shut_down` | This runtime is shut down, so it refuses to allocate a lease into it. | -| `limrun_instance_unreachable` | The instance stopped answering, so its app state cannot be read. | -| `limrun_adb_tunnel_cleaned_up` | The ADB tunnel of this lease was already cleaned up, so nothing can be typed over it. | | `limrun_app_sync_retired` | The app-sync session of this lease has ended, so no further sync runs on it. | | `limrun_app_sync_failed` | App sync or local cache maintenance failed; check the device for the app before retrying. | @@ -296,7 +296,7 @@ These reasons can come from more than one command. | Reason | Meaning | | --- | --- | | `provider_session_create_timeout` | The provider did not create the WebDriver session within the session-creation budget. | -| `provider_session_released_during_allocation` | The provider ended the session an allocation was waiting on by releasing its lease. | +| `provider_session_released_during_allocation` | Releasing the lease interrupted the allocation; `details.cleanup` reports how cleanup ended. | | `provider_session_shutdown_during_allocation` | The WebDriver runtime could not finish the allocation: shutdown was in progress or done. | | `provider_session_release_in_progress` | The lease is still releasing its previous session, so a new allocation gets no session. | | `provider_session_cleanup_incomplete` | Shutdown left WebDriver sessions running, so they may still be billed. | From 32215b3bc2053a94d17a85d87e7dd50ef131b37b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sun, 22 Nov 2026 01:58:44 +0100 Subject: [PATCH 6/9] docs(reasons): say WebDriver shutdown could not confirm cleanup Co-Authored-By: Claude Opus 5.5 --- packages/provider-webdriver/src/runtime-session.ts | 2 +- website/docs/docs/error-reasons.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/provider-webdriver/src/runtime-session.ts b/packages/provider-webdriver/src/runtime-session.ts index 0bd1ad0387..c0a3afd364 100644 --- a/packages/provider-webdriver/src/runtime-session.ts +++ b/packages/provider-webdriver/src/runtime-session.ts @@ -33,7 +33,7 @@ const WEBDRIVER_SESSION_REASONS = { sessionShutdownDuringAllocation: { reason: 'provider_session_shutdown_during_allocation' }, // The lease is still releasing its previous session, so a new allocation gets no session. sessionReleaseInProgress: { reason: 'provider_session_release_in_progress' }, - // Shutdown left WebDriver sessions running, so they may still be billed. + // Shutdown could not confirm that all WebDriver sessions and provider resources were cleaned up. sessionCleanupIncomplete: { reason: 'provider_session_cleanup_incomplete' }, } as const satisfies ReasonTable<'webdriver provider'>; diff --git a/website/docs/docs/error-reasons.md b/website/docs/docs/error-reasons.md index dc4110364e..c77701735c 100644 --- a/website/docs/docs/error-reasons.md +++ b/website/docs/docs/error-reasons.md @@ -299,7 +299,7 @@ These reasons can come from more than one command. | `provider_session_released_during_allocation` | Releasing the lease interrupted the allocation; `details.cleanup` reports how cleanup ended. | | `provider_session_shutdown_during_allocation` | The WebDriver runtime could not finish the allocation: shutdown was in progress or done. | | `provider_session_release_in_progress` | The lease is still releasing its previous session, so a new allocation gets no session. | -| `provider_session_cleanup_incomplete` | Shutdown left WebDriver sessions running, so they may still be billed. | +| `provider_session_cleanup_incomplete` | Shutdown could not confirm that all WebDriver sessions and provider resources were cleaned up. | | `text_entry_clear_target_unavailable` | `fill` has no focused element reference to clear before it types the replacement text. | | `webdriver_request_timeout` | The transport stopped waiting on a WebDriver request the driver may still be carrying out. | | `webdriver_connect_refused` | The request never reached the driver: the connection was refused or the host is unreachable. | From 4e08567e2ebf14c7a4bd00ec7c4489436dd912d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sun, 22 Nov 2026 03:03:36 +0100 Subject: [PATCH 7/9] refactor(reasons): split the shared Revyl outcomes from the client's HTTP rows; fix the unconfirmed summary REVYL_OUTCOME_REASONS holds the three outcomes deployment and snapshot code also publish; the HTTP-only rows become private to revyl-client.ts. provider-unconfirmed now says agent-device could not confirm the outcome, since a timeout can occur before any provider call. Co-Authored-By: Claude Opus 5.5 --- packages/provider-revyl/src/deployment.ts | 10 +-- packages/provider-revyl/src/revyl-client.ts | 71 +++++++++++---------- packages/provider-revyl/src/snapshot.ts | 4 +- website/docs/docs/error-reasons.md | 4 +- 4 files changed, 47 insertions(+), 42 deletions(-) diff --git a/packages/provider-revyl/src/deployment.ts b/packages/provider-revyl/src/deployment.ts index eb17fe67e2..202adfd025 100644 --- a/packages/provider-revyl/src/deployment.ts +++ b/packages/provider-revyl/src/deployment.ts @@ -8,7 +8,7 @@ import { Deadline, type DeadlineClock, pollUntilSettled } from '@agent-device/ho import { AppError, type ReasonTable } from '@agent-device/kernel/errors'; import type { EnvMap } from '@agent-device/kernel/source-value'; import { - REVYL_PROVIDER_REASONS, + REVYL_OUTCOME_REASONS, type RevylClient, type RevylProviderReason, } from './revyl-client.ts'; @@ -60,7 +60,7 @@ export async function deployRevylApp( const scoped = AbortSignal.any([signal, budget]); const timedOut = (cause?: unknown) => installStopped( - REVYL_PROVIDER_REASONS.unconfirmed.reason, + REVYL_OUTCOME_REASONS.unconfirmed.reason, `Revyl did not finish the install within ${budgetMs / 1000} s.`, cause, ); @@ -196,7 +196,7 @@ async function installAndWait( const installId = accepted.install_id?.trim(); if (accepted.status !== 'accepted' || !installId) { throw new AppError('COMMAND_FAILED', 'Revyl did not accept the app install.', { - reason: REVYL_PROVIDER_REASONS.refused.reason, + reason: REVYL_OUTCOME_REASONS.refused.reason, ...(accepted.status === undefined ? {} : { providerDetail: accepted.status }), }); } @@ -212,7 +212,7 @@ async function installAndWait( return requireInstalled(value.status, value.result ?? undefined); } throw new AppError('COMMAND_FAILED', `Revyl reported install status "${value.status}".`, { - reason: REVYL_PROVIDER_REASONS.refused.reason, + reason: REVYL_OUTCOME_REASONS.refused.reason, installId, }); } @@ -229,7 +229,7 @@ function requireInstalled( 'COMMAND_FAILED', `Revyl could not install the app${error === undefined ? '' : `: ${error}`}`, { - reason: REVYL_PROVIDER_REASONS.refused.reason, + reason: REVYL_OUTCOME_REASONS.refused.reason, installStatus: status, ...(error === undefined ? {} : { providerDetail: error }), }, diff --git a/packages/provider-revyl/src/revyl-client.ts b/packages/provider-revyl/src/revyl-client.ts index f7c7226848..2df78d5af1 100644 --- a/packages/provider-revyl/src/revyl-client.ts +++ b/packages/provider-revyl/src/revyl-client.ts @@ -51,21 +51,25 @@ export type RevylClientOptions = Readonly<{ * owner beside the code that classifies it. `missing_provider_credentials` sits with the credential * reader instead, which the plugin's eager entry loads before this module exists. */ -export const REVYL_PROVIDER_REASONS = { +/** Request outcomes the Revyl client, deployment and snapshot code all publish. */ +export const REVYL_OUTCOME_REASONS = { // Revyl refused the request or the action it carries. refused: { reason: 'provider-refused' }, - // Revyl never answered the request, or the connection to its backend failed. - unreachable: { reason: 'provider-unreachable' }, // Revyl answered in a way agent-device cannot read, such as a body that is not JSON. responseInvalid: { reason: 'provider-response-invalid' }, + // agent-device could not confirm the outcome of the request; check the session before retrying. + unconfirmed: { reason: 'provider-unconfirmed' }, +} as const satisfies ReasonTable<'revyl provider'>; + +const REVYL_HTTP_REASONS = { + // Revyl never answered the request, or the connection to its backend failed. + unreachable: { reason: 'provider-unreachable' }, // Revyl rejected the credentials on the request. authRejected: { reason: 'provider-auth-rejected' }, // The session the request addresses no longer exists at Revyl. sessionGone: { reason: 'provider-session-gone' }, // Revyl rejected the request because its state conflicts with what it asks for. conflict: { reason: 'provider-conflict' }, - // Revyl took the request but left its outcome unconfirmed; check the session before retrying. - unconfirmed: { reason: 'provider-unconfirmed' }, // Revyl refused a request it never routed, with a status that settles the failure. requestFailed: { reason: 'provider-request-failed' }, // Revyl gave no response before the request's own deadline passed. @@ -74,9 +78,10 @@ export const REVYL_PROVIDER_REASONS = { invalidProviderUrl: { reason: 'invalid_provider_url' }, } as const satisfies ReasonTable<'revyl provider'>; -/** The `details.reason` spellings {@link REVYL_PROVIDER_REASONS} declares. */ +/** The `details.reason` spellings the Revyl client publishes: its HTTP rows and the shared outcomes. */ export type RevylProviderReason = - (typeof REVYL_PROVIDER_REASONS)[keyof typeof REVYL_PROVIDER_REASONS]['reason']; + | (typeof REVYL_HTTP_REASONS)[keyof typeof REVYL_HTTP_REASONS]['reason'] + | (typeof REVYL_OUTCOME_REASONS)[keyof typeof REVYL_OUTCOME_REASONS]['reason']; /** * Which half of the API one request belongs to, which is what a 404 or 410 means. A route that @@ -307,7 +312,7 @@ export function createRevylClient(options: RevylClientOptions): RevylClient { throw new AppError( 'COMMAND_FAILED', 'Revyl storage did not accept the app upload.', - { reason: REVYL_PROVIDER_REASONS.unreachable.reason }, + { reason: REVYL_HTTP_REASONS.unreachable.reason }, error, ); } @@ -316,7 +321,7 @@ export function createRevylClient(options: RevylClientOptions): RevylClient { 'COMMAND_FAILED', `Revyl storage refused the app upload with HTTP ${response.status}.`, { - reason: REVYL_PROVIDER_REASONS.refused.reason, + reason: REVYL_OUTCOME_REASONS.refused.reason, status: response.status, }, ); @@ -377,7 +382,7 @@ async function sendOnce( return new AppError( 'COMMAND_FAILED', `Revyl did not answer ${request.method} ${request.path}.`, - { reason: REVYL_PROVIDER_REASONS.unreachable.reason, path: request.path }, + { reason: REVYL_HTTP_REASONS.unreachable.reason, path: request.path }, error, ); } @@ -392,7 +397,7 @@ function isRetryable(request: RevylRequest, outcome: RevylResponse | Error): boo if (outcome instanceof Error) { return ( outcome instanceof AppError && - outcome.details?.reason === REVYL_PROVIDER_REASONS.unreachable.reason + outcome.details?.reason === REVYL_HTTP_REASONS.unreachable.reason ); } if (request.retryServerError === true && outcome.status === 500) return true; @@ -415,7 +420,7 @@ function requestTimedOut(request: RevylRequest, cause: unknown): AppError { request.timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS } ms.`, { - reason: REVYL_PROVIDER_REASONS.requestTimeout.reason, + reason: REVYL_HTTP_REASONS.requestTimeout.reason, path: request.path, hint: 'Revyl may have carried out the request. Check the session before retrying it.', }, @@ -461,7 +466,7 @@ function assertLifecycleAccepted( 'COMMAND_FAILED', `Revyl did not stop the session${message === undefined ? '' : `: ${message}`}`, { - reason: REVYL_PROVIDER_REASONS.refused.reason, + reason: REVYL_OUTCOME_REASONS.refused.reason, operation, ...(message === undefined ? {} : { providerDetail: message }), hint: 'The Revyl session may still be rented. End it from Revyl if it stays listed.', @@ -494,8 +499,8 @@ function assertWorkerActionSuccess( { reason: response.execution_uncertain === true - ? REVYL_PROVIDER_REASONS.unconfirmed.reason - : REVYL_PROVIDER_REASONS.refused.reason, + ? REVYL_OUTCOME_REASONS.unconfirmed.reason + : REVYL_OUTCOME_REASONS.refused.reason, path: request.path, ...(error === undefined ? {} : { providerDetail: error }), }, @@ -535,7 +540,7 @@ function parseJson(request: RevylRequest, response: RevylResponse): T { throw new AppError( 'COMMAND_FAILED', `Revyl returned a response to ${request.method} ${request.path} that is not JSON (HTTP ${response.status}).`, - { reason: REVYL_PROVIDER_REASONS.responseInvalid.reason, path: request.path }, + { reason: REVYL_OUTCOME_REASONS.responseInvalid.reason, path: request.path }, error, ); } @@ -557,7 +562,7 @@ type RevylStatusVerdict = Readonly<{ const REVYL_REQUEST_FAILED: RevylStatusVerdict = { code: 'COMMAND_FAILED', - reason: REVYL_PROVIDER_REASONS.requestFailed.reason, + reason: REVYL_HTTP_REASONS.requestFailed.reason, uncertain: false, retryable: false, }; @@ -565,7 +570,7 @@ const REVYL_REQUEST_FAILED: RevylStatusVerdict = { /** A server error Revyl has no rule for: the request went in, the verdict did not come back. */ const REVYL_SERVER_ERROR: RevylStatusVerdict = { code: 'COMMAND_FAILED', - reason: REVYL_PROVIDER_REASONS.unconfirmed.reason, + reason: REVYL_OUTCOME_REASONS.unconfirmed.reason, uncertain: true, retryable: false, }; @@ -575,61 +580,61 @@ const REVYL_STATUS_VERDICTS: Readonly> = { 400: REVYL_REQUEST_FAILED, 401: { code: 'UNAUTHORIZED', - reason: REVYL_PROVIDER_REASONS.authRejected.reason, + reason: REVYL_HTTP_REASONS.authRejected.reason, uncertain: false, retryable: false, }, 403: { code: 'UNAUTHORIZED', - reason: REVYL_PROVIDER_REASONS.authRejected.reason, + reason: REVYL_HTTP_REASONS.authRejected.reason, uncertain: false, retryable: false, }, 404: { code: 'SESSION_NOT_FOUND', - reason: REVYL_PROVIDER_REASONS.sessionGone.reason, + reason: REVYL_HTTP_REASONS.sessionGone.reason, uncertain: false, retryable: false, }, 408: { code: 'COMMAND_FAILED', - reason: REVYL_PROVIDER_REASONS.unconfirmed.reason, + reason: REVYL_OUTCOME_REASONS.unconfirmed.reason, uncertain: true, retryable: false, }, 409: { code: 'COMMAND_FAILED', - reason: REVYL_PROVIDER_REASONS.conflict.reason, + reason: REVYL_HTTP_REASONS.conflict.reason, uncertain: false, retryable: false, }, 410: { code: 'SESSION_NOT_FOUND', - reason: REVYL_PROVIDER_REASONS.sessionGone.reason, + reason: REVYL_HTTP_REASONS.sessionGone.reason, uncertain: false, retryable: false, }, 500: { code: 'COMMAND_FAILED', - reason: REVYL_PROVIDER_REASONS.unconfirmed.reason, + reason: REVYL_OUTCOME_REASONS.unconfirmed.reason, uncertain: true, retryable: false, }, 502: { code: 'COMMAND_FAILED', - reason: REVYL_PROVIDER_REASONS.unconfirmed.reason, + reason: REVYL_OUTCOME_REASONS.unconfirmed.reason, uncertain: true, retryable: true, }, 503: { code: 'COMMAND_FAILED', - reason: REVYL_PROVIDER_REASONS.unconfirmed.reason, + reason: REVYL_OUTCOME_REASONS.unconfirmed.reason, uncertain: true, retryable: true, }, 504: { code: 'COMMAND_FAILED', - reason: REVYL_PROVIDER_REASONS.unconfirmed.reason, + reason: REVYL_OUTCOME_REASONS.unconfirmed.reason, uncertain: true, retryable: true, }, @@ -644,7 +649,7 @@ const REVYL_STATUS_VERDICTS: Readonly> = { function revylFailure(route: RevylRoute, status: number): RevylStatusVerdict { const verdict = REVYL_STATUS_VERDICTS[status] ?? (status >= 500 ? REVYL_SERVER_ERROR : REVYL_REQUEST_FAILED); - if (verdict.reason === REVYL_PROVIDER_REASONS.sessionGone.reason && route !== 'session') + if (verdict.reason === REVYL_HTTP_REASONS.sessionGone.reason && route !== 'session') return REVYL_REQUEST_FAILED; return verdict; } @@ -668,7 +673,7 @@ export function revylFailureRefusedTheRequest(error: unknown): boolean { */ export function isRevylSessionGone(error: unknown): boolean { return ( - error instanceof AppError && error.details?.reason === REVYL_PROVIDER_REASONS.sessionGone.reason + error instanceof AppError && error.details?.reason === REVYL_HTTP_REASONS.sessionGone.reason ); } @@ -693,7 +698,7 @@ export function resolveRevylBackendUrl(raw: string): string { url = new URL(raw); } catch { throw new AppError('INVALID_ARGS', 'REVYL_API_URL is not a valid URL.', { - reason: REVYL_PROVIDER_REASONS.invalidProviderUrl.reason, + reason: REVYL_HTTP_REASONS.invalidProviderUrl.reason, }); } const loopback = isLoopbackHostname(url.hostname); @@ -702,7 +707,7 @@ export function resolveRevylBackendUrl(raw: string): string { 'INVALID_ARGS', 'REVYL_API_URL must use HTTPS; plain HTTP is allowed only on loopback.', { - reason: REVYL_PROVIDER_REASONS.invalidProviderUrl.reason, + reason: REVYL_HTTP_REASONS.invalidProviderUrl.reason, hint: 'Example: https://backend.revyl.ai', }, ); @@ -711,7 +716,7 @@ export function resolveRevylBackendUrl(raw: string): string { throw new AppError( 'INVALID_ARGS', 'REVYL_API_URL must be an origin without credentials, query, or fragment.', - { reason: REVYL_PROVIDER_REASONS.invalidProviderUrl.reason }, + { reason: REVYL_HTTP_REASONS.invalidProviderUrl.reason }, ); } return url.origin; diff --git a/packages/provider-revyl/src/snapshot.ts b/packages/provider-revyl/src/snapshot.ts index 6e85b0bf7d..0ce625c8e3 100644 --- a/packages/provider-revyl/src/snapshot.ts +++ b/packages/provider-revyl/src/snapshot.ts @@ -6,7 +6,7 @@ import { acquireProviderKeyboard } from '@agent-device/contracts/tap-keyboard-oc import type { IosTreeNode } from '@agent-device/capture-kit/ios-ax-tree'; import type { RevylPlatform } from './device.ts'; import type { RevylSession } from './revyl-session.ts'; -import { REVYL_PROVIDER_REASONS } from './revyl-client.ts'; +import { REVYL_OUTCOME_REASONS } from './revyl-client.ts'; /** Reads one Revyl worker's accessibility tree and the box its actions measure. */ export type RevylSnapshotReader = Readonly<{ @@ -103,7 +103,7 @@ function invalidIosHierarchy(cause?: unknown): AppError { return new AppError( 'COMMAND_FAILED', 'Revyl returned an iOS hierarchy that is not an accessibility node tree.', - { reason: REVYL_PROVIDER_REASONS.responseInvalid.reason }, + { reason: REVYL_OUTCOME_REASONS.responseInvalid.reason }, cause, ); } diff --git a/website/docs/docs/error-reasons.md b/website/docs/docs/error-reasons.md index c77701735c..b7980659b4 100644 --- a/website/docs/docs/error-reasons.md +++ b/website/docs/docs/error-reasons.md @@ -261,12 +261,12 @@ These reasons can come from more than one command. | `provider-viewport-unavailable` | The session reports no viewport, so a scroll distance or screenshot density has nothing to scale by. | | `provider-invalid-response` | Revyl answered a worker action with a value outside the field's own range. | | `provider-refused` | Revyl refused the request or the action it carries. | -| `provider-unreachable` | Revyl never answered the request, or the connection to its backend failed. | | `provider-response-invalid` | Revyl answered in a way agent-device cannot read, such as a body that is not JSON. | +| `provider-unconfirmed` | agent-device could not confirm the outcome of the request; check the session before retrying. | +| `provider-unreachable` | Revyl never answered the request, or the connection to its backend failed. | | `provider-auth-rejected` | Revyl rejected the credentials on the request. | | `provider-session-gone` | The session the request addresses no longer exists at Revyl. | | `provider-conflict` | Revyl rejected the request because its state conflicts with what it asks for. | -| `provider-unconfirmed` | Revyl took the request but left its outcome unconfirmed; check the session before retrying. | | `provider-request-failed` | Revyl refused a request it never routed, with a status that settles the failure. | | `request_timeout` | Revyl gave no response before the request's own deadline passed. | | `invalid_provider_url` | `REVYL_API_URL` is not an origin Revyl's API can be addressed at. | From 739bfbf07ce107e73f9d787bdd64e156df1d6bd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sun, 22 Nov 2026 08:25:35 +0100 Subject: [PATCH 8/9] docs(revyl): describe the split outcome and HTTP reason tables in one block Co-Authored-By: Claude Opus 5.5 --- packages/provider-revyl/src/revyl-client.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/provider-revyl/src/revyl-client.ts b/packages/provider-revyl/src/revyl-client.ts index 2df78d5af1..d5f5a44a07 100644 --- a/packages/provider-revyl/src/revyl-client.ts +++ b/packages/provider-revyl/src/revyl-client.ts @@ -46,12 +46,11 @@ export type RevylClientOptions = Readonly<{ }>; /** - * Every `details.reason` the Revyl provider publishes, keyed by what the failure means. The status - * table below and every Revyl refusal site read these rows, so the plugin's wire vocabulary has one - * owner beside the code that classifies it. `missing_provider_credentials` sits with the credential - * reader instead, which the plugin's eager entry loads before this module exists. + * Request outcomes the Revyl client, deployment and snapshot code all publish. With + * `REVYL_HTTP_REASONS` below, these rows are every `details.reason` this client publishes. + * `missing_provider_credentials` sits with the credential reader instead, which the plugin's eager + * entry loads before this module exists. */ -/** Request outcomes the Revyl client, deployment and snapshot code all publish. */ export const REVYL_OUTCOME_REASONS = { // Revyl refused the request or the action it carries. refused: { reason: 'provider-refused' }, From 90bab50147c70bd91112d7a26cd05538f456e4a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Sun, 22 Nov 2026 09:15:29 +0100 Subject: [PATCH 9/9] refactor(revyl): keep the provider reason union private and narrow the install-stop reasons Co-Authored-By: Claude Opus 5.5 --- packages/provider-revyl/src/deployment.ts | 8 ++------ packages/provider-revyl/src/revyl-client.ts | 5 +++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/provider-revyl/src/deployment.ts b/packages/provider-revyl/src/deployment.ts index 202adfd025..b9c55850e7 100644 --- a/packages/provider-revyl/src/deployment.ts +++ b/packages/provider-revyl/src/deployment.ts @@ -7,11 +7,7 @@ import { packGzipTar } from '@agent-device/host-kit/gzip-tar'; import { Deadline, type DeadlineClock, pollUntilSettled } from '@agent-device/host-kit/retry'; import { AppError, type ReasonTable } from '@agent-device/kernel/errors'; import type { EnvMap } from '@agent-device/kernel/source-value'; -import { - REVYL_OUTCOME_REASONS, - type RevylClient, - type RevylProviderReason, -} from './revyl-client.ts'; +import { REVYL_OUTCOME_REASONS, type RevylClient } from './revyl-client.ts'; import type { RevylWorkerActionResponse } from './revyl-types.ts'; /** Why a Revyl app deployment is refused. */ @@ -111,7 +107,7 @@ async function uploadAndInstall( * cancellation. `request_canceled` is the kernel's cancellation vocabulary, which no provider table * re-declares, so it is named here as the one spelling this wrapper also takes. */ -type RevylInstallStopReason = RevylProviderReason | 'request_canceled'; +type RevylInstallStopReason = typeof REVYL_OUTCOME_REASONS.unconfirmed.reason | 'request_canceled'; function installStopped(reason: RevylInstallStopReason, message: string, cause: unknown): AppError { return new AppError( diff --git a/packages/provider-revyl/src/revyl-client.ts b/packages/provider-revyl/src/revyl-client.ts index d5f5a44a07..ee348c1475 100644 --- a/packages/provider-revyl/src/revyl-client.ts +++ b/packages/provider-revyl/src/revyl-client.ts @@ -47,7 +47,8 @@ export type RevylClientOptions = Readonly<{ /** * Request outcomes the Revyl client, deployment and snapshot code all publish. With - * `REVYL_HTTP_REASONS` below, these rows are every `details.reason` this client publishes. + * `REVYL_HTTP_REASONS` below, these rows are the provider-owned reasons this client publishes; + * `request_canceled` is shared cancellation vocabulary. * `missing_provider_credentials` sits with the credential reader instead, which the plugin's eager * entry loads before this module exists. */ @@ -78,7 +79,7 @@ const REVYL_HTTP_REASONS = { } as const satisfies ReasonTable<'revyl provider'>; /** The `details.reason` spellings the Revyl client publishes: its HTTP rows and the shared outcomes. */ -export type RevylProviderReason = +type RevylProviderReason = | (typeof REVYL_HTTP_REASONS)[keyof typeof REVYL_HTTP_REASONS]['reason'] | (typeof REVYL_OUTCOME_REASONS)[keyof typeof REVYL_OUTCOME_REASONS]['reason'];