Skip to content

Conversation

tmat
Copy link
Member

@tmat tmat commented Oct 1, 2025

Description

Implements support for auto-restart when runtime rude edit is encountered.
Fixes #48515

Background

Certain Hot Reload edits are applied speculatively - the compiler emits two code paths gated by a runtime check. If the expected code path is executed the edit works as the user intended (the executed code matches the source code) and the application continues executing flawlessly. The other code path throws HotReloadException with message that explains why the edit failed.

Examples of such edits include renaming a method, changing method signature, changing lambda signature, changing lambda closure, etc. In these cases a new method or lambda is emitted that matches the code, but the application may still hold onto a delegate to the previous version of the method. If such no longer valid delegate is invoked the HotReloadException is thrown.

Change

In this change, the Hot Reload agent loaded into the application process hooks into the HotReloadException constructor via a hook added by dotnet/roslyn#79790 when the HotReloadException is emitted into the delta. The exception construction is intercepted, a notification is sent to the host (dotnet-watch/VS/VS Code) and the current thread is suspended (to avoid throwing the exception). When the host receives the notification it triggers auto-restarts of the process.

The change refactors the pipe communication to allow for sending the rude edit notification at arbitrary time. Previously the pipe expected serialized sequence of request - response messages. Instead, we now asynchronously read incoming messages in a loop and trigger the corresponding action based on the response type received.

Before

RRE_Before

After

RRE_After

Customer Impact

Impacts Hot Reload scenarios for all types of projects but especially Aspire and web app scenarios.

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Justification: The impact is limited to dotnet-watch.

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

@tmat tmat force-pushed the RuntimeRudeEdits branch from 5bf4441 to 6e29a9f Compare October 1, 2025 19:19
@tmat tmat marked this pull request as ready for review October 1, 2025 19:34
@tmat tmat requested a review from a team as a code owner October 1, 2025 19:34
@tmat
Copy link
Member Author

tmat commented Oct 1, 2025

@DustinCampbell ptal

Copy link
Member

@DustinCampbell DustinCampbell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pretty cool way to solve this problem. Just had a few questions.

@tmat tmat changed the title Auto-restart project on runtime rude edit [dotnet-watch] Auto-restart project on runtime rude edit Oct 3, 2025
@tmat
Copy link
Member Author

tmat commented Oct 3, 2025

Requires #51032

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.

2 participants