Skip to content

feat(runtime): add shared grain activation setup - #11305

Merged
ReubenBond merged 1 commit into
dotnet:mainfrom
ReubenBond:rb-feat-grain-lifecycle-composition
Sep 17, 2026
Merged

ReubenBond merged 1 commit into
dotnet:mainfrom
ReubenBond:rb-feat-grain-lifecycle-composition

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Problem

Grain-scoped features need a composition point after the grain is fully constructed and before lifecycle startup. Providers currently own individual enrollment paths, and a reusable integration can otherwise require a feature-specific grain base class or an extra scoped registrar for every activation.

Solution

Add GrainTypeSharedContext.AddActivationSetup(Action<IGrainContext>). Existing IConfigureGrainTypeComponents implementations select applicable grain classes once while configuring a shared context, then compose reusable setup actions. Each activation invokes that cached plan after GrainInstance is assigned and creation accounting completes, before the grain object's lifecycle participation and lifecycle startup. Setup registration closes when shared configuration completes.

The actions run in registration order and can explicitly resolve activation-scoped state or enroll existing ILifecycleParticipant<IGrainLifecycle> implementations. Shared actions can execute concurrently across activations; actual feature state stays in the activation scope. Custom grain activators and individual stateless workers use the same boundary. Setup failures follow normal activation failure and disposal handling.

Compatibility and rationale

Existing concrete, keyed, participant-interface, and manually enrolled DI registrations retain their current behavior. Applicability and shared setup are explicit; the runtime adds no service sweep, per-activation registrar, participant array, or identity set. Activations without setup take a null-delegate fast path. Existing grain-object participation, migration, and lifecycle stage ordering are preserved.

Includes focused activation coverage, generated API surface, and a compiled documentation example selecting grain classes by an application-owned interface. This is the runtime prerequisite for the separate composition-based Journaling work and replacement of #11279; Journaling source changes remain in that follow-up.

Microsoft Reviewers: Open in CodeFlow

Copilot AI lite review requested due to automatic review settings September 17, 2026 17:53

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.

Copilot review overview

🔵 Needs a closer look

The runtime lifecycle changes are broad and warrant final human review.

Review effort: Lite
Findings: None

What changed in this PR

Adds grain-scoped activation setup composition before lifecycle startup.

Changes:

  • Adds cached, ordered activation setup actions.
  • Integrates setup across activation paths and lifecycle handling.
  • Adds tests, API metadata, and documentation examples.
File Summary
test/​Orleans.Runtime.Internal.Tests/​ActivationsLifeCycleTests/​ActivationDataLifecycleTests.cs Adds coverage for ordering, failures, scopes, and stateless workers.
src/​Orleans.Runtime/​Catalog/​GrainTypeSharedContext.cs Adds setup registration and configuration sealing.
src/​Orleans.Runtime/​Catalog/​ActivationData.cs Runs setup during activation construction.
src/​Orleans.Runtime/​Activation/​IGrainContextActivator.cs Completes shared-context configuration.
src/​api/​Orleans.Runtime/​Orleans.Runtime.cs Updates the generated API surface.
docs/​site/​src/​content/​docs/​snippets/​compiled/​Grains/​GrainSnippets.cs Adds a compiled setup example.
docs/​site/​src/​content/​docs/​implementation/​orleans-lifecycle.md Documents activation composition; use “registration order” terminology.
docs/​site/​src/​content/​docs/​grains/​grain-lifecycle.md Adds shared activation setup guidance.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@ReubenBond ReubenBond changed the title feat(runtime): support grain-scoped lifecycle participants feat(runtime): add shared grain activation setup Sep 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Code coverage

Metric Pull request Current main Variance
Lines 82.20% (112,425 / 136,768) 82.23% (112,462 / 136,757) -0.0337 pp
Branches 71.47% (32,425 / 45,369) 71.48% (32,425 / 45,365) -0.0063 pp

Report-only conclusion: regressed.

The current-main baseline is commit ad71848f84 and uses the same reviewed coverage matrix.

Coverage combines every CI test matrix job, including providers, CodeGen, .NET 8/10, Linux, Windows, and macOS, using canonical physical source and branch identities.

The comparison remains report-only while normal line and branch variance is calibrated.

Coverage details

@ReubenBond
ReubenBond merged commit 9303d4e into dotnet:main Sep 17, 2026
73 checks passed
@ReubenBond
ReubenBond deleted the rb-feat-grain-lifecycle-composition branch September 17, 2026 20:03
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants