Repository navigation
fix(codegen): honor RPC parameter field IDs - #11179
Conversation
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
It changes core RPC wire-serialization field-ID behavior and compatibility characteristics, which warrants final human review despite solid targeted test coverage.
Review tier: Lite
Findings: None
What changed in this PR
This PR updates Orleans RPC invokable serialization so wire field IDs are derived from serialized-parameter ordinals (excluding CancellationToken), while allowing explicit [Id] on parameters to override the automatic ID assignment. It also adds diagnostics for invalid/duplicate parameter IDs and ensures incremental generator caching is invalidated when parameter [Id] attributes change.
Changes:
- Update invokable field-ID assignment to exclude
CancellationTokenfrom automatic ID ordinals and apply explicit[Id]overrides, with collision/cancellation-token diagnostics. - Extend the proxy interface incremental model to capture explicit parameter field IDs so attribute-only changes trigger regeneration.
- Add focused unit tests covering automatic/explicit ID behavior and invalid cases; annotate existing test grain interfaces to preserve prior wire IDs where needed.
| File | Description |
|---|---|
| test/Orleans.CodeGenerator.Tests/RpcParameterFieldIdTests.cs | New tests validating RPC parameter field-ID assignment rules and new diagnostics. |
| test/Orleans.CodeGenerator.Tests/ModelExtractorTests.cs | Verifies extracted proxy model captures explicit parameter [Id] values. |
| test/Orleans.CodeGenerator.Tests/IncrementalCachingTests.cs | Ensures changing a parameter [Id] invalidates cached proxy outputs. |
| test/Grains/TestGrainInterfaces/IGenericInterfaces.cs | Adds explicit parameter [Id] annotations to preserve existing wire IDs for methods with CancellationToken. |
| test/Grains/TestGrainInterfaces/ICancellationTestSystemTarget.cs | Adds explicit parameter [Id] annotations to preserve existing wire IDs for system target methods with CancellationToken. |
| src/Orleans.Serialization.Abstractions/Annotations.cs | Documents [Id] semantics for RPC parameters (override serialized-ordinal; exclude CancellationToken; require uniqueness). |
| src/Orleans.CodeGenerator/Model/ProxyInterfaceModelExtractor.cs | Captures explicit parameter field IDs in the extracted method parameter model. |
| src/Orleans.CodeGenerator/Model/MethodModel.cs | Extends MethodParameterModel to include ExplicitFieldId. |
| src/Orleans.CodeGenerator/InvokableGenerator.cs | Implements new field-ID assignment logic and throws diagnostics for invalid RPC parameter IDs. |
| src/Orleans.CodeGenerator/Diagnostics/InvalidRpcParameterIdDiagnostic.cs | Adds diagnostic descriptors for invalid cancellation-token IDs and duplicate field IDs. |
| src/Orleans.CodeGenerator/Diagnostics/DiagnosticRuleId.cs | Introduces ORLEANS0112 for invalid RPC parameter field identifiers. |
| src/Orleans.CodeGenerator/AnalyzerReleases.Unshipped.md | Registers the new diagnostic rule in unshipped analyzer releases. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
It changes core RPC wire-field ID assignment semantics in the code generator (with compatibility implications), so it should receive final human review despite strong test coverage.
Review tier: Lite
Findings: None
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The newly added RpcParameterFieldIdTests test file is missing using Xunit;, which will fail compilation in Orleans.CodeGenerator.Tests.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review tier: Lite
Findings: 1
New issues introduced by this change (2)
| Severity | Finding |
|---|---|
test/Orleans.CodeGenerator.Tests/RpcParameterFieldIdTests.cs — [Fact]/Assert are used but Xunit is not imported in this new test file, which will fail to… |
|
test/Grains/TestGrainInterfaces/ICancellationTestSystemTarget.cs — The <param> tags are now out of order relative to the updated method signature (token moved to… |
Suppressed comments (1)
test/Grains/TestGrainInterfaces/ICancellationTestSystemTarget.cs:29
- The
<param>tags are now out of order relative to the updated method signature (token moved to last). Reordering the tags will keep IntelliSense/docs aligned with the declaration.
/// <param name="target">The target system target to call.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="delay">The delay to wait.</param>
/// <param name="callId">A unique identifier for this call, used to track cancellations.</param>
Task CallOtherLongRunningTask(
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
It changes core RPC wire field-id assignment semantics (with potential cross-version compatibility impact) and should receive final maintainer review despite strong test coverage.
Review tier: Lite
Findings: None
Issues resolved since last review (2)
| Severity | Finding |
|---|---|
test/Grains/TestGrainInterfaces/ICancellationTestSystemTarget.cs — The <param> tags are now out of order relative to the updated method signature (token moved to… View resolved comment |
|
test/Orleans.CodeGenerator.Tests/RpcParameterFieldIdTests.cs — [Fact]/Assert are used but Xunit is not imported in this new test file, which will fail to… View resolved comment |


RPC invokable serialization derived field IDs from CLR parameter ordinals, so
CancellationTokenparameters consumed wire IDs and explicit parameter[Id]attributes were ignored.This change assigns automatic IDs from serialized-parameter ordinals, applies explicit IDs as overrides, and keeps CLR argument ordering independent from wire-field numbering. Invalid cancellation-token IDs and field-ID collisions produce source-generator diagnostics at the offending parameter. A non-final
CancellationTokenparameter now produces warningORLEANS0113while generation continues, guiding RPC declarations toward the established token-last convention.The incremental proxy model includes explicit parameter IDs so attribute-only changes invalidate cached generator output. Existing test RPC declarations and call sites now place
CancellationTokenlast.Microsoft Reviewers: Open in CodeFlow