feat(codegen): support stable field naming and hot reload - #10932
Merged
Conversation
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Pull request overview
Updates the Orleans code generator to produce Hot Reload–friendlier generated serializers/copiers by stabilizing generated field naming and (optionally) enabling lazy, self-healing resolution paths in Debug/HotReloadSafe builds.
Changes:
- Introduces stable generated field/accessor naming keyed by
[Id]and by member type (with hash suffixes for collisions). - Adds Hot Reload–safe codegen mode (defaulting to Debug optimization level, overridable via
OrleansHotReload) which stores anICodecProviderand uses lazy??=initialization patterns for codecs/copiers/accessors. - Adds targeted unit tests and refreshes source-generator snapshot baselines accordingly.
File summaries
| File | Description |
|---|---|
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithSuppressReferenceTrackingAttribute.verified.cs | Snapshot update for hot-reload-safe ctor/field shape. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithOmitDefaultMemberValuesAnnotation.verified.cs | Snapshot update for hot-reload-safe ctor/field shape. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestRecordsWithParameterIdAttributes.verified.cs | Snapshot update for stable accessor naming and lazy accessors/codecs. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestRecords.verified.cs | Snapshot update for stable type-keyed codec/copier field names and lazy init. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs | Snapshot update (formatting/line shifts) from generator changes. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithDifferentKeyTypes.verified.cs | Snapshot update for codec/copier ctor signature changes and stored codec provider. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs | Snapshot update (formatting/line shifts) from generator changes. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs | Snapshot update for codec/copier ctor signature changes and stored codec provider. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs | Snapshot update for stable field naming (e.g., _copier_ComplexData) and codec-provider storage. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClassWithConstructorParameters.verified.cs | Snapshot update for type-keyed codec/copier fields and hot-reload-safe ??= access. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClass.verified.cs | Snapshot update for type-keyed codec/copier fields and hot-reload-safe ??= access. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestCompoundTypeAlias.verified.cs | Snapshot update for codec-provider storage in codec/copier. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithParameterizedConstructor.verified.cs | Snapshot update for codec/copier ctor signature changes and type-keyed fields. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithOptionalConstructorParameters.verified.cs | Snapshot update for stable accessor naming and lazy accessors. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithNoPublicConstructors.verified.cs | Snapshot update for codec/copier ctor signature changes and codec-provider storage. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithInterfaceConstructorParameter.verified.cs | Snapshot update for type-keyed codec/copier fields and hot-reload-safe ??= access. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateSerializerAnnotation.verified.cs | Snapshot update for type-keyed codec fields and codec-provider storage. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs | Snapshot update (formatting/line shifts) from generator changes. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassReferenceProperties.verified.cs | Snapshot update for stable accessor naming and lazy accessors. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassPrimitiveTypesUsingFullName.verified.cs | Snapshot update for type-keyed codec/copier fields and hot-reload-safe ??= access. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassPrimitiveTypes.verified.cs | Snapshot update for type-keyed codec/copier fields and hot-reload-safe ??= access. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassNestedTypes.verified.cs | Snapshot update for stable type-keyed codec/copier fields and lazy init. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassesWithGeneratedActivatorConstructorAnnotation.verified.cs | Snapshot update for codec-provider storage in codec/copier. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicStruct.verified.cs | Snapshot update for codec-provider storage in value serializer. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicGrain.verified.cs | Snapshot update for codec/copier ctor signature changes and codec-provider storage. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithoutNamespace.verified.cs | Snapshot update for codec-provider storage in codec/copier. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithInheritance.verified.cs | Snapshot update for codec-provider storage and stable generated field naming. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithDifferentAccessModifiers.verified.cs | Snapshot update for codec-provider storage in codec/copier. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithAnnotatedFields.verified.cs | Snapshot update for stable accessor naming and lazy accessors. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClass.verified.cs | Snapshot update for codec-provider storage in codec/copier. |
| test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestAlias.verified.cs | Snapshot update for codec-provider storage in value serializer. |
| test/Orleans.CodeGenerator.Tests/HotReloadCodegenTests.cs | Adds tests validating Hot Reload–safe shapes, lazy init behavior, and property override behavior. |
| test/Orleans.CodeGenerator.Tests/GeneratedFieldNamesTests.cs | Adds unit tests for stable accessor/type-keyed naming and collision handling. |
| src/Orleans.CodeGenerator/SyntaxGeneration/GeneratedFieldNames.cs | Adds stable field/accessor naming helpers (with collision hashing). |
| src/Orleans.CodeGenerator/SourceGeneratorOptionsParser.cs | Adds Orleans_HotReload option parsing and defaults HotReloadSafe based on optimization level. |
| src/Orleans.CodeGenerator/SerializerGenerator.cs | Implements hot-reload-safe serializer shape (codec provider storage, lazy ??= usage, stable naming). |
| src/Orleans.CodeGenerator/SerializableSourceOutputGenerator.cs | Wires compilation into options creation so optimization level can drive HotReloadSafe. |
| src/Orleans.CodeGenerator/ReferenceAssemblyDataProvider.cs | Wires compilation into options creation so optimization level can drive HotReloadSafe. |
| src/Orleans.CodeGenerator/ProxySourceOutputGenerator.cs | Wires compilation into options creation so optimization level can drive HotReloadSafe. |
| src/Orleans.CodeGenerator/Model/SerializableTypeDescription.cs | Declares serializable types as supporting hot-reload member addition. |
| src/Orleans.CodeGenerator/Model/ProxyMethodDescription.cs | Marks generated invokables as not supporting hot-reload member addition. |
| src/Orleans.CodeGenerator/Model/ISerializableTypeDescription.cs | Adds SupportsHotReloadMemberAddition contract for generators. |
| src/Orleans.CodeGenerator/Model/GeneratedInvokableDescription.cs | Marks generated invokables as not supporting hot-reload member addition. |
| src/Orleans.CodeGenerator/CopierGenerator.cs | Implements hot-reload-safe copier shape (codec provider storage, lazy ??= usage, stable naming). |
| src/Orleans.CodeGenerator/CodeGeneratorOptions.cs | Adds HotReloadSafe option controlling hot-reload-safe generation paths. |
| src/Orleans.CodeGenerator/build/Microsoft.Orleans.CodeGenerator.props | Exposes OrleansHotReload (via compiler-visible Orleans_HotReload) to the generator. |
Review details
- Files reviewed: 43/46 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
ReubenBond
approved these changes
Sep 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Adding serialized members can change generated serializer and copier fields. Existing generated instances have already run their constructors, so newly added dependencies must remain addressable and initialize on first use for Hot Reload to succeed.
Solution
[Id]and generated codec/copier fields stable 64-bit type-identity names.<OrleansHotReload>true</OrleansHotReload>so normal builds retain eager readonly initialization.ICodecProvideravailable and lazily resolve dependencies added to existing serializer and copier instances.Supported updates add strongly typed
[Id]members to[GenerateSerializer]classes and records. A restart rebuilds serializer metadata after updates which introduce new types through polymorphic declarations or container element types. Grain interfaces and generated invokable types retain their existing compatibility requirements.Microsoft Reviewers: Open in CodeFlow