Skip to content

fix(core): construct grain references without dynamic code - #11371

Merged
ReubenBond merged 3 commits into
dotnet:mainfrom
ReubenBond:rb-nativeaot-grain-references
Oct 2, 2026
Merged

ReubenBond merged 3 commits into
dotnet:mainfrom
ReubenBond:rb-nativeaot-grain-references

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Production GrainReferenceActivatorProvider unconditionally emits a DynamicMethod, so NativeAOT reference construction throws even when the generated proxy constructor has been preserved.

Use a cached ConstructorInvoker when dynamic code is unavailable, and retain the existing emitted constructor delegate on JIT runtimes. Generated AddInterfaceProxy registrations provide the static constructor/interface roots; narrowly scoped annotations document the collection-to-activation boundary. Constructor failures continue to propagate directly, and explicitly preserved non-public proxy constructors remain supported. These constructors are selected by runtime proxy metadata, so the native branch uses cached reflection; future generated context factories can bind constructors statically.

Add focused production-provider cases in the existing Orleans.Core.Tests project and a GrainReferences scenario in the shared reusable Orleans.NativeAotSmoke harness. The scenario covers generated inherited interfaces, grain keys, interface version, shared dependency identity, invocation options, and constructor failures.

The shared harness and centralized discovery runner from #11367 are now merged into main. GrainReferences.smoke.json registers this feature with the existing Windows/Linux NativeAOT matrix. Its legacy-visible policy retains broader library AOT diagnostics and rejects warnings or errors from the production constructor path and proxy interface discovery. This feature contributes scenario source and metadata with no workflow or runner changes. The merged runner discovers both grain-reference platforms and successfully publishes, gates diagnostics, and executes this branch's win-x64 native scenario.

The verified capability is runtime-selected, non-generic production grain-reference construction. The actual production path reproduces the original DynamicMethod failure before the fix and succeeds natively afterward. The scenario supplies real TypeConverter and CodecProvider dependencies with empty payload manifests to isolate construction from serializer manifest startup, tracked in #11368. Generic proxy closure, payload serialization, and full client/silo startup retain their separate NativeAOT requirements.

Microsoft Reviewers: Open in CodeFlow

Copilot AI balanced review requested due to automatic review settings October 1, 2026 16:02

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

🟢 Approval recommended

The implementation preserves JIT behavior while adding focused NativeAOT handling, diagnostics, and comprehensive coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Enables grain-reference construction under NativeAOT without changing the optimized JIT path.

Changes:

  • Uses cached ConstructorInvoker instances when dynamic code is unavailable.
  • Adds JIT and NativeAOT coverage for proxy construction and failure behavior.
  • Adds CI validation and implementation documentation.
File Description
.github/​workflows/​analyzer-audit.yml Adds cross-platform NativeAOT smoke jobs.
docs/​site/​src/​content/​docs/​implementation/​serialization.md Documents proxy construction paths.
src/​Orleans.Core/​GrainReferences/​GrainReferenceActivator.cs Adds the NativeAOT-compatible constructor path.
src/​Orleans.Core/​Orleans.Core.csproj Exposes internals to the smoke executable.
test/​Orleans.Core.Tests/​GrainReferences/​GrainReferenceActivatorTests.cs Tests construction behavior and failures.
test/​Orleans.Core.Tests/​Orleans.Core.Tests.csproj Links the shared fixture into unit tests.
test/​Orleans.GrainReferences.NativeAotSmoke/​Orleans.GrainReferences.NativeAotSmoke.csproj Defines the NativeAOT executable.
test/​Orleans.GrainReferences.NativeAotSmoke/​Program.cs Exercises construction under NativeAOT.
test/​Orleans.GrainReferences.NativeAotSmoke/​README.md Explains smoke-test scope and usage.
test/​Orleans.GrainReferences.NativeAotSmoke/​ReferenceConstructionFixture.cs Provides shared production-provider fixtures.

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

Copilot AI balanced review requested due to automatic review settings October 1, 2026 16:13

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

🟢 Approval recommended

The implementation is focused, comprehensively covered, and both NativeAOT platform jobs pass.

Review effort: Balanced
Findings: None

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Code coverage

Metric Pull request Current main Variance
Lines 82.84% (115,407 / 139,310) 82.88% (115,459 / 139,303) -0.0415 pp
Branches 72.18% (33,507 / 46,421) 72.19% (33,510 / 46,419) -0.0096 pp

Report-only conclusion: regressed.

The current-main baseline is commit cc1a9ff176 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

Copilot AI balanced review requested due to automatic review settings October 1, 2026 17:09

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

🟡 Changes recommended

The new GrainReferences NativeAOT scenario is not currently discovered or executed by CI.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)

Comment thread test/Orleans.NativeAotSmoke/GrainReferences.smoke.json
Copilot AI balanced review requested due to automatic review settings October 1, 2026 23:49
@ReubenBond
ReubenBond force-pushed the rb-nativeaot-grain-references branch from 26c2a6c to 73e65b6 Compare October 1, 2026 23:49

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

🟢 Approval recommended

The fallback is narrowly scoped, preserves existing JIT behavior, and has focused unit and cross-platform NativeAOT coverage.

Review effort: Balanced
Findings: None

Resolved since last review (1)

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.

2 participants