Skip to content

[release/17.0] Write the WinUI E2E ready marker atomically so the test never reads an empty file - #22049

Closed
Mitch Denny (mitchdenny) wants to merge 1 commit into
mitchdenny-backport-17-0-50-pr21910from
mitchdenny-backport-17-0-51-pr21932
Closed

Mitch Denny (mitchdenny) wants to merge 1 commit into
mitchdenny-backport-17-0-50-pr21910from
mitchdenny-backport-17-0-51-pr21932

Conversation

@mitchdenny

Copy link
Copy Markdown
Member

Description

Backport of #21932 to release/17.0 (cherry-picked from 8f00c66 with no modifications).

Layer 51 of 55 in the release/17.0 backport stack; stacked on #22048.

Backport recommendation: No — Extension test flake.

Validation: Stable patch IDs match the original commit. Builds/tests not run for this unchanged cherry-pick.

Backport of #21932

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No

…n empty file (#21932)

**What failed:** `[vscode] Aspire WinUI debug E2E > debugs an unpackaged
WinUI project through its generated apphost executable` failed on
attempt 1 in
[42448442647](https://github.com/microsoft/aspire/actions/runs/42448442647/job/128635064936)
(tracker #21600, unowned rank 1):

```
AssertionError [ERR_ASSERTION]: The input did not match the regular expression /^ready:\d+$/. Input:
''
```

**Why:** The generated WinUI fixture app wrote its ready marker with
`File.WriteAllText(readyFile, …)`. That call creates the file before it
writes the content. `waitForReadyMarker` polls for the file and returns
its first successful read, so a poll that landed in that gap returned
`''` and failed the assertion. The app had started correctly; the test
read the file before the content was written.

**How fixed:** The fixture app (`extension/scripts/run-e2e.js`) now
writes `ready:<pid>` to `<marker>.tmp` and then `File.Move(…, overwrite:
true)` renames it into place. Because the rename is atomic, the marker
path is either missing or holds the full content, so the test's first
read is always complete. The assertion, timeouts and polling are
unchanged. The existing `e2eLaunchProfile` unit test now checks for the
atomic write and rejects a direct `File.WriteAllText(readyFile, …)`.

## Failure stats (14d, attempt 1)

| Scope | Attempt-1 test failures / runs where the job executed | Rate |
Passed on rerun |
|---|---|---|---|
| PR | 4 / 457 | 0.9% | 4 / 4 |
| main | 0 / 99 | 0% | n/a |

Main over 30 days: 0 test-level failures in 216 runs (0 / 99 in the last
14d plus 0 / 117 in the 16 days before). This job had 9 other attempt-1
failures that never reached the test and are excluded: 8 were "hosted
runner lost communication" and 1 was an `aspire-extension` artifact
download failure.

Test-level failures (all four):
-
[42448442647](https://github.com/microsoft/aspire/actions/runs/42448442647/job/128635064936)
(PR #21921, unrelated Java debug change): `The input did not match the
regular expression /^ready:\d+$/. Input: ''` ← **fixed by this PR**
-
[42257446455](https://github.com/microsoft/aspire/actions/runs/42257446455/job/128037952447)
(PR branch `aspireagent/fix-e2e-notification-dismiss-hover-race`):
`Timed out after 120000ms waiting for the C# language server to resolve
generated InitializeComponent … Last definitions: []` (the
`tree-actions` shard also failed in the same attempt)
-
[41532732531](https://github.com/microsoft/aspire/actions/runs/41532732531/job/125585902027)
(PR #20950): `Timed out after 240000ms waiting for the WinUI OnLaunched
marker.` AppHost hosting startup took 1m42s, and 4 other Windows shards
failed in the same attempt.
-
[41501727353](https://github.com/microsoft/aspire/actions/runs/41501727353/job/125481870825)
(PR #21183): `The C# definition probe for InitializeComponent … Timed
out after 129ms waiting for E2E control revision`. `dotnet
--list-runtimes` took 53s, Roslyn never started, and 6 other shards
failed in the same attempt.

All four are genuine flakes, not caused by their PRs. The last three
come from whole-runner slowness on Windows, which is tracked in #21570
with telemetry in #21644. This PR does not address them because fixing
them would mean raising timeouts.

**Local regression evidence:** A harness ran the fixture's exact
before/after C# writer against a Node reader that uses
`waitForReadyMarker`'s semantics (first successful read is asserted
against `/^ready:\d+$/`), polling tightly, with 500 marker publications
per run:
- Before (`File.WriteAllText(readyFile, …)`): **10/10 runs** saw an
empty marker (475–496 torn first reads out of about 500 per run).
- After (write `.tmp`, then `File.Move` with `overwrite: true`): **0/10
runs** saw an empty marker (0 torn reads out of about 4,980
publications).

The harness ran on Linux. On Windows, `File.Move(overwrite: true)` maps
to `MoveFileEx(MOVEFILE_REPLACE_EXISTING)` within the same directory,
which is also atomic for readers.

**PR CI** ([run
42472017876](https://github.com/microsoft/aspire/actions/runs/42472017876)):
`VS Code extension E2E (Windows, winui-debug)` and the Windows extension
unit tests (including the updated `e2eLaunchProfile` test) passed on
attempt 1. Three unrelated jobs failed on attempt 1: a GitHub 'Unicorn'
outage while downloading Deno in `launch-profiles`, and the known
`tree-actions` flakes (`Expected e2e-worker to expose an endpoint URL`,
addressed by #21914; `Timed out … waiting for running AppHost` on
Linux). After reruns, all 70 checks pass.

**Verdict: MODERATE.** The fixed race is proven deterministically (10/10
→ 0/10) and matches the newest failure's exact signature. However, it
accounts for only 1 of the 4 attempt-1 test failures in 14d. The other 3
belong to the Windows runner-slowness family in #21570.

## Confidence

High that this removes the empty-marker failure mode: the gap is
inherent to `File.WriteAllText` and the reader returns on its first
read. Low that it changes the C# language server / OnLaunched timeout
failures, which this PR does not target.

**How we stop this recurring:** Fixture processes that publish readiness
files for E2E polling should write a temp file and rename it into place.
The unit test now enforces this for the WinUI marker.

## Checklist

- Is this feature complete?
  - [x] Yes. Ready to ship.
  - [ ] No. Follow-up changes expected.
- Are you including unit tests for the changes and scenario tests if
relevant?
  - [x] Yes
  - [ ] No
- Did you add public API?
  - [ ] Yes
  - [x] No
- Does the change make any security assumptions or guarantees?
  - [ ] Yes
  - [x] No

**🤖 Posted by AspireAgent (AI Agent)**

Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
(cherry picked from commit 8f00c66)
@github-actions

This comment has been minimized.

@mitchdenny

Copy link
Copy Markdown
Member Author

Approved for inclusion in release/17.0. Do not merge yet.

@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/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 22049

Or

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

@github-actions

This comment has been minimized.

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