Skip to content

[net11] Fail fast on Appium session creation after the device is lost - #40300

Merged
kubaflo merged 1 commit into
net11from
kubaflo-net11-appium-session-fast-fail
Nov 16, 2026
Merged

kubaflo merged 1 commit into
net11from
kubaflo-net11-appium-session-fast-fail

Conversation

@kubaflo

@kubaflo kubaflo commented Nov 16, 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

Follow-up to #40273, which recovers a lost Android emulator between UI test attempts. That recovery cannot help when the emulator dies during an attempt: every remaining fixture then calls AppiumServerContext.CreateUIClientContext, which tries to create a session 11 times (retries++ < 10, about 20s each because UiAutomator2 waits 20s for a device). Each fixture fails only after 3m40s.

Evidence from maui-pr-uitests run 1682664 (PR #40273), job "Controls (API 30) Label":

  • The emulator vanished about 3 minutes into attempt 1.
  • All 126 Label tests then failed in OneTimeSetUp with Could not find a connected Android device in 20000ms, each after 3m40s.
  • The test step took 195 minutes; normally it takes 16–23 minutes.
  • Only after that did the between-attempt recovery restart the emulator.

net11 run 1683205 showed the same job still running after 115+ minutes. The candidate (#40116) and main have identical copies of this file, so no existing fix covers it.

Change: after one fixture exhausts all retries, later fixtures in the same test process get a single attempt. A successful session restores full retries.

  • The first failure still gets the full retry budget, so transient Appium or device hiccups keep the current tolerance.
  • CI retries start a new dotnet test process, so each attempt starts with full retries, and the emulator recovery from [net11] Recover lost Android emulator before UI test retry #40273 still runs before it.
  • No test is skipped, and no tolerance or baseline changes.

Validation

Ran a local console harness that references UITest.Core and UITest.Appium, starts the real Appium server (uiautomator2 3.9.1), and calls CreateUIClientContext with an Android config and no connected device. This simulates fixtures after the emulator is lost.

Build Fixture 1 Fixture 2 Fixture 3
net11 (baseline, d0547a0) 221s 221s —
This PR 221s 20s 20s

For a 126-fixture category, the time to fail after losing the emulator drops from about 7.7h (capped by the job timeout) to about 45 min. The same error message is still reported for every test.

Issues Fixed

Fixes CI hangs in maui-pr-uitests Android jobs after mid-attempt emulator loss (no tracking issue).

When the Android emulator dies mid attempt, every remaining fixture spent
11 x 20s retrying session creation (3m40s each), turning a 126-test
category into a ~3h hang before the between-attempt emulator recovery
could run. After one fixture exhausts its retries, later fixtures get a
single attempt; a successful session restores full retries.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@kubaflo
kubaflo temporarily deployed to copilot-pat-pool November 16, 2026 15:16 — 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 -- 40300

Or

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

@azure-pipelines

This comment has been minimized.

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Nov 16, 2026
@kubaflo

kubaflo commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

/rebase

@kubaflo

This comment has been minimized.

@azure-pipelines

This comment has been minimized.

@MauiBot

MauiBot commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

PR Test Gate

@kubaflo — existing-test verification; Setup did not capture a tested commit.

Result INCONCLUSIVE Platform Android


🧪 Gate analysis — click to expand

⚠ Inconclusive. Setup, build, or execution did not produce a conclusive result. This does not prove the fix is incorrect.

No interpretable test-group summary was produced. No additional test execution is inferred.

Setup did not capture a verified PR head; no commit is claimed as tested.

No immutable without-fix baseline was prepared.

@MauiBot MauiBot removed the s/agent-review-in-progress AI review is currently running for this PR label Nov 16, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expert Review — 1 finding

Reviewed commit a5c5673.

See inline comments for details.

// Once a fixture exhausts every retry the device is usually gone (e.g. a crashed emulator).
// Give later fixtures a single attempt so the rest of the run fails in minutes instead of hours,
// leaving time for the CI retry to recover the device; a successful session restores full retries.
int maxRetries = _sessionRetriesExhausted ? 0 : MaxSessionRetries;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[moderate] Regression Prevention and Test Coverage - No committed regression test exercises this cross-call retry state; the local console harness described in the PR is not included. Add deterministic infrastructure coverage using the same server context: exhausting 11 attempts must reduce subsequent calls to one attempt, a successful session must restore the full budget, and 10 transient failures followed by success must leave the next call's budget unchanged. Existing UI fixtures acquire their session during setup and do not assert these attempt counts, so they cannot detect the original repeated-delay behavior or a regression in the recovery/reset boundary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not adding a committed test here. UITest.Appium has no unit-test project, and CreateUIClientContext builds real AppiumAndroidApp drivers directly. A deterministic attempt-count test would need a new test project plus a driver-factory seam in shared UI-test infrastructure. That is a larger refactor than this targeted CI-reliability fix.

Validation for this change:

  • A local harness ran against a bogus Android serial. Before the fix, every call made 11 attempts; after it, the first call made 11 and later calls made 1.
  • The raw CI evidence from runs 1682664 and 1683205 is linked in the description and comments.

The reset paths are a single assignment: a successful session clears the flag, and each new dotnet test process starts cleared. If maintainers want a seam and test project for UITest.Appium, I'd suggest that as a separate change.

Auto-replied by the GitHub Copilot app

@kubaflo

kubaflo commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

More evidence from the net11 post-merge run 1683205, job "Controls (API 30) Label" (raw log 6131):

  • Attempt 1 began at 13:16Z. The first test failed after 3m25s; each of the other 125 failed in OneTimeSetUp after 3m40s with Could not find a connected Android device in 20000ms. The attempt reported Failed: 126, Total time: 2.9361 Hours.
  • Attempt 2 logged The Android emulator is no longer available; restarting it... (recovery from [net11] Recover lost Android emulator before UI test retry #40273) and then passed (Passed: 124, Skipped: 2, 14.4 min).
  • The test step took 195 minutes, only 45 minutes short of the 240-minute job timeout. With this PR, attempt 1 would fail after one full retry cycle plus about 20s per remaining fixture, roughly 45 minutes instead of 2.9 hours.

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Nov 16, 2026
@MauiBot

MauiBot commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

PR Test Gate

@kubaflo — existing-test verification; Setup did not capture a tested commit.

Result INCONCLUSIVE Platform Android


🧪 Gate analysis — click to expand

⚠ Inconclusive. Setup, build, or execution did not produce a conclusive result. This does not prove the fix is incorrect.

No interpretable test-group summary was produced. No additional test execution is inferred.

Setup did not capture a verified PR head; no commit is claimed as tested.

No immutable without-fix baseline was prepared.

@MauiBot MauiBot removed the s/agent-review-in-progress AI review is currently running for this PR label Nov 16, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expert Review — 1 finding

Reviewed commit a5c5673.

Previously reported findings were not duplicated.

@kubaflo
kubaflo merged commit 5d735a4 into net11 Nov 16, 2026
147 of 190 checks passed
@kubaflo
kubaflo deleted the kubaflo-net11-appium-session-fast-fail branch November 16, 2026 19:08
@kubaflo kubaflo mentioned this pull request Nov 16, 2026
1 task
github-actions Bot pushed a commit to MykhailoDav/maui that referenced this pull request Nov 16, 2026
…dotnet#40300)

<!-- 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

Follow-up to dotnet#40273, which recovers a lost Android emulator **between**
UI test attempts. That recovery cannot help when the emulator dies
**during** an attempt: every remaining fixture then calls
`AppiumServerContext.CreateUIClientContext`, which tries to create a
session 11 times (`retries++ < 10`, about 20s each because UiAutomator2
waits 20s for a device). Each fixture fails only after **3m40s**.

Evidence from `maui-pr-uitests` run
[1682664](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1682664)
(PR dotnet#40273), job "Controls (API 30) Label":
- The emulator vanished about 3 minutes into attempt 1.
- All 126 Label tests then failed in `OneTimeSetUp` with `Could not find
a connected Android device in 20000ms`, each after 3m40s.
- The test step took **195 minutes**; normally it takes 16–23 minutes.
- Only after that did the between-attempt recovery restart the emulator.

`net11` run
[1683205](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1683205)
showed the same job still running after 115+ minutes. The candidate
(dotnet#40116) and `main` have identical copies of this file, so no existing
fix covers it.

**Change:** after one fixture exhausts all retries, later fixtures in
the same test process get a single attempt. A successful session
restores full retries.
- The first failure still gets the full retry budget, so transient
Appium or device hiccups keep the current tolerance.
- CI retries start a new `dotnet test` process, so each attempt starts
with full retries, and the emulator recovery from dotnet#40273 still runs
before it.
- No test is skipped, and no tolerance or baseline changes.

### Validation

Ran a local console harness that references `UITest.Core` and
`UITest.Appium`, starts the real Appium server (uiautomator2 3.9.1), and
calls `CreateUIClientContext` with an Android config and no connected
device. This simulates fixtures after the emulator is lost.

| Build | Fixture 1 | Fixture 2 | Fixture 3 |
| --- | --- | --- | --- |
| `net11` (baseline, d0547a0) | 221s | 221s | — |
| This PR | 221s | 20s | 20s |

For a 126-fixture category, the time to fail after losing the emulator
drops from about 7.7h (capped by the job timeout) to about 45 min. The
same error message is still reported for every test.

### Issues Fixed

Fixes CI hangs in `maui-pr-uitests` Android jobs after mid-attempt
emulator loss (no tracking issue).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Vignesh-SF3580 pushed a commit to Vignesh-SF3580/maui that referenced this pull request Nov 17, 2026
…dotnet#40300)

<!-- 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

Follow-up to dotnet#40273, which recovers a lost Android emulator **between**
UI test attempts. That recovery cannot help when the emulator dies
**during** an attempt: every remaining fixture then calls
`AppiumServerContext.CreateUIClientContext`, which tries to create a
session 11 times (`retries++ < 10`, about 20s each because UiAutomator2
waits 20s for a device). Each fixture fails only after **3m40s**.

Evidence from `maui-pr-uitests` run
[1682664](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1682664)
(PR dotnet#40273), job "Controls (API 30) Label":
- The emulator vanished about 3 minutes into attempt 1.
- All 126 Label tests then failed in `OneTimeSetUp` with `Could not find
a connected Android device in 20000ms`, each after 3m40s.
- The test step took **195 minutes**; normally it takes 16–23 minutes.
- Only after that did the between-attempt recovery restart the emulator.

`net11` run
[1683205](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1683205)
showed the same job still running after 115+ minutes. The candidate
(dotnet#40116) and `main` have identical copies of this file, so no existing
fix covers it.

**Change:** after one fixture exhausts all retries, later fixtures in
the same test process get a single attempt. A successful session
restores full retries.
- The first failure still gets the full retry budget, so transient
Appium or device hiccups keep the current tolerance.
- CI retries start a new `dotnet test` process, so each attempt starts
with full retries, and the emulator recovery from dotnet#40273 still runs
before it.
- No test is skipped, and no tolerance or baseline changes.

### Validation

Ran a local console harness that references `UITest.Core` and
`UITest.Appium`, starts the real Appium server (uiautomator2 3.9.1), and
calls `CreateUIClientContext` with an Android config and no connected
device. This simulates fixtures after the emulator is lost.

| Build | Fixture 1 | Fixture 2 | Fixture 3 |
| --- | --- | --- | --- |
| `net11` (baseline, d0547a0) | 221s | 221s | — |
| This PR | 221s | 20s | 20s |

For a 126-fixture category, the time to fail after losing the emulator
drops from about 7.7h (capped by the job timeout) to about 45 min. The
same error message is still reported for every test.

### Issues Fixed

Fixes CI hangs in `maui-pr-uitests` Android jobs after mid-attempt
emulator loss (no tracking issue).

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

<!-- 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

Follow-up to dotnet#40273, which recovers a lost Android emulator **between**
UI test attempts. That recovery cannot help when the emulator dies
**during** an attempt: every remaining fixture then calls
`AppiumServerContext.CreateUIClientContext`, which tries to create a
session 11 times (`retries++ < 10`, about 20s each because UiAutomator2
waits 20s for a device). Each fixture fails only after **3m40s**.

Evidence from `maui-pr-uitests` run
[1682664](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1682664)
(PR dotnet#40273), job "Controls (API 30) Label":
- The emulator vanished about 3 minutes into attempt 1.
- All 126 Label tests then failed in `OneTimeSetUp` with `Could not find
a connected Android device in 20000ms`, each after 3m40s.
- The test step took **195 minutes**; normally it takes 16–23 minutes.
- Only after that did the between-attempt recovery restart the emulator.

`net11` run
[1683205](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1683205)
showed the same job still running after 115+ minutes. The candidate
(dotnet#40116) and `main` have identical copies of this file, so no existing
fix covers it.

**Change:** after one fixture exhausts all retries, later fixtures in
the same test process get a single attempt. A successful session
restores full retries.
- The first failure still gets the full retry budget, so transient
Appium or device hiccups keep the current tolerance.
- CI retries start a new `dotnet test` process, so each attempt starts
with full retries, and the emulator recovery from dotnet#40273 still runs
before it.
- No test is skipped, and no tolerance or baseline changes.

### Validation

Ran a local console harness that references `UITest.Core` and
`UITest.Appium`, starts the real Appium server (uiautomator2 3.9.1), and
calls `CreateUIClientContext` with an Android config and no connected
device. This simulates fixtures after the emulator is lost.

| Build | Fixture 1 | Fixture 2 | Fixture 3 |
| --- | --- | --- | --- |
| `net11` (baseline, d0547a0) | 221s | 221s | — |
| This PR | 221s | 20s | 20s |

For a 126-fixture category, the time to fail after losing the emulator
drops from about 7.7h (capped by the job timeout) to about 45 min. The
same error message is still reported for every test.

### Issues Fixed

Fixes CI hangs in `maui-pr-uitests` Android jobs after mid-attempt
emulator loss (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 — a5c56736 Deployed Nov 16, 2026 by kubaflo via conclusion #3009
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.

2 participants