Skip to content

fix(journaling): resolve trimming and NativeAOT warnings - #11513

Merged
ReubenBond merged 8 commits into
dotnet:mainfrom
ReubenBond:rb-fix-journaling-aot-warnings
Oct 17, 2026
Merged

ReubenBond merged 8 commits into
dotnet:mainfrom
ReubenBond:rb-fix-journaling-aot-warnings

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Problem

With the trim, AOT, and single-file analyzers enabled (the repository's compatibility analyzer audit), the journaling and durable jobs code on main reports 14 warnings:

Project Warnings
Orleans.Journaling IL2026/IL3050 JsonSerializerOptions.Default; IL2091 Activator.CreateInstance<T>(); IL2091 ×2 IOptions<TOptions>/IOptionsMonitor<TOptions>
Orleans.DurableJobs IL2026 ×2 DiagnosticSource.Write<T>
Orleans.Journaling.AzureStorage IL2026/IL3050 ×2 reflection-based JsonSerializer; IL2026/IL3050 ConfigurationBinder.Bind
Orleans.Journaling.Redis, Orleans.Journaling.S3, Orleans.DurableJobs.AzureStorage none

Solution

  • JournaledPersistentState<T> creates default state through the serializer's IActivatorProvider, which is the pattern StateStorageBridge<TState> uses for classic IPersistentState<T>. Annotating T instead would be a false fix. The type is registered as an open-generic implementation of the unannotated IPersistentState<>, and DI's VerifyOpenGenericServiceTrimmability check (on by default in trimmed apps) rejects implementation generic parameters whose annotations the service type lacks. As a result, journaled persistent state now matches classic persistent state for state types without a parameterless constructor (for example, positional records). Before this change, those types threw MissingMethodException.
  • CodecProvider.GetActivator<T>() returns a DefaultNullableActivator<T> for Nullable<T>, which creates null, the same result as Activator.CreateInstance<T?>(). Previously it selected DefaultValueTypeActivator<T?>, which violates that type's struct constraint, so both journaled and classic IPersistentState<int?> failed to construct. Like the other default activators, it is rooted with DynamicDependency, and the serialization trimmed smoke covers all three default activators.
  • JSON journal codecs constructed with options: null keep using JsonSerializerOptions.Default, behind one accessor with a scoped suppression. Trimmed and NativeAOT publishing disables System.Text.Json reflection. With reflection disabled, JsonSerializerOptions.Default uses an empty type-info resolver, so missing metadata surfaces as the existing configuration error.
  • Azure Table journal metadata uses a source-generated JsonSerializerContext. The stored JSON is unchanged; a new test pins the wire format.
  • AzureTableStorageJournalingProviderBuilder reads each configurable member of AzureTableJournalStorageOptions and its nested ClientOptions (EnableTenantDiscovery, Retry, Diagnostics) with ConfigurationBinder.GetValue. On net10.0, the project enables the configuration-binding source generator, which binds these values without reflection. Like Bind, invalid values throw InvalidOperationException. The generator can't bind these four types as objects: they expose client instances, pipeline policies and delegates, and the Azure option types lack public constructors. For them it reports SYSLIB1100/SYSLIB1101, which #pragma, [SuppressMessage] and .editorconfig can't suppress at a call site. When the ClientOptions section is present, the builder creates TableClientOptions if it isn't already set. net8.0 uses the reflection-based binder for the same calls.
  • DurableJobsEvents writes every payload through one private helper. The helper constrains TEvent to the event base type and annotates it with PublicFields | PublicProperties, which is a superset of what DiagnosticSource.Write<T> requires. A single justified IL2026 suppression covers it. DiagnosticSource.Write is unconditionally [RequiresUnreferencedCode], so keeping DiagnosticListener requires this one suppression.
  • GetJournalStorageOptions<TOptions> carries the PublicParameterlessConstructor requirement through to IOptions<TOptions>/IOptionsMonitor<TOptions>.
  • Regression gate: each of the six project files enables the trim, AOT, and single-file analyzers on net10.0. With TreatWarningsAsErrors, any new warning fails the build.

Rationale

  • These projects aren't marked IsAotCompatible. That property also stamps the assemblies as trimmable, so ILLink would trim them in the default partial mode. Their required Orleans.Core/Orleans.Runtime dependencies still carry unresolved trimming and AOT warnings, and the NativeAOT smoke scenarios don't exercise journaling. Enabling the analyzers stops regressions in this code without claiming end-to-end AOT support.
  • No public API changes: every changed member is internal or private, and Release pack package validation passes for the changed packages.
Microsoft Reviewers: Open in CodeFlow

Copilot AI balanced review requested due to automatic review settings October 15, 2026 19:26

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.

🟡 Changes recommended

Eager activator resolution breaks nullable persistent-state creation and recovery.

1 open finding
What changed in this PR

Addresses trimming and NativeAOT analyzer warnings in journaling and durable jobs without claiming end-to-end AOT compatibility.

Changes:

  • Uses serializer activation and trim-aware JSON metadata.
  • Replaces reflection-based configuration binding and annotates diagnostic payloads.
  • Enables compatibility analyzers and adds regression tests.

Automated coverage results were unavailable.

File Description
test/​Orleans.Journaling.Tests/​UpstreamMainCompatibilityTests.cs Supplies state activators.
test/​Orleans.Journaling.Tests/​DurableStateManagerTests.cs Tests default-state activation.
test/​Orleans.Journaling.Tests/​DurableStateAndTcsRecoveryTests.cs Updates recovery setup with activators.
test/​Orleans.Journaling.Tests/​AzureTableJournalStorageTests.cs Pins metadata JSON format.
test/​Orleans.Journaling.Tests/​AzureTableCodecRecoveryTests.cs Supplies recovery-state activators.
test/​Orleans.Journaling.Tests/​AzureBlobCodecRecoveryTests.cs Supplies recovery-state activators.
test/​Orleans.Journaling.Json.Tests/​JsonCodecTests.cs Tests reflection-enabled defaults.
test/​Orleans.Journaling.Json.Tests/​CodecRecoveryTests.cs Supplies JSON-state activators.
src/​Orleans.Journaling/​JournalingHostingExtensions.cs Propagates options constructor requirements.
src/​Orleans.Journaling/​JournaledPersistentState.cs Uses serializer-provided activation.
src/​Orleans.Journaling/​Formats/​Json/​JsonTypeInfoHelpers.cs Guards reflection-based defaults.
src/​Orleans.DurableJobs/​Diagnostics/​DurableJobsEvents.cs Centralizes annotated diagnostic writes.
src/​Directory.Build.props Enables compatibility analyzers for six projects.
src/​Azure/​Orleans.Journaling.AzureStorage/​AzureTableStorageJournalingProviderBuilder.cs Parses operational options explicitly.
src/​Azure/​Orleans.Journaling.AzureStorage/​AzureTableJournalStorage.cs Uses generated JSON metadata.

🧠 Review effort: Balanced


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Code coverage

Metric Pull request Current main Variance
Lines 83.57% (119,026 / 142,429) 83.58% (118,996 / 142,381) -0.0071 pp
Branches 73.22% (35,436 / 48,398) 73.20% (35,418 / 48,386) +0.0190 pp

Report-only conclusion: mixed.

The current-main baseline is commit 1d3361287c 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 16, 2026 14:59

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.

🟡 Changes recommended

The nullable fallback activator lacks constructor preservation and can fail in fully trimmed applications.

1 open finding
1 resolved since last review

🧠 Review effort: Balanced

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.

🔵 Needs a closer look

Client-option compatibility remains unresolved, and cross-package trimming behavior requires final human validation.

0 open findings

1 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Medium severity Preserve ClientOptions configuration overrides during explicit parsing

src/​Azure/​Orleans.Journaling.AzureStorage/​AzureTableStorageJournalingProviderBuilder.cs:26

Replacing Bind(options) with explicit parsing drops the ClientOptions subtree. If an earlier options callback initializes ClientOptions and calls ConfigureTableServiceClient, configuration such as Provider:ClientOptions:Retry:MaxRetries previously updated that instance. With no connection setting or service key overriding the callback, the provider still creates its client from those options, but now silently ignores the configured retry limit. Preserve trim-safe parsing of previously supported client settings and add a regression test combining programmatic client setup with configuration overrides.

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 16, 2026 17:41

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.

🔵 Needs a closer look

The configuration rewrite silently ignores previously supported nested Azure Table client settings.

0 open findings

Previously missed (1)

In code that hasn't changed since last review

Medium severity Preserve nested ClientOptions configuration during trim-safe binding

src/​Azure/​Orleans.Journaling.AzureStorage/​AzureTableStorageJournalingProviderBuilder.cs:25

Replacing Bind(options) with these scalar reads silently drops nested ClientOptions configuration. When an application preconfigures ClientOptions and calls ConfigureTableServiceClient(connectionString), a setting such as Provider:ClientOptions:Retry:MaxRetries previously updated that instance before client creation; it is now ignored. The deferred factory still consumes ClientOptions (AzureTableJournalStorageOptions.cs:237–240), so existing retry settings no longer take effect. Preserve the previously supported nested settings through trim-safe binding, and add a regression test with a preconfigured client-options instance and factory.

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 16, 2026 23:48
@ReubenBond

Copy link
Copy Markdown
Member Author

Addressed the "Preserve nested ClientOptions configuration" finding from the review summary in 28e6064.

It was valid. I checked the reflection-based Bind that main uses: with ClientOptions preconfigured, it applied ClientOptions:Retry:*, ClientOptions:Diagnostics:* and ClientOptions:EnableTenantDiscovery to that instance. With ClientOptions null, it threw because TableClientOptions can't be constructed through binding.

The builder now reads those settings explicitly with GetValue, which the configuration-binding generator intercepts. That means no trimming or AOT warnings and no SYSLIB diagnostics. The generator can't Bind RetryOptions or DiagnosticsOptions, even into an existing instance, because they have no public constructors (SYSLIB1100). When the ClientOptions section is present and ClientOptions is null, the builder now creates a TableClientOptions instead of throwing. Invalid values still throw, as Bind did.

New tests in AzureTableStorageJournalingProviderBuilderTests cover both cases, preconfigured and null ClientOptions, through a ConfigureTableServiceClient factory. They also cover an invalid retry value, and confirm that ClientOptions stays unset when the section is absent.

Auto-replied by the GitHub Copilot app

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.

🔵 Needs a closer look

Shared activation changes, generated binding, and trimming suppressions warrant human confirmation of publish-time behavior on the latest revision.

No open issues 🎉

Review effort: Balanced

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.

🟢 Approval recommended

No unresolved blocking issues remain, and targeted regression tests cover the behavior changes and previously reported defects.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 17, 2026 13:43

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.

🔵 Needs a closer look

Framework-specific generated binding and trimming suppressions warrant human validation of the latest revision.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 17, 2026 13:57

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.

🔵 Needs a closer look

Cross-cutting trimming suppressions and generated configuration binding need final human validation across supported deployment modes.

No open issues 🎉

Review effort: Balanced

Remove the trimming and NativeAOT analyzer warnings from Orleans.Journaling, its storage providers, and Orleans.DurableJobs, and enable the trim, AOT, and single-file analyzers for these projects on net10.0 so regressions fail the build.

- JournaledPersistentState creates default state with the serializer's IActivatorProvider, matching StateStorageBridge.
- JSON journal codecs use JsonSerializerOptions.Default only when System.Text.Json reflection is enabled.
- Azure Table journal metadata uses a source-generated JsonSerializerContext.
- The Azure Table journaling provider builder reads operational options explicitly instead of using reflection-based ConfigurationBinder.Bind.
- DurableJobsEvents writes payloads through a single annotated DiagnosticListener helper.
- GetJournalStorageOptions flows the options constructor requirement to IOptions/IOptionsMonitor.
- Return null from the default activator for Nullable<T>; it previously violated DefaultValueTypeActivator's struct constraint, breaking nullable journaled and classic persistent state.
- Throw when an Azure Table journaling option is configured with an invalid value, matching ConfigurationBinder.Bind.
- Use JsonSerializerOptions.Default directly; with reflection disabled it uses an empty resolver and reports missing metadata.
…hen trimming

Root DefaultNullableActivator<> with DynamicDependency like the other default activators, and cover the default nullable, value-type, and reference-type activators in the serialization trimmed smoke.
…urationBinder.GetValue

Replace the private TryParseValue helper with ConfigurationBinder.GetValue, which throws for invalid values like Bind, and enable the configuration-binding source generator so the primitive GetValue calls stay trim- and AOT-safe.
…uration

Bind previously applied ClientOptions:Retry, ClientOptions:Diagnostics, and ClientOptions:EnableTenantDiscovery to the configured TableClientOptions, which clients created through ConfigureTableServiceClient read. Restore those settings with explicit GetValue reads, which the configuration-binding generator supports; it cannot bind RetryOptions or DiagnosticsOptions as objects because they lack public constructors. TableClientOptions is created when the section is present instead of failing as Bind did.
…nfiguration-binding generator

On net10.0, the configuration-binding source generator binds AzureTableJournalStorageOptions, including nested ClientOptions retry and diagnostics settings, without reflection. Create ClientOptions before binding because TableClientOptions has no bindable constructor, and suppress SYSLIB1100/SYSLIB1101 for the client, pipeline, and delegate members configured in code. net8.0 keeps the reflection-based binder.
…ator cannot bind

AzureTableJournalStorageOptions, TableClientOptions, RetryOptions, and DiagnosticsOptions expose client instances, pipeline policies, delegates, or lack public constructors, so the configuration-binding generator reports SYSLIB1100/SYSLIB1101 for them, and those diagnostics cannot be suppressed per call site. Read their configurable members individually with GetValue, which the generator binds, and remove the project-wide SYSLIB1100/SYSLIB1101 suppression.
Move the net10.0 trim, AOT, and single-file analyzer settings from per-project conditions in src/Directory.Build.props into the six journaling and durable jobs project files.
Copilot AI balanced review requested due to automatic review settings October 17, 2026 14:53
@ReubenBond
ReubenBond force-pushed the rb-fix-journaling-aot-warnings branch from 04b9f66 to 3747a70 Compare October 17, 2026 14: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.

🟢 Approval recommended

No unresolved blocking issues remain, and focused regression coverage addresses the changed behavior and previously reported trimming failures.

No open issues 🎉

Review effort: Balanced

@ReubenBond
ReubenBond enabled auto-merge October 17, 2026 16:00
@ReubenBond
ReubenBond disabled auto-merge October 17, 2026 16:01
@ReubenBond
ReubenBond merged commit 9f8310c into dotnet:main Oct 17, 2026
94 checks passed
@ReubenBond
ReubenBond deleted the rb-fix-journaling-aot-warnings branch October 17, 2026 16:01
ReubenBond added a commit to ReubenBond/orleans that referenced this pull request Oct 18, 2026
Matches dotnet#11513: the net10.0 build of Orleans.Messaging runs the trim, NativeAOT, and single-file analyzers. The package builds without IL warnings.
ReubenBond added a commit to ReubenBond/orleans that referenced this pull request Oct 18, 2026
Matches dotnet#11513: the net10.0 build of Orleans.Messaging runs the trim, NativeAOT, and single-file analyzers. The package builds without IL warnings.
ReubenBond added a commit to ReubenBond/orleans that referenced this pull request Oct 18, 2026
Matches dotnet#11513: the net10.0 build of Orleans.Messaging runs the trim, NativeAOT, and single-file analyzers. The package builds without IL warnings.
ReubenBond added a commit to ReubenBond/orleans that referenced this pull request Oct 19, 2026
Matches dotnet#11513: the net10.0 build of Orleans.Messaging runs the trim, NativeAOT, and single-file analyzers. The package builds without IL warnings.
ReubenBond added a commit to ReubenBond/orleans that referenced this pull request Oct 19, 2026
Matches dotnet#11513: the net10.0 build of Orleans.Messaging runs the trim, NativeAOT, and single-file analyzers. The package builds without IL warnings.
ReubenBond added a commit to ReubenBond/orleans that referenced this pull request Oct 19, 2026
Matches dotnet#11513: the net10.0 build of Orleans.Messaging runs the trim, NativeAOT, and single-file analyzers. The package builds without IL warnings.
ReubenBond added a commit to ReubenBond/orleans that referenced this pull request Oct 31, 2026
Matches dotnet#11513: the net10.0 build of Orleans.Messaging runs the trim, NativeAOT, and single-file analyzers. The package builds without IL warnings.
ReubenBond added a commit to ReubenBond/orleans that referenced this pull request Nov 11, 2026
Matches dotnet#11513: the net10.0 build of Orleans.Messaging runs the trim, NativeAOT, and single-file analyzers. The package builds without IL warnings.
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 17, 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.

3 participants