GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(persistence): make persistent state operations concurrency-safe by ReubenBond · Pull Request #10255 · dotnet/orleans

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Jul 9, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Depends on #10641, which adds cancellation-token support to IGrainStorage and flows those tokens through StateStorageBridge<TState>.

Injected IPersistentState<TState> currently forwards storage operations directly, allowing reentrant grain work to overlap reads, writes, and clears against the same in-memory state and ETag. This is a frequent source of persistence races and currently requires application-level workarounds.

This change serializes storage operations inside StateStorageBridge<TState>, preserving write coalescing and allowing reads or clears to be satisfied by successful predecessor operations when the local state is already current. Because the behavior is implemented in the bridge, persistent-state injections receive concurrency-safe behavior without user code changes.

The accompanying tests cover write and clear coalescing, read satisfaction, failure recovery, ordering, ETag consistency, cancellation interactions with queued operations, and IPersistentState<TState> interface dispatch.

Microsoft Reviewers: Open in CodeFlow

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@azure-pipelines

azure-pipelines Bot commented Jul 9, 2026

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ReubenBond
ReubenBond requested a lite review from Copilot July 9, 2026 20:16
Copilot started reviewing on behalf of ReubenBond July 9, 2026 20:17
View session
@ReubenBond ReubenBond changed the title Make persistent state operations concurrency-safe fix(persistence): make persistent state operations concurrency-safe Jul 9, 2026
Copilot AI reviewed Jul 9, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this 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 makes StateStorageBridge<TState> serialize storage operations (read/write/clear) to prevent overlapping operations against the same in-memory state/ETag during reentrant grain execution, and adds targeted concurrency tests to validate coalescing and ordering behaviors.

Changes:

  • Implemented an internal queue/serialization mechanism in StateStorageBridge<TState> for read/write/clear operations, including write/clear coalescing and “read satisfied by predecessor” behavior.
  • Added cancelable waiters for IStorage.*Async(CancellationToken) without canceling the underlying queued storage operation.
  • Added a comprehensive test suite covering ordering, coalescing, failure recovery, and interface dispatch through IStorage/IPersistentState.
Show a summary per file
File Description
test/Orleans.Core.Tests/Storage/StateStorageBridgeConcurrencyTests.cs Adds concurrency-focused unit tests validating the new serialized/coalesced storage operation behavior.
src/Orleans.Runtime/Storage/StateStorageBridge.cs Serializes storage operations via an internal queued-operation tail and adds explicit IStorage cancellation-token dispatch.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 1

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/Orleans.Runtime/Storage/StateStorageBridge.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Copilot AI review requested due to automatic review settings August 17, 2026 23:00
@ReubenBond
ReubenBond force-pushed the rebond/persistent-state-concurrency-safe branch from 73ebd0d to 2c7ee4e Compare August 17, 2026 23:00
Copilot started reviewing on behalf of ReubenBond August 17, 2026 23:01
View session
Copilot AI reviewed Aug 17, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 12/12 changed files
  • Comments generated: 1
  • Review effort level: Lite

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/Orleans.Runtime/Storage/StateStorageBridge.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

ReubenBond and others added 3 commits August 17, 2026 17:14
@ReubenBond
fix: make persistent state operations concurrency safe
3b9be1e
Serialize storage reads, writes, and clears in StateStorageBridge so injected IPersistentState instances are concurrency-safe by default while preserving write coalescing.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 3536a7cc-e412-4016-a017-52640074e072
@ReubenBond
test: assert persistent state etag consistency
631a85e
Update the StateStorageBridge concurrency tests so successful write and clear operations assign fresh pseudo-random ETags and the scheduling tests assert the resulting ETag behavior.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 3536a7cc-e412-4016-a017-52640074e072
@ReubenBond
test(persistence): align concurrency cancellation coverage
09964a7
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 96fb7f2b-cc70-4b64-b137-da3b83c1e1bd
@ReubenBond
ReubenBond force-pushed the rebond/persistent-state-concurrency-safe branch from 2c7ee4e to 09964a7 Compare August 18, 2026 00:17
@ReubenBond
docs(persistence): remove redundant cancellation guidance
efd1e6f
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 96fb7f2b-cc70-4b64-b137-da3b83c1e1bd
Copilot AI review requested due to automatic review settings August 18, 2026 00:18
Copilot started reviewing on behalf of ReubenBond August 18, 2026 00:18
View session
@ReubenBond
fix(persistence): initialize predecessor-satisfied reads
2b8b522
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 96fb7f2b-cc70-4b64-b137-da3b83c1e1bd
Copilot AI reviewed Aug 18, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 3/3 changed files
  • Comments generated: 4
  • Review effort level: Lite

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/Orleans.Runtime/Storage/StateStorageBridge.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/Orleans.Runtime/Storage/StateStorageBridge.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread docs/site/src/content/docs/tutorials-and-samples/custom-grain-storage.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread test/Orleans.Core.Tests/Storage/StateStorageBridgeConcurrencyTests.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

Copilot AI review requested due to automatic review settings August 18, 2026 00:24
Copilot started reviewing on behalf of ReubenBond August 18, 2026 00:25
View session
@ReubenBond
ReubenBond marked this pull request as ready for review August 18, 2026 00:25
Copilot AI reviewed Aug 18, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Review details

Suppressed comments (1)

docs/site/src/content/docs/tutorials-and-samples/custom-grain-storage.md:34

  • The tutorial no longer mentions the CancellationToken overloads on IGrainStorage operations (added in #10641). Without this, the doc implies only the cancellation-free methods are relevant, which is now inaccurate and could lead provider authors to miss cancellation propagation behavior.

Consider reintroducing a short paragraph noting that Orleans will call the CancellationToken overloads when available, and that the new overloads have default interface implementations which delegate to the existing methods (preserving compatibility).


Therefore, `stateName` and `grainState.State?.GetType().Name` aren't interchangeable. The first identifies one of a grain's logical state records and is stable independently of the payload implementation. The second is only the runtime type name of the current payload; it can be `null`, can differ from `typeof(T)` when polymorphism is involved, and can change during a refactoring. The sample uses `stateName` and `grainId` for identity and delegates payload type handling to the configured serializer.
  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ReubenBond
fix(persistence): enforce context for satisfied operations
9c86a59
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 96fb7f2b-cc70-4b64-b137-da3b83c1e1bd
Copilot AI review requested due to automatic review settings August 18, 2026 00:30
Copilot started reviewing on behalf of ReubenBond August 18, 2026 00:30
View session
Copilot AI reviewed Aug 18, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Review details

Suppressed comments (1)

src/Orleans.Runtime/Storage/StateStorageBridge.cs:150

  • When a clear coalesces with an existing queued clear (the operation = tail path), this call does not perform any runtime-context validation. A non-activation thread can therefore call ClearStateAsync() during the coalescing window and receive a successfully-completing Task, bypassing the intended "Activation access violation" guard.
        private Task ClearStateInternalAsync(CancellationToken cancellationToken)
        {
            QueuedStorageOperation operation;

            lock (_storageOperationLock)
            {
                if (!cancellationToken.CanBeCanceled
                    && _storageOperationTail is { Kind: StorageOperationKind.Clear, Started: false, CanBeCanceled: false } tail)
                {
                    operation = tail;
                }
                else
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/Orleans.Runtime/Storage/StateStorageBridge.cs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@ReubenBond
test(transactions): execute storage wrapper on scheduler
5768669
Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 96fb7f2b-cc70-4b64-b137-da3b83c1e1bd
Copilot AI review requested due to automatic review settings August 18, 2026 01:18
Copilot started reviewing on behalf of ReubenBond August 18, 2026 01:19
View session
Copilot AI reviewed Aug 18, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 4/4 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
This was referenced Sep 7, 2026
Bump the orleans group with 10 updates bartul/agave#87
Merged
Bump the dotnet group with 5 updates dotnet/docs#55908
Merged
Bump the dotnet group with 4 updates dotnet/docs#55909
Merged
Bump the dotnet group with 4 updates dotnet/docs#55910
Merged
Bump the dotnet group with 5 updates dotnet/docs#55911
Merged
Bump the dotnet group with 4 updates IvanMarkitan/dotnet-docs#838
Closed
Bump the dotnet group with 6 updates IvanMarkitan/dotnet-docs#839
Closed
Bump the dotnet group with 7 updates IvanMarkitan/dotnet-docs#840
Closed
Bump Microsoft.Orleans.Sdk and Microsoft.Orleans.Server IvanMarkitan/dotnet-docs#843
Open
Bump Microsoft.Orleans.Clustering.Redis and 4 others IvanMarkitan/dotnet-docs#845
Closed
Bump the dotnet group with 7 updates IvanMarkitan/dotnet-docs#846
Open
Bump the dotnet group with 5 updates BillWagner/docs#9804
Closed
Bump the dotnet group with 4 updates BillWagner/docs#9805
Closed
Bump the dotnet group with 4 updates BillWagner/docs#9806
Closed
Bump the dotnet group with 5 updates BillWagner/docs#9807
Closed
Bump the dotnet group with 7 updates zbalkan/docs#2339
Closed
Bump the dotnet group with 5 updates zbalkan/docs#2340
Closed
Bump the dotnet group with 6 updates zbalkan/docs#2341
Closed
Bump the dotnet group with 10 updates zbalkan/docs#2347
Open
@ReubenBond ReubenBond mentioned this pull request Sep 13, 2026
Mitigate usability issues with timers & Grain reentrancy #8320
Closed
This was referenced Sep 14, 2026
chore(deps): Bump the nuget-patch-and-minor group with 25 updates petesramek/microservices-vs-virtual-actors#9
Closed
chore(deps): Bump Meziantou.Analyzer and 12 others petesramek/microservices-vs-virtual-actors#10
Closed
chore: Bump ManagedCode.Orleans.RateLimiting.Server and 4 others managedcode/Communication#160
Closed
Bump the dotnet group with 4 updates IvanMarkitan/dotnet-docs#869
Open
Bump the dotnet group with 6 updates IvanMarkitan/dotnet-docs#870
Open
Bump the dotnet group with 7 updates IvanMarkitan/dotnet-docs#877
Open
Bump the dotnet group with 7 updates zbalkan/docs#2373
Open
Bump the dotnet group with 5 updates zbalkan/docs#2377
Open
Bump the dotnet group with 6 updates zbalkan/docs#2393
Open
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@ReubenBond
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.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.