Skip to content

fix(hr): don't block hot reload on non-fatal source-generator errors - #24012

Merged
dr1rrb merged 2 commits into
masterfrom
dev/dr/hr-generator-error-emit-gate
Aug 8, 2026
Merged

dr1rrb merged 2 commits into
masterfrom
dev/dr/hr-generator-error-emit-gate

Conversation

@dr1rrb

@dr1rrb dr1rrb commented Aug 7, 2026

Copy link
Copy Markdown
Member

Problem

Surfaced by unoplatform/studio.live#3317 (Uno SDK 6.7.0-dev.914 → 6.7.0-dev.938, which moves embedded Roslyn 4.14 → 5.6). The regression guard ReswSupportTests.When_ReswCorruptedDuringHotReload_Then_XamlEditsStillWork passes on 914 and fails on 938.

Root cause. Roslyn 5.x's Edit-and-Continue (UnitTestingHotReloadService.EmitSolutionUpdateAsync) refuses to emit any metadata update while a source generator reports an Error-severity diagnostic — even when the C# compilation itself succeeds. A corrupt .resw makes the Uno XAML generator report UXAML0003 (Error) on every generator pass while the assembly still compiles, so a single broken generator input froze all hot reload (including valid edits to unrelated files) until the .resw was fixed. Roslyn 4.x did not gate on generator diagnostics — hence 914 green, 938 red.

The trap: source-generator diagnostics never appear in Compilation.GetDiagnostics() (only via the internal Project.GetSourceGeneratorDiagnosticsAsync()), so the change-set-scoped blocked-compilation audit (spec 054) can't see them — the pass reports NoChanges, not Failed, and the reason is invisible.

Confirmed with a source-generated-document dump: after the XAML edit with a corrupt .resw, the generated MainPage code does contain the edit (the generator is innocent), yet EnC emits 0 updates while UXAML0003 is present and emits normally once it is gone. (EnC baseline / commitUpdates is not the cause — hot reload recovers as soon as the .resw is valid again.)

Fix

In HotReloadManager.ProcessSolutionChanged, read the change-set projects' source-generator error diagnostics (via Project.GetSourceGeneratorDiagnosticsAsync, resolved through the same ResolveAuditProjects scope as the spec-054 audit) and suppress them for the EnC emit (SpecificDiagnosticOptions → Suppress). A non-fatal generator error then degrades to stale generated output instead of frozen hot reload, restoring 4.x behavior. Generated code that genuinely does not compile still reports a C# (CSxxxx) error and stays blocked through the existing audit / rude-edit paths, so this never lets non-compiling code hot-reload. The bypassed errors are surfaced in the HR log so a broken .resw isn't silent.

The suppression is applied to the emit itself, not as a retry after a blocked emit: EmitSolutionUpdateAsync advances the EnC baseline as a side effect, so a throwaway first emit would consume the change and leave a second nothing to apply.

Also centralizes hot-reload diagnostic reporting — compilation errors, EnC emit diagnostics, solution-update diagnostics, and the new bypassed-generator diagnostics — into a per-cycle DiagnosticsReporter (severity coloring, per-category WASM formatting caps since memory.grow() is irreversible); GetCompilationErrors becomes a pure getter.

Verification

  • studio.live ReswSupportTests — When_ReswCorruptedDuringHotReload + all 4 sibling resw tests pass (Desktop; the Wasm rows are unrelated to this fix — they need the wasm-tools workload to build the sample).
  • Uno.HotReload.Tests — 135/135 pass.

Roslyn 5.x's Edit-and-Continue refuses to emit any metadata update while a
source generator reports an Error-severity diagnostic, even when the C#
compilation itself succeeds. A corrupt .resw makes the Uno XAML generator
report UXAML0003 (Error) on every pass while the assembly still compiles, so a
single broken generator input froze all hot reload -- including valid edits to
unrelated files -- until it was fixed. Roslyn 4.x did not gate on generator
diagnostics.

Generator diagnostics never appear in compilation.GetDiagnostics() (only via
the internal Project.GetSourceGeneratorDiagnosticsAsync()), so the
change-set-scoped blocked-compilation audit (spec 054) could not see them: the
pass just reported NoChanges, with no visible reason.

Read the change-set projects' source-generator error diagnostics and suppress
them for the EnC emit, so a non-fatal generator error degrades to stale
generated output instead of blocking hot reload. Generated code that genuinely
does not compile still reports a C# error and stays blocked via the existing
audit / rude-edit paths. The suppression is applied to the emit itself, not as
a retry: EmitSolutionUpdateAsync advances the EnC baseline as a side effect, so
a throwaway first emit would consume the change.

Also centralizes hot-reload diagnostic reporting (compilation / emit /
solution-update / the new generator diagnostics) into a per-cycle
DiagnosticsReporter -- severity coloring, per-category WASM formatting caps;
GetCompilationErrors is now a pure getter.

Surfaced by unoplatform/studio.live#3317 (Uno SDK 6.7.0-dev.914 -> dev.938,
embedded Roslyn 4.14 -> 5.6). Verified: studio.live ReswSupportTests
When_ReswCorruptedDuringHotReload now passes (Desktop) with its 4 sibling resw
tests; Uno.HotReload.Tests 135/135.
@dr1rrb
dr1rrb marked this pull request as ready for review August 7, 2026 21:02
Copilot AI lite review requested due to automatic review settings August 7, 2026 21:02
@github-actions

github-actions Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

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


Review complete

  • Gather context & understand the request
  • Read changed files
  • Review HotReloadManager.cs changes
  • Review DiagnosticsReporter.cs (new file)
  • Review RoslynExtensions.GeneratorDiagnostics.cs (new file)
  • Post inline comments
  • Post summary

Overall verdict: fix-first (2 inline findings, 1 cross-cutting concern)

The root cause diagnosis is correct and the fix strategy is sound — suppressing generator errors at the emit level rather than as a retry preserves the EnC baseline, and the DiagnosticsReporter refactor is clean. Two issues need attention before merge:

2 inline comments posted:

Severity Location Issue
Medium RoslynExtensions.GeneratorDiagnostics.cs:37 Reflection invoke + cast are both unguarded — a TargetInvocationException or InvalidCastException (e.g., if the internal API returns Task<> instead of ValueTask<> on a future Roslyn version) propagates as "Internal error" and fails the entire hot-reload cycle. The XML-doc contract promises empty-on-unavailable, but only the null-method case is handled.
Low RoslynExtensions.GeneratorDiagnostics.cs:63 WithSuppressedDiagnostics iterates all solution projects, but the error IDs were collected only from audited (change-set) projects. If a non-audited project independently reports the same ID (e.g., two resw-broken projects, same UXAML0003), its generator error is silently suppressed in the emit for this pass, even though it was never part of the change set. Scoping the loop to the audited project IDs would close the gap.

Cross-cutting concern (no specific line):

No unit test was added to Uno.HotReload.Tests for the generator-error suppression path. The HotReloadManagerHarness is well-suited to cover it — StubWatchService already intercepts EmitSolutionUpdateAsync and could assert the suppressed-ID solution is passed through while the outcome is still Success. The studio.live integration test validates the end-to-end scenario but not the internal suppression logic in isolation. Per the repo's red/fix/green convention this is worth adding.

What looks good:

  • The DiagnosticsReporter centralization is a clean SRP improvement — no more scattered CSharpDiagnosticFormatter + WASM cap logic spread across the manager.
  • Making GetCompilationErrors a pure static getter (no tracker side-effects, no ResolveAuditProjects duplication) is the right direction.
  • The WithSuppressedDiagnostics no-op fast-path (distinct.Length == 0 → same reference) is thoughtful for the common pass.
  • Applying suppression to the emit only (not stored back) correctly respects the EnC baseline invariant described in the PR body.
  • The OperatingSystem.IsBrowser() limits in DiagnosticsReporter are correctly computed once at class initialization, not per-call.

@github-actions

github-actions Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

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


Code Review

  • Gather context and understand the PR
  • Read changed files
  • Review HotReloadManager.cs changes
  • Review DiagnosticsReporter.cs (new file)
  • Review RoslynExtensions.GeneratorDiagnostics.cs (new file)
  • Post inline comments and summary

Verdict: ship with minor items addressed

The overall design is sound: reading source-generator diagnostics through the internal Roslyn API (reflection-bound, matching the Studio Live approach) and suppressing them via SpecificDiagnosticOptions is the correct minimal intervention. The DiagnosticsReporter centralization is a clean improvement, and the per-category WASM caps are correctly placed. The root-cause analysis in the PR body is thorough and the fix is well-scoped.

Issues found (3 inline comments):

Severity File Finding
Medium RoslynExtensions.GeneratorDiagnostics.cs:37 Unguarded reflection cast — a Roslyn return-type change throws InvalidCastException and terminates the hot-reload cycle as InternalError instead of degrading gracefully to []. Suggest try/catch.
Low RoslynExtensions.GeneratorDiagnostics.cs:55 WithSuppressedDiagnostics iterates all solution projects, so a non-audited project that independently reports the same diagnostic ID (e.g. UXAML0003) also gets suppressed. Whether this matches the intended Roslyn-4.x-parity semantics or the spec-054 scoping should be documented explicitly.
Low RoslynExtensions.GeneratorDiagnostics.cs:31 Silent degradation when the internal Roslyn API is absent — no log entry signals that the fix isn't active. A one-time warn would make future Roslyn version mismatches diagnosable.

Cross-cutting observations (no inline comment needed):

  • GetCompilationErrors being synchronous inside a when guard is a pre-existing issue, flagged as informational only.
  • DiagnosticsReporter.Report cap logic (reported >= max) is correct — the "and N more" count is exact.
  • ANSI reset at end of each colored string (\x1B[0m) correctly prevents color bleed, matching the existing convention in the file.
  • CompilationAudit.Errors changing from ImmutableArray<string> to ImmutableArray<Diagnostic> is a clean improvement — formatting is now deferred to DiagnosticsReporter where WASM caps live.

@kazo0

kazo0 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

@Mergifyio backport release/stable/6.7

@mergify

mergify Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

backport release/stable/6.7

✅ Backports have been created

Details

Cherry-pick of c0ce315 has failed:

On branch mergify/bp/release/stable/6.7/pr-24012
Your branch is ahead of 'origin/release/stable/6.7' by 1 commit.
  (use "git push" to publish your local commits)

You are currently cherry-picking commit c0ce315db5.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ListViewBase.cs

no changes added to commit (use "git add" and/or "git commit -a")

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

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 updates Uno.HotReload to prevent Roslyn 5.x Edit-and-Continue from freezing hot reload when source generators report error-severity diagnostics that don’t actually break C# compilation (e.g., a corrupt .resw causing UXAML0003). It does so by collecting generator diagnostics for the changed-project scope and suppressing their IDs only for the EnC emit, plus centralizing diagnostic formatting/reporting in a per-cycle reporter.

Changes:

  • Add reflection-based access to Project.GetSourceGeneratorDiagnosticsAsync() and utilities to suppress diagnostics IDs via SpecificDiagnosticOptions for a single emit.
  • In HotReloadManager.ProcessSolutionChanged, detect generator error diagnostics for the audited project scope and suppress them during EmitSolutionUpdateAsync so hot reload can continue.
  • Introduce DiagnosticsReporter to centralize diagnostic formatting, severity coloring, and WASM-side reporting caps.

Reviewed changes

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

File Description
src/Uno.HotReload/Utils/RoslynExtensions.GeneratorDiagnostics.cs Adds reflection-bound access to internal generator diagnostics and a helper to suppress diagnostic IDs during compilation/emit.
src/Uno.HotReload/Tracking/DiagnosticsReporter.cs Adds a per-cycle diagnostics reporter to format/color/cap diagnostics output consistently across categories.
src/Uno.HotReload/HotReloadManager.cs Integrates generator-error suppression into the EnC emit path and routes diagnostic reporting through DiagnosticsReporter.

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

Comment thread src/Uno.HotReload/HotReloadManager.cs Resolved
Comment thread src/Uno.HotReload/HotReloadManager.cs Resolved
@dr1rrb
dr1rrb enabled auto-merge August 7, 2026 21:15
@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 226524 has failed on Uno.UI - CI.

When_Reorder_DragDrop_ScrollsAwayFromDraggedItem_KeepsExtentAndPositions
fails intermittently on the iOS Skia CI leg, always on the mid-drag
extent assertion and always with the same values: ExtentHeight 1560
instead of 1440, exactly 3 phantom 40px rows. Observed on master build
225991 (attempt 1, passed on retry), PR #24007 build 226424, and PR
#24012 build 226524 where 5/5 stage attempts failed on this single test
across different hosted agents.

The identical values every failure point at a timing-dependent residue
of the extent estimation fixed by #23946 surfacing on the iOS simulator
profile — tracked in #24013. Desktop and Android Skia legs keep running
the test, so the regression coverage #23946 added stays in place.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NsWEWZN3E2AtwQm7UU1cFm
Copilot AI review requested due to automatic review settings August 8, 2026 01:20
@github-actions

github-actions Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kazo0's task in 2m 35s —— View job


Review complete

  • Gather context & understand the request
  • Read changed files
  • Review RoslynExtensions.GeneratorDiagnostics.cs
  • Review DiagnosticsReporter.cs
  • Review HotReloadManager.cs changes
  • Post inline comments
  • Post summary

Overall verdict: fix-first (1 blocking finding, 3 low-severity)

The root cause analysis is correct and the approach — collecting generator errors via reflection then suppressing them in SpecificDiagnosticOptions before the emit — is the right minimal intervention. The DiagnosticsReporter refactor is clean: WASM caps computed once at class init, formatting deferred to the reporter, GetCompilationErrors is now a pure static getter. The emitSolution being a local snapshot (never stored back to workspace.CurrentSolution) correctly preserves the EnC baseline invariant.

4 inline comments posted:

Severity Location Issue
Medium RoslynExtensions.GeneratorDiagnostics.cs:37 Unguarded Invoke + hard cast — TargetInvocationException or InvalidCastException (return-type change in a future Roslyn) propagates as InternalError terminating the cycle instead of the promised graceful empty return. Multiple prior reviews flagged this; still unaddressed. Suggestion included.
Low RoslynExtensions.GeneratorDiagnostics.cs:34 Silent empty return when the Roslyn internal API is absent — no log entry, so a version mismatch that disables the fix is invisible. A one-time warning at that path would help diagnosability.
Low DiagnosticsReporter.cs:30 AnalyzerLimit / ReportAnalyzerDiagnostics names describe analyzer diagnostics but the code and call sites deal with source-generator diagnostics — a distinct Roslyn concept. Rename to GeneratorLimit / ReportGeneratorDiagnostics.
Low RoslynExtensions.GeneratorDiagnostics.cs:55 IDs suppressed solution-wide but collected from change-set projects only — the doc comment doesn't state whether solution-wide suppression is intentional Roslyn-4.x parity or an oversight. A clarifying comment would prevent unintentional future re-scoping.

What looks good:

  • The DiagnosticsReporter centralization is a clean SRP improvement
  • The no-suppression fast path (distinct.Length == 0 → same reference) is thoughtful on the common path
  • WASM caps computed at static class-init, not per-call
  • CompilationAudit.Errors changed from ImmutableArray<string> to ImmutableArray<Diagnostic> is correct — defers formatting to the reporter where caps live
  • auditedProjects resolved once and shared between the generator-error read and the compilation-error audit is clean
  • Given_ListViewBase.cs: gating the Skia-iOS flaky test with a [GitHubWorkItem] tracking issue is the right pattern

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.

Suppressed comments (1)

src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ListViewBase.cs:5511

  • This PR is described as a hot-reload Roslyn/source-generator diagnostic fix, but this hunk also changes ListViewBase runtime-test platform coverage by excluding Skia-iOS. To keep the PR scope auditable, please either mention this test change in the PR description (with rationale/issue link) or move it to a dedicated PR.
		// Skia-iOS is excluded: the mid-drag extent intermittently measures 3 rows too large there (1560 vs 1440),
		// same values every failure — tracked in the linked issue; Desktop/Android Skia keep covering the regression.
		[PlatformCondition(ConditionMode.Include, RuntimeTestPlatforms.Skia & ~RuntimeTestPlatforms.SkiaIOS)]
		[GitHubWorkItem("https://github.com/unoplatform/uno/issues/24013")]

@unodevops

Copy link
Copy Markdown
Contributor

@dr1rrb
dr1rrb merged commit c0e8dc8 into master Aug 8, 2026
52 checks passed
@dr1rrb
dr1rrb deleted the dev/dr/hr-generator-error-emit-gate branch August 8, 2026 13:46
kazo0 added a commit that referenced this pull request Aug 9, 2026
When_Reorder_DragDrop_ScrollsAwayFromDraggedItem_KeepsExtentAndPositions
fails intermittently on the iOS Skia CI leg, always on the mid-drag
extent assertion and always with the same values: ExtentHeight 1560
instead of 1440, exactly 3 phantom 40px rows. Observed on master build
225991 (attempt 1, passed on retry), PR #24007 build 226424, and PR
#24012 build 226524 where 5/5 stage attempts failed on this single test
across different hosted agents.

The identical values every failure point at a timing-dependent residue
of the extent estimation fixed by #23946 surfacing on the iOS simulator
profile — tracked in #24013. Desktop and Android Skia legs keep running
the test, so the regression coverage #23946 added stays in place.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NsWEWZN3E2AtwQm7UU1cFm
(cherry picked from commit c0ce315)

# Conflicts:
#	src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ListViewBase.cs
kazo0 added a commit that referenced this pull request Aug 9, 2026
…6.7/pr-24012

fix(hr): don't block hot reload on non-fatal source-generator errors (backport #24012)
dr1rrb pushed a commit that referenced this pull request Aug 10, 2026
#24012 suppresses source-generator errors for the EnC emit so a non-fatal
generator error degrades to stale generated output instead of freezing hot
reload. It reports them to the console, but `diagnostics` is then assigned
`emitDiagnostics` outright, so they never reach the operation consumers see.

That loses the only actionable message for the file the user just edited.
Invalid XAML reports UXAML0001 among the generator errors, while the emit —
handed a degraded generated tree — reports a rude edit such as
ENC0020 "Renaming method 'IMainPage_Bindings.UpdateResources()' requires
restarting the application", naming generated code the user never wrote.
Consumers were shown only the misleading half.

Carry the suppressed generator errors alongside the emit diagnostics. No
dedup is required, unlike the compilation-error FIXME below it: generator
diagnostics never appear in compilation.GetDiagnostics(), so they cannot
already be present in emitDiagnostics. They are also already scoped to the
change set's projects via auditedProjects.

Fixes #24022

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
dr1rrb pushed a commit that referenced this pull request Aug 11, 2026
#24012 suppresses source-generator errors for the EnC emit so a non-fatal
generator error degrades to stale generated output instead of freezing hot
reload. It reports them to the console, but `diagnostics` is then assigned
`emitDiagnostics` outright, so they never reach the operation consumers see.

That loses the only actionable message for the file the user just edited.
Invalid XAML reports UXAML0001 among the generator errors, while the emit —
handed a degraded generated tree — reports a rude edit such as
ENC0020 "Renaming method 'IMainPage_Bindings.UpdateResources()' requires
restarting the application", naming generated code the user never wrote.
Consumers were shown only the misleading half.

Carry the suppressed generator errors alongside the emit diagnostics. No
dedup is required, unlike the compilation-error FIXME below it: generator
diagnostics never appear in compilation.GetDiagnostics(), so they cannot
already be present in emitDiagnostics. They are also already scoped to the
change set's projects via auditedProjects.

Fixes #24022

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
(cherry picked from commit 67e44b2)
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.

5 participants