Skip to content

CI: make /perf work on pre-gate PRs (self-contained C# overlay) + fix Rust column (#674) - #677

Merged
Alexandre Zollinger Chohfi (azchohfi) merged 13 commits into
mainfrom
azchohfi-fix-perf-self-contained-build
Jun 26, 2026
Merged

Alexandre Zollinger Chohfi (azchohfi) merged 13 commits into
mainfrom
azchohfi-fix-perf-self-contained-build

Conversation

@azchohfi

@azchohfi Alexandre Zollinger Chohfi (azchohfi) commented Jun 25, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The on-demand /perf gate (added by #662, issue #661) benchmarks a PR's src/Reactor/ against the trusted main baseline by building the StressPerf WinUI harnesses self-contained, so they launch on a windows-latest runner that has no machine-wide Windows App SDK runtime.

Two defects broke the first live run (run 28202538748, against #656):

  1. Self-contained build is a no-op on pre-gate PRs. The self-contained knob is a PropertyGroup that CI: on-demand perf comparison (/perf) vs main baseline #662 added to each harness .csproj. Any PR opened before CI: on-demand perf comparison (/perf) vs main baseline #662 merged (the entire in-flight fleet) has a tree that predates that block, so -p:PerfCiSelfContained=true does nothing → the harness builds framework-dependent → on the runner it can't find the WinAppSDK runtime → hangs in the bootstrapper (0-byte output) → the 100s watchdog kills it → no PR metrics → red check + an all-n/a comparison comment. This defeats the gate's core promise: works on every already-open PR with no rebase.

  2. Rust column fails with 0xC0000135 (Perf CI: Rust cross-framework column n/a — test_reactor_perf exits 0xC0000135 (DLL-not-found) at runtime #674). The workflow patches the windows-rs test_reactor_perf crate to as_self_contained(), which embeds a side-by-side manifest requiring the WinAppSDK runtime DLLs next to the exe at process start — but upstream stages those DLLs with all errors swallowed (let _ = …), so a single runner hiccup stages zero DLLs while the crate still "Finishes" → every run exits 0xC0000135 (DLL-not-found) → no metrics → n/a column.

Fix

(1) Compare-mode harness .csproj overlay — Build-Harness in Run-PerfBenchmark.ps1. When building a PR tree in compare mode ($BaselineRoot set and $TreeRoot -ne $BaselineRoot), back up the PR's harness .csproj, overlay the trusted baseline copy (which always carries the self-contained block) for the build, then restore the original. The harness .csproj is fixed test scaffolding — the build recipe for the StocksGrid workload — not the code under measurement: the PR's actual perf change in src/Reactor/ is still compiled via the harness's relative ProjectReference into the PR tree, and the PR's harness sources still come from the PR checkout. So the overlay is fair and makes the self-contained build present regardless of PR age, with no rebase. It is build-scoped and side-effect-free: the original is restored even if the build (or the overlay copy itself) throws, so a developer's worktree is never left modified and repeated runs are deterministic.

Scoping note: we deliberately do not pass -p:WindowsAppSDKSelfContained=true globally on the command line — it would flow into the referenced class libraries (Reactor.csproj, StressPerf.Shared), which reject self-contained packaging. The csproj scopes the flag to the executable; the overlay preserves that scoping.

(2) Rust runtime DLL staging (#674) — new Stage-RustRuntime in Run-PerfBenchmark.ps1, called from Invoke-RustLeg after the crate builds. It explicitly stages the WinAppSDK runtime DLLs next to test_reactor_perf.exe (reusing the build-script's own cached runtime nupkg when present, else downloading the pinned Microsoft.WindowsAppSDK.Runtime package over HTTPS from nuget.org), so the embedded side-by-side manifest resolves at process start. It verifies a required set of DLLs and completeness against the actual MSIX payload (not a single sentinel), so a partial prior stage can't read as "done." Unlike upstream's silent staging, a failure is logged; the Rust leg stays continue-on-error (non-blocking for the four C# metrics).

Review feedback addressed

  • Overlay left the tree modified → overlay is now build-scoped (backup + restore in finally).
  • README overstated provenance → reworded: in compare mode the PR supplies src/Reactor/ and the harness sources; only the .csproj build recipe is normalized from the baseline and restored after the build, so a PR that edits harness sources still has those changes measured.
  • Backup orphaned if the overlay copy throws → overlay moved inside the try/finally and the backup marker is set only after the backup file exists, so the finally always restores and removes it.
  • Invoke-WebRequest -UseBasicParsing → dropped (no-op/compat-only in pwsh 7).
  • Single-sentinel staging check → Stage-RustRuntime now verifies a required DLL set + completeness vs. the MSIX payload (a partial stage no longer faults the loader silently).
  • Rust staging undocumented → CI README now describes the staging + best-effort n/a fallback.

Review process

Ran the repo's pr-review skill (8 dimensions + a multi-model cross-check). Correctness, docs, and test-coverage findings are fixed above + below. Two security findings (no checksum/signature on the runtime download; archive extraction not path-validated) were downgraded by the multi-model cross-check to medium/low and accepted as defense-in-depth: the fetch is a pinned package over HTTPS from the canonical nuget.org the whole repo already restores from, on an ephemeral windows-latest runner, extracted via Windows tar/libarchive into fresh temp dirs, feeding only the non-blocking Rust column.

Validation

  • pwsh tests/stress_perf/ci/PerfLib.Tests.ps1 → 61/61.
  • pwsh tests/stress_perf/ci/RunPerfBenchmark.Tests.ps1 → 16/16 (new committed test, wired into perf-lib-tests.yml): overlay only for PR trees in compare mode; never local/baseline; tree restored on build-failure and overlay-copy-failure; graceful when the trusted csproj is missing; staging idempotency gate.
  • Stage-RustRuntime exercised end-to-end (x64 + arm64) out-of-band: stages microsoft.ui.xaml.dll + Microsoft.WindowsAppRuntime.dll, idempotent.
  • Run-PerfBenchmark.ps1 parses clean; StressPerf ARM64 build OK.

Final acceptance is a live /perf re-run on a pre-gate PR (e.g. comment /perf on #656 after this lands) — a maintainer should run it. Local validation cannot reproduce the windows-latest no-runtime environment.

Refs #661, #662. Fixes #674.

Co-authored-by: Copilot [email protected]

…eeded)

The /perf gate builds the StressPerf harnesses self-contained so they launch on
a windows-latest runner with no machine-wide Windows App SDK runtime. That
relies on a PropertyGroup (gated on PerfCiSelfContained=true) that PR #662 added
to each harness .csproj. PRs opened BEFORE #662 merged lack that block in their
tree, so -p:PerfCiSelfContained=true is a no-op: the harness builds
framework-dependent, hangs in the WinAppSDK bootstrapper on the runner, the
watchdog kills it -> all-n/a comparison + red check. That defeats the gate's
"works on every already-open PR with no rebase" promise.

Fix: in Run-PerfBenchmark.ps1 Build-Harness, in compare mode only, overlay the
trusted harness .csproj from the baseline tree over the PR tree's copy before
dotnet build. The harness .csproj is fixed test scaffolding (the StocksGrid
build recipe, including the self-contained knob), not the code under
measurement -- the PR's actual change lives in src/Reactor/, which the harness
still compiles via its relative ProjectReference into the PR tree. Keeps the
existing -p:PerfCiSelfContained=true and the csproj-scoped flag, so it never
leaks into the class libraries that reject self-contained packaging.

Never runs in local single-tree mode or when building the baseline itself;
falls back to the PR tree copy if the trusted csproj is missing.

Co-authored-by: Copilot <[email protected]>

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.

Pull request overview

Updates the /perf stress-perf CI harness build so pre-gate PRs (whose harness .csproj predates the PerfCiSelfContained block) can still be built self-contained on windows-latest without requiring a rebase, by sourcing the harness project file from the trusted baseline tree in compare mode.

Changes:

  • In compare mode, Build-Harness copies the harness .csproj from the baseline checkout over the PR checkout before building.
  • Documentation updated to explain the compare-mode overlay behavior and the “no rebase” guarantee.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
tests/stress_perf/ci/Run-PerfBenchmark.ps1 Overlays baseline harness .csproj onto PR tree in compare mode before dotnet build.
tests/stress_perf/ci/README.md Documents the overlay behavior and the rationale for supporting already-open PRs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/stress_perf/ci/README.md Resolved
Copilot PR review on #677 flagged two things on the harness csproj overlay:

* The overlay left the PR/worktree csproj modified after the build (dirty git
  status, stateful across runs). Make it build-scoped: back up the original
  csproj, overlay the trusted baseline copy for the build, and restore it in a
  finally - so the checkout is never left modified, even on build failure.
  Matters for local compare runs against a developer's own worktree.

* The README overstated provenance (implied only src/Reactor/ comes from the
  PR). Clarify that in compare mode the PR supplies src/Reactor/ AND the
  harness/workload sources under tests/stress_perf/ - only the .csproj build
  recipe is sourced from the trusted baseline (and restored afterwards).

Co-authored-by: Copilot <[email protected]>
@azchohfi Alexandre Zollinger Chohfi (azchohfi) changed the title CI: make /perf self-contained build work on pre-gate PRs (no rebase needed) CI: make /perf work on pre-gate PRs (self-contained C# overlay) + fix Rust column (#674) Jun 25, 2026

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

@azchohfi
Alexandre Zollinger Chohfi (azchohfi) force-pushed the azchohfi-fix-perf-self-contained-build branch from 2e859e2 to 1f27583 Compare June 25, 2026 23:06
Move the compare-mode csproj overlay inside the build try/finally and set
the backup marker only after the backup file is written, so a failed
trusted Copy-Item can never orphan a *.perfci-orig file or leave the PR
csproj swapped out. Addresses Copilot review on PR #677.

Co-authored-by: Copilot <[email protected]>
The /perf workflow patches the windows-rs test_reactor_perf build.rs to
windows_reactor_setup::as_self_contained(), which embeds an app.manifest that
declares the WinAppSDK runtime DLLs as SxS <file> entries - so the loader
requires those DLLs next to the exe at process start. as_self_contained() also
copies them there during cargo build, but every download/extract/copy step in
the upstream helper swallows its error (let _ = .. / .ok()), so a single
transient runner hiccup leaves ZERO DLLs staged while the build still
'Finishes'. The exe then dies at load with 0xC0000135 (STATUS_DLL_NOT_FOUND)
and 0-byte stdout/stderr, so the Rust column reads n/a (run 28202538748).

Add Stage-RustRuntime (called from Invoke-RustLeg after the exe is resolved):
explicitly extract the runtime nupkg + per-arch MSIX and copy the runtime DLLs
next to test_reactor_perf.exe, with a sentinel check, an idempotent skip, and
loud logging if nothing lands. Reuses the build script's own download cache
(auto-syncs the version) and falls back to fetching 2.1.3. Keeps the leg
hermetic (no machine-wide runtime install) and best-effort: any failure only
leaves the Rust column n/a; the C# legs are unaffected.

Validated locally end-to-end for x64 and arm64 (stages microsoft.ui.xaml.dll +
Microsoft.WindowsAppRuntime.dll, ~50 files, idempotent). Final acceptance is a
live /perf re-run, since the loader behaviour only reproduces on a clean runner.

Co-authored-by: Copilot <[email protected]>
Address pr-review findings on PR #677:
- Stage-RustRuntime now verifies a REQUIRED SET of runtime DLLs (not a single
  sentinel) for both the idempotency early-return and the post-copy success
  check, and validates completeness against the actual MSIX payload — a partial
  prior stage no longer reads as 'done' and silently faults the loader (#674).
- Document the Rust runtime staging + best-effort fallback in the CI README.
- Add tests/stress_perf/ci/RunPerfBenchmark.Tests.ps1 covering the compare-mode
  csproj overlay/restore guarantees (incl. build-failure and overlay-copy-failure
  cleanup) and the staging idempotency gate; wire it into perf-lib-tests.yml.

Co-authored-by: Copilot <[email protected]>

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

…afety

Stage-RustRuntime: gate the idempotency early-return on a positive completion
marker written only after a fully verified stage, instead of the presence of a
DLL subset. The per-file copy loop swallows errors, so a prior partial stage
could leave the two required DLLs present while others are missing and still
fault the loader at process start; a subset check would wrongly short-circuit
that incomplete state and never finish staging. The marker only exists once
every manifest-referenced runtime file has been verified next to the exe.

RunPerfBenchmark.Tests.ps1: capture ParseError[] from ParseInput and fail fast
so a syntax error in the orchestrator script is caught by CI instead of silently
yielding unreliable extracted function text. Update the staging idempotency test
to the marker semantics and add a negative test proving a DLL subset without the
marker does NOT early-return.

Addresses Copilot review comments on HEAD 9e959c6 (PR #677).

Co-authored-by: Copilot <[email protected]>

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

The completeness check trusted $msixOut, a scratch dir cached across invocations
whose extraction was guarded only by a single sentinel file. A stale/partial
prior `tar -xf` could leave $msixOut incomplete; the next call would then skip
re-extraction, derive $srcDlls from the partial payload, pass the "copied
everything I extracted" check, and write the completion marker from an
incomplete runtime — leaving the Rust exe to still fault at load (0xC0000135)
while subsequent calls incorrectly early-return.

Since we only reach this code when the marker is absent, treat the cache as
untrusted: clear and re-extract $msixOut fresh, and require BOTH a clean tar exit
and the sentinel before trusting it as the completeness source. A partial or
failed extraction now returns without writing the marker, so the next call
retries instead of locking in a broken stage.

Addresses Copilot review comment on HEAD d88a6c0 (PR #677).

Co-authored-by: Copilot <[email protected]>

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Two issues:

1. perf-lib-tests (Linux) failure: RunPerfBenchmark.Tests.ps1 printed "PASSED:
   all N assertions" but the job exited 1. The workflow runs it via
   `pwsh -Command ". '<script>'"` (dot-source), under which a non-zero
   $LASTEXITCODE left over from the stubbed `dotnet` build-failure scenario leaks
   into the process exit code on Linux (Windows -File invocation masked it). Add
   an explicit `exit 0` on the success path, mirroring PerfLib.Tests.ps1.

2. Stage-RustRuntime (Copilot review on c656a01): the completion marker alone
   was treated as sufficient to skip staging. If the marker survives but the
   runtime DLLs are externally removed (manual cleanup / partial dir wipe), the
   function would early-return into a broken exe. Now the early-return requires
   BOTH the marker AND the core required DLLs; a stale marker (DLLs missing) is
   deleted and a full restage proceeds.

Tests: update the staging idempotency case to seed marker + core DLLs, and add a
stale-marker case (marker present, DLLs missing -> no early-return + marker
deleted). 19 assertions; verified exit 0 under both -File and -Command.

Addresses Copilot review comment on HEAD c656a01 (PR #677).

Co-authored-by: Copilot <[email protected]>

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

…check

Three Copilot review points on Stage-RustRuntime (HEAD f589e9c):

- nupkg selection: was "largest file in the cache", which is arbitrary when
  multiple WinAppSDK runtime versions linger in the shared windows-reactor-setup
  cache and could stage a version that mismatches the crate's embedded SxS
  manifest (reintroducing 0xC0000135). Now selects the highest *version*
  deterministically (still downloads the pinned version when the cache is empty).

- extract dir: was a stable path (perfci-runtime-extract), so a different nupkg
  version selected later could reuse a stale cross-version MSIX payload because
  $msix already existed. Now keyed by the selected nupkg name/version, so the
  extracted payload always matches the chosen nupkg.

- completeness check: validated only *.dll, but the copy loop also stages *.pri
  (and swallows per-file errors), so a failed .pri copy could still write the
  completion marker. Now verifies the full copied set (.dll + .pri) before the
  marker is written.

PerfLib 61/61, RunPerfBenchmark 19/19 (exit 0 under both -File and dot-source).

Addresses Copilot review comments on HEAD f589e9c (PR #677).

Co-authored-by: Copilot <[email protected]>

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Two Copilot review points on Stage-RustRuntime (HEAD 0a8e567):

- nupkg selection now prefers the pinned $pkg.$ver.nupkg when it is already
  cached (reproducible, matches the version this script would download), and only
  falls back to the highest cached *version* when the pinned copy is absent. Keeps
  the deterministic-not-by-size guarantee while restoring reproducibility.

- the "staging incomplete" log said "DLL(s) missing" but the completeness check
  now counts .dll AND .pri; reworded to "file(s) missing".

PerfLib 61/61, RunPerfBenchmark 19/19 (exit 0). Verified selection: pinned wins
when cached, highest-version otherwise.

Addresses Copilot review comments on HEAD 0a8e567 (PR #677).

Co-authored-by: Copilot <[email protected]>

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

If the per-arch MSIX extraction fails or is incomplete (tar non-zero or
sentinel missing), the cached \ file is now deleted before returning.
Section 2 skips the nupkg re-extract while \ exists, so a truncated/
corrupt MSIX would otherwise be reused on every subsequent call and keep the
Rust leg failing until the cache was manually cleared. Evicting it forces the
next invocation to re-extract a fresh MSIX from the nupkg.

Co-authored-by: Copilot <[email protected]>

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

…lure

When the staged WinAppSDK runtime nupkg is missing or fails the >=1MB size
sanity-check (failed download or corrupt cache entry), delete it before
returning. The pinned-cache fast path prefers a cached \.\.nupkg when
present, so a 0-byte/truncated file would otherwise be reused on every run and
permanently pin the Rust leg at n/a. This completes the same self-healing
eviction already applied to the extracted MSIX and the MSIX-extract scratch dir.

Co-authored-by: Copilot <[email protected]>

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

…r safe)

The framework MSIX name was hard-coded to Microsoft.WindowsAppRuntime.2.msix.
The non-pinned cache fallback can select a different cached package version; a
future WinAppSDK major would ship a differently numbered framework MSIX and
staging would always fail 'MSIX not found' even with a valid runtime present.
Keep the exact 2.x name as the fast path (the '2' is the stable API-contract
major across all 2.x), and only if absent glob for the framework MSIX by its
stable stem (Microsoft.WindowsAppRuntime.<major>.msix), scoped so it can't pick
an unrelated DDLM/Singleton package lacking the runtime DLLs.

Co-authored-by: Copilot <[email protected]>

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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

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.

Perf CI: Rust cross-framework column n/a — test_reactor_perf exits 0xC0000135 (DLL-not-found) at runtime

2 participants