Repository navigation
Recognize safely completed Task results in VSTHRD103 - #1647
Merged
Andrew Arnott (AArnott) merged 1 commit intoAug 22, 2026
Merged
Conversation
Share conservative Task completion analysis between VSTHRD103 and VSTHRD104. Suppress Result diagnostics for stable IsCompletedSuccessfully guards and the actual antecedent parameter of BCL Task.ContinueWith callbacks, while retaining diagnostics across writes, aliases, captured storage, and deferred execution boundaries. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR improves the C# analyzers for VSTHRD103 and VSTHRD104 by recognizing additional patterns where Task<TResult>.Result access is guaranteed not to block, specifically when the task is conservatively proven completed (e.g., guarded by IsCompletedSuccessfully) and for the antecedent parameter inside BCL Task.ContinueWith callbacks.
Changes:
- Introduces a shared
TaskCompletionAnalysishelper to conservatively prove completion atResultaccess sites. - Updates VSTHRD103 and VSTHRD104 analyzers to suppress diagnostics for proven-safe
Task.Resultaccess (includingContinueWithantecedent usage). - Adds targeted regression tests covering guarded completion, reassignment/ref aliasing, loop backedges, local function mutation, and deferred query scenarios.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/TaskCompletionAnalysis.cs | Adds shared conservative completion-proof logic for safe Task.Result access. |
| src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/VSTHRD103UseAsyncOptionAnalyzer.cs | Uses TaskCompletionAnalysis to suppress VSTHRD103 when Result is proven non-blocking. |
| src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/VSTHRD104OfferAsyncOptionAnalyzer.cs | Uses TaskCompletionAnalysis to suppress VSTHRD104 when Result is proven non-blocking. |
| test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD103UseAsyncOptionAnalyzerTests.cs | Adds coverage for the new suppression/proof behavior and conservative non-suppression cases. |
| test/Microsoft.VisualStudio.Threading.Analyzers.Tests/VSTHRD104OfferAsyncOptionAnalyzerTests.cs | Adds regression tests ensuring conservative behavior is preserved for tricky mutation/ref/loop cases. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Oleg Tkachenko (olegtk)
approved these changes
Aug 22, 2026
Andrew Arnott (AArnott)
deleted the
aarnott-fix-vsthrd103-flow-suppressions
branch
August 22, 2026 02:57
This was referenced Oct 26, 2026
Merged
Open
Closed
Bump the dev-minor-patch group with 16 updates
actions-marketplace-validations/macalbert_envilder#47
Open
Open
Open
Open
This was referenced Oct 30, 2026
Closed
This was referenced Nov 6, 2026
Open
Open
Open
Open
This was referenced Nov 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Task.Resultwhen the same stable task is proven complete byIsCompletedSuccessfullyResulton the actual antecedent parameter of a BCLTask.ContinueWithcallbackFixes #1125
Fixes #680
Issue #1480
This does not globally suppress EF Core
DbSet.AddRange. EF Core documents thatAddRangeAsyncis required for special asynchronous value generators, so the analyzer cannot determine from the call site whether the synchronous operation is appropriate. A built-in suppression would hide valid VSTHRD103 diagnostics. Projects that do not use such generators can use the existingvs-threading.SyncMethodsToExcludeFromVSTHRD103.txtconfiguration with:References #1480.
Validation
Microsoft.VisualStudio.Threading.Analyzers.Testssuite acrossnet472,net8.0, andnet8.0-windows