Skip to content

Record delivered subscription events as Ok on client disconnect - #10138

Merged
michaelstaib merged 2 commits into
mainfrom
mst/fusion-subscription-event-activity-race
Jul 22, 2026
Merged

michaelstaib merged 2 commits into
mainfrom
mst/fusion-subscription-event-activity-race

Conversation

@michaelstaib

Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings July 22, 2026 13:11

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 improves Fusion subscription observability and resilience by (1) explicitly recording when a subscription event has been delivered to the client (so diagnostics aren’t downgraded by a later client disconnect) and (2) treating event stream broker read failures as graceful stream termination while still emitting diagnostic error signals.

Changes:

  • Add a new SubscriptionEventDelivered diagnostic callback and invoke it after a subscription event result is yielded.
  • Handle broker read exceptions in EventStreamExecutionNode by reporting SubscriptionEventError and completing the stream without surfacing a raw exception to the consumer.
  • Add a new regression test covering broker read failure behavior for event streams.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/HotChocolate/Fusion/test/Fusion.Execution.Tests/Execution/Subscriptions/EventStreamBrokerReadFailureTests.cs New test validating graceful completion + diagnostic error reporting when the broker read fails after emitting an event.
src/HotChocolate/Fusion/src/Fusion.Execution/Execution/OperationPlanExecutor.cs Emits SubscriptionEventDelivered after yielding each subscription event result.
src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/EventStreamExecutionNode.cs Catches broker read failures, reports diagnostics, and terminates the stream gracefully.
src/HotChocolate/Fusion/src/Fusion.Execution/Diagnostics/IFusionExecutionDiagnosticEvents.cs Introduces new SubscriptionEventDelivered API surface.
src/HotChocolate/Fusion/src/Fusion.Execution/Diagnostics/FusionExecutionDiagnosticEventListener.cs Adds a virtual no-op implementation for SubscriptionEventDelivered.
src/HotChocolate/Fusion/src/Fusion.Execution/Diagnostics/AggregateFusionExecutionDiagnosticEvents.cs Forwards SubscriptionEventDelivered to all aggregated listeners.
src/HotChocolate/Fusion/src/Fusion.Diagnostics/Listeners/FusionActivityExecutionDiagnosticEventListener.cs Stores the active subscription event span and marks it delivered when notified.
src/HotChocolate/Diagnostics/src/Diagnostics.Core/Spans/SubscriptionEventSpan.cs Adds delivered tracking and forces ActivityStatusCode.Ok on completion when delivered.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1244 to +1254
// Execution resumes here only after the consumer finished writing the
// yielded result to the client and asked for the next event. Record the
// delivery before the event scope is disposed at the end of this loop
// iteration, so a client abort that races the resume cannot erase the
// delivered event's success status. An event whose write failed never
// resumes the stream and therefore is never reported as delivered.
context.DiagnosticEvents.SubscriptionEventDelivered(
context,
subscriptionNode,
schemaName,
subscriptionResult.Id);
@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Patch coverage

79.7% of changed lines covered (51/64)

File Covered Changed Patch %
…/Diagnostics/AggregateFusionExecutionDiagnosticEvents.cs 0 10 0.0% 🔴
…/Fusion.Execution/Execution/Nodes/EventStreamExecutionNode.cs 32 35 91.4% 🟡
…/src/Diagnostics.Core/Spans/SubscriptionEventSpan.cs 5 5 100.0% 🟢
…/Listeners/FusionActivityExecutionDiagnosticEventListener.cs 7 7 100.0% 🟢
…/Diagnostics/FusionExecutionDiagnosticEventListener.cs 2 2 100.0% 🟢
…/src/Fusion.Execution/Execution/OperationPlanExecutor.cs 5 5 100.0% 🟢
Uncovered changed lines (JSON)
{
  "sha": "1f226f969467f6fc462db129d621bc8d71e0baa5",
  "files": [
    { "path": "src/HotChocolate/Fusion/src/Fusion.Execution/Diagnostics/AggregateFusionExecutionDiagnosticEvents.cs", "ranges": [[380, 389]] },
    { "path": "src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/EventStreamExecutionNode.cs", "ranges": [[271, 273]] }
  ]
}

Project coverage: 53.8% (231518/430378 lines)

@michaelstaib
michaelstaib merged commit 9f18b95 into main Jul 22, 2026
6 of 7 checks passed
@michaelstaib
michaelstaib deleted the mst/fusion-subscription-event-activity-race branch July 22, 2026 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants