fix(mobile): recognize stale-ref refusals by agent-device's typed reason

Merged
TH
2mo ago
+49-15

What and why

  • staleOr decided NODE_STALE with a regex over agent-device's message. agent-device 0.21.16 gave stale refs a typed details.reason (callstack/agent-device#2960, added at this repo's request), and its ref frames refuse with four more reasons. The engine now reads the reason:

    const STALE_REF_REASONS: ReadonlySet<string> = new Set([
      'ref_not_found',
      'ref_frame_expired',
      'ref_generation_mismatch',
      'plain_ref_requires_complete_frame',
      'ref_not_issued',
    ]);
    
  • Three of the five messages never matched the regex ("minted from a superseded snapshot generation", "needs a complete snapshot", "was not issued by the current ref frame"), so those refusals would fail the action as ENGINE_FAILURE instead of re-resolving the node. The engine sends plain refs, so it rarely meets them today; the point is that a reworded message in a later agent-device release can no longer change the classification.

  • It keys on the reason alone, not on details.dispatched === 'no': agent-device refuses all five before the action reaches the device, but a drag's refusal comes back as dispatched: 'unknown' (callstack/agent-device#3183). Requiring no would stop retrying a stale dragTo that main retries today.

  • The unsupported and no-session message checks stay as they are: a platform refusing a setting or permission e2e itself names (siri on Android, faceid on Android) still arrives as INVALID_ARGS text.

Verified

Ran it locally: yes

  • iOS 26.2 simulator, agent-device 0.21.20 through the engine's client. Each refusal was captured live and passed through staleOr from main and from this branch (the pinned ref in row two is sent by hand, to get that reason):
Refusalagent-device sendsmainthis branch
press @e9999ref_not_found, dispatched noNODE_STALE (retryable)NODE_STALE (retryable)
press @e15~s708703 after a newer snapshotref_generation_mismatch, dispatched noENGINE_FAILURENODE_STALE (retryable)
drag @e15 @e31 after a tapref_frame_expired, dispatched unknownNODE_STALE (retryable)NODE_STALE (retryable)
  • E2E_AGENT_DEVICE_SIMULATOR=1 pnpm --filter @e2e-dev/mobile exec vitest run: unit and simulator integration tests pass on Settings.
  • Not run locally: the mobile benchmark. This Mac has Xcode 26.2, which cannot build the Expo SDK 57 app; the PR's mobile jobs run it on iOS and Android.

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.
  • Breaking change: title carries !, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).
  • Docs updated in the same PR: the docs/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.