Repository navigation
feat(streaming): support provider-encoded cache offsets - #11153
Conversation
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The changes appear correct and well-covered by focused tests, with only a minor test namespace consistency nit noted.
Review tier: Lite
Findings: 1
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
test/Orleans.Streaming.Tests/OrleansRuntime/Streams/EncodedOffsetPooledQueueCacheTests.cs — This file is located under OrleansRuntime/Streams but uses the UnitTests.StreamingTests… |
What changed in this PR
Adds provider-defined cursor positioning to Orleans’ pooled streaming cache by introducing an adapter-level comparison hook, ensuring providers with encoded/authoritative offsets can correctly order and locate cached messages.
Changes:
- Add
ICacheDataAdapter.Compare(defaulting to numericSequenceNumber/EventIndexordering) and route pooled-cache comparisons through it. - Add an adapter-aware
CachedMessageBlock.GetIndexOfFirstMessageLessThanOrEqualTooverload and update pooled-cache cursor positioning/cache-miss detection to use the adapter comparison. - Add focused tests for encoded-offset behavior, update legacy numeric tests, regenerate API surface, and document the comparison contract.
| File | Description |
|---|---|
| test/Orleans.Streaming.Tests/OrleansRuntime/Streams/EncodedOffsetPooledQueueCacheTests.cs | Adds tests validating cursor positioning and cache-miss behavior using provider-encoded offsets. |
| test/Orleans.Streaming.Tests/OrleansRuntime/Streams/CachedMessageBlockTests.cs | Extends existing tests to validate both legacy numeric and adapter-aware search paths. |
| src/Orleans.Streaming/Common/PooledCache/PooledQueueCache.cs | Routes cursor bounds/block selection/in-block lookup/cache-miss detection through ICacheDataAdapter.Compare. |
| src/Orleans.Streaming/Common/PooledCache/ICacheDataAdapter.cs | Introduces Compare with a default implementation preserving existing numeric ordering. |
| src/Orleans.Streaming/Common/PooledCache/CachedMessageBlock.cs | Adds adapter-aware overload for locating the newest message <= a provided token. |
| src/api/Orleans.Streaming/Orleans.Streaming.cs | Regenerates API surface to include new adapter compare method and block overload. |
| docs/site/src/content/docs/streaming/custom-queue-adapter.md | Documents the pooled-cache position contract and when to override ICacheDataAdapter.Compare. |
💡 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
A few small but concrete issues (documentation inconsistency and brittle test assertions tied to internal call counts) should be addressed before approval.
Review tier: Lite
Findings: None
Issues resolved since last review (1)
| Severity | Finding |
|---|---|
test/Orleans.Streaming.Tests/OrleansRuntime/Streams/EncodedOffsetPooledQueueCacheTests.cs — This file is located under OrleansRuntime/Streams but uses the UnitTests.StreamingTests… View resolved comment |
Suppressed comments (3)
Previously missed (2) — in code that hasn't changed since the last review.
src/Orleans.Streaming/Common/PooledCache/CachedMessageBlock.cs:199
- The existing overload
GetIndexOfFirstMessageLessThanOrEqualTo(StreamSequenceToken)returns the newest message <= token (it scans fromwriteIndex - 1down), but its XML docs describe the first message. The new overload’s docs correctly say “newest”, so the two overloads now have conflicting documentation. Please update the original overload’s XML docs to match the actual behavior so consumers aren’t misled.
test/Orleans.Streaming.Tests/OrleansRuntime/Streams/EncodedOffsetPooledQueueCacheTests.cs:29 - This assertion couples the test to an implementation detail (number of comparisons performed). It can become brittle if the search logic is optimized while still correctly using the adapter. Prefer asserting only that
Compareis invoked (e.g.,> 0) and rely on the index assertions for functional correctness.
This issue also appears on line 76 of the same file.
test/Orleans.Streaming.Tests/OrleansRuntime/Streams/EncodedOffsetPooledQueueCacheTests.cs:76
- This assertion couples the test to an implementation detail (number of comparisons performed). It can become brittle if the cursor positioning logic is optimized while still correctly using the adapter. Prefer asserting only that
Compareis invoked (e.g.,> 0) and rely on the token/offset assertions for functional correctness.
Assert.True(adapter.CompareCallCount >= 4);

Problem
PooledQueueCachepositions cursors by comparing the numeric fields stored inCachedMessage. Providers whose authoritative position is encoded in the cached payload cannot distinguish messages which intentionally share those numeric fields.Solution
Add a default
ICacheDataAdapter.Compareimplementation which preserves existing sequence-number and event-index ordering. Route pooled-cache cursor bounds, block selection, in-block lookup, and cache-miss detection through the adapter method. Add focused encoded-offset and legacy numeric tests, regenerate the Orleans.Streaming API surface, and document the custom pooled-cache position contract.Rationale
This independently mergeable change is extracted from #11076 and #10588. It establishes the provider-owned comparison boundary without carrying safe progress state, memory ownership changes, recoverable-stream infrastructure, or replay APIs.
Related: #756 and #10920.
Microsoft Reviewers: Open in CodeFlow