Skip to content

Document async validation cancellation contract - #132794

Merged
ViveliDuCh merged 2 commits into
mainfrom
docs/async-validation-cancellation-contract
Aug 27, 2026
Merged

Document async validation cancellation contract#132794
ViveliDuCh merged 2 commits into
mainfrom
docs/async-validation-cancellation-contract

Conversation

@ViveliDuCh

Copy link
Copy Markdown
Member

Summary

  • Document that AsyncValidationAttribute implementations must observe cancellation promptly.
  • Explain that ignoring cancellation can delay validation failure and short-circuiting because started validation tasks are awaited before returning.
  • Document timeout-configured cancellation tokens for callers that need to bound validation time.

This is the documentation follow-up requested in #132705 (comment).

Testing

  • build.cmd clr+libs -rc Release
  • dotnet.cmd build src\libraries\System.ComponentModel.Annotations\src\System.ComponentModel.Annotations.csproj
  • System.ComponentModel.Annotations.Tests: 984 passed
  • Microsoft.Extensions.Options.Tests: 335 passed
  • Microsoft.Extensions.Options.SourceGeneration.Tests: 136 passed
  • Microsoft.Extensions.Options.SourceGeneration.Unit.Tests: 185 passed, 1 skipped

Note

This pull request description was generated with GitHub Copilot.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: c5c574e4-16c6-4f14-9125-3cd4120763df
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-componentmodel-dataannotations
See info in area-owners.md if you want to be subscribed.

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

Documents the cancellation/short-circuiting contract for AsyncValidationAttribute async validation so implementers understand they must observe cancellation promptly, and callers understand how to bound validation duration.

Changes:

  • Add <remarks> to IsValidAsync documenting that implementations must stop promptly when cancellation is requested, and that the infrastructure may cancel after a failure and awaits started tasks.
  • Add <remarks> to GetValidationResultAsync describing the same behavior for derived implementations and suggesting timeout-configured cancellation tokens for callers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: c5c574e4-16c6-4f14-9125-3cd4120763df
Copilot AI review requested due to automatic review settings August 26, 2026 21:05

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 1 out of 1 changed files in this pull request and generated no new comments.

@ViveliDuCh

Copy link
Copy Markdown
Member Author

/ba-g #132830 (pre-existing known issue) plus #132851, opened for the one unmatched test error. Docs-only PR, both unrelated.

@ViveliDuCh
ViveliDuCh merged commit 22d4a3b into main Aug 27, 2026
78 of 80 checks passed
@ViveliDuCh
ViveliDuCh deleted the docs/async-validation-cancellation-contract branch August 27, 2026 20:39
@ViveliDuCh

Copy link
Copy Markdown
Member Author

/backport to release/11.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0 (link to workflow run)

@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Aug 28, 2026
artl93 pushed a commit that referenced this pull request Aug 28, 2026
Backport of #132794 to release/11.0

/cc @jeffhandley @tarekgh

## Customer Impact

- [ ] Customer reported
- [x] Found internally

Async DataAnnotations validation is new in .NET 11 (#128656). The
reliability fix #132685, backported for RC2 as #132705, moves validation
task creation inside the cancel-and-await cleanup scope so no task can
outlive the public `Validator` call and keep using caller-owned state.

Review of that backport surfaced one residual edge that cannot be fixed
in code: a validator that ignores its `CancellationToken`. Because
cancellation is cooperative, cleanup must still await such a validator,
and a timeout would only trade the stall for returning while a rogue
task still uses caller-owned state. The agreed resolution was to
document the contract. This PR adds remarks on
`AsyncValidationAttribute` that implementations must observe the token,
and that callers wanting a time bound should pass one linked to a
timeout. Without it, the new scenario's cancellation contract ships
significantly incomplete in the .NET 11 API docs. The underlying need
was identified during security review.

This meets the .NET 11 bug bar as:

- A significantly incomplete scenario for a feature new in the release —
the documented cancellation contract for async DataAnnotations
validation.
- A reliability guarantee: the documented contract is what stops
implementers from reintroducing the escaped-background-work race that
#132705 fixed.

## Regression

- [ ] Yes
- [x] No

Not a regression. Async DataAnnotations validation is new in .NET 11
(#128656); this completes that new feature's documented contract rather
than restoring prior behavior.

## Testing

Documentation-only change: XML doc comment remarks on
`AsyncValidationAttribute`. No API surface, IL, or runtime behavior
changes, so there is nothing to unit-test and no new tests were added.
Verified by building `System.ComponentModel.Annotations` so the doc
comments and any `<see cref>` references resolve. Existing
`System.ComponentModel.Annotations.Tests` are unaffected.

## Risk

Minimal. The change touches only XML documentation comments in one file.
It adds no API, no code, no IL, and does not alter validation results,
task ordering, or cancellation behavior. The only review surface is
wording accuracy.

> [!NOTE]
> This pull request description was generated with GitHub Copilot.

Co-authored-by: Viviana Dueñas <50237907+ViveliDuCh@users.noreply.github.com>
Copilot-Session: c5c574e4-16c6-4f14-9125-3cd4120763df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants