Repository navigation
fix(hr): harden the collectible analyzer loader (review follow-up of #23863) - #23947
Conversation
…follow-up) Delegate resolution to the compiler context (LoadFromAssemblyName, like Roslyn's own loader) so host dependencies it has not loaded yet unify to it instead of loading a split-identity analyzer-local copy; publish shadow copies via a staging file + atomic rename so concurrent loads (threads or dev-server processes sharing the temp root) never observe a partial PE; retain every dependency location registered per file name and resolve to the best version (exact match, else highest compatible) instead of first-registered-wins; Path.Join throughout.
|
Claude finished @dr1rrb's task in 4m 50s —— View job Code Review
Overall: ship after addressing the two findings below (one test coverage gap, one code clarity nit). Verdict: fix-first (nit scale — nothing blocking correctness)The four pillars described in the PR are mechanically sound:
Findings1 — Test coverage (moderate): 2 — Informational (no action needed)
|
There was a problem hiding this comment.
Pull request overview
This PR hardens CollectibleAnalyzerAssemblyLoader in Uno.HotReload to more closely mirror Roslyn’s analyzer loading semantics: delegating dependency resolution to the compiler AssemblyLoadContext, making shadow-copy publication atomic, and selecting the best dependency candidate when multiple versions are registered.
Changes:
- Delegate dependency resolution to
_compilerContext.LoadFromAssemblyName(...)(Roslyn-like behavior; avoids split-identity duplicates and avoids a linear scan). - Make shadow-copy publication atomic via staging +
File.Move, and publish PDB before DLL. - Track multiple dependency locations per file name and resolve to the best match (exact version preferred, otherwise highest compatible).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/Uno.HotReload/Roslyn/CollectibleAnalyzerAssemblyLoader.cs |
Implements compiler-context delegated resolution, atomic shadow-copy publication, and best-candidate dependency path selection. |
src/Uno.HotReload.Tests/Roslyn/Given_CollectibleAnalyzerAssemblyLoader.cs |
Adds regression tests for lazy compiler-context resolution and multi-version dependency selection, plus fixture helpers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23947/wasm-skia-net9/index.html |
carldebilly
left a comment
There was a problem hiding this comment.
Panel review of the loader hardening. The change is sound and faithfully mirrors Roslyn's own loader shape: the compiler-context delegation (LoadFromAssemblyName + bare-catch fall-through) matches AnalyzerAssemblyLoader.Core.cs, the staging-to-rename publish is a same-volume atomic move with the destination-exists race handled, a crash between the PDB and DLL publishes self-heals on retry, and both new regression tests genuinely fail on the previous code. No public-surface change; the multi-version registry keeps the lock-free/immutable idiom.
Approving — nothing below blocks. Inline: 8 medium and a handful of low/info suggestions. The two most valuable follow-ups are per-user isolation of the shared shadow-copy root and verifying the winner after a lost publish race; the rest are identity-check uniformity on the single-candidate path, diagnosability of the silent fallbacks, staging-file cleanup on non-race failures, and test coverage for the highest-compatible-version fallback and the atomic-publish guarantees.
autocarl
left a comment
There was a problem hiding this comment.
Follow-up review on exact head ceae5b4f517f39cc87bef13da28e8aa4e04f0130.
The three findings carried over from #23863 are correctly addressed for a clean cache: compiler-context resolution now delegates through LoadFromAssemblyName, registered same-name candidates are retained and version-selected, and new shadow copies are published by staging + atomic rename.
Validation on this head:
Uno.HotReloadRelease builds for net9.0 and net10.0: 0 warnings / 0 errors;Uno.HotReload.Testsnet10.0: 120/120 passed;- net9.0 test binary: 120/120 passed under the installed net10 roll-forward (the local host does not have the net9 runtime);
- hosted checks: 49 success, 2 neutral, no failing check;
- isolated regression probe: the legacy partial-final-cache scenario is reproducible.
One blocking upgrade-path issue remains inline: this implementation keeps the exact cache namespace/key used by the previously merged direct-copy code and trusts any existing final DLL, so the interrupted-copy artifact this change is intended to recover from remains permanently poisoned after upgrading. Requesting changes until existing entries are versioned or validated/rebuilt.
GetBestKnownPath now takes the already-validated simpleName (self-contained lookup and identity comparison instead of relying on a guard in its caller), and the highest-compatible-version fallback gets dedicated coverage — in a fresh context, since a context that already loaded the simple name answers later requests from its own by-name cache without calling Load() again.
|
Claude finished @dr1rrb's task in 2m 13s —— View job Code Review
Verdict: fix-first (one-liner unblock)The two previous findings from the last Claude review are correctly addressed in head
Remaining blocker1 — Informational (no action needed)
|
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23947/wasm-skia-net9/index.html |
|
|
The shadow cache root moves from the shared temp directory to per-user LocalApplicationData (user-only mode on Unix): this closes the shared-root pre-plant/swap surface and retires, by namespace, anything a pre-atomic- publish version of the cache may have left truncated at still-reachable keys. The key now folds in the file size, staging files are never leaked (cleanup on every failure path plus an age-gated startup sweep), the identity check applies to every registered candidate (single-candidate fast path removed), an optional IReporter traces candidate selection and compiler-context fallbacks, and simple names carrying invalid file-name characters are rejected before any probing.
|
Claude finished @dr1rrb's task in 5m 35s —— View job Code Review
Verdict: ship (one low-severity nit)All findings from the previous two Claude review rounds and from
Findings1 — PDB publish failure is fatal to the DLL load (LOW): Informational (no action needed)
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/Uno.HotReload.Tests/Roslyn/Given_CollectibleAnalyzerAssemblyLoader.cs:285
- This test deliberately writes staging/PDB debris into the real shadow-copy cache under LocalApplicationData (via GetShadowCopyPath) but only deletes the temp "root" directory. That leaves persistent artifacts in the user's profile (and in CI agents), which can accumulate and potentially affect later runs. Clean up the per-key shadow directory in the finally block as best-effort test hygiene.
finally
{
Directory.Delete(root, recursive: true);
}
src/Uno.HotReload/Roslyn/CollectibleAnalyzerAssemblyLoader.cs:107
- GetBestKnownPath always orders the candidate set with OrderBy, which forces a full buffer+sort even when there is only a single registered location (likely the common case). This adds avoidable allocations/CPU on every dependency bind attempt; only sort when there are multiple candidates (ties) to keep determinism.
// Ordinal order is load-bearing, not cosmetic: ImmutableHashSet enumeration order is
// unspecified, and a deterministic scan keeps the winner stable when candidates tie.
foreach (var path in candidates.OrderBy(static p => p, StringComparer.Ordinal))
{
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23947/wasm-skia-net9/index.html |
|
@Mergifyio backport release/stable/6.7 |
✅ Backports have been createdDetails
|
Follow-up to #23863 — the review-round-4 changes: the PR auto-merged the moment its last review conversations were resolved, before these fixes were pushed, so the "Done" replies on those threads describe the changes delivered here.
Changes (all on
CollectibleAnalyzerAssemblyLoader)Loadnow tries_compilerContext.LoadFromAssemblyName(assemblyName)(bare-catch fall-through, the exact shape of Roslyn's own loader) instead of probing the context's already-loadedAssemblies. Dependencies the compiler context can resolve but has not loaded yet materialize in it — no split-identity analyzer-local copy — and resolution stays correct when assemblies keep appearing at runtime (e.g. NuGet packages added to the app through hot reload). This also removes the per-Loadlinear scan discussed in fix(hr): align workspace analyzer flavors and Roslyn with the SDK compiler (spec 053) #23863 (comment) without any cache to invalidate: the ALC's internal by-name lookup is authoritative and re-probed by the runtime on every miss.File.Move; the PDB is published before the DLL so a visible DLL means the bundle is whole. Rename-publish was chosen over an in-processConcurrentDictionary<string, Task<string>>because the shadow key is deterministic and the temp root shared: the race also exists across dev-server processes, and a process killed mid-copy would otherwise poison the key with a permanent partial file.AddDependencyLocationretains every location registered for a file name (distinct projects may carry distinct versions of the same analyzer package), and resolution mirrors Roslyn'sGetBestPath: exact requested version wins, otherwise the highest version with a compatible identity (simple name + public key token when requested).Path.Jointhroughout the file and the test helper (CodeQL findings).Validation
Uno.HotReload.Tests: 120/120 passing, including two new regression tests —When_CompilerContextResolvesLazily_Then_AnalyzerRequestsUnifyToIt(lazily-resolving compiler context + same-directory copy of the assembly: the request must materialize in the compiler context; fails on the previous enumeration-based code) andWhen_MultipleVersionsRegistered_Then_RequestedVersionWins(two registered versions: the exact requested one must win over the first registered).Uno.HotReloadcompiles warning-free on both flavors: net9.0 (Roslyn 4.14) and net10.0 (Roslyn 5.6).