Skip to content

feat(streaming): support provider-encoded cache offsets - #11153

Merged
ReubenBond merged 2 commits into
dotnet:mainfrom
ReubenBond:rb-feat-streaming-encoded-cache-offsets
Sep 10, 2026
Merged

ReubenBond merged 2 commits into
dotnet:mainfrom
ReubenBond:rb-feat-streaming-encoded-cache-offsets

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Sep 5, 2026 •

Copy link
Copy Markdown
Member

Problem

PooledQueueCache positions cursors by comparing the numeric fields stored in CachedMessage. Providers whose authoritative position is encoded in the cached payload cannot distinguish messages which intentionally share those numeric fields.

Solution

Add a default ICacheDataAdapter.Compare implementation 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

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 changes appear correct and well-covered by focused tests, with only a minor test namespace consistency nit noted.

Review tier: Lite
Findings: 1 Low severity

New issues introduced by this change (1)
Severity Finding
Low severity 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 numeric SequenceNumber/EventIndex ordering) and route pooled-cache comparisons through it.
  • Add an adapter-aware CachedMessageBlock.GetIndexOfFirstMessageLessThanOrEqualTo overload 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.

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

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

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
Low severity 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 from writeIndex - 1 down), 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 Compare is 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 Compare is invoked (e.g., > 0) and rely on the token/offset assertions for functional correctness.
        Assert.True(adapter.CompareCallCount >= 4);

@ReubenBond
ReubenBond merged commit d38e31d into dotnet:main Sep 10, 2026
71 checks passed
@ReubenBond
ReubenBond deleted the rb-feat-streaming-encoded-cache-offsets branch September 10, 2026 00:15
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 10, 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