Skip to content

refactor(streaming): add typed cache cursor results - #9714

Merged
ReubenBond merged 5 commits into
dotnet:mainfrom
BMagerMT:recover-from-exception-at-oldest-message
Sep 5, 2026
Merged

ReubenBond merged 5 commits into
dotnet:mainfrom
BMagerMT:recover-from-exception-at-oldest-message

Conversation

@BMagerMT

@BMagerMT BMagerMT commented Oct 8, 2025 •

Copy link
Copy Markdown
Contributor

Queue cache cursor acquisition and advancement currently use QueueCacheMissException for expected cursor states. This change introduces typed results so normal cache misses, empty/end states, and unsupported positioning can be handled without exception control flow.

This follows #9711, which owns the message-loss recovery behavior. The duplicate recovery implementation from the original version of this PR has been removed. Delivery cache misses continue inclusively from EarliestAvailable, while unsupported custom caches continue through their established token-based recovery path.

The change:

  • adds allocation-conscious typed acquisition and movement results with structured cache-miss details
  • implements the typed APIs directly in pooled, simple, generator, memory, and Event Hubs caches
  • migrates PersistentStreamPullingAgent to typed results for expected cache states
  • enforces cursor ownership invariants so rejected cursors are disposed and invalid results terminate instead of entering recovery loops
  • retains existing public cursor APIs as obsolete compatibility wrappers with their legacy cursor, QueueCacheMissException, and NotSupportedException behavior
  • preserves third-party cache and cursor implementations through default interface adapters
  • regenerates the Orleans Streaming and Event Hubs public API surfaces

The branch history is consolidated into implementation/API and test commits.

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.

Pull Request Overview

This PR introduces a new OldestInStreamToken to handle cache miss scenarios by allowing the pulling agent to restart from the oldest available message in the cache, rather than passing null or attempting to extract a token from the exception.

Key Changes:

  • Introduced OldestInStreamToken class that represents the oldest position in a stream
  • Updated cache miss handling to use OldestInStreamToken.Instance instead of null
  • Added cache logic to handle OldestInStreamToken by positioning cursors at the oldest message

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/Orleans.Streaming/Core/OldestInStreamToken.cs New token class representing the oldest position in a stream
src/Orleans.Streaming/PersistentStreams/PersistentStreamPullingAgent.cs Updated cache miss exception handling to use OldestInStreamToken.Instance
src/Orleans.Streaming/Common/PooledCache/PooledQueueCache.cs Added logic to position cursor at oldest message when OldestInStreamToken is provided
test/TesterInternal/OrleansRuntime/Streams/PooledQueueCacheTests.cs Added test coverage for getting cursor at oldest entry

@ReubenBond

Copy link
Copy Markdown
Member

@benjaminpetit PTAL

@ReubenBond
ReubenBond force-pushed the recover-from-exception-at-oldest-message branch from 6711e20 to dbf8374 Compare August 10, 2026 23:12
@ReubenBond
ReubenBond self-requested a review as a code owner August 10, 2026 23:12
@ReubenBond
ReubenBond force-pushed the recover-from-exception-at-oldest-message branch from dbf8374 to f97071a Compare August 10, 2026 23:15
@ReubenBond ReubenBond changed the title Make it so when there is a cache miss exception the pulling agent can… fix(streaming): recover cache cursors from oldest message Aug 10, 2026
@ReubenBond
ReubenBond force-pushed the recover-from-exception-at-oldest-message branch 3 times, most recently from 257519e to cad42be Compare August 23, 2026 09:09
@github-actions

github-actions Bot commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Code coverage

Metric Pull request
Lines 81.80% (106,573 / 130,292)
Branches 70.88% (30,412 / 42,906)

Report-only conclusion: current-main baseline stale.

The newest successful coverage run tested b64c6d7, not current main d0582bd.

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 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.

🟢 Approval recommended

The behavioral change is targeted, has a safe fallback path for unsupported caches, and includes focused regression tests covering the new scenarios.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

@ReubenBond
ReubenBond force-pushed the recover-from-exception-at-oldest-message branch from c375322 to 751f9f3 Compare September 4, 2026 01:51
@ReubenBond

Copy link
Copy Markdown
Member

Current CI cannot compile Orleans.Runtime on net8.0: the branch reports a broad set of missing runtime types (SchedulerInstruments, GrainPropertiesResolver, IRingRange, ILocalSiloDetails, and others). This is a branch integration/build issue and needs a rebase onto current main, conflict resolution, and a successful dotnet build Orleans.slnx -bl before retrying CI. The separate EHStreamingResumeTests.ResumeAfterInactivityNotInCache failure is already tracked by #10661.

@ReubenBond
ReubenBond force-pushed the recover-from-exception-at-oldest-message branch 3 times, most recently from f1d00ee to 85a9b6b Compare September 4, 2026 20:54
@ReubenBond
ReubenBond requested a lite review from Copilot September 4, 2026 21:01

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.

🟡 Changes recommended

It introduces source/binary-breaking public API removals (GetCursorAtPosition) which should be preserved via [Obsolete] wrappers to maintain provider compatibility.

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

Review details
  • Files reviewed: 23/23 changed files
  • Comments generated: 2
  • Review effort level: Lite

@ReubenBond
ReubenBond force-pushed the recover-from-exception-at-oldest-message branch from 85a9b6b to 49f16d8 Compare September 4, 2026 21:45
@ReubenBond
ReubenBond force-pushed the recover-from-exception-at-oldest-message branch from a73f6c6 to e1da931 Compare September 5, 2026 00:47
@ReubenBond ReubenBond changed the title fix(streaming): recover cache cursors from oldest message refactor(streaming): add typed cache cursor results Sep 5, 2026
@ReubenBond
ReubenBond force-pushed the recover-from-exception-at-oldest-message branch from 816db2c to 505e335 Compare September 5, 2026 14:17
@ReubenBond
ReubenBond merged commit 5b42a3a into dotnet:main Sep 5, 2026
71 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 6, 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.

3 participants