Skip to content

[net11] Restart a wedged Android emulator before retrying UI test setup - #40381

Merged
kubaflo merged 1 commit into
net11from
kubaflo-net11-restart-wedged-emulator
Nov 18, 2026
Merged

kubaflo merged 1 commit into
net11from
kubaflo-net11-restart-wedged-emulator

Conversation

@kubaflo

@kubaflo kubaflo commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Target Branch

This PR is for Initial base
New features, API changes, or .NET 12 work (including .NET 12 fixes) main
.NET 11 servicing fixes net11, for review
Older servicing, release integration, infrastructure, or documentation The branch designated for that work

For .NET 11 fixes, only a maintainer retargets the approved PR to the active
inflight lane and merges it after CI validates that final base. Do not merge
individual fixes directly into net11; agents must not retarget or merge.

Description of Change

Android UI test jobs can lose all tests when the emulator wedges before it finishes booting. uitest-prepare already retries five times (RunUITestSetupWithRetry), but each retry reuses the same emulator. Every attempt waits another 600 s on that wedged instance. The restart added in #40273 runs only before test attempts, not before setup retries.

Examples:

  • net11 UI build 1687571, Android API30 Shadow (log 6089): the emulator shows offline and then "no devices" for about an hour. All 5 setup attempts wait on the same process, which stays alive until final cleanup. No tests run.
  • Candidate UI build 1686311 CV2 (log 3682) has the same five attempts with no relaunch. There the device was stuck unauthorized.

Change (eng/devices/android.cake):

  • I extracted the existing [net11] Recover lost Android emulator before UI test retry #40273 restart logic into RestartEmulatorIfNotBooted(nextStep).
  • uitest-prepare calls it before setup attempts 2–5.
  • It restarts only an emulator this script launched, and only when sys.boot_completed is not set. Booted devices and externally provided devices are untouched.
  • EnsureDeviceForUITestAttempt keeps its behavior.

The root cause of the emulator wedge is unknown. This change only lets the retries recover from it.

Validation

Local, API30 google_apis_playstore arm64 AVD, with CI retries enabled (AGENT_NAME set) and an isolated ADB server and home directory. To simulate the wedge, a watcher sends SIGSTOP to the emulator process 2 s after launch. This reproduces the CI shape: adb shows device offline and the boot wait fails at 600 s.

  • Baseline (net11 android.cake): attempt 1 failed with "The emulator did not finish booting in time". Attempt 2 waited again on the same stopped PID, with no relaunch. Red.
  • This PR: attempt 1 failed the same way. Then "The Android emulator is not booted; restarting it before retrying UI test setup." The emulator was killed and relaunched, booted in 15 s, and the APK installed. Exit 0. Green.
  • Control (no wedge): normal boot, no restart. Exit 0.

The unauthorized mode (log 3682) was not reproduced locally. A relaunch is expected to help it as well, but that is not validated.

Issues Fixed

Fixes net11 Android UI test jobs lost to an emulator that wedges during boot (no tracking issue).

uitest-prepare retries reused the same emulator after a boot timeout, so
every setup attempt waited on the same wedged instance. Restart the
script-launched emulator when it is not booted before each setup retry.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@kubaflo
kubaflo temporarily deployed to copilot-pat-pool November 18, 2026 13:08 — with GitHub Actions Inactive
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 40381

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 40381"

@kubaflo
kubaflo temporarily deployed to copilot-pat-pool November 18, 2026 13:08 — with GitHub Actions Inactive
@azure-pipelines

This comment has been minimized.

@kubaflo
kubaflo temporarily deployed to copilot-pat-pool November 18, 2026 13:09 — with GitHub Actions Inactive
@kubaflo
kubaflo temporarily deployed to copilot-pat-pool November 18, 2026 13:12 — with GitHub Actions Inactive
@kubaflo
kubaflo temporarily deployed to copilot-pat-pool November 18, 2026 13:14 — with GitHub Actions Inactive
@github-actions github-actions Bot added area-infrastructure CI, Maestro / Coherency, upstream dependencies/versions platform/android labels Nov 18, 2026
@kubaflo
kubaflo temporarily deployed to copilot-pat-pool November 18, 2026 13:14 — with GitHub Actions Inactive
@kubaflo
kubaflo merged commit 1581878 into net11 Nov 18, 2026
13 of 23 checks passed
@kubaflo
kubaflo deleted the kubaflo-net11-restart-wedged-emulator branch November 18, 2026 13:19
kubaflo added a commit that referenced this pull request Nov 18, 2026
Take net11's eng/devices/android.cake (#40381 supersedes the #40273 copy on this branch).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@kubaflo kubaflo mentioned this pull request Nov 18, 2026
1 task
SuthiYuvaraj pushed a commit to SuthiYuvaraj/maui that referenced this pull request Nov 23, 2026
…up (dotnet#40381)

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Description of Change

Android UI test jobs can lose all tests when the emulator wedges before
it finishes booting. `uitest-prepare` already retries five times
(`RunUITestSetupWithRetry`), but each retry reuses the same emulator.
Every attempt waits another 600 s on that wedged instance. The restart
added in dotnet#40273 runs only before test attempts, not before setup
retries.

Examples:
- net11 UI build 1687571, Android API30 Shadow (log 6089): the emulator
shows `offline` and then "no devices" for about an hour. All 5 setup
attempts wait on the same process, which stays alive until final
cleanup. No tests run.
- Candidate UI build 1686311 CV2 (log 3682) has the same five attempts
with no relaunch. There the device was stuck `unauthorized`.

Change (`eng/devices/android.cake`):
- I extracted the existing dotnet#40273 restart logic into
`RestartEmulatorIfNotBooted(nextStep)`.
- `uitest-prepare` calls it before setup attempts 2–5.
- It restarts only an emulator this script launched, and only when
`sys.boot_completed` is not set. Booted devices and externally provided
devices are untouched.
- `EnsureDeviceForUITestAttempt` keeps its behavior.

The root cause of the emulator wedge is unknown. This change only lets
the retries recover from it.

### Validation

Local, API30 `google_apis_playstore` arm64 AVD, with CI retries enabled
(`AGENT_NAME` set) and an isolated ADB server and home directory. To
simulate the wedge, a watcher sends SIGSTOP to the emulator process 2 s
after launch. This reproduces the CI shape: adb shows `device offline`
and the boot wait fails at 600 s.
- **Baseline (net11 `android.cake`):** attempt 1 failed with "The
emulator did not finish booting in time". Attempt 2 waited again on the
same stopped PID, with no relaunch. **Red.**
- **This PR:** attempt 1 failed the same way. Then "The Android emulator
is not booted; restarting it before retrying UI test setup." The
emulator was killed and relaunched, booted in 15 s, and the APK
installed. Exit 0. **Green.**
- **Control (no wedge):** normal boot, no restart. Exit 0.

The `unauthorized` mode (log 3682) was not reproduced locally. A
relaunch is expected to help it as well, but that is not validated.

### Issues Fixed

Fixes net11 Android UI test jobs lost to an emulator that wedges during
boot (no tracking issue).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
SuthiYuvaraj pushed a commit to SuthiYuvaraj/maui that referenced this pull request Nov 23, 2026
…up (dotnet#40381)

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Description of Change

Android UI test jobs can lose all tests when the emulator wedges before
it finishes booting. `uitest-prepare` already retries five times
(`RunUITestSetupWithRetry`), but each retry reuses the same emulator.
Every attempt waits another 600 s on that wedged instance. The restart
added in dotnet#40273 runs only before test attempts, not before setup
retries.

Examples:
- net11 UI build 1687571, Android API30 Shadow (log 6089): the emulator
shows `offline` and then "no devices" for about an hour. All 5 setup
attempts wait on the same process, which stays alive until final
cleanup. No tests run.
- Candidate UI build 1686311 CV2 (log 3682) has the same five attempts
with no relaunch. There the device was stuck `unauthorized`.

Change (`eng/devices/android.cake`):
- I extracted the existing dotnet#40273 restart logic into
`RestartEmulatorIfNotBooted(nextStep)`.
- `uitest-prepare` calls it before setup attempts 2–5.
- It restarts only an emulator this script launched, and only when
`sys.boot_completed` is not set. Booted devices and externally provided
devices are untouched.
- `EnsureDeviceForUITestAttempt` keeps its behavior.

The root cause of the emulator wedge is unknown. This change only lets
the retries recover from it.

### Validation

Local, API30 `google_apis_playstore` arm64 AVD, with CI retries enabled
(`AGENT_NAME` set) and an isolated ADB server and home directory. To
simulate the wedge, a watcher sends SIGSTOP to the emulator process 2 s
after launch. This reproduces the CI shape: adb shows `device offline`
and the boot wait fails at 600 s.
- **Baseline (net11 `android.cake`):** attempt 1 failed with "The
emulator did not finish booting in time". Attempt 2 waited again on the
same stopped PID, with no relaunch. **Red.**
- **This PR:** attempt 1 failed the same way. Then "The Android emulator
is not booted; restarting it before retrying UI test setup." The
emulator was killed and relaunched, booted in 15 s, and the APK
installed. Exit 0. **Green.**
- **Control (no wedge):** normal boot, no restart. Exit 0.

The `unauthorized` mode (log 3682) was not reproduced locally. A
relaunch is expected to help it as well, but that is not validated.

### Issues Fixed

Fixes net11 Android UI test jobs lost to an emulator that wedges during
boot (no tracking issue).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
SuthiYuvaraj pushed a commit to SuthiYuvaraj/maui that referenced this pull request Nov 25, 2026
…up (dotnet#40381)

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Description of Change

Android UI test jobs can lose all tests when the emulator wedges before
it finishes booting. `uitest-prepare` already retries five times
(`RunUITestSetupWithRetry`), but each retry reuses the same emulator.
Every attempt waits another 600 s on that wedged instance. The restart
added in dotnet#40273 runs only before test attempts, not before setup
retries.

Examples:
- net11 UI build 1687571, Android API30 Shadow (log 6089): the emulator
shows `offline` and then "no devices" for about an hour. All 5 setup
attempts wait on the same process, which stays alive until final
cleanup. No tests run.
- Candidate UI build 1686311 CV2 (log 3682) has the same five attempts
with no relaunch. There the device was stuck `unauthorized`.

Change (`eng/devices/android.cake`):
- I extracted the existing dotnet#40273 restart logic into
`RestartEmulatorIfNotBooted(nextStep)`.
- `uitest-prepare` calls it before setup attempts 2–5.
- It restarts only an emulator this script launched, and only when
`sys.boot_completed` is not set. Booted devices and externally provided
devices are untouched.
- `EnsureDeviceForUITestAttempt` keeps its behavior.

The root cause of the emulator wedge is unknown. This change only lets
the retries recover from it.

### Validation

Local, API30 `google_apis_playstore` arm64 AVD, with CI retries enabled
(`AGENT_NAME` set) and an isolated ADB server and home directory. To
simulate the wedge, a watcher sends SIGSTOP to the emulator process 2 s
after launch. This reproduces the CI shape: adb shows `device offline`
and the boot wait fails at 600 s.
- **Baseline (net11 `android.cake`):** attempt 1 failed with "The
emulator did not finish booting in time". Attempt 2 waited again on the
same stopped PID, with no relaunch. **Red.**
- **This PR:** attempt 1 failed the same way. Then "The Android emulator
is not booted; restarting it before retrying UI test setup." The
emulator was killed and relaunched, booted in 15 s, and the APK
installed. Exit 0. **Green.**
- **Control (no wedge):** normal boot, no restart. Exit 0.

The `unauthorized` mode (log 3682) was not reproduced locally. A
relaunch is expected to help it as well, but that is not validated.

### Issues Fixed

Fixes net11 Android UI test jobs lost to an emulator that wedges during
boot (no tracking issue).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

This branch was previously deployed

1 inactive deployment
copilot-pat-pool — d9879568 Deployed Nov 18, 2026 by kubaflo via conclusion #3082
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-infrastructure CI, Maestro / Coherency, upstream dependencies/versions platform/android

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant