From a75f4e7d5095d1e40f4d0a8b22a03bcbf401b25c Mon Sep 17 00:00:00 2001 From: Usein Mambediiev Date: Fri, 6 Nov 2026 19:00:12 -0800 Subject: [PATCH 1/2] fix issue #333 --- .../SqlOrchestrationService.cs | 10 +-- .../Integration/Orchestrations.cs | 87 +++++++++++++++++++ .../Utils/TestService.cs | 22 +++++ 3 files changed, 114 insertions(+), 5 deletions(-) diff --git a/src/DurableTask.SqlServer/SqlOrchestrationService.cs b/src/DurableTask.SqlServer/SqlOrchestrationService.cs index ba75e3a..9b65bc0 100644 --- a/src/DurableTask.SqlServer/SqlOrchestrationService.cs +++ b/src/DurableTask.SqlServer/SqlOrchestrationService.cs @@ -453,7 +453,7 @@ public override async Task CompleteTaskOrchestrationWorkItemAsync( command.Parameters.Add("@InstanceID", SqlDbType.VarChar, size: 100).Value = instance.InstanceId; command.Parameters.Add("@ExecutionID", SqlDbType.VarChar, size: 50).Value = instance.ExecutionId; command.Parameters.Add("@RuntimeStatus", SqlDbType.VarChar, size: 30).Value = orchestrationState.OrchestrationStatus.ToString(); - command.Parameters.Add("@CustomStatusPayload", SqlDbType.VarChar).Value = orchestrationState.Status ?? SqlString.Null; + command.Parameters.Add("@CustomStatusPayload", SqlDbType.VarChar, size: -1 /* max */).Value = orchestrationState.Status ?? SqlString.Null; bool hasSession = workItem.Session != null; bool keepLocked = hasSession && !IsTerminalStatus(orchestrationState.OrchestrationStatus); @@ -666,7 +666,7 @@ public override async Task CreateTaskOrchestrationAsync(TaskMessage creationMess command.Parameters.Add("@Version", SqlDbType.VarChar, size: 100).Value = startEvent.Version; command.Parameters.Add("@InstanceID", SqlDbType.VarChar, size: 100).Value = instance.InstanceId; command.Parameters.Add("@ExecutionID", SqlDbType.VarChar, size: 50).Value = instance.ExecutionId; - command.Parameters.Add("@InputText", SqlDbType.VarChar).Value = startEvent.Input; + command.Parameters.Add("@InputText", SqlDbType.VarChar, size: -1 /* max */).Value = startEvent.Input; command.Parameters.Add("@StartTime", SqlDbType.DateTime2).Value = startEvent.ScheduledStartTime; command.Parameters.Add("@TraceContext", SqlDbType.VarChar, size: 800).Value = SqlUtils.GetTraceContext(startEvent); @@ -674,7 +674,7 @@ public override async Task CreateTaskOrchestrationAsync(TaskMessage creationMess if (dedupeStatuses?.Length > 0) { - command.Parameters.Add("@DedupeStatuses", SqlDbType.VarChar).Value = string.Join(",", dedupeStatuses); + command.Parameters.Add("@DedupeStatuses", SqlDbType.VarChar, size: -1 /* max */).Value = string.Join(",", dedupeStatuses); } try @@ -812,7 +812,7 @@ public override async Task ForceTerminateTaskOrchestrationAsync(string instanceI using SqlCommand command = this.GetSprocCommand(connection, $"{this.settings.SchemaName}.TerminateInstance"); command.Parameters.Add("@InstanceID", SqlDbType.VarChar, size: 100).Value = instanceId; - command.Parameters.Add("@Reason", SqlDbType.VarChar).Value = reason; + command.Parameters.Add("@Reason", SqlDbType.VarChar, size: -1 /* max */).Value = reason; await SqlUtils.ExecuteNonQueryAsync(command, this.traceHelper, instanceId); } @@ -1011,7 +1011,7 @@ public async Task RewindTaskOrchestrationAsync(string instanceId, string reason) using SqlCommand command = this.GetSprocCommand(connection, $"{this.settings.SchemaName}._RewindInstance"); command.Parameters.Add("@InstanceID", SqlDbType.VarChar, size: 100).Value = instanceId; - command.Parameters.Add("@Reason", SqlDbType.VarChar).Value = reason; + command.Parameters.Add("@Reason", SqlDbType.VarChar, size: -1 /* max */).Value = reason; await SqlUtils.ExecuteNonQueryAsync(command, this.traceHelper); } diff --git a/test/DurableTask.SqlServer.Tests/Integration/Orchestrations.cs b/test/DurableTask.SqlServer.Tests/Integration/Orchestrations.cs index 27a0ef6..632e7f7 100644 --- a/test/DurableTask.SqlServer.Tests/Integration/Orchestrations.cs +++ b/test/DurableTask.SqlServer.Tests/Integration/Orchestrations.cs @@ -446,6 +446,93 @@ public async Task Termination() LogAssert.CheckpointCompleted(orchestrationName)); } + // Each 'あ' is 3 bytes in UTF-8, so this string is under 8,000 characters but over 8,000 bytes. + // Regression coverage for https://github.com/microsoft/durabletask-mssql/issues/333. + static readonly string LargeUtf8Payload = new string('あ', 3000); + + [Fact] + public async Task LargeUtf8Input() + { + TestInstance instance = await this.testService.RunOrchestration( + LargeUtf8Payload, + orchestrationName: "EchoOrchestration", + implementation: (ctx, input) => Task.FromResult(input)); + + await instance.WaitForCompletion(expectedOutput: LargeUtf8Payload); + } + + [Fact] + public async Task LargeUtf8CustomStatus() + { + // Keep the input small so this test exercises only the custom status parameter. + TestInstance instance = await this.testService.RunOrchestration( + "input", + orchestrationName: "CustomStatusOrchestration", + new LargeCustomStatusOrchestration()); + + OrchestrationState state = await instance.WaitForCompletion(expectedOutput: "done"); + Assert.Equal(LargeUtf8Payload, JToken.Parse(state.Status).ToString()); + } + + class LargeCustomStatusOrchestration : TaskOrchestration + { + string status; + + public override Task RunTask(OrchestrationContext context, string input) + { + this.status = LargeUtf8Payload; + return Task.FromResult("done"); + } + + public override string OnGetStatus() => this.status; + } + + [Fact] + public async Task LargeUtf8TerminateReason() + { + TestInstance instance = await this.testService.RunOrchestration( + "input", + orchestrationName: "OrchestrationWithTimer", + implementation: (ctx, input) => ctx.CreateTimer(ctx.CurrentUtcDateTime.AddSeconds(30), input)); + + await instance.WaitForStart(); + await instance.TerminateAsync(LargeUtf8Payload); + + await instance.WaitForCompletion( + TimeSpan.FromSeconds(10), + expectedStatus: OrchestrationStatus.Terminated, + expectedOutput: LargeUtf8Payload); + } + + [Fact] + public async Task LargeUtf8RewindReason() + { + bool shouldFail = true; + + TestInstance instance = await this.testService.RunOrchestration( + "input", + orchestrationName: "RewindableOrchestration", + implementation: (ctx, input) => ctx.ScheduleTask("MaybeFail", "", input), + activities: ("MaybeFail", TestService.MakeActivity((TaskContext ctx, string input) => + { + if (shouldFail) + { + throw new InvalidOperationException("Kah-BOOOOM!!!"); + } + + return input; + }))); + + await instance.WaitForCompletion(expectedStatus: OrchestrationStatus.Failed); + + shouldFail = false; + await this.testService.OrchestrationServiceMock.Object.RewindTaskOrchestrationAsync( + instance.InstanceId, + LargeUtf8Payload); + + await instance.WaitForCompletion(expectedOutput: "input"); + } + [Theory] [InlineData(10)] [InlineData(300)] diff --git a/test/DurableTask.SqlServer.Tests/Utils/TestService.cs b/test/DurableTask.SqlServer.Tests/Utils/TestService.cs index 5d21ea3..a212fa9 100644 --- a/test/DurableTask.SqlServer.Tests/Utils/TestService.cs +++ b/test/DurableTask.SqlServer.Tests/Utils/TestService.cs @@ -330,6 +330,28 @@ public async Task> RunOrchestrationWithTags> RunOrchestration( + TInput input, + string orchestrationName, + TaskOrchestration orchestration) + { + this.worker.AddTaskOrchestrations(new TestObjectCreator( + orchestrationName, + string.Empty, + orchestration)); + + DateTime utcNow = DateTime.UtcNow; + OrchestrationInstance instance = await this.client.CreateOrchestrationInstanceAsync( + orchestrationName, + string.Empty, + Guid.NewGuid().ToString("N"), + input); + + return new TestInstance(this.client, instance, orchestrationName, string.Empty, utcNow, input); + } + public void RegisterInlineActivity(string name, string version, TaskActivity activity) { this.worker.AddTaskActivities(new TestObjectCreator(name, version, activity)); From fbb3c4fc816a4a89168932ea3c42f68c2f1265df Mon Sep 17 00:00:00 2001 From: Usein Mambediiev Date: Mon, 9 Nov 2026 11:25:55 -0800 Subject: [PATCH 2/2] address review comment --- .../Integration/Orchestrations.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/DurableTask.SqlServer.Tests/Integration/Orchestrations.cs b/test/DurableTask.SqlServer.Tests/Integration/Orchestrations.cs index 632e7f7..cc90078 100644 --- a/test/DurableTask.SqlServer.Tests/Integration/Orchestrations.cs +++ b/test/DurableTask.SqlServer.Tests/Integration/Orchestrations.cs @@ -531,6 +531,17 @@ await this.testService.OrchestrationServiceMock.Object.RewindTaskOrchestrationAs LargeUtf8Payload); await instance.WaitForCompletion(expectedOutput: "input"); + + // The rewind reason is persisted as the payload of a GenericEvent in the orchestration history. + // Rewind also converts the failure-related events into GenericEvents (with their original + // payloads), so look for the one carrying the reason rather than for a single GenericEvent. + string historyJson = await this.testService.OrchestrationServiceMock.Object.GetOrchestrationHistoryAsync( + instance.InstanceId, + executionIdFilter: null); + Assert.Single( + JArray.Parse(historyJson), + e => e.Value("EventType") == (int)EventType.GenericEvent + && e.Value("Data") == LargeUtf8Payload); } [Theory]