Skip to content

fix(hr): Re-point hot-reload baselines to the RID-specific build outputs - #23799

Merged
dr1rrb merged 6 commits into
masterfrom
dev/dr/hr-rid-baseline-align
Jul 21, 2026
Merged

dr1rrb merged 6 commits into
masterfrom
dev/dr/hr-rid-baseline-align

Conversation

@dr1rrb

@dr1rrb dr1rrb commented Jul 16, 2026

Copy link
Copy Markdown
Member

GitHub Issue: unoplatform/uno-private#2256

Master port of #23798 (release/stable/6.6-first fix), with unit-test coverage and a draft follow-up spec. Second half of the uno-private#2256 investigation — the first half (netX.0-skia TFM misreport) is #23790.

PR Type:

🐞 Bugfix

What changed? 🚀

With the correct target framework reported and the workspace correctly restricted, hot reload on Android still produced Found 0 metadata updates — silently, for C# and XAML edits alike.

The hot-reload workspace evaluates the head project without a RuntimeIdentifier, so EnC captures its baseline from the RID-less intermediate assembly path (obj/Debug/net10.0-android/App.dll). A device deployment however builds RID-specific (obj/Debug/net10.0-android/android-x64/App.dll): the RID-less assembly either does not exist — Roslyn's EnC then treats the project as "not built" (EditSession: mvid == Guid.Empty) and silently emits zero updates — or is a stale twin from an earlier RID-less build whose MVID does not match the deployed module, so emitted deltas would be dropped by the application.

  • RoslynExtensions.AlignHeadProjectCompilationOutputs (new, Uno.HotReload/Utils, chained after FilterHeadProjectTargetFramework in the solution load): re-points the kept head flavor's CompilationOutputInfo to the assembly the running application was actually built from. Trigger is declarative — the RuntimeIdentifier captured from the application's build; no filesystem guessing in the decision, and no global property pushed to the workspace (a global RID would relocate the expected outputs of every project reference, which MSBuild's project-to-project protocol builds RID-less). Candidates are accepted by module readability (a valid PE with an MVID — the primitive Roslyn's EnC uses to decide a project is "built"), preferring the RID-specific path over a potentially stale RID-less twin, with a recursive probe of the evaluated output directory as fallback for custom layouts (reference-assembly ref/refint folders excluded). Project references are left untouched.
  • No more silence: when nothing readable is found, an explicit warning states the probed paths and that hot reload will produce no updates — previously the only trace was project not built inside Roslyn's own EnC session log.
  • 7 unit tests (Uno.HotReload.Tests) covering the no-RID pass-through and warning, RID-specific preference over the stale twin, subtree probing with ref/refint exclusion, module-readability as the acceptance gate, untouched non-head projects, and the null-AssemblyPath warning — the fixture emits real minimal PE files since the alignment reads module metadata.
  • Draft spec 051 (specs/051-hotreload-baseline-identity-handshake, marked draft — hard requirement: needs reviews before implementation): the follow-up design transporting the RuntimeIdentifier and the loaded modules' MVIDs in ConfigureServer, so baseline selection and diagnostics rely on module identity (the invariant debugger-based EnC gets from the debuggee) instead of readability heuristics. Not implemented here.

PR Checklist ✅

Copilot AI review requested due to automatic review settings July 16, 2026 22:02
@github-actions

github-actions Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @dr1rrb's task in 3m 30s —— View job


Code Review

  • Gather context
  • Read changed files
  • Review implementation (RoslynExtensions.CompilationOutputAlignment.cs)
  • Review unit tests (Given_AlignHeadProjectCompilationOutputs.cs)
  • Review integration point (ServerHotReloadProcessor.MetadataUpdate.cs)
  • Review spec (spec.md)
  • Post inline findings
  • Write summary

Verdict: fix-first — 2 correctness issues (overly-broad exception catches) and 2 test-quality issues (missing assertions). The approach and architecture are sound.

Summary

The design is solid: declarative trigger (RID from the build properties), module-readability as the acceptance gate, and an explicit warning when nothing readable is found all match how Roslyn's EnC itself decides a project is "built". The chaining after FilterHeadProjectTargetFramework, the non-mutation of project references, and the fallback hierarchy (RID-specific → subtree probe → evaluated path → warn) are all correct. The 7-test fixture — with real emitted PE files — is the right approach given the MVID-readability gate.

Issues found (4)

Correctness (2 — inline comments posted):

  • catch (Exception) in TryReadMvid (line 160): swallows programming errors alongside the expected IO/PE failures. Should be narrowed to IOException or UnauthorizedAccessException or BadImageFormatException.
  • catch (Exception) in FindNewestReadableCandidate (line 139): same problem. Should catch IOException or UnauthorizedAccessException only.

Test quality (2 — inline comments posted):

  • When_Rid_And_OnlyRidlessOutput_Then_EvaluatedKept (line 118): asserts the path value but not that the solution was not remapped (Assert.AreSame is missing, unlike the analogous no-RID test).
  • When_Rid_Then_RidSpecificOutputPreferred (line 84): no negative assertion that the RID-less twin (evaluatedPath) was rejected. Adding Assert.AreNotEqual(evaluatedPath, ...) makes the preference contract explicit.

Minor / non-blocking

  • ref/refint exclusion in FindNewestReadableCandidate (line 131) checks only the immediate parent directory of the found file. A path like ref/sub/App.dll would slip through. In the standard .NET SDK output layout this never happens (ref assemblies sit directly in ref/ or refint/), so it's an acceptable simplification today — but worth noting as a latent edge case for custom layouts. Inline comment suggests a stricter ancestor walk if the team wants it.
  • Path.GetDirectoryName(evaluatedPath)! (line 77): null-forgiving operator is correct given that AssemblyPath in a workspace is always absolute, but a guard or an assertion would make the assumption explicit.
  • Spec spec.md: well-scoped DRAFT. The private repo references in the References section (uno-private#2256) are internal-only — per AGENTS.md §"Public Documentation and Spec References", public specs must not require private identifiers to understand them. Those references are informational-only here (the spec is self-contained without them), but they technically violate the one-way dependency rule. Consider replacing them with generic descriptions.

Integration point (ServerHotReloadProcessor.MetadataUpdate.cs)

The chain .FilterHeadProjectTargetFramework(...).AlignHeadProjectCompilationOutputs(...) is correct and placed before HotReloadManager.CreateAsync, which is exactly the right moment (before EnC captures baselines). runtimeIdentifier is read from properties.GetValueOrDefault("RuntimeIdentifier"), which correctly returns null when absent — and AlignHeadProjectCompilationOutputs handles that case.

@dr1rrb
dr1rrb marked this pull request as ready for review July 16, 2026 22:03
@github-actions

github-actions Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @dr1rrb's task in 5m 19s —— View job


Code Review — fix(hr): Re-point hot-reload baselines to the RID-specific build outputs

  • Gather context
  • Read changed files
  • Review implementation (RoslynExtensions.CompilationOutputAlignment.cs)
  • Review unit tests (Given_AlignHeadProjectCompilationOutputs.cs)
  • Review integration point (ServerHotReloadProcessor.MetadataUpdate.cs)
  • Review spec (spec.md)
  • Post inline findings
  • Write summary

Verdict: fix-first

2 confirmed bugs (one from existing bot review), 1 AGENTS.md violation, plus the five pre-existing bot findings I confirmed below.

Summary

New findings (3 inline comments posted)

Severity Location Issue
Must-fix spec.md:4 uno-private#2256 is a private issue reference — violates AGENTS.md §Public Documentation. Replace with generic description ("an internal investigation into…") in both the status header and the References section.
Should-fix RoslynExtensions.CompilationOutputAlignment.cs:38 AlignHeadProjectCompilationOutputs and its delegate FindNewestReadableCandidate do unbounded recursive filesystem I/O (Directory.EnumerateFiles + TryReadMvid in a loop) but accept no CancellationToken. The call site at ServerHotReloadProcessor.MetadataUpdate.cs:102 already holds ct2. Add CancellationToken cancellationToken = default and thread it through.
Minor Given_AlignHeadProjectCompilationOutputs.cs:153 When_OutputPathUnset_Then_Warns asserts count only; every other warning test also asserts content. Inconsistency worth closing.

Confirmed pre-existing bot findings (agree with all five)

File Line Issue
CompilationOutputAlignment.cs 138 catch (Exception) in FindNewestReadableCandidate — should narrow to IOException or UnauthorizedAccessException
CompilationOutputAlignment.cs 160 catch (Exception) in TryReadMvid — should narrow to IOException or UnauthorizedAccessException or BadImageFormatException
CompilationOutputAlignment.cs 131 ref/refint exclusion checks only the immediate parent folder — a path like obj/Debug/net10.0-android/ref/sub/App.dll passes the filter. An ancestry walk is more robust.
Given_AlignHeadProjectCompilationOutputs.cs 118 When_Rid_And_OnlyRidlessOutput_Then_EvaluatedKept — missing Assert.AreSame(workspace.CurrentSolution, aligned) to make the "no remap happened" contract explicit.
Given_AlignHeadProjectCompilationOutputs.cs 84 When_Rid_Then_RidSpecificOutputPreferred — missing Assert.AreNotEqual(evaluatedPath, aligned.GetProject(projectId)!.CompilationOutputInfo.AssemblyPath) to lock in that the RID-less twin lost.

What looks good

  • The root-cause analysis is correct and the fix targets it directly (no guard-only mitigation).
  • The declarative RID trigger (from the build property bag, not filesystem guessing) is the right design choice.
  • Chaining after FilterHeadProjectTargetFramework in the existing pipeline is the right integration point — it operates on the already-reduced solution and its sequential position is safe.
  • The test fixture using real CSharpCompilation.Emit() to produce genuine PEs is the right call given the MVID-readability acceptance gate.
  • The FindNewestReadableCandidate evaluatedPath exclusion (.Where(!PathEquals(...))) correctly prevents the fallback from re-selecting the known-bad RID-less path.
  • The spec is well-structured, appropriately scoped as draft, and the failure modes it documents (stale RID-specific output, ambiguous probe, library staleness, config mismatch) are all real and unaddressed by this PR — good signposting.

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

This PR improves Uno Hot Reload reliability on Android (and other RID-split builds) by aligning Roslyn EnC baselines with the RID-specific assembly actually deployed, adding explicit warnings when baselines can’t be read, and introducing unit tests plus a draft follow-up design spec.

Changes:

  • Capture the runtime identifier from the client’s MSBuild properties and align the head project’s CompilationOutputInfo.AssemblyPath to RID-specific build outputs during workspace initialization.
  • Add RoslynExtensions.AlignHeadProjectCompilationOutputs to prefer readable RID-specific assemblies (with fallback probing) and emit actionable warnings when no readable baseline exists.
  • Add unit tests covering alignment behavior and add a draft spec for a future identity-based (MVID) handshake.

Reviewed changes

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

File Description
src/Uno.UI.RemoteControl.Server.Processors/HotReload/ServerHotReloadProcessor.MetadataUpdate.cs Chains the new compilation-output alignment step after head TFM filtering during solution load.
src/Uno.HotReload/Utils/RoslynExtensions.CompilationOutputAlignment.cs Implements RID-aware baseline selection by remapping head project compilation output paths based on readable PE/MVID.
src/Uno.HotReload.Tests/Utils/Given_AlignHeadProjectCompilationOutputs.cs Adds unit tests validating RID/no-RID behavior, candidate probing rules, and warning emission.
specs/051-hotreload-baseline-identity-handshake/spec.md Adds a draft spec describing a future protocol to make baseline selection identity-based rather than heuristic.

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

@unodevops

Copy link
Copy Markdown
Contributor

@ajpinedam ajpinedam 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.

Some of the Copilot comments seem legit

Copilot AI review requested due to automatic review settings July 20, 2026 15:23
@github-actions github-actions Bot added area/build Categorizes an issue or PR as relevant to build infrastructure kind/documentation labels Jul 20, 2026
@github-actions

github-actions Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @dr1rrb's task in 2m 44s —— View job


Code Review

  • Read changed files (post-feedback iteration)
  • Review implementation (RoslynExtensions.CompilationOutputAlignment.cs)
  • Review unit tests (Given_AlignHeadProjectCompilationOutputs.cs)
  • Review integration point (ServerHotReloadProcessor.MetadataUpdate.cs)
  • Review spec (spec.md)
  • Post inline findings
  • Write summary

Verdict: fix-first (one remaining finding)

The feedback commit addressed all prior findings — FindNewestReadableCandidate's catch (Exception) narrowed to when (e is not OperationCanceledException), the ref/refint exclusion now walks the full ancestor chain, CancellationToken is threaded through, the loop iterates Project directly, all three test assertion gaps are closed, and the uno-private#2256 reference is gone from the spec. One issue from the original two-catch review remains open.

Remaining finding (1 inline comment posted)

Severity Location Issue
Should-fix RoslynExtensions.CompilationOutputAlignment.cs:177 TryReadMvid still has bare catch (Exception) — the FindNewestReadableCandidate catch was narrowed but this one was not. Suggestion posted.

What's clean

  • Root cause (RID-less baseline → EnC "project not built" silence) is correctly identified and fixed at the source — no guard-only mitigation.
  • CancellationToken is correctly propagated; ThrowIfCancellationRequested() fires per enumerated candidate in the Where predicate.
  • The ref/refint ancestor walk (feedback iteration) is now correct for nested layouts.
  • Path.Join is already used (not Path.Combine) — the CodeQL Path.Combine warnings from the earlier bot review were false positives.
  • Test assertions are complete: negative assertion in When_Rid_Then_RidSpecificOutputPreferred, Assert.AreSame in When_Rid_And_OnlyRidlessOutput_Then_EvaluatedKept, content check in When_OutputPathUnset_Then_Warns.
  • Spec is self-contained and publicly shareable.
  • Integration chain (.FilterHeadProjectTargetFramework(…).AlignHeadProjectCompilationOutputs(…, ct2)) is correctly sequenced before HotReloadManager.CreateAsync.

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 5 out of 5 changed files in this pull request and generated 1 comment.

@unodevops

Copy link
Copy Markdown
Contributor

Copilot AI review requested due to automatic review settings July 20, 2026 16:07
@github-actions

github-actions Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @dr1rrb's task in 1m 54s —— View job


Code Review

  • Gather context from prior reviews
  • Read current state of changed files
  • Check remaining TryReadMvid catch-narrowing finding
  • Check for any new issues in the latest commit
  • Post inline comments
  • Write summary

Verdict: ship

The TryReadMvid bare-catch finding — the sole remaining issue from the previous review — has been addressed in this iteration. catch (Exception e) when (e is IOException or UnauthorizedAccessException or BadImageFormatException or InvalidOperationException) at line 185 correctly matches the exception types the PEReader/File.OpenRead path can produce.

All prior findings are resolved:

Finding Status
TryReadMvid bare catch (Exception) ✅ Narrowed to IO/PE/auth exceptions
FindNewestReadableCandidate bare catch (Exception) ✅ Narrowed to when (e is not OperationCanceledException)
ref/refint immediate-parent-only exclusion ✅ Full ancestor walk implemented
No CancellationToken on filesystem I/O ✅ Threaded through with per-candidate ThrowIfCancellationRequested()
When_Rid_And_OnlyRidlessOutput_Then_EvaluatedKept missing Assert.AreSame ✅ Added
When_Rid_Then_RidSpecificOutputPreferred missing negative assertion ✅ Added
When_OutputPathUnset_Then_Warns missing content assertion ✅ StringAssert.Contains(..., "app(net10.0-android)")
Path.Combine → Path.Join in tests and implementation ✅ Whole-file switch done
Private issue reference in spec (uno-private#2256) ✅ Scrubbed — spec is self-contained
foreach iterating ProjectId then doing GetProject ✅ Iterates Project directly now
Null Path.GetDirectoryName null-forgiving operator ✅ Explicit null/empty guard with warning and continue

What looks good

  • TryReadMvid now handles all the right failure modes: IOException (file missing/locked), UnauthorizedAccessException (permissions race), BadImageFormatException (corrupt/truncated PE), InvalidOperationException (PE metadata not present) — exactly what File.OpenRead + PEReader.GetMetadataReader() can throw.
  • FindNewestReadableCandidate's catch (Exception e) when (e is not OperationCanceledException) is a conscious trade-off: it keeps the broad IO-race swallow while ensuring cancellation always propagates. The accept/reject was noted in the prior review.
  • Test suite is thorough: 8 tests with real emitted PEs, covering every branch (no-RID pass-through, RID-specific preference, subtree probe with ref/refint exclusion, module-readability gate, untouched non-head projects, null path warning, bare-filename warning, evaluated-path fallback).
  • AlignHeadProjectCompilationOutputs chains correctly in the integration pipeline — after FilterHeadProjectTargetFramework and before HotReloadManager.CreateAsync, passing the already-held ct2.

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 5 out of 5 changed files in this pull request and generated 1 comment.

@unodevops

Copy link
Copy Markdown
Contributor

dr1rrb added 6 commits July 20, 2026 14:32
The workspace evaluates the head without a RuntimeIdentifier, so EnC
captures its baseline from the RID-less intermediate path. A device
deployment builds RID-specific: the RID-less assembly either doesn't
exist — Roslyn then treats the project as 'not built' and silently
emits zero updates — or is a stale twin whose MVID doesn't match the
deployed module, so the emitted deltas are dropped by the application.

After the target-framework filtering, re-point the kept head flavor's
CompilationOutputInfo to the assembly the running application was
actually built from: trigger is the RuntimeIdentifier captured from
the application's build (declarative — no filesystem guessing in the
decision), candidates are accepted only when their module is readable
(the same primitive Roslyn's EnC uses to decide a project is 'built'),
preferring the RID-specific path over a potentially stale RID-less
twin, with a directory probe fallback for custom output layouts
(reference-assembly folders excluded). When nothing readable is found,
warn explicitly instead of letting EnC no-op silently.

Project references are left untouched: MSBuild's project-to-project
protocol builds them RID-less, their evaluated paths are correct.
Seven unit tests over AlignHeadProjectCompilationOutputs: no-RID
pass-through and anti-silence warning, RID-specific output preferred
over a stale RID-less twin, subtree probing with reference-assembly
folders excluded, evaluated path kept when no RID output exists,
module-readability as the acceptance gate (file existence is not
enough), non-head projects untouched, and the null-AssemblyPath
warning. Fixture emits real minimal PE files, as the alignment reads
module metadata.
RID and loaded-module MVIDs transported in ConfigureServer so the
server can select and validate EnC baselines by module identity — the
invariant debugger-based EnC gets from the debuggee and watch-mode
Roslyn cannot check — instead of readability heuristics. Marked draft:
hard requirement to review before implementation (protocol change).
- Required CancellationToken threaded through the output probing
  (ThrowIfCancellationRequested per candidate, OCE not swallowed)
- ref/refint exclusion walks the full ancestry, not only the parent
- Path.Join instead of Path.Combine (no rooted-segment reset)
- Iterate Project instances directly instead of re-fetching by id
- Tests: no-remap AreSame, RID-preference negative check, warning
  content assertion
- Spec 051: private-tracker references reworded to generic terms
The specs are internal working documents; the markdown line-length
rule floods PRs touching them with notices.
- Guard a directory-less output assembly path (warn + skip) instead
  of null-forcing Path.GetDirectoryName, with test coverage
- Narrow TryReadMvid to the expected open/read/parse failures
Copilot AI review requested due to automatic review settings July 20, 2026 21:33
@dr1rrb
dr1rrb force-pushed the dev/dr/hr-rid-baseline-align branch from ac1ee5e to 8f90603 Compare July 20, 2026 21:33
@github-actions

github-actions Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @dr1rrb's task in 1m 52s —— View job


Code Review

  • Gather context from prior reviews
  • Read current state of changed files
  • Check Copilot finding: IsNullOrEmpty vs IsNullOrWhiteSpace for runtimeIdentifier
  • Check for any new issues in the latest commit
  • Post inline comments
  • Write summary

Verdict: fix-first (one remaining finding)

The second-round feedback commit (8f906034) addressed the TryReadMvid bare-catch narrowing and the null-forgiving Path.GetDirectoryName guard — both are now correct. One finding remains open.

Remaining finding (1 inline comment posted)

Severity Location Issue
Should-fix RoslynExtensions.CompilationOutputAlignment.cs:60 string.IsNullOrEmpty(runtimeIdentifier) should be IsNullOrWhiteSpace. MSBuild property values can be whitespace-only; IsNullOrEmpty passes them through, causing Path.Join to probe a path with a blank directory segment (silently failing). The sibling FilterHeadProjectTargetFramework already uses IsNullOrWhiteSpace consistently for the same reason.

What's clean

  • TryReadMvid catch: when (e is IOException or UnauthorizedAccessException or BadImageFormatException or InvalidOperationException) — all expected open/read/parse failures covered.
  • FindNewestReadableCandidate catch: when (e is not OperationCanceledException) — cancellation propagates correctly.
  • Null/empty output-path guard with warning + continue instead of null-forcing Path.GetDirectoryName! — new test When_Rid_And_OutputPathHasNoDirectory_Then_Warns covers the branch.
  • ref/refint ancestor walk, CancellationToken threading, Path.Join throughout, test assertions — all from prior rounds, verified still in place.
  • Integration chain (.FilterHeadProjectTargetFramework(…).AlignHeadProjectCompilationOutputs(…, ct2)) correctly sequenced before HotReloadManager.CreateAsync.

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 5 out of 5 changed files in this pull request and generated 1 comment.

@dr1rrb
dr1rrb merged commit e84f849 into master Jul 21, 2026
72 checks passed
@dr1rrb
dr1rrb deleted the dev/dr/hr-rid-baseline-align branch July 21, 2026 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/build Categorizes an issue or PR as relevant to build infrastructure kind/documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants