Repository navigation
fix(streaming): recover legacy sequence tokens - #11155
Conversation
There was a problem hiding this comment.
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
EventSequenceTokenCompatibilityand 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.
There was a problem hiding this comment.
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.
6f25ce6 to
4e81996
Compare
There was a problem hiding this comment.
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
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
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… |
4e81996 to
6fb133e
Compare
There was a problem hiding this comment.
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 |
|---|---|
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 |
6fb133e to
e5859ca
Compare
There was a problem hiding this comment.
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
New issues introduced by this change (2)
| Severity | Finding |
|---|---|
src/Orleans.Streaming/PersistentStreams/PersistentStreamPullingAgent.cs — IsBefore now delegates to EventSequenceTokenCompatibility.Compare, which can throw… |
|
test/Orleans.Streaming.Tests/StreamingTests/PersistentStreamPullingAgentTests.cs — The IQueueCacheCursor.GetCurrent implementation should match the interface nullability… |
There was a problem hiding this comment.
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 |
|---|---|
test/Orleans.Streaming.Tests/StreamingTests/PersistentStreamPullingAgentTests.cs — The IQueueCacheCursor.GetCurrent implementation should match the interface nullability… View resolved comment |
|
src/Orleans.Streaming/PersistentStreams/PersistentStreamPullingAgent.cs — IsBefore now delegates to EventSequenceTokenCompatibility.Compare, which can throw… View resolved comment |
002d801 to
fb6901f
Compare
There was a problem hiding this comment.
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


Problem
Persisted stream positions created by earlier inherited event-token factories can deserialize as exact
EventSequenceTokenorEventSequenceTokenV2instances. 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
PendingBatch/AdvanceCursorPastTokenresume path.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.