Skip to content

Write the WinUI E2E ready marker atomically so the test never reads an empty file - #21932

Merged
Ankit Jain (radical) merged 1 commit into
mainfrom
aspireagent/winui-ready-marker-atomic-write
Nov 10, 2026
Merged

Ankit Jain (radical) merged 1 commit into
mainfrom
aspireagent/winui-ready-marker-atomic-write

Conversation

@davidfowl

@davidfowl David Fowler (davidfowl) commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

What failed: [vscode] Aspire WinUI debug E2E > debugs an unpackaged WinUI project through its generated apphost executable failed on attempt 1 in 42448442647 (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):

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): 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?
    • 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
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
    • No

🤖 Posted by AspireAgent (AI Agent)

The WinUI fixture app wrote its ready marker with File.WriteAllText, which
creates the file before writing its content. The E2E test returns the first
successful read of the marker, so it could observe an empty file and fail
/^ready:\d+$/. Write to a temporary file and rename it into place.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@davidfowl David Fowler (davidfowl) added the agent:working An AI agent is actively working on this issue or PR label Nov 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026

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

Or

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

@aspire-repo-bot
aspire-repo-bot Bot requested a balanced review from Copilot November 8, 2026 10:34
@github-actions github-actions Bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Tests selector

0 / 101 PR test projects · 2 PR jobs, from 2 changed files.

Selected PR test projects (0 / 101)

none — no PR-gated .NET test projects run for this change.

Selected PR jobs (2)

extension-e2e, extension-unit


How these were chosen — grouped by what changed

Job reasons

Job Triggered by
extension-e2e extension/scripts/run-e2e.js, extension/src/test/e2eLaunchProfile.test.ts
extension-unit extension/scripts/run-e2e.js, extension/src/test/e2eLaunchProfile.test.ts

Selection computed for commit 61b89f8.

Copilot AI 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.

🟢 Approval recommended

No active review issues were identified for the change to publish the readiness marker through a temporary file and rename.

No open issues 🎉

What changed in this PR

Fixes an empty-file race in the VS Code WinUI E2E fixture’s readiness marker without changing polling, assertions, or timeouts.

Changes:

  • Writes the complete ready:<pid> marker to a temporary file, then renames it into place.
  • Updates the existing unit test to require the write-then-rename pattern and reject direct marker writes.
File Description
extension/​src/​test/​e2eLaunchProfile.test.ts Checks that the fixture uses atomic marker publication.
extension/​scripts/​run-e2e.js Publishes the WinUI readiness marker through a temporary file and rename.

Review effort: Balanced

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@radical

Ankit Jain (radical) commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

[automated] Validation report for PR #21932

Disposition: supported for the empty-marker failure; no additional CI run is warranted by the evidence gathered.

This is an inspection of existing execution evidence, not a new test run or
statistical demonstration that all WinUI flakes are eliminated.

Revision and scope

  • PR: #21932, open when inspected.
  • PR head and local checkout: 61b89f8f4f55b61aa2857dacf84a77dc22ae1ae1.
  • CI checkout for both Windows jobs: 6a1581bdfc34f6e62d7859ff922b0f5250bda813
    (refs/pull/21932/merge), not the PR-head commit. Its parents are
    2fefac5abe97fbfa878abac3b9f3b5dbbd211cd7 and the PR head above.
  • Source-tree equivalence: GitHub's commit API reports the same tree,
    5bf1357346c4cdcbbe413c79338923ef8e371c4c, for the
    CI merge commit
    and PR head.
    The checked-out source tree therefore matches the head, but the commit identities differ.
  • Branch: aspireagent/winui-ready-marker-atomic-write.
  • Diff: two files, eight additions and two deletions.
  • Changed behavior: the generated WinUI fixture writes the complete marker to
    a sibling .tmp file before moving it to the polled path.
  • The reader, readiness assertion, polling interval and timeouts are unchanged.

Original failure: verified from primary evidence

The original Windows WinUI job, attempt 1
failed the named test, rather than setup or language-server initialization:

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

''

That job checked out merge commit
bc0b899cce063ee4ecee9e7c7961f776dc933e03, not the original run's
head commit 2a001a2d07bc5fd6bac3fd27b6e617b7ec6f19fc. This is an observed
failure from a separate revision, not a controlled before/after experiment.

