Skip to content

fix(membership): preserve core membership invariants - #11307

Merged
ReubenBond merged 8 commits into
dotnet:mainfrom
ReubenBond:rb-fix-membership-core-invariants
Sep 18, 2026
Merged

ReubenBond merged 8 commits into
dotnet:mainfrom
ReubenBond:rb-fix-membership-core-invariants

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

The runtime's in-memory membership table retains caller-owned entries, allowing later mutations to change stored state outside conditional writes. Heartbeat-only writes can invalidate membership concurrency tokens, and cleanup can remove silos which are still progressing through their lifecycle.

This focused core change:

  • Copies runtime in-memory entries on insert and update, including suspect lists.
  • Keeps full-row updates as supplied-row replacements guarded by the existing row existence and row/table ETag checks. A successful full-row write can replace the stored IAmAliveTime with an earlier supplied value.
  • Keeps periodic heartbeats as single-owner, single-column blind writes of the supplied timestamp. Both in-memory paths use their existing local dictionary lookup (and InProcess lock) and assign only IAmAliveTime. All other membership fields, the row ETag, and the table version/ETag remain unchanged. Canonical inserts and updates continue to create new tokens.
  • Restricts those two tables' cleanup to Dead rows and bases retention on the latest startup, heartbeat, or suspect-vote timestamp.
  • Uses expired Dead rows and their effective update times to trigger early cleanup requests from the cleanup agent. Periodic and count-based requests retain their existing scheduling rules; the configured provider owns the actual deletion operation.
  • Preserves those tables' existing unversioned cleanup policy, with regressions for retained non-Dead rows, strict cutoffs, and cleanup at the maximum table version.
  • Checks TableVersion.Next() for overflow and covers the boundary in the existing core test project.
  • Binds the development membership system target to ClusterOptions.ClusterId and rejects foreign-cluster deletion with ArgumentException before mutation. Cancellation takes priority; own-cluster deletion preserves the existing terminal table invalidation. Focused regressions exercise the real target and its DI construction.

Focused raw-table, in-process-table, and cleanup-agent regressions accompany these changes. Heartbeat regressions cover owner reports, including equal timestamps and clock adjustments, while checking retained membership fields and concurrency tokens. Exact interleaving regressions read row/table tokens, write an owner heartbeat, then successfully commit a canonical update using the original tokens; that update advances the version and replaces its tokens. These interleaving assertions cover canonical state independently of the resulting raw heartbeat value. The baseline already contains #11296, which owns snapshot-level observed liveness maxima and same-version Dead-row pruning semantics.

Compatibility and risk

Public signatures, serialization IDs, RPC aliases, storage schemas, and ETag formats remain compatible. This change requires no schema migration or specially ordered rollout. During a mixed-version upgrade, the in-memory table owner's implementation determines its write/cleanup behavior and the elected cleanup silo determines request timing. Development clustering retains its existing primary-lifetime requirement.

The intentional behavior changes are conservative retention of non-Dead rows, stable row and table tokens across in-memory heartbeat writes, rejection of foreign-cluster deletion, and an OverflowException from TableVersion.Next() at int.MaxValue instead of integer wraparound. Abandoned non-Dead entries remain until the membership protocol declares them Dead. Storage accepts supplied liveness values directly during heartbeats and full-row replacements; snapshot merging retains its existing observed-maximum behavior.

Provider scope

The public XML contract requires canonical fields and the table version/ETag to remain stable across heartbeat-only activity. Returned row ETags are provider-defined and may be physical metadata which changes on heartbeat. Providers can validate a separate canonical row token or rely on atomic table-ETag CAS plus an existing-row update and ignore the supplied row ETag. Previously read row/table inputs remain usable for a canonical update after heartbeat-only activity while the row exists and the table ETag remains current. The raw and in-process implementations retain their stronger row-token stability and independent row checks.

Provider-wide absent-row heartbeat and effective-update-time cleanup contract additions remain in the provider follow-ups. Existing external-provider cleanup behavior, including removal of old non-Active rows, remains scoped to those implementations. Changing the cleanup agent's eligibility predicate improves scheduling; provider-specific changes establish the corresponding storage guarantees.

The conformance kit/shared test preparation is tracked in #11308, and provider corrections are in the separate provider PRs (#11309 through #11316). Hosted conformance integration and membership-table routing support remain in their respective follow-up layers.

Microsoft Reviewers: Open in CodeFlow

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

🟡 Changes recommended

Provider implementations still do not enforce the required monotonic liveness and Dead-only cleanup contracts.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 High severity · 1 Low severity

Open (3)
What changed in this PR

This PR hardens membership-table invariants around state isolation, monotonic liveness, cleanup, and table-version overflow.

Changes:

  • Added defensive copying and monotonic heartbeat handling.
  • Restricted cleanup to sufficiently old Dead entries.
  • Added regression coverage for cleanup, conformance, and version boundaries.
File Summary
test/​TestInfrastructure/​Orleans.TestingHost.Tests/​InProcessMembershipTableTests.cs Adds in-process isolation and cleanup regression coverage.
test/​Orleans.Runtime.Internal.Tests/​MembershipTests/​InMemoryMembershipTableTests.cs Updates in-memory cleanup expectations.
test/​Orleans.Runtime.Internal.Tests/​MembershipTests/​InMemoryMembershipTableConformanceTests.cs Adds conformance regressions; includes a minor test-name typo.
test/​Orleans.Core.Tests/​Membership/​TableVersionTests.cs Tests table-version overflow behavior.
test/​Orleans.Core.Tests/​Membership/​MembershipTableCleanupAgentTests.cs Covers cleanup eligibility and timestamp cutoffs.
src/​Orleans.TestingHost/​InProcess/​InProcessMembershipTable.cs Applies defensive copying and monotonic liveness semantics.
src/​Orleans.Runtime/​MembershipService/​MembershipTableCleanupAgent.cs Restricts cleanup decisions to expired Dead entries; provider operations still require corresponding updates.
src/​Orleans.Runtime/​MembershipService/​InMemoryMembershipTable.cs Preserves detached entries and maximum heartbeat timestamps.
src/​Orleans.Core/​SystemTargetInterfaces/​IMembershipTable.cs Defines updated liveness and cleanup contracts; provider implementations do not yet fully satisfy them.
src/​Orleans.Core/​Configuration/​Options/​ClusterMembershipOptions.cs Clarifies dead-entry retention options.

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

@github-actions

github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Code coverage

Metric Pull request
Lines 82.24% (112,522 / 136,819)
Branches 71.49% (32,444 / 45,385)

Report-only conclusion: current-main baseline stale.

The newest successful coverage run tested 986e5c7, not current main dcf2925.

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 review requested due to automatic review settings September 17, 2026 23:34

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 reviewed changes are covered by focused tests, with only a minor documentation nit noted.

Review effort: Lite
Findings: None

Resolved since last review (3)

Copilot AI review requested due to automatic review settings September 18, 2026 02:25

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

Core membership and cleanup behavior changes span multiple implementations and warrant final human review.

Review effort: Lite
Findings: None

@ReubenBond
ReubenBond marked this pull request as ready for review September 18, 2026 15:11
Copilot AI review requested due to automatic review settings September 18, 2026 15:51

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

No blocking issues remain; the only feedback is a minor documentation nit.

Review effort: Lite
Findings: None

Copilot AI review requested due to automatic review settings September 18, 2026 16:03

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

No unresolved review comments remain, and all reviewed changes are assessed as approval-ready.

Review effort: Lite
Findings: None

Copilot AI review requested due to automatic review settings September 18, 2026 16:08

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

No unresolved review comments were identified, and focused regression coverage is included.

Review effort: Lite
Findings: None

Copilot AI review requested due to automatic review settings September 18, 2026 19:45
This was referenced Oct 6, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 19, 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.

2 participants