Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="3.9.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.9.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="3.9.0" />
<PackageVersion Include="Microsoft.DurableTask.Client.Grpc" Version="1.16.1" />
<PackageVersion Include="Microsoft.DurableTask.Worker.Grpc" Version="1.16.1" />
<PackageVersion Include="Microsoft.DurableTask.Abstractions" Version="1.16.1" />
<PackageVersion Include="Microsoft.DurableTask.Client.Grpc" Version="1.17.0" />
<PackageVersion Include="Microsoft.DurableTask.Worker.Grpc" Version="1.17.0" />
<PackageVersion Include="Microsoft.DurableTask.Abstractions" Version="1.17.0" />
<PackageVersion Include="Microsoft.DurableTask.Analyzers" Version="0.1.0" />
<PackageVersion Include="Microsoft.Extensions.Azure" Version="1.7.0" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="6.0.3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ message EntityLockGrantedEvent {
string criticalSectionId = 1;
}

message ExecutionRewoundEvent {
google.protobuf.StringValue reason = 1;
google.protobuf.StringValue parentExecutionId = 2; // used only for rewinding suborchestrations, null otherwise
google.protobuf.StringValue instanceId = 3; // used only for rewinding suborchestrations, null otherwise
TraceContext parentTraceContext = 4; // used only for rewinding suborchestrations, null otherwise
}

message HistoryEvent {
int32 eventId = 1;
google.protobuf.Timestamp timestamp = 2;
Expand Down Expand Up @@ -251,6 +258,7 @@ message HistoryEvent {
EntityLockRequestedEvent entityLockRequested = 27;
EntityLockGrantedEvent entityLockGranted = 28;
EntityUnlockSentEvent entityUnlockSent = 29;
ExecutionRewoundEvent executionRewound = 30;
}
}

Expand Down Expand Up @@ -287,6 +295,7 @@ message CompleteOrchestrationAction {
google.protobuf.StringValue newVersion = 4;
repeated HistoryEvent carryoverEvents = 5;
TaskFailureDetails failureDetails = 6;
map<string, string> tags = 7;
}

message TerminateOrchestrationAction {
Expand Down
4 changes: 2 additions & 2 deletions src/WebJobs.Extensions.DurableTask/Grpc/Protos/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# The following files were downloaded from branch main at 2025-10-13 23:40:09 UTC
https://raw.githubusercontent.com/microsoft/durabletask-protobuf/97cf9cf6ac44107b883b0f4ab1dd62ee2332cfd9/protos/orchestrator_service.proto
# The following files were downloaded from branch main at 2025-11-05 19:08:35 UTC
https://raw.githubusercontent.com/microsoft/durabletask-protobuf/8c0d166673593700cfa9d0b123cd55e025b2846e/protos/orchestrator_service.proto
22 changes: 15 additions & 7 deletions src/WebJobs.Extensions.DurableTask/HttpApiHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,22 +1015,30 @@ private async Task<HttpResponseMessage> HandleRewindInstanceRequestAsync(
DurableOrchestrationStatus status = await client.GetStatusAsync(instanceId);
if (status == null)
{
return request.CreateResponse(HttpStatusCode.NotFound);
return request.CreateResponse(
HttpStatusCode.NotFound,
$"No orchestration with instance ID \"${instanceId}\" found.");
}

switch (status.RuntimeStatus)
if (status.RuntimeStatus != OrchestrationRuntimeStatus.Failed)
{
case OrchestrationRuntimeStatus.Canceled:
case OrchestrationRuntimeStatus.Terminated:
case OrchestrationRuntimeStatus.Completed:
return request.CreateResponse(HttpStatusCode.Gone);
return request.CreateResponse(
HttpStatusCode.PreconditionFailed,
$"This orchestration has status {status.RuntimeStatus}, but only orchestrations in the \"Failed\" state can be rewound.");
}

string reason = request.GetQueryNameValuePairs()["reason"];

try
{
#pragma warning disable 0618
await client.RewindAsync(instanceId, reason);
await client.RewindAsync(instanceId, reason);
#pragma warning restore 0618
}
catch (NotImplementedException e)
{
return request.CreateErrorResponse(HttpStatusCode.NotImplemented, "Rewind is not supported by the underlying storage provider.", e);
}

return request.CreateResponse(HttpStatusCode.Accepted);
}
Expand Down
3 changes: 3 additions & 0 deletions src/WebJobs.Extensions.DurableTask/ProtobufUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ public static P.HistoryEvent ToHistoryEventProto(HistoryEvent e)
Input = resumedEvent.Reason,
};
break;
case EventType.ExecutionRewound:
payload.ExecutionRewound = new P.ExecutionRewoundEvent();
break;
default:
throw new NotSupportedException($"Found unsupported history event '{e.EventType}'.");
}
Expand Down
28 changes: 26 additions & 2 deletions src/WebJobs.Extensions.DurableTask/TaskHubGrpcServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,33 @@ private OrchestrationStatus[] GetStatusesNotToOverride()

public async override Task<P.RewindInstanceResponse> RewindInstance(P.RewindInstanceRequest request, ServerCallContext context)
{
try
{
#pragma warning disable CS0618 // Type or member is obsolete
await this.GetClient(context).RewindAsync(request.InstanceId, request.Reason);
#pragma warning restore CS0618 // Type or member is obsolete
await this.GetClient(context).RewindAsync(request.InstanceId, request.Reason);
#pragma warning restore CS0618 // Type or member is obsolete
}
catch (ArgumentException ex)
{
// Instance ID does not exist.
throw new RpcException(new Status(StatusCode.NotFound, ex.Message));
}
catch (InvalidOperationException ex)
{
// Orchestration is not in a failed state.
throw new RpcException(new Status(StatusCode.FailedPrecondition, ex.Message));
}
catch (NotImplementedException ex)
{
// Rewind is not supported by the underlying storage provider.
throw new RpcException(new Status(StatusCode.Unimplemented, ex.Message));
}
catch (Exception ex)
{
// Any other unexpected exceptions.
throw new RpcException(new Status(StatusCode.Unknown, ex.Message));
}

return new P.RewindInstanceResponse();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<AssemblyName>Microsoft.Azure.WebJobs.Extensions.DurableTask</AssemblyName>
<RootNamespace>Microsoft.Azure.WebJobs.Extensions.DurableTask</RootNamespace>
<MajorVersion>3</MajorVersion>
<MinorVersion>6</MinorVersion>
<MinorVersion>7</MinorVersion>
<PatchVersion>0</PatchVersion>
<VersionPrefix>$(MajorVersion).$(MinorVersion).$(PatchVersion)</VersionPrefix>
<FileVersion>$(MajorVersion).$(MinorVersion).$(PatchVersion)</FileVersion>
Expand Down
2 changes: 1 addition & 1 deletion src/Worker.Extensions.DurableTask/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;

// TODO: Find a way to generate this dynamically at build-time
[assembly: ExtensionInformation("Microsoft.Azure.WebJobs.Extensions.DurableTask", "3.6.0")]
[assembly: ExtensionInformation("Microsoft.Azure.WebJobs.Extensions.DurableTask", "3.7.0")]
[assembly: InternalsVisibleTo("Worker.Extensions.DurableTask.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100cd1dabd5a893b40e75dc901fe7293db4a3caf9cd4d3e3ed6178d49cd476969abe74a9e0b7f4a0bb15edca48758155d35a4f05e6e852fff1b319d103b39ba04acbadd278c2753627c95e1f6f6582425374b92f51cca3deb0d2aab9de3ecda7753900a31f70a236f163006beefffe282888f85e3c76d1205ec7dfef7fa472a17b1")]
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ static string BuildUrl(string url, params string?[] queryValues)
SendEventPostUri = BuildUrl($"{instanceUrl}/raiseEvent/{{eventName}}", commonQueryParameters),
StatusQueryGetUri = BuildUrl(instanceUrl, commonQueryParameters),
TerminatePostUri = BuildUrl($"{instanceUrl}/terminate", "reason={{text}}", commonQueryParameters),
RewindPostUri = BuildUrl($"{instanceUrl}/rewind", "reason={{text}}", commonQueryParameters),
SuspendPostUri = BuildUrl($"{instanceUrl}/suspend", "reason={{text}}", commonQueryParameters),
ResumePostUri = BuildUrl($"{instanceUrl}/resume", "reason={{text}}", commonQueryParameters)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,11 @@ public override Task<string> RestartAsync(
string instanceId, bool restartWithNewInstanceId = false,CancellationToken cancellation = default)
{
return this.inner.RestartAsync(instanceId, restartWithNewInstanceId, cancellation);
}

public override Task RewindInstanceAsync(
string instanceId, string reason, CancellationToken cancellation = default)
{
return this.inner.RewindInstanceAsync(instanceId, reason, cancellation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<AssemblyOriginatorKeyFile>..\..\sign.snk</AssemblyOriginatorKeyFile>

<!-- Version information -->
<VersionPrefix>1.9.0</VersionPrefix>
<VersionPrefix>1.10.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<AssemblyVersion>$(VersionPrefix).0</AssemblyVersion>
<!-- FileVersionRevision is expected to be set by the CI. -->
Expand Down
196 changes: 196 additions & 0 deletions test/e2e/Apps/BasicDotNetIsolated/RewindOrchestration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Collections.Concurrent;
using System.Net;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.DurableTask;
using Microsoft.DurableTask.Client;
using Microsoft.DurableTask.Entities;
using Microsoft.Extensions.Logging;

namespace Microsoft.Azure.Durable.Tests.E2E;

public static class RewindOrchestration
{
private static readonly ConcurrentDictionary<string, int> invocationCounts = [];
private static readonly EntityInstanceId entityId = new(nameof(InvocationCounterEntity), "entity");

[Function(nameof(RewindParentOrchestration))]
public static async Task<ConcurrentDictionary<string, int>> RewindParentOrchestration(
[OrchestrationTrigger] TaskOrchestrationContext context)
{
OrchestrationInput? input = context.GetInput<OrchestrationInput>();
if (input?.Name == "run")
{
await context.CreateTimer(context.CurrentUtcDateTime.AddMinutes(10), CancellationToken.None);
return [];
}
else if (input?.Name == "complete")
{
return [];
}
else if (input?.Name == "fail")
{
Task[] subOrchestrationTasks =
{
context.CallSubOrchestratorAsync<string>(
nameof(SucceedSubOrchestration), "succeed_sub_1"),
context.CallSubOrchestratorAsync<string>(
nameof(FailParentSubOrchestration), new OrchestrationInput("fail_parent_sub_1", input.NumFailures, input.CallEntities)),
context.CallSubOrchestratorAsync<string>(
nameof(FailParentSubOrchestration), new OrchestrationInput("fail_parent_sub_2", input.NumFailures, input.CallEntities)),
context.CallSubOrchestratorAsync<string>(
nameof(SucceedSubOrchestration), "succeed_sub_2")
};
await Task.WhenAll(subOrchestrationTasks);
return invocationCounts;
}
else
{
throw new ArgumentException("Invalid input");
}
}

[Function(nameof(FailChildSubOrchestration))]
public static async Task<string> FailChildSubOrchestration(
[OrchestrationTrigger] TaskOrchestrationContext context)
{
OrchestrationInput input = context.GetInput<OrchestrationInput>()!;
List<Task> tasks =
[
context.CallActivityAsync<string>(nameof(SucceedActivity), input.Name + "_succeed_activity"),
context.CallActivityAsync<string>(nameof(FailActivity), new OrchestrationInput(input.Name + "_fail_activity_1", input.NumFailures, input.CallEntities)),
context.CallActivityAsync<string>(nameof(FailActivity), new OrchestrationInput(input.Name + "_fail_activity_2", input.NumFailures, input.CallEntities))
];
if (input.CallEntities)
{
tasks.Add(context.Entities.SignalEntityAsync(entityId, input.Name + "_signal_entity"));
tasks.Add(context.Entities.CallEntityAsync(entityId, input.Name + "_call_entity"));
}
await Task.WhenAll(tasks);
return "Ok, sub done!";
}

[Function(nameof(FailParentSubOrchestration))]
public static async Task<string> FailParentSubOrchestration(
[OrchestrationTrigger] TaskOrchestrationContext context)
{
OrchestrationInput input = context.GetInput<OrchestrationInput>()!;
await context.CallActivityAsync<string>(nameof(SucceedActivity), input.Name + "_succeed_activity");
if (input.CallEntities)
{
await context.Entities.CallEntityAsync(entityId, input.Name + "_call_entity");
}
await context.CallSubOrchestratorAsync<string>(nameof(FailChildSubOrchestration), new OrchestrationInput(input.Name + "_child", input.NumFailures, input.CallEntities));
return "Ok, sub done!";
}

[Function(nameof(SucceedSubOrchestration))]
public static async Task<string> SucceedSubOrchestration(
[OrchestrationTrigger] TaskOrchestrationContext context)
{
await context.CallActivityAsync<string>(nameof(SucceedActivity), context.GetInput<string>() + "_succeed_activity");
return "Ok, sub done!";
}

[Function(nameof(SucceedActivity))]
public static string SucceedActivity([ActivityTrigger] string input, FunctionContext executionContext)
{
UpdateInvocationCount(input);
return $"Hello, {input}!";
}

[Function(nameof(FailActivity))]
public static string FailActivity([ActivityTrigger] OrchestrationInput failInfo, FunctionContext executionContext)
{
if (UpdateInvocationCount(failInfo.Name!) <= failInfo.NumFailures)
{
throw new Exception("Failure!");
}
return "Success!";
}

[Function(nameof(RewindInstance))]
public static async Task<HttpResponseData> RewindInstance(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
[DurableClient] DurableTaskClient client,
string instanceId)
{
string rewindReason = "Rewinding the instance for testing.";
try
{
await client.RewindInstanceAsync(instanceId, rewindReason);

}
catch (InvalidOperationException)
{
return req.CreateResponse(HttpStatusCode.PreconditionFailed);
}
catch (ArgumentException)
{
return req.CreateResponse(HttpStatusCode.NotFound);
}
catch (NotImplementedException)
{
return req.CreateResponse(HttpStatusCode.NotImplemented);
}
return req.CreateResponse(HttpStatusCode.OK);
}

[Function(nameof(HttpStart_RewindOrchestration))]
public static async Task<HttpResponseData> HttpStart_RewindOrchestration(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
[DurableClient] DurableTaskClient client,
FunctionContext executionContext,
string input,
int numFailures,
bool callEntities,
bool? delay)
{
invocationCounts.Clear();
ILogger logger = executionContext.GetLogger(nameof(HttpStart_RewindOrchestration));

string instanceId = await client.ScheduleNewOrchestrationInstanceAsync(
nameof(RewindParentOrchestration),
new OrchestrationInput(input, numFailures, callEntities),
delay == true ? new StartOrchestrationOptions { StartAt = DateTimeOffset.UtcNow.AddMinutes(1) } : null);

logger.LogInformation("Started orchestration with ID = '{instanceId}'.", instanceId);

// Returns an HTTP 202 response with an instance management payload.
// See https://learn.microsoft.com/azure/azure-functions/durable/durable-functions-http-api#start-orchestration
return await client.CreateCheckStatusResponseAsync(req, instanceId);
}

[Function(nameof(InvocationCounterEntity))]
public static Task InvocationCounterEntity([EntityTrigger] TaskEntityDispatcher dispatcher)
{
return dispatcher.DispatchAsync(operation =>
{
UpdateInvocationCount(operation.Name);
return default;
});
}

private static int UpdateInvocationCount(string key)
{
if (!invocationCounts.TryGetValue(key, out int invocationCount))
{
invocationCount = 0;
invocationCounts[key] = invocationCount;
}
invocationCounts[key] = ++invocationCount;
return invocationCount;
}

public class OrchestrationInput(string name, int numFailures, bool callEntities)
{
public string? Name { get; set; } = name;

public int NumFailures { get; set; } = numFailures;

public bool CallEntities { get; set; } = callEntities;
}
}
Loading
Loading