Skip to content

feat(automation): reserve devices and clean up idle emulators - #910

Merged
nixuuu merged 2 commits into
devfrom
feat/emulator-wait-and-autostart
Nov 17, 2026
Merged

nixuuu merged 2 commits into
devfrom
feat/emulator-wait-and-autostart

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Change

Agents can reserve a free device with acquire_device, wait up to 240 seconds, or boot another existing Android AVD or iOS simulator. A worker shares exclusive reservations across harnesses, normal tool calls and Preview, with a limit of two virtual devices started by Canopy.

release_device, five minutes of inactivity, thread archival and worker shutdown close the thread's device session and release its reservation. Durable records recover reservations after a restart. Only virtual devices started by Canopy are shut down; existing user emulators and physical devices stay running. Active operations drain before cleanup, queued work is fenced, and cleanup failures retain ownership for retry.

Device MCP stays available with the owner's grant and the pinned CLI even when no device is running. Existing owner, turn and permission checks still apply. Device replay is unavailable because nested scripts can bypass reservation lifecycle tracking; individual tools and bound batches remain available.

This uses configured local devices, not emulator cloning or SDK installation. An Android crash before its runtime serial is recorded retains an uncertain reservation for investigation instead of guessing which process to stop. Custom provider plugins that imitate native device IDs are unsupported. The behavior, limits and release availability are documented in docs/automation-tools.md.

Verification

Completed locally in this worktree:

  • 35 worker adapter, Preview and live automation activity integration tests through a scoped check:tmp run, including updated device version and cold-device MCP expectations.

  • 31 reservation/durability tests and 13 pinned CLI adapter tests through scoped check:tmp runs.

  • Managed MCP, device policy, device reservations, archive cleanup, Preview adapters and Android input tests through scoped check:tmp runs.

  • 20 gateway/worker automation integration tests, including grants, readiness, owner scope and permission modes.

  • Worker and gateway typechecks, edited-file lint/format checks, and diff/content review.

One cleanup-admission test hit its default 5-second limit during a parallel local run and passed in isolation with a 15-second limit. No real emulator was started. CI owns the full repository verification gate and must pass on the PR revision.

Copy audit (§8): no controls, labels, layout or other UI copy changed. New text is English MCP instructions and runtime diagnostics; exact tool and selector names are intentional for agent operation. UI layout/name-width checks are not applicable.

@nixuuu
nixuuu enabled auto-merge (squash) November 17, 2026 06:31
@nixuuu
nixuuu merged commit 2068280 into dev Nov 17, 2026
16 checks passed
@nixuuu
nixuuu deleted the feat/emulator-wait-and-autostart branch November 17, 2026 06:46
nixuuu added a commit that referenced this pull request Nov 18, 2026
## Change

An Android AVD whose reservation contains only the configuration name
can leave a binary worker offline during a nightly update. The ownership
check correctly refuses to stop the emulator, but the error used to
interrupt shutdown after the executable was replaced and the reporting
channel was canceled.

Updates and supervisor handover now share the graceful stop path with
signal-driven shutdown. The worker logs the cleanup error, attempts to
flush the journal, and exits with the requested supervisor code. The
durable AVD reservation stays in place for recovery after startup. The
update result still follows WorkerLink startup confirmation or the
supervisor's rollback.

Fixes: #910

## Verification

- The new integration test runs a pair of compiled nightly worker
binaries and a fake `agent-device`. It verifies that the worker comes
back active after supervisor handover, reports success for the same
attempt, retains the reservation, and sends no emulator shutdown
command.
- 48 tests passed through `check:tmp` across the new regression, worker
shutdown, and the device backend and pool.
- Five existing tests passed through `check:tmp` for rollback and
retrying a lost failure report.
- Worker and integration test typechecks, lint and formatting for the
edited TypeScript files, and `git diff --check` passed. GitHub CI runs
the full gate.
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