Skip to content

fix(streaming): drain detached pulling-agent work - #11268

Merged
ReubenBond merged 8 commits into
dotnet:mainfrom
ReubenBond:rb-fix-drain-detached-stream-work
Sep 16, 2026
Merged

ReubenBond merged 8 commits into
dotnet:mainfrom
ReubenBond:rb-fix-drain-detached-stream-work

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Sep 16, 2026 •

Copy link
Copy Markdown
Member

Problem

Persistent stream pulling agents stop the queue pump before shutdown, but explicit subscription handshakes and consumer deliveries run independently. Those operations can still update delivery progress, reacquire cache cursors, or release batch protection after the final checkpoint scan and receiver cleanup. Producer registration also holds a cache pin which was previously drained after receiver shutdown.

Solution

Use the existing internal AdmissionGate to own accepted registration, attachment, and delivery lifetimes. Shutdown closes admission and stops polling, awaits receiver initialization, the pump, and admitted work, then reports final progress, disposes subscription cursors, and shuts down the receiver. Producer unregistration follows receiver cleanup. Preserve checkpoint uncertainty for registrations pending when shutdown begins.

A completed handshake establishes a new subscription generation. Older delivery completions retain their original handshake context and release their work while preserving the replacement cursor, replay token, and progress. This prevents the shutdown drain from checkpointing past a rewind accepted while an earlier delivery was in flight.

Keep the immediate public AddSubscriber acknowledgement and existing consumer/pump coalescing and retry limits. Reused agents await the previous full shutdown before opening a fresh per-run gate; cancellation of that initialization wait leaves the old run closed.

Focused regressions cover blocked delivery and explicit handshakes, live-cache token recovery, registration and delivery pins, late admission, failure/cancellation, immediate acknowledgement, conservative checkpoints, shutdown after an overlapping rewind, and reuse across a canceled initialization wait and a second shutdown. Update existing checkpoint expectations for completed in-flight work and document the handoff ordering.

Integration

Independent change based on 8c4887aba920b9250ad2914a039777a43781603f. The open grain-hosted pulling-agent work in #11255 overlaps this implementation and will need to retain these admission, rewind, and reuse guarantees in its shared runtime.

Microsoft Reviewers: Open in CodeFlow

Copilot AI lite review requested due to automatic review settings September 16, 2026 00:52

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 critical test compilation issue must be fixed before approval.

Get a fresh assessment by requesting another Copilot review.

Review tier: Lite
Findings: 1 High severity

Open (1)
What changed in this PR

This pull request hardens persistent stream pulling-agent shutdown by draining admitted work before checkpointing and receiver cleanup.

Changes:

  • Adds admission-gated shutdown and safe agent reuse.
  • Expands lifecycle, checkpoint, pin, cancellation, and reuse regression coverage.
  • Documents shutdown and queue-handoff ordering.
File Summary
test/​Orleans.Streaming.Tests/​StreamingTests/​PersistentStreamPullingAgentTests.cs Adds focused shutdown, checkpoint, pin, cancellation, and reuse tests.
src/​Orleans.Streaming/​PersistentStreams/​PersistentStreamPullingAgent.cs Coordinates admission draining, cleanup, checkpointing, and agent reuse.
docs/​site/​src/​content/​docs/​implementation/​streams-implementation/​index.md Documents shutdown and queue-handoff behavior.

💡 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 16, 2026 01:07

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

Five unresolved findings remain, including three critical shutdown and cursor-safety issues.

Get a fresh assessment by requesting another Copilot review.

Review tier: Lite
Findings: 3 High severity

Open (3)
Resolved since last review (1)

Copilot AI review requested due to automatic review settings September 16, 2026 01:16

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

Unresolved critical cleanup and checkpoint-safety issues, plus a detached attachment race, block approval.

Get a fresh assessment by requesting another Copilot review.

Review tier: Lite
Findings: 4 High severity

Open (4)
Resolved since last review (1)

Copilot AI review requested due to automatic review settings September 16, 2026 01: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

Unresolved critical handshake-ordering issues and moderate lifecycle/checkpoint issues remain.

Get a fresh assessment by requesting another Copilot review.

Review tier: Lite
Findings: 6 High severity

Open (6)

Copilot AI review requested due to automatic review settings September 16, 2026 01:47

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.

@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Code coverage

Metric Pull request Current main Variance
Lines 81.99% (111,802 / 136,367) 81.96% (111,718 / 136,302) +0.0225 pp
Branches 71.11% (32,104 / 45,148) 71.07% (32,050 / 45,096) +0.0377 pp

Report-only conclusion: improved.

The current-main baseline is commit 1544049879 and uses the same reviewed coverage matrix.

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

@ReubenBond
ReubenBond marked this pull request as ready for review September 16, 2026 02:09
Copilot AI review requested due to automatic review settings September 16, 2026 02:17

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 critical race can unregister a replacement subscription during an in-flight delivery failure.

Get a fresh assessment by requesting another Copilot review.

Review tier: Lite
Findings: 1 High severity

Open (1)
Resolved since last review (5)

Copilot AI review requested due to automatic review settings September 16, 2026 02:46
This was referenced Oct 12, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 16, 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