Repository navigation
feat(automation): reserve devices and clean up idle emulators - #910
Merged
Merged
Conversation
nixuuu
enabled auto-merge (squash)
November 17, 2026 06:31
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:tmprun, including updated device version and cold-device MCP expectations.31 reservation/durability tests and 13 pinned CLI adapter tests through scoped
check:tmpruns.Managed MCP, device policy, device reservations, archive cleanup, Preview adapters and Android input tests through scoped
check:tmpruns.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.