Repository navigation
fix(streaming): drain detached pulling-agent work - #11268
Conversation
There was a problem hiding this comment.
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
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.
There was a problem hiding this comment.
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
Open (3)
Resolved since last review (1)
There was a problem hiding this comment.
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
Open (4)
Resolved since last review (1)
There was a problem hiding this comment.
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
Open (6)
Track overlapping handshake resolution by generation · New Do not let stale handshakes replace a newer rewind · New Retain subscriptions with unresolved handshake state Cached shutdown can skip cleanup after cancellation Do not run error protocol for an obsolete delivery Preserve uncertainty when a late stream registration is rejected
Code coverage
Report-only conclusion: improved. The current-main baseline is commit 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 |

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
AdmissionGateto 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
AddSubscriberacknowledgement 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