Skip to content

fix(streaming): recover legacy sequence tokens - #11155

Merged
ReubenBond merged 9 commits into
dotnet:mainfrom
ReubenBond:rb-fix-streaming-legacy-token-recovery
Sep 10, 2026
Merged

ReubenBond merged 9 commits into
dotnet:mainfrom
ReubenBond:rb-fix-streaming-legacy-token-recovery

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Sep 5, 2026 •

Copy link
Copy Markdown
Member

Problem

Persisted stream positions created by earlier inherited event-token factories can deserialize as exact EventSequenceToken or EventSequenceTokenV2 instances. Current provider tokens can be derived types carrying provider metadata, which makes upgrade-time comparison asymmetric and can cause duplicate delivery or incorrect resume positioning.

This correctness foundation is extracted from the final compatibility implementation in #10588 and separated from the broader replay work in #11076. Related: #756.

Solution

  • Define explicit compatibility domains for event token equality and ordering, without runtime reflection.
  • Keep unknown and previously compiled derived token types isolated by default; current custom tokens explicitly opt into a shared numeric domain.
  • Preserve concrete token subtypes and metadata when creating per-event tokens.
  • Normalize the historical Event Hubs V1 factory shape only at recovery comparison boundaries.
  • Keep Kinesis ordering authoritative on arbitrary-precision shard sequence values and Redis ordering authoritative on full entry identity.
  • Apply compatibility comparison at retained-cache positioning, duplicate acknowledgement, delivery progress, and the existing PendingBatch/AdvanceCursorPastToken resume path.
  • Document the custom adapter token contract and regenerate affected API surfaces.

Rationale

Recovery comparisons need to recognize positions persisted by earlier Orleans versions without weakening provider-specific token identity or changing normal delivery metadata. Explicit domains make that contract deterministic and extensible without method metadata inspection. Default isolation preserves custom providers compiled before the new hook, while recovery-only normalization preserves established provider behavior.

Copilot AI lite review requested due to automatic review settings September 5, 2026 15:56

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 equality/ordering semantics used in streaming recovery across multiple providers, so it warrants final human review despite strong test coverage.

Review tier: Lite
Findings: None

What changed in this PR

Improves upgrade-time correctness for persistent streaming by introducing a shared compatibility comparison for legacy EventSequenceToken/EventSequenceTokenV2 (and contract-inheriting subclasses), while keeping provider-specific token identity rules intact for Event Hubs, Kinesis, and Redis.

Changes:

  • Introduces EventSequenceTokenCompatibility and updates core streaming recovery/positioning paths to use compatibility comparisons at recovery boundaries.
  • Updates token implementations to preserve concrete subtypes/metadata when producing per-event tokens and to enforce symmetric equality/ordering/hash contracts.
  • Adds focused regression tests across generic tokens, Event Hubs, Kinesis, Redis, and pulling-agent handshake/dedup behavior, plus documentation updates and regenerated API surfaces.
File Description
test/​Orleans.Streaming.Tests/​StreamingTests/​PersistentStreamPullingAgentTests.cs Adds a regression test validating derived-token duplicate skipping when resuming from a legacy acknowledged token.
test/​Orleans.Streaming.Tests/​StreamingTests/​LegacySequenceTokenRecoveryTests.cs New fixture and tests covering cross-version numeric-token compatibility, duplicate detection, and provider isolation when contracts are overridden.
test/​Extensions/​Orleans.Streaming.Kinesis.Tests/​KinesisSequenceTokenTests.cs New tests for Kinesis shard-sequence numeric ordering (beyond long), equality semantics, allocation behavior, and serialization compatibility.
test/​Extensions/​Orleans.Streaming.EventHubs.Tests/​EventHubSequenceTokenTests.cs New tests validating Event Hubs V1/V2 symmetry, ordering, legacy normalization behavior, and base-token incompatibility.
test/​Extensions/​Orleans.Redis.Tests/​Streaming/​RedisStreamSequenceTokenTests.cs New tests ensuring Redis token equality/ordering uses full entry identity and rejects base-token comparisons.
src/​Redis/​Orleans.Streaming.Redis/​Streams/​RedisStreamSequenceToken.cs Makes CreateSequenceTokenForEvent properly override and strengthens CompareTo to be type-safe and consistent with Redis identity.
src/​Orleans.Streaming/​PersistentStreams/​PersistentStreamPullingAgent.cs Uses compatibility comparisons in recovery cursor advancement and delivery-progress ordering.
src/​Orleans.Streaming/​Orleans.Streaming.csproj Adds InternalsVisibleTo for the Event Hubs provider assembly (to use shared internal compatibility helpers).
src/​Orleans.Streaming/​Internal/​StreamSubscriptionHandleImpl.cs Uses compatibility equality for dedup/resume checks while preserving provider contracts.
src/​Orleans.Streaming/​Common/​PooledCache/​PooledQueueCache.cs Applies compatibility comparisons when refreshing cursors and when validating purged-token boundaries.
src/​Orleans.Streaming/​Common/​EventSequenceTokenV2.cs Preserves concrete subtype in per-event tokens and implements numeric-contract compatibility in equality/ordering.
src/​Orleans.Streaming/​Common/​EventSequenceTokenCompatibility.cs New internal compatibility helper for recovery-boundary comparisons and contract-inheritance detection.
src/​Orleans.Streaming/​Common/​EventSequenceToken.cs Preserves concrete subtype in per-event tokens, adds legacy normalization hook, and implements numeric-contract compatibility in equality/ordering.
src/​Azure/​Orleans.Streaming.EventHubs/​Providers/​Streams/​EventHub/​EventHubSequenceToken.cs Implements Event Hubs-specific compatibility/normalization for legacy base-token recovery while keeping public provider contract intact.
src/​AWS/​Orleans.Streaming.Kinesis/​Streams/​KinesisSequenceToken.cs Makes Kinesis ordering authoritative on shard-sequence magnitude using cached BigInteger parsing and enforces incompatibility with base tokens.
src/​api/​Orleans.Streaming/​Orleans.Streaming.cs Regenerates public API surface for token factory virtual method changes.
src/​api/​Azure/​Orleans.Streaming.EventHubs/​Orleans.Streaming.EventHubs.cs Regenerates public API surface for Event Hub token equality/ordering/hash overrides.
docs/​site/​src/​content/​docs/​streaming/​custom-queue-adapter.md Documents legacy token recovery behavior and the required token contract characteristics for custom adapters.

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

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 token equality/ordering semantics and recovery behavior across multiple providers, which is correctness-critical and warrants final human review despite the added tests.

Review tier: Lite
Findings: None

Suppressed comments (2)

Previously missed (2) — in code that hasn't changed since the last review.

docs/site/src/content/docs/streaming/custom-queue-adapter.md:94

  • This numbered list has two consecutive items ending with “and”, which reads awkwardly. Only the penultimate item should end with “and”.
    test/Extensions/Orleans.Streaming.EventHubs.Tests/EventHubSequenceTokenTests.cs:7
  • Namespace is inconsistent with the rest of the Orleans.Streaming.EventHubs test project (which uses the ServiceBus.Tests.* namespaces), making related tests harder to locate and group logically.

Copilot AI review requested due to automatic review settings September 10, 2026 00:00
@ReubenBond
ReubenBond force-pushed the rb-fix-streaming-legacy-token-recovery branch from 6f25ce6 to 4e81996 Compare September 10, 2026 00:00

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 token equality/ordering semantics and multiple recovery/resume paths across providers, warranting careful human validation of behavioral compatibility and edge cases.

Review tier: Lite
Findings: 1 Low severity

New issues introduced by this change (1)
Severity Finding
Low severity docs/​site/​src/​content/​docs/​streaming/​custom-queue-adapter.md — The numbered list has two consecutive items ending with "; and", which reads awkwardly and results…

Copilot AI review requested due to automatic review settings September 10, 2026 01:35
@ReubenBond
ReubenBond force-pushed the rb-fix-streaming-legacy-token-recovery branch from 4e81996 to 6fb133e Compare September 10, 2026 01:35

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 streaming token equality/ordering and recovery behavior across multiple providers and public APIs, requiring final human validation of compatibility and runtime impact.

Review tier: Lite
Findings: None

Issues resolved since last review (1)
Severity Finding
Low severity docs/​site/​src/​content/​docs/​streaming/​custom-queue-adapter.md — The numbered list has two consecutive items ending with "; and", which reads awkwardly and results… View resolved comment

Copilot AI review requested due to automatic review settings September 10, 2026 15:37
@ReubenBond
ReubenBond force-pushed the rb-fix-streaming-legacy-token-recovery branch from 6fb133e to e5859ca Compare September 10, 2026 15:37

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

A new compatibility-based comparison in delivery-progress calculation can throw on incompatible tokens and should be made resilient to avoid destabilizing shutdown/checkpoint reporting paths.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Lite
Findings: 1 Medium severity · 1 Low severity

New issues introduced by this change (2)
Severity Finding
Medium severity src/​Orleans.Streaming/​PersistentStreams/​PersistentStreamPullingAgent.cs — IsBefore now delegates to EventSequenceTokenCompatibility.Compare, which can throw…
Low severity test/​Orleans.Streaming.Tests/​StreamingTests/​PersistentStreamPullingAgentTests.cs — The IQueueCacheCursor.GetCurrent implementation should match the interface nullability…

Copilot AI review requested due to automatic review settings September 10, 2026 19:24

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 fundamental token equality/ordering semantics across multiple providers and recovery paths, so it warrants final human review despite the added regression coverage.

Review tier: Lite
Findings: None

Issues resolved since last review (2)
Severity Finding
Low severity test/​Orleans.Streaming.Tests/​StreamingTests/​PersistentStreamPullingAgentTests.cs — The IQueueCacheCursor.GetCurrent implementation should match the interface nullability… View resolved comment
Medium severity src/​Orleans.Streaming/​PersistentStreams/​PersistentStreamPullingAgent.cs — IsBefore now delegates to EventSequenceTokenCompatibility.Compare, which can throw… View resolved comment

Copilot AI review requested due to automatic review settings September 10, 2026 19:43
@ReubenBond
ReubenBond force-pushed the rb-fix-streaming-legacy-token-recovery branch from 002d801 to fb6901f Compare September 10, 2026 19: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 stream-token equality/ordering semantics and multiple recovery paths across providers, warranting careful human validation despite added regression coverage.

Review tier: Lite
Findings: None

@ReubenBond
ReubenBond merged commit d42e018 into dotnet:main Sep 10, 2026
72 checks passed
@ReubenBond
ReubenBond deleted the rb-fix-streaming-legacy-token-recovery branch September 10, 2026 20:53
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 11, 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