Skip to content

fix(codegen): honor RPC parameter field IDs - #11179

Merged
ReubenBond merged 4 commits into
dotnet:mainfrom
ReubenBond:rb-fix-codegen-rpc-parameter-ids
Sep 7, 2026
Merged

ReubenBond merged 4 commits into
dotnet:mainfrom
ReubenBond:rb-fix-codegen-rpc-parameter-ids

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

RPC invokable serialization derived field IDs from CLR parameter ordinals, so CancellationToken parameters 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 CancellationToken parameter now produces warning ORLEANS0113 while 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 CancellationToken last.

Microsoft Reviewers: Open in CodeFlow

Copilot AI lite review requested due to automatic review settings September 7, 2026 05:39

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

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 CancellationToken from 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.

Copilot AI review requested due to automatic review settings September 7, 2026 05: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.

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

Copilot AI review requested due to automatic review settings September 7, 2026 15:32

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 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 High severity · 1 Low severity

New issues introduced by this change (2)
Severity Finding
High severity test/​Orleans.CodeGenerator.Tests/​RpcParameterFieldIdTests.cs — [Fact]/Assert are used but Xunit is not imported in this new test file, which will fail to…
Low severity 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(

Copilot AI review requested due to automatic review settings September 7, 2026 19:14

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

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
Low severity test/​Grains/​TestGrainInterfaces/​ICancellationTestSystemTarget.cs — The &lt;param&gt; tags are now out of order relative to the updated method signature (token moved to… View resolved comment
High severity 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

@ReubenBond
ReubenBond merged commit 0abd816 into dotnet:main Sep 7, 2026
72 checks passed
@ReubenBond
ReubenBond deleted the rb-fix-codegen-rpc-parameter-ids branch September 7, 2026 21:03
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