From e587e35b721acc6e7acb1a31712ba6907c12b1d6 Mon Sep 17 00:00:00 2001 From: halspang Date: Thu, 22 May 2025 12:58:41 -0700 Subject: [PATCH 1/2] Fix history events buildup from version reject When an orchestration was being rejected due to a versioning mismatch an issue would cause the history events of the orchestration to build continuously. This was caused by the orchestration adding an OrchestrationStarted event before the versioning took place and was saved even on a rejected version. This change causes the versioning code to exit the process method entirely instead of just prematurely end the process loop. This avoids the commit of the history. Signed-off-by: halspang --- src/DurableTask.Core/TaskOrchestrationDispatcher.cs | 2 +- .../AzureStorageScenarioTests.cs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/DurableTask.Core/TaskOrchestrationDispatcher.cs b/src/DurableTask.Core/TaskOrchestrationDispatcher.cs index 764d885e9..a9bb94bd1 100644 --- a/src/DurableTask.Core/TaskOrchestrationDispatcher.cs +++ b/src/DurableTask.Core/TaskOrchestrationDispatcher.cs @@ -406,7 +406,7 @@ protected async Task OnProcessWorkItemAsync(TaskOrchestrationWorkItem work else // Abandon work item in all other cases (will be retried later). { await this.orchestrationService.AbandonTaskOrchestrationWorkItemAsync(workItem); - break; + return false; } } } diff --git a/test/DurableTask.AzureStorage.Tests/AzureStorageScenarioTests.cs b/test/DurableTask.AzureStorage.Tests/AzureStorageScenarioTests.cs index aa3ca3355..aee05e945 100644 --- a/test/DurableTask.AzureStorage.Tests/AzureStorageScenarioTests.cs +++ b/test/DurableTask.AzureStorage.Tests/AzureStorageScenarioTests.cs @@ -2518,6 +2518,9 @@ public async Task OrchestrationRejectsWithVersionMismatch() status = await client.GetStatusAsync(); Assert.IsTrue(OrchestrationStatus.Running == status?.OrchestrationStatus || OrchestrationStatus.Pending == status?.OrchestrationStatus); + var history = await client.GetOrchestrationHistoryAsync(client.InstanceId); + Assert.AreEqual(0, history.Count, "A rejected orchestration should have no history as it should never have been started."); + await host.StopAsync(); } } From dced275107beccfee6fb2a065bde4857245577cb Mon Sep 17 00:00:00 2001 From: halspang Date: Fri, 23 May 2025 09:58:30 -0700 Subject: [PATCH 2/2] Return true to signify interrupted work Signed-off-by: halspang --- .../TaskOrchestrationDispatcher.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/DurableTask.Core/TaskOrchestrationDispatcher.cs b/src/DurableTask.Core/TaskOrchestrationDispatcher.cs index a9bb94bd1..42564cddf 100644 --- a/src/DurableTask.Core/TaskOrchestrationDispatcher.cs +++ b/src/DurableTask.Core/TaskOrchestrationDispatcher.cs @@ -406,7 +406,7 @@ protected async Task OnProcessWorkItemAsync(TaskOrchestrationWorkItem work else // Abandon work item in all other cases (will be retried later). { await this.orchestrationService.AbandonTaskOrchestrationWorkItemAsync(workItem); - return false; + return true; } } } @@ -1059,9 +1059,10 @@ TaskMessage ProcessScheduleTaskDecision( eventId: scheduleTaskOrchestratorAction.Id, name: scheduleTaskOrchestratorAction.Name, version: scheduleTaskOrchestratorAction.Version, - input: scheduleTaskOrchestratorAction.Input) { - Tags = scheduleTaskOrchestratorAction.Tags - }; + input: scheduleTaskOrchestratorAction.Input) + { + Tags = scheduleTaskOrchestratorAction.Tags + }; ActivitySpanId clientSpanId = ActivitySpanId.CreateRandom(); @@ -1080,9 +1081,10 @@ TaskMessage ProcessScheduleTaskDecision( scheduledEvent = new TaskScheduledEvent( eventId: scheduleTaskOrchestratorAction.Id, name: scheduleTaskOrchestratorAction.Name, - version: scheduleTaskOrchestratorAction.Version) { - Tags = scheduleTaskOrchestratorAction.Tags - }; + version: scheduleTaskOrchestratorAction.Version) + { + Tags = scheduleTaskOrchestratorAction.Tags + }; if (parentTraceActivity != null) {