The original diagnostics artifact
contains both:

  • .test-results/e2e/winui-debug/mocha.json: one failure, ERR_ASSERTION,
    actual: "", operator: "match", currentRetry: 0.
  • The generated AspireE2E.WinUI/App.xaml.cs with
    File.WriteAllText(readyFile, $"ready:{Environment.ProcessId}");.

The reader in extension/src/test-e2e/winUiDebug.e2e.test.ts returns its first
successful readFileSync(...).trim(), retrying only ENOENT. A read during
creation-before-content publication therefore returns the exact empty string
shown in the incident. It does not wait for a later complete read.

CI merge-checkout execution: verified, not inferred from green checks

The two Windows jobs below checked out merge commit
6a1581bdfc34f6e62d7859ff922b0f5250bda813 on workflow attempt 1.
Its source tree is identical to the PR head as established above; these are
merge-checkout results, not direct-head-checkout results.
The overall workflow subsequently reached attempt 3; that is not the basis
for these case-specific results.

Case Existing result Evidence
Real Windows WinUI debug scenario One pass, zero pending, zero failures, currentRetry: 0 WinUI job and diagnostics artifact
Updated fixture regression assertion Named test passed Windows unit job
Produced fixture source Sibling temporary-file write followed by File.Move(..., overwrite: true) Generated AspireE2E.WinUI/App.xaml.cs inside the CI merge-checkout diagnostics artifact

The WinUI log explicitly shows WinUI: enabled, the focused compiled
winUiDebug.e2e.test.js spec and:

Aspire extension E2E shard 'winui-debug' passed: 1/1 tests in 80839ms.

Its retained Mocha result independently confirms execution without a test retry.
The generated C# fixture contains the new writer, rather than an older source
or CLI-only artifact.

The passing E2E source checks the full /^ready:\d+$/ marker, the WinUI resource
reaching Running, selection of the generated apphost executable, and clean
debug/AppHost shutdown. The marker itself is removed by teardown; its absence
from the retained artifact is not evidence of a missing publication.

Execution environment recorded in the job: Windows x64, VS Code 1.130.0,
ExTester 8.23.0, C# extension 2.140.9, and Aspire CLI/AppHost identity
17.1.0-pr.21932.g61b89f8f.

Existing CI commands and outcomes, not commands newly executed by this assignment:

Command Result
corepack yarn compile and corepack yarn compile-e2e Succeeded in the Windows WinUI merge-checkout job
node scripts/run-e2e.js, with ASPIRE_EXTENSION_E2E_ENABLE_WINUI=true, shard winui-debug, focused spec One test passed
corepack yarn test Unit runner exited zero: 4,153 passing, nine pending; changed WinUI test passed

The unit command also ran compilation and lint. Webpack reported four warnings;
this report does not claim a warning-free build.

Routing and failure prevention

The existing extension/** rules in eng/github-ci/test-trigger-map.yml select
both extension-unit and extension-e2e. The PR's selector output reports those
two jobs for both changed paths, and the inspected jobs actually executed.
No new test project, route, timeout, quarantine or workflow change is introduced.

The updated unit test would fail if the writer reverted to a direct
File.WriteAllText(readyFile, ...): it requires the temporary-file write and
move statements and rejects the direct write. This is source-shape coverage,
not a concurrency test. The E2E provides actual Windows execution, but one
passing execution alone cannot measure the remaining flake rate.

For the platform implementation, the .NET 10
Windows filesystem source
and MoveFile interop source
confirm that overwrite delegates to MoveFileExW with
MOVEFILE_REPLACE_EXISTING and MOVEFILE_COPY_ALLOWED. The fixture uses sibling
paths in one workspace directory, not a cross-volume publication. This
inspection does not establish a universal atomicity guarantee for arbitrary
filesystems or multiple concurrent publishers.

Limits and CI admission

  • The PR body's Linux stress-harness counts and historical failure rates were
    not independently reproduced or audited. They are not used for this disposition.
  • No new local build, test scenario, dependency installation, CI dispatch or
    rerun was performed. Existing Windows CI supplied the case-specific execution.
  • No additional execution case plan or case-specific CI budget was supplied.
    Consequently no CI work was admitted or dispatched.
  • If a controlled Windows before/after concurrency experiment is required,
    it needs a frozen revision, reader/writer semantics, assertions, repetition
    count, stop conditions and an explicitly admitted budget before execution.
  • This fix addresses the observed empty-marker assertion, not language-server,
    startup-timeout or general Windows-runner-slowness failures.

Evidence sources

Logs were retrieved through gh api .../actions/jobs/<job-id>/logs; diagnostic
archives through gh api .../actions/artifacts/<artifact-id>/zip. The archives
were inspected without extracting or executing their contents.

Evidence copies are retained in session storage. No repository file was changed,
no commit was created, and no PR description or review was modified.

-- AnkitAgent

@radical Ankit Jain (radical) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[automated] Looks good to me. Writing to a sibling temporary file and moving it into place after the write completes closes the empty-read window in this single-writer test fixture.

One precision on “atomic”: I’d describe this as preventing readers from seeing a partially written marker, rather than as a universal atomicity guarantee. On Windows, .NET’s File.Move uses MoveFileExW (.NET implementation, Windows API documentation). The same-directory move is appropriate here, but this doesn’t imply crash durability or multi-writer coordination.

No blocking issues found; one non-blocking clarification on atomicity scope.

@radical
Ankit Jain (radical) merged commit 8f00c66 into main Nov 10, 2026
280 of 288 checks passed
@microsoft-github-policy-service microsoft-github-policy-service Bot added this to the 17.1 milestone Nov 10, 2026
@aspire-repo-bot

Copy link
Copy Markdown
Contributor

✅ No documentation update needed.

Proven false positive; skipped (docs_optional → test_only / build_or_ci_only).

  • Triggered signal: pr_body_has_cli_flag_mention (evidence: PR body text mentioning dotnet --list-runtimes, which is not an Aspire flag).
  • Changed files: extension/scripts/run-e2e.js and extension/src/test/e2eLaunchProfile.test.ts are E2E test harness only; the change writes a test ready-marker atomically. There is no user-facing change.

Mitch Denny (mitchdenny) pushed a commit that referenced this pull request Nov 10, 2026
…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)
Mitch Denny (mitchdenny) pushed a commit that referenced this pull request Nov 10, 2026
…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)
David Fowler (davidfowl) added a commit that referenced this pull request Nov 10, 2026
#21938)

## Description

**What failed:** `[vscode] Aspire Blazor browser debugger E2E > hits a
managed breakpoint for hosted-global` in **VS Code extension E2E
(Windows, browser-debugger)**, on main in run
[42413925421](https://github.com/microsoft/aspire/actions/runs/42413925421)
([job](https://github.com/microsoft/aspire/actions/runs/42413925421/job/128531739772))
and on a PR branch in run
[42312596518](https://github.com/microsoft/aspire/actions/runs/42312596518)
([job](https://github.com/microsoft/aspire/actions/runs/42312596518/job/128225566096)).
The test reported only the masked bridge error `Failed to apply E2E
control revision …: E2E control command failed.`

**Why:** `hosted-global` is the only Blazor scenario that uses
`closeMode: 'natural'`. The proof continues the breakpoint, asks
js-debug for its CDP proxy and sends `Page.close` over that socket. The
js-debug traces in both failing runs' diagnostics artifacts
(`blazor-debugadapter-*.json`, `proxyActivity`) show the page target
detaching before the browser answered. js-debug v1.117.0's
`CDPSession._onClose`
([connection.ts#L385-L388](https://github.com/microsoft/vscode-js-debug/blob/v1.117.0/src/cdp/connection.ts#L385-L388))
rejects the pending call with `setCause(0, 'Connection is closed')`, and
the proxy (`sendOrDie`) relays it to the client as
`{"id":1,"error":{"code":0,"message":"Connection is closed"}}`, keeping
the proxy socket open. Passing runs get `{"id":1,"result":{}}`.
`closeBrowserPageThroughCdp` already accepted a socket *close* after
`Page.close` as "target gone", but treated this equivalent error reply
as `Browser CDP Page.close failed`, which fails the proof even though
the page, Mono and root sessions then terminate normally (they do in
both traces).

**Fix:** `closeBrowserPageThroughCdp` now treats the js-debug
target-closed reply (`code === 0 && message === 'Connection is closed'`)
the same as the socket-close case. This doesn't weaken the proof: the
caller still requires every proof session (root, browser, managed) to
terminate and `debug-in-browser` to return to `Enabled`. Any other
`Page.close` error (e.g. `-32601 Method not found`) still fails.

**Regression tests** (`extension/src/test/e2eStateFileBridge.test.ts`,
run against the real `executeE2eControlCommand` product path):
- `accepts target disconnection (target-closed reply) during Page.close
only after all proof sessions terminate`: the CI failure, which fails
without the fix with the exact CI error `Browser CDP Page.close failed:
{"code":0,"message":"Connection is closed"}`.
- `rejects a target-closed Page.close reply while a proof session
remains active`: shows the reply is not a bypass, because the proof
still fails if the managed session stays alive.
- The existing socket-close case is kept, parametrized alongside the new
one.

Dedupe: no open issue or PR covers `hosted-global`.
#21912 covers a different browser-debugger failure (the
`maps managed Edge debugging` before-all hook CLI `--version` probe),
and none of the AspireAgent PRs #21911–#21932 touch this test. Tracker:
#21600.

## Confidence

Paired local runs of `e2eStateFileBridge.test.js` under VS Code 1.131.0
(`vscode-test`, xvfb), same machine and commit, toggling only the
product change:

| | runs green | per-run result |
|---|---|---|
| before (fix reverted, new tests kept) | **0/10** | 61 passing, 2
failing (the two new tests, with the CI error) |
| after | **10/10** | 63 passing, 0 failing |

`yarn lint` and `yarn compile-tests` pass. This is a test-harness change
only (`extension/src/testing`), so there's no product behavior change
and no E2E behavior evidence beyond the CI `browser-debugger` shards on
this PR.

## Failure stats (14d, attempt 1)

Window 2026-10-25 12:00 → 2026-11-08 12:00 UTC, `ci.yml`, attempt-1 jobs
only. The denominator is decided attempt-1 runs (same definition as
#21600). Hits are verified from each failed `VS Code extension E2E
(Windows, browser-debugger)` job's mocha failure line (48 failed jobs
scanned over 30d).

- **This signature** (`hits a managed breakpoint for hosted-global` →
`Page.close` target-closed reply): **3/1157** decided runs, **2 main / 1
PR** (main 2/160, PR 1/997).
- **Any `hosted-global` failure:** 4/1157. The extra one (run
40728167754) is a different cause, `Timed out after 300000ms waiting for
browser navigation to 'counter'`, which this PR does **not** claim to
fix.
- **30d main:** **2** verified hits (both are in the 14d window). Six
older or other main browser-debugger failures had expired or unavailable
logs and could not be classified.
- The two newest failures show only the masked `E2E control command
failed.`; the js-debug traces in their diagnostics artifacts show the
`{"code":0,"message":"Connection is closed"}` proxy reply. The 10-28
main failure predates the masking and prints the exact error.

| Run | Date (UTC) | Branch | Job | Error |
|---|---|---|---|---|
|
[42413925421](https://github.com/microsoft/aspire/actions/runs/42413925421)
| 11-07 21:02 | main |
[128531739772](https://github.com/microsoft/aspire/actions/runs/42413925421/job/128531739772)
| masked; trace shows target-closed reply |
|
[42312596518](https://github.com/microsoft/aspire/actions/runs/42312596518)
| 11-06 23:32 | PR (eerhardt-dashboard-authorize-anonymous-pages) |
[128225566096](https://github.com/microsoft/aspire/actions/runs/42312596518/job/128225566096)
| masked; trace shows target-closed reply |
|
[40606196498](https://github.com/microsoft/aspire/actions/runs/40606196498)
| 10-28 00:02 | main |
[122561450397](https://github.com/microsoft/aspire/actions/runs/40606196498/job/122561450397)
| `Browser CDP Page.close failed: {"code":0,"message":"Connection is
closed"}` |
|
[40728167754](https://github.com/microsoft/aspire/actions/runs/40728167754)
| 10-28 16:39 | PR (native-bundle-continuation) |
[122971965889](https://github.com/microsoft/aspire/actions/runs/40728167754/job/122971965889)
| different cause: navigation timeout (not addressed) |

## Verdict

**STRONG**: the failure was reproduced deterministically through the
product code path, and the before-fix run fails with the exact CI error
string (0/10 → 10/10). js-debug traces from both recent failures and the
unmasked 10-28 main error point to the same cause. The frequency is low
(3/1157), so CI alone will take time to confirm the absence of hits.

This PR's own CI (head `bbb5a79f`) was green on both `browser-debugger`
shards on attempt 1. The attempt-1 rerun was only for the unrelated
`tree-actions` flake (#21796, fix in #21914).

**How we stop this recurring:** CDP proxy transport outcomes after
`Page.close` (socket close *or* js-debug's target-closed reply) are now
classified in one place, `isCdpProxyTargetClosedError`, with unit tests
pinning both forms. The proof's real gate stays session termination plus
command reset, so future js-debug transport variations can't silently
mask a real leak.

## 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-vscode-extension needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants