Skip to content

Conversation

@ReubenBond
Copy link
Member

@ReubenBond ReubenBond commented Dec 17, 2025

Adds a new Roslyn analyzer that warns when grain code uses ConfigureAwait(false) or ConfigureAwait(ConfigureAwaitOptions) without the ContinueOnCapturedContext flag.

Grains must maintain their execution context to ensure proper execution within the grain's activation context. Using ConfigureAwait(false) or ConfigureAwait without ContinueOnCapturedContext can cause the continuation to run outside the grain's context, leading to concurrency issues and loss of grain identity.

To make it easier for developers to stay in the pit of success, this PR introduces a new analyzer ORLEANS0014 (Warning severity) detects problematic ConfigureAwait usage in grain classes.
It includes a code fix that automatically:

  • Converts ConfigureAwait(false) to ConfigureAwait(true)
  • Converts ConfigureAwait(ConfigureAwaitOptions.None) to ConfigureAwait(ConfigureAwaitOptions.ContinueOnCapturedContext)
  • Adds ContinueOnCapturedContext flag to other ConfigureAwaitOptions combinations

The analyzer applies to classes implementing IGrain or ISystemTarget. We could extend it to IAddressable, but I am being conservative for now since IGrainObserver implementations do not strictly require this. It applies to ConfigureAwait calls on Task, Task<T>, ValueTask, ValueTask<T>, IAsyncEnumerable<T>

Microsoft Reviewers: Open in CodeFlow

Copilot AI review requested due to automatic review settings December 17, 2025 04:55
Copy link
Contributor

Copilot AI left a comment

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 adds a new Roslyn analyzer (ORLEANS0014) that detects and warns against problematic ConfigureAwait usage in grain code. Grains must maintain their execution context to ensure proper execution within the grain's activation context. Using ConfigureAwait(false) or ConfigureAwait without the ContinueOnCapturedContext flag can cause continuations to run outside the grain's context, leading to concurrency issues.

Key changes:

  • New analyzer detects ConfigureAwait(false) and ConfigureAwait(ConfigureAwaitOptions) without ContinueOnCapturedContext in grain classes
  • Code fix provider automatically converts ConfigureAwait(false) to ConfigureAwait(true) or adds the ContinueOnCapturedContext flag to ConfigureAwaitOptions
  • Applies to classes implementing IGrain or ISystemTarget interfaces

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Orleans.Analyzers/ConfigureAwaitAnalyzer.cs New analyzer implementation that detects problematic ConfigureAwait usage in grain classes
src/Orleans.Analyzers/ConfigureAwaitCodeFix.cs Code fix provider that automatically corrects ConfigureAwait issues
src/Orleans.Analyzers/SyntaxHelpers.cs Adds IsGrainClass extension method for detecting grain classes
src/Orleans.Analyzers/Constants.cs Adds new constants for IGrainBase, IGrain, and ISystemTarget fully qualified names
src/Orleans.Analyzers/Resources.resx Adds resource strings for analyzer title, message, description, and code fix title
src/Orleans.Analyzers/Resources.Designer.cs Auto-generated resource accessor properties for the new analyzer messages
src/Orleans.Analyzers/AnalyzerReleases.Unshipped.md Documents the new ORLEANS0014 analyzer rule
test/Analyzers.Tests/ConfigureAwaitAnalyzerTest.cs Comprehensive test suite covering analyzer and code fix behavior across various scenarios
src/Orleans.Streaming/PersistentStreams/PersistentStreamPullingAgent.cs Applies the analyzer fix by adding ContinueOnCapturedContext flag
src/Orleans.Runtime/Placement/Repartitioning/ActivationRepartitioner.MessageSink.cs Applies the analyzer fix by adding ContinueOnCapturedContext flag
Files not reviewed (1)
  • src/Orleans.Analyzers/Resources.Designer.cs: Language not supported

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.

1 participant