Skip to content

fix(processor): restore a rebooted device with its usage and timeout - #1158

Open
koral-- wants to merge 2 commits into
masterfrom
fix/restore-owner-usage
Open

koral-- wants to merge 2 commits into
masterfrom
fix/restore-owner-usage

Conversation

@koral--

@koral-- koral-- commented Nov 21, 2026

Copy link
Copy Markdown
Member

Bug

When a device is kept for its owner across a reboot (POST /api/v1/user/devices/{serial}/reboot?keepOwnership=true, or a device that disappears while in use when the processor runs with --auto-restore-owner), it came back as a different kind of reservation than the one the owner had:

  • Usage was lost. restoreDeviceOwner passed the claimed usage as the AutoGroupMessage identifier, and the device joined with no usage. A device reserved through POST /api/v1/user/devices (usage automation) came back as a plain reservation. The device list showed Stop Using instead of Automated, admins had no Stop Automation, and the API reported usage: null.
  • Timeout was lost. AutoGroupMessage had no timeout, and the claim did not store one. The restored reservation used the provider --group-timeout (900 s by default) instead of the timeout the client asked for.

Change

  • AutoGroupMessage gets optional string usage = 3 and optional uint32 timeout = 4. The processor fills both from the claim. The identifier is now '' for a restore. The other senders put an ADB fingerprint or a VNC auth response there, and autojoin listeners match on it. A restore has no credential, and an empty identifier never matches a pending ADB or VNC authorization.
  • JoinGroupMessage gets optional uint32 timeout = 6 (5 stays reserved). The Android group plugin and the iOS bridge report the timeout that was requested, not the resolved one. A reservation on the provider default therefore stays on the default after a restore.
  • The processor stores that timeout on the device row as ownerTimeout. reserveDeviceOwner copies it into the claim as restoreOwner.timeout. Every write that clears usage (release, ready, initial state) clears it too. datautil.normalize keeps it out of API responses, as it already does for restoreOwner.
  • The Android group plugin and the iOS bridge join with the usage and timeout from AutoGroupMessage. On iOS, restoring automation turns Appium mode on again, the same as the original reservation did.
  • doc/device-states.md: the claimed bullet now says that the reservation comes back with its usage and timeout.

All new fields are optional. Mixed versions keep working: an older worker reports no timeout, an older claim has none, and either case falls back to the provider default, as before. Lease reservations (leaseId) are never claimed, so they are unaffected.

How tested

  • npm run lint (0 errors, no new warnings), node build.mts typecheck, npm run test:unit (832 passing, plus the ios-prototype tests).

  • New unit tests:

    • processor: replays the claim with usage, timeout and an empty identifier, and drops an expired claim.
    • Android group plugin: joins with the carried usage and timeout, falls back to --group-timeout, and reports the requested timeout on join.
    • iOS bridge: restores automation with its timeout and Appium mode.
    • dbapi: ownerTimeout is written, cleared and copied into the claim.
    • datautil: ownerTimeout is stripped.

    With this branch's tests, the lib code from master fails 15 of them.

  • E2E, locally: an API 29 emulator, stf local emulator-5560, RethinkDB in Docker. I reserved the device with POST /api/v1/user/devices {"serial":"emulator-5560","timeout":180000}, called reboot?keepOwnership=true, and waited until it was present and ready with a new reservation:

    master this branch
    claim during the reboot {email, usage: "automation", expiresAt} {email, usage: "automation", timeout: 180000, expiresAt}
    owner after the restore e2e@example.com e2e@example.com
    usage after the restore (API) null "automation"
    device list Stop Using Automated
    idle release after the restore still owned after 300 s (--group-timeout 900 s) automatic_timeout exactly 180 s after the restore (run twice: 00:26:54 → 00:29:54, 00:31:06 → 00:34:06)

🤖 Generated with Claude Code

koral-- and others added 2 commits November 21, 2026 01:19
A device kept for its owner across a reboot (keepOwnership=true or
--auto-restore-owner) came back as a plain reservation: the processor
sent the claimed usage as the AutoGroupMessage identifier, and the
device joined with no usage and the provider --group-timeout. An API
reservation with usage "automation" therefore showed as Busy instead of
Automated, and lost the timeout its client asked for.

AutoGroupMessage now carries usage and timeout, and its identifier is
empty for a restore, since no ADB or VNC authorization waits on it.
Workers report the requested timeout on JoinGroupMessage, the processor
stores it as ownerTimeout, and reserveDeviceOwner copies it into the
claim. The iOS provider replays both as well.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Covers the processor replaying a claim as AutoGroupMessage, the Android
and iOS workers joining with the carried usage and timeout, the claim
copying the reservation timeout, and the timeout staying out of API
responses. Documents that a restored reservation keeps its usage and
timeout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

✅ STF CI report

All green  ·  6 test tiers (6 pass / 0 fail / 0 skip)  ·  20 Android versions (20 with a usable device in STF)

Test tiers

Tier Result
✅ Build (npm + webpack) deps cache hit
✅ Lint (eslint + jsonlint + translations + workflow shell) lib/, res/ and root JS + JSON, translation catalogs, and every workflow run: block
✅ Unit tests (mocha) lib/util, lib/wire and lib/db specs
✅ Component tests (vitest + React) 257 specs, 0 failed, 0 errored
✅ Integration + device-less E2E (stf local + RethinkDB + Playwright + SeaweedFS) stf local success, fake devices success, web UI suite success, storage success
✅ Docker Compose + AVD + Playwright (Android 16, API 36) 21 Playwright tests, image success, Compose/AVD success, teardown success

Android device matrix

Android API Image Boot In STF Usable SIM IDs Screen Touch Shell UI E2E Teardown
✅ 5.0 21 ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
✅ 5.1 22 ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
✅ 6.0 23 ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
✅ 7 24 ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
✅ 7.1 25 ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
✅ 8 26 ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
✅ 8.1 27 ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
✅ 9 28 ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
✅ 10 29 ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
✅ 11 30 ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
✅ 12 31 ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
✅ 12L 32 ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
✅ 13 33 ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
✅ 14 34 ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
✅ 15 35 ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
✅ 16 36 ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
✅ 16.1 36.1 ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
✅ 17 37.0 ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
✅ 17 37.1 ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅
✅ 17 37.2 ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅ ✅

Image = a system image is published for that API and arch. Boot = emulator reached sys.boot_completed and answers adb. In STF = the device registered with the STF provider. Usable = STF offered it as Use and handed over control. SIM IDs = imei, imsi, iccid and phoneNumber landed on the device document, which from API 23 up needs an STFService build whose agent answers --telephony (a leg whose emulator reports no usable SIM records a pass, because there is nothing to read). Screen = minicap frames reached the browser canvas and kept changing. Touch = a browser tap and swipe showed up in getevent on the device, at the coordinates they were aimed at: the tap within 5% of the centre of the touch axes, the swipe descending monotonically from 0.75 to 0.25 (the emulator runs with adb root, which minitouch needs to open /dev/input). Shell = the dashboard shell widget ran a command on it. UI E2E = the rest of the Playwright web UI suite. Teardown = the emulator action shut the AVD down and exited on its own.

Logs, screenshots, logcat and Playwright traces are attached to the run as artifacts · full run · commit 5ab8bfb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant