Skip to content

Add Poison Message Handling to the Dispatchers#1331

Open
sophiatev wants to merge 16 commits into
mainfrom
stevosyan/add-poison-message-handling
Open

Add Poison Message Handling to the Dispatchers#1331
sophiatev wants to merge 16 commits into
mainfrom
stevosyan/add-poison-message-handling

Conversation

@sophiatev
Copy link
Copy Markdown
Contributor

@sophiatev sophiatev commented Mar 24, 2026

This PR adds poison message handling to the activity, entity, and orchestration dispatchers. The general policy followed is that we want to make sure when poison message handling is enabled:

  1. exceptions are not thrown from the dispatchers which would cause repeated aborting of the work item in the case of an irrecoverable error
  2. we stop dispatching a message after its dispatch count exceeds the user-configured maximum
  3. whenever possible, we surface this information to the customer via a failed orchestration or entity operation

Depending on the type of "irrecoverable" error, the backends might have to add special edge-case handling for the poison message. The SDK's responsibility is simply to mark the message as poisoned and prevent its processing.

Note that we have intentionally chosen not to include poison message handling for unlock requests. This is because failing to unlock an entity could leave an entire task hub in a bad state, so we retain the current behavior.

Copilot AI review requested due to automatic review settings March 24, 2026 19:21
Comment thread src/DurableTask.Core/IOrchestrationService.cs Outdated
Comment thread src/DurableTask.Core/TaskOrchestrationDispatcher.cs
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 “poison message” handling across the orchestration, entity, and activity dispatchers by tracking per-event dispatch attempts and failing/dropping work once a configured maximum dispatch count is exceeded.

Changes:

  • Adds DispatchCount to HistoryEvent (and propagates it into entity request messages) and adds MaxDispatchCount to IOrchestrationService.
  • Adds poison detection logic in TaskOrchestrationDispatcher, TaskEntityDispatcher, and TaskActivityDispatcher to fail/drop over-dispatched messages.
  • Adds structured logging support for poison message detection.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
src/DurableTask.Core/TaskOrchestrationDispatcher.cs Detects over-dispatched orchestration events and fails the orchestration with non-retriable FailureDetails.
src/DurableTask.Core/TaskEntityDispatcher.cs Propagates dispatch counts into entity requests, filters/handles poison operations, and emits poison logs/failures.
src/DurableTask.Core/TaskActivityDispatcher.cs Detects poison activity events and either discards or fails activities based on dispatch count.
src/DurableTask.Core/Logging/LogHelper.cs Adds PoisonMessageDetected structured logging helpers.
src/DurableTask.Core/Logging/LogEvents.cs Adds a new structured log event type for poison message detection.
src/DurableTask.Core/Logging/EventIds.cs Introduces a new event id for poison detection logs.
src/DurableTask.Core/IOrchestrationService.cs Adds MaxDispatchCount configuration knob for providers.
src/DurableTask.Core/History/HistoryEvent.cs Adds DispatchCount to all history events for serialization/transport.
src/DurableTask.Core/Entities/OrchestrationEntityContext.cs Adds AbandonAcquire() to reset critical section lock acquisition state.
src/DurableTask.Core/Entities/EventFormat/RequestMessage.cs Adds DispatchCount field to entity request messages.

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

Comment thread src/DurableTask.Core/TaskOrchestrationDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskOrchestrationDispatcher.cs Outdated
Comment thread src/DurableTask.Core/Logging/LogEvents.cs Outdated
Comment thread src/DurableTask.Core/TaskActivityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/Logging/LogHelper.cs Outdated
Comment thread src/DurableTask.Core/TaskActivityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/IOrchestrationService.cs Outdated
Comment thread src/DurableTask.Core/TaskOrchestrationDispatcher.cs
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskActivityDispatcher.cs Outdated
Copilot AI review requested due to automatic review settings March 24, 2026 20:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 9 comments.


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

Comment thread src/DurableTask.Core/TaskActivityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/History/HistoryEvent.cs
Comment thread src/DurableTask.Core/TaskActivityDispatcher.cs Outdated
Comment thread src/DurableTask.ServiceBus/ServiceBusOrchestrationService.cs Outdated
Comment thread src/DurableTask.AzureStorage/AzureStorageOrchestrationService.cs Outdated
Comment thread src/DurableTask.Core/Logging/LogEvents.cs
Comment thread src/DurableTask.Core/TaskActivityDispatcher.cs
Comment thread src/DurableTask.Core/TaskOrchestrationDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs Outdated
Copilot AI review requested due to automatic review settings March 25, 2026 19:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 10 comments.


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

Comment thread src/DurableTask.Core/TaskOrchestrationDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskActivityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskOrchestrationDispatcher.cs
Comment thread src/DurableTask.Core/TaskActivityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/Logging/LogHelper.cs
Comment thread src/DurableTask.Core/TaskOrchestrationDispatcher.cs Outdated
…ase of poison message handling, except for entity unlock requests
Comment thread src/DurableTask.Core/TaskActivityDispatcher.cs Outdated
Copilot AI review requested due to automatic review settings April 1, 2026 19:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 10 comments.


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

Comment thread src/DurableTask.Core/TaskActivityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskActivityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskActivityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/Logging/LogHelper.cs
Comment thread src/DurableTask.Core/TaskHubWorker.cs Outdated
Copy link
Copy Markdown
Member

@cgillum cgillum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sharing some initial feedback - I unfortunately haven't reviewed everything yet.

Comment thread src/DurableTask.Core/History/HistoryEvent.cs Outdated
Comment thread src/DurableTask.Core/History/HistoryEvent.cs Outdated
Comment thread src/DurableTask.Core/Logging/LogEvents.cs
Comment thread src/DurableTask.Core/Logging/LogHelper.cs Outdated
Comment thread src/DurableTask.Core/TaskActivityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskActivityDispatcher.cs Outdated
Copy link
Copy Markdown
Member

@cgillum cgillum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finished reviewing all the changes.

Comment thread src/DurableTask.Core/TaskActivityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskActivityDispatcher.cs Outdated
);
traceActivity?.SetStatus(ActivityStatusCode.Error, message);
}
else
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff is a little hard to read due to the refactoring churn. I'm not sure how accurate my quick reading of the code is, but I'm wondering if introducing this else is part of the problem. Instead of having an else block, can we exit early from the function in the if block and remove else? That would make the code simpler if possible.

Comment thread src/DurableTask.Core/TaskHubWorker.cs Outdated
Comment thread src/DurableTask.Core/TaskOrchestrationDispatcher.cs
Comment thread src/DurableTask.Core/TaskOrchestrationDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskOrchestrationDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskOrchestrationDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs Outdated
runtimeState.OrchestrationInstance,
request,
$"Entity request has dispatch count {request.DispatchCount} which exceeds the maximum dispatch count " +
$"of {this.maxDispatchCount} and will be failed.");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that we log the fact that a message is poisoned, but we still process it anyways? I would have expected some kind of short-circuit logic to stop us from processing it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do want to process it in the sense that we want to make sure to send a calling orchestration the failure details if we can

Co-authored-by: Chris Gillum <cgillum@microsoft.com>
Copilot AI review requested due to automatic review settings June 2, 2026 23:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 14 comments.

Comment thread src/DurableTask.Core/TaskOrchestrationDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskOrchestrationDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskActivityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskActivityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskHubWorker.cs
Co-authored-by: Chris Gillum <cgillum@gmail.com>
Copilot AI review requested due to automatic review settings June 2, 2026 23:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 19 comments.

Comment thread src/DurableTask.Core/TaskActivityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskActivityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskActivityDispatcher.cs
Comment thread src/DurableTask.Core/TaskOrchestrationDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskOrchestrationDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskHubWorker.cs
Comment thread src/DurableTask.Core/TaskHubWorker.cs Outdated
Comment thread src/DurableTask.Core/TaskOrchestrationDispatcher.cs
Copilot AI review requested due to automatic review settings June 3, 2026 22:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

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

Comment thread src/DurableTask.Core/TaskOrchestrationDispatcher.cs
Comment thread src/DurableTask.Core/TaskOrchestrationDispatcher.cs
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs Outdated
Comment thread src/DurableTask.Core/TaskActivityDispatcher.cs
Copilot AI review requested due to automatic review settings June 3, 2026 23:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

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

Comment thread src/DurableTask.Core/TaskOrchestrationDispatcher.cs
Comment thread src/DurableTask.Core/TaskEntityDispatcher.cs
// This can happen if not all of the operations in the batch were executed, in which case we populate the remaining
// activities with the failure details if they are available.
// If not, this work will be deferred and tried again, so we do not want to publish the activity.
for (int i = results.Count; i < traceActivities.Count; i++)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not related to this PR but while working on it I realized this old logic I had for trace activities was incorrect so I took the chance to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants