Skip to content

fix(hr): never commit a rejected rude edit - #25499

Closed
kazo0 wants to merge 1 commit into
masterfrom
dev/steve/hr-rude-edit-commit
Closed

kazo0 wants to merge 1 commit into
masterfrom
dev/steve/hr-rude-edit-commit

Conversation

@kazo0

@kazo0 kazo0 commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #25378

PR Type:

🐞 Bugfix

What changed? 🚀

Current behavior. After one rude edit (e.g. ENC0014, adding an interface to a class's base list), the DevServer never recovers until the app restarts. Every later C# edit is reported Success but the app applies nothing, and reverting the rude edit is itself reported as a rude edit.

Root cause. On the Roslyn 5.6 the host embeds, EditSession reports a blocking rude edit as ModuleUpdateStatus.Ready, with the project in ProjectsToRebuild (the UnitTesting API passes no running projects). UnitTestingHotReloadService.EmitSolutionUpdateAsync commits every Ready result before it checks for errors. CommitSolutionUpdate then:

  • adopts the rejected text as the committed solution, so the revert diffs against it and is rude (ENC0014 + ENC0033);
  • discards the project's emit baselines, so the next emit restarts at generation 0 from the on-disk DLL while the app is at generation N, and the app rejects the delta. On a fresh host (N = 0) the restart matches the app, which is why the issue saw a fresh host recover.

Roslyn 4.14 isn't affected: it reports a rude edit as RestartRequired/Blocked and never commits it.

Fix. WatchHotReloadService.EmitSolutionUpdateAsync now emits with commitUpdates: false first, and re-emits with commitUpdates: true only when the result has updates and no errors. A result with errors is never committed. The cost is a second emit on successful updates; analyses are cached, so only the delta emit runs again (not measured). If it shows up, the upgrade path is binding IEditAndContinueService.Commit/DiscardSolutionUpdate directly.

Validation.

  • New Given_WatchHotReloadService_RudeEdit drives the real Roslyn EnC pipeline: applied update → rude edit → rude edit plus a benign change (must still be rude) → revert plus a benign change (must apply). It fails without the fix at the issue's R2 step and passes with it.
  • Uno.HotReload.Tests and Given_HotReloadService (XAML metadata updates, same shim) pass on net10.0 (Roslyn 5.6). They weren't run on net11.0 (no .NET 11 SDK locally).
  • The issue's R1→R5 sequence against a live DevServer and app hasn't been rerun yet. Run it on a host that has already applied at least one update, because a fresh host hides the bug. The InternalError streaks described in the issue are expected to share this cause but weren't reproduced.

PR Checklist ✅

🤖 Generated with Claude Code

https://claude.ai/code/session_01VeCSvPDzotdW75dHUPyYcf

Roslyn 5.x reports a blocking rude edit as a Ready update (project to
rebuild), and UnitTestingHotReloadService commits it before checking
for errors. The commit adopts the rejected text and discards the
project's emit baseline, so the revert is itself rude and later deltas
restart at generation 0 while the app is at generation N.

Emit without committing first, and re-emit with commit only when the
update is clean.

Fixes #25378

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VeCSvPDzotdW75dHUPyYcf
Copilot AI balanced review requested due to automatic review settings October 14, 2026 19:38

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.

🔵 Needs a closer look

It changes behavior in a reflection-based Roslyn EnC shim across multiple Roslyn versions, and the author notes the live DevServer end-to-end sequence and net11.0 path were not re-validated, so a human should confirm no subtle EnC regression.

0 open findings

What changed in this PR

This PR fixes a Hot Reload DevServer bug (#25378) where a single rude edit (e.g. ENC0014 adding an interface to a base list) permanently poisons the EnC session until the app restarts. The root cause is that Roslyn 5.x reports a blocking rude edit as a Ready module update with the project marked for rebuild, and the previous shim always emitted with commitUpdates: true, so the rejected text was adopted as the committed baseline and the project's emit baselines were discarded — causing every subsequent delta to restart at generation 0 while the app sits at generation N.

Changes:

  • WatchHotReloadService.EmitSolutionUpdateAsync now emits once with commitUpdates: false, and only re-emits with commitUpdates: true when the result has updates and no error diagnostics — so rude edits and errored results are never committed.
  • The reflection delegate signature and a new private EmitAsync helper were introduced to carry the explicit commitUpdates flag; the XML doc and an outdated HotReloadManager comment were updated to match the new "commit only clean updates" behavior.
  • Added Given_WatchHotReloadService_RudeEdit which drives the real Roslyn EnC pipeline (applied → rude → still-rude → revert) to prove a rejected rude edit is not committed and that reverting returns to the last applied update.
File Description
src/​Uno.HotReload/​Microsoft/​WatchHotReloadService.cs Adds a commitUpdates flag to the emit delegate and splits emit into a non-committing probe plus a committing re-emit that runs only for clean updates.
src/​Uno.HotReload/​HotReloadManager.cs Updates a stale comment that assumed emit always advances the EnC baseline as a side effect.
src/​Uno.HotReload.Tests/​Microsoft/​Given_WatchHotReloadService.RudeEdit.cs New test validating a rude edit stays rejected/uncommitted and that reverting returns to the last applied update.

No blocking issues were found: the public EmitSolutionUpdateAsync(Solution, CancellationToken) signature and its IWatchHotReloadService contract are unchanged, all _emitSolutionUpdateAsync references were updated consistently, and the new test follows the existing Given_WatchHotReloadService.References conventions and compiles cleanly under the project's ImplicitUsings/Nullable settings.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@dr1rrb

dr1rrb commented Oct 14, 2026

Copy link
Copy Markdown
Member

Heads-up: this is the same root cause I hit in #24085. On Roslyn 5.x a rude edit comes back as Ready with zero updates and the project in ProjectsToRebuild, so UnitTestingHotReloadService commits the rejected solution as the baseline of the next emit.

#24085 addresses it more broadly. Instead of emitting twice through the UnitTesting wrapper, EnCEngine drives the EnC service directly with the policy the 4.x Watch API used: commit exactly when deltas are delivered to the app, discard otherwise. It also surfaces ProjectsToRebuild/ProjectsToRestart through HotReloadEmitResult, which the wrapper drops, so the host can tell a clean cycle from a rejected one. It is covered by the MetadataUpdate scenario suite re-enabled in #24072: 8 scenarios go green without touching a single expectation.

It needs a rebase on master, but it would be worth checking whether it covers #25378 before landing a narrower fix for the same bug.

@unodevops

Copy link
Copy Markdown
Contributor

@kazo0

kazo0 commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #24085, which fixes the same root cause (Roslyn 5.x commits a rejected rude edit through UnitTestingHotReloadService) with a single emit and an explicit commit/discard instead of the double emit here. #24085 is rebased on master and now closes #25378; the test from this PR moved there as When_EditedWhileRudeEditPending_Then_StaysRejectedUntilReverted.

@kazo0 kazo0 closed this Oct 14, 2026
@kazo0
kazo0 deleted the dev/steve/hr-rude-edit-commit branch October 14, 2026 20:38
@unodevops

Copy link
Copy Markdown
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants