Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace DurableTask.AzureStorage.Messaging
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Azure;
using DurableTask.Core;
using DurableTask.Core.History;
using Newtonsoft.Json;
Expand Down Expand Up @@ -234,5 +233,11 @@ bool IsNonexistantInstance()
{
return this.RuntimeState.Events.Count == 0 || this.RuntimeState.ExecutionStartedEvent == null;
}

public Task EndSessionAsync()
{
// No-op
return Task.CompletedTask;
}
}
}
7 changes: 7 additions & 0 deletions src/DurableTask.Core/IOrchestrationSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

#nullable enable
namespace DurableTask.Core
{
using System.Collections.Generic;
Expand All @@ -30,5 +31,11 @@ public interface IOrchestrationSession
/// and the dispatcher will shut down the session.
/// </remarks>
Task<IList<TaskMessage>> FetchNewOrchestrationMessagesAsync(TaskOrchestrationWorkItem workItem);
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

With #nullable enable enabled in this file, FetchNewOrchestrationMessagesAsync is documented to allow returning null to end the session, but the signature returns a non-nullable Task<IList<TaskMessage>>. Consider updating the return type annotation to Task<IList<TaskMessage>?> (nullable reference annotation only) so implementers using nullable analysis don’t get misleading contracts/warnings and the signature matches the documented behavior.

Suggested change
Task<IList<TaskMessage>> FetchNewOrchestrationMessagesAsync(TaskOrchestrationWorkItem workItem);
Task<IList<TaskMessage>?> FetchNewOrchestrationMessagesAsync(TaskOrchestrationWorkItem workItem);

Copilot uses AI. Check for mistakes.

/// <summary>
/// Ends the session.
/// </summary>
/// <returns>A task that completes when the session has been ended.</returns>
Task EndSessionAsync();
Comment on lines +35 to +39
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

IOrchestrationSession is a public interface in a netstandard2.0 library; adding EndSessionAsync() is a breaking change for any external providers that implement this interface (they will fail to compile until they add the new method). If backward compatibility is required, consider introducing a new optional interface (e.g., IOrchestrationSessionWithEnd/IOrchestrationSession2) and feature-detect it in the dispatchers, or provide an alternative non-interface-based extension point.

Copilot uses AI. Check for mistakes.
}
}
1 change: 1 addition & 0 deletions src/DurableTask.Core/TaskEntityDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ async Task OnProcessWorkItemSessionAsync(TaskOrchestrationWorkItem workItem)
if (concurrencyLockAcquired)
{
this.concurrentSessionLock.Release();
await workItem.Session.EndSessionAsync();
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/DurableTask.Core/TaskOrchestrationDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ async Task OnProcessWorkItemSessionAsync(TaskOrchestrationWorkItem workItem)
"OnProcessWorkItemSession-Release",
$"Releasing extended session after {processCount} batch(es).");
this.concurrentSessionLock.Release();
await workItem.Session.EndSessionAsync();
}
Comment on lines 295 to 299
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

The dispatchers now rely on IOrchestrationSession.EndSessionAsync() being invoked when an extended session ends (after releasing the concurrentSessionLock). Please add/adjust automated coverage that asserts EndSessionAsync() is called in the extended-session flow (and not skipped on important exit paths like completion/interrupt), since this call is necessary for the DTS scenario and regressions here are easy to miss in existing integration tests.

Copilot uses AI. Check for mistakes.
}
}
Expand Down Expand Up @@ -553,10 +554,6 @@ protected async Task<bool> OnProcessWorkItemAsync(TaskOrchestrationWorkItem work
orchestratorMessages.AddRange(subOrchestrationRewindMessages);
workItem.OrchestrationRuntimeState = newRuntimeState;
runtimeState = newRuntimeState;
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

In the RewindOrchestration decision path, the dispatcher no longer marks the work item as rewinding/interrupted. This can cause OnProcessWorkItemAsync to return false, so the extended session loop continues fetching/processing while the orchestration history/runtime state was manually rewritten by ProcessRewindOrchestrationDecision. Previously the code intentionally ended the extended session in this case to avoid persisting inconsistent cached session state; please restore an equivalent interrupt/end-session signal here (e.g., set isRewinding/isInterrupted) so the session terminates after processing a rewind decision.

Suggested change
runtimeState = newRuntimeState;
runtimeState = newRuntimeState;
// Mark this session as rewinding/interrupted so the extended session loop terminates
isRewinding = true;
isInterrupted = true;

Copilot uses AI. Check for mistakes.
// Setting this to true here will end an extended session if it is in progress.
// We don't want to save the state across executions, since we essentially manually modify
// the orchestration history here and so that stored by the extended session is incorrect.
isRewinding = true;
break;
default:
throw TraceHelper.TraceExceptionInstance(
Expand Down
Loading