From 6be2c7a9e1a798c70261c33e778f1ef42e8592dd Mon Sep 17 00:00:00 2001 From: Austin Deal Date: Thu, 22 Jan 2026 10:54:35 -0800 Subject: [PATCH 1/6] Fix TemporalWorker::ExecuteAsync(Func) swallowing exceptions from void-returning workflows --- src/Temporalio/Worker/TemporalWorker.cs | 10 +++--- .../Testing/WorkflowEnvironmentTests.cs | 34 +++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/Temporalio/Worker/TemporalWorker.cs b/src/Temporalio/Worker/TemporalWorker.cs index e28f2905d..7dbdf2452 100644 --- a/src/Temporalio/Worker/TemporalWorker.cs +++ b/src/Temporalio/Worker/TemporalWorker.cs @@ -260,11 +260,11 @@ public Task ExecuteAsync(CancellationToken stoppingToken) => public Task ExecuteAsync( Func untilComplete, CancellationToken stoppingToken = default) => ExecuteInternalAsync( - () => untilComplete().ContinueWith( - _ => ValueTuple.Create(), - default, - TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.OnlyOnRanToCompletion, - TaskScheduler.Current), + async () => + { + await untilComplete().ConfigureAwait(false); + return ValueTuple.Create(); + }, stoppingToken); /// diff --git a/tests/Temporalio.Tests/Testing/WorkflowEnvironmentTests.cs b/tests/Temporalio.Tests/Testing/WorkflowEnvironmentTests.cs index 5993eea96..367790017 100644 --- a/tests/Temporalio.Tests/Testing/WorkflowEnvironmentTests.cs +++ b/tests/Temporalio.Tests/Testing/WorkflowEnvironmentTests.cs @@ -50,6 +50,17 @@ public async Task RunAsync() public Task SomeSignalAsync() => Task.CompletedTask; } + [Workflow] + public class VoidWorkflowThatFails + { + [WorkflowRun] + public async Task RunAsync() + { + await Task.Yield(); + throw new ApplicationFailureException("Intentional failure", nonRetryable: true); + } + } + [OnlyIntelFact] public async Task StartTimeSkippingAsync_SlowWorkflowAutoSkip_ProperlySkips() { @@ -290,4 +301,27 @@ public async Task StartLocal_SearchAttributes_ProperlyRegistered() }); Assert.Equal(attrVals, (await handle.DescribeAsync()).TypedSearchAttributes); } + + [Fact] + public async Task ExecuteAsync_VoidWorkflowFailure_PropagatesException() + { + // This test verifies that ExecuteAsync(Func) properly propagates exceptions + // from void-returning workflows. This is a regression test for a bug where + // ContinueWith with OnlyOnRanToCompletion caused exceptions to be swallowed. + string queue = $"tq-{Guid.NewGuid()}"; + await using var env = await WorkflowEnvironment.StartLocalAsync(); + using var worker = new TemporalWorker( + env.Client, + new TemporalWorkerOptions(queue).AddWorkflow()); + + var exc = await Assert.ThrowsAsync(async () => + await worker.ExecuteAsync(async () => + await env.Client.ExecuteWorkflowAsync( + (VoidWorkflowThatFails wf) => wf.RunAsync(), + new(id: $"wf-{Guid.NewGuid()}", taskQueue: queue)))); + + Assert.NotNull(exc.InnerException); + var appExc = Assert.IsType(exc.InnerException); + Assert.Equal("Intentional failure", appExc.Message); + } } \ No newline at end of file From 85bee6c7c6fa3a637db255d9047f8915e0608c21 Mon Sep 17 00:00:00 2001 From: Austin Deal Date: Thu, 22 Jan 2026 10:54:35 -0800 Subject: [PATCH 2/6] Create new GeneralWorkerTests, move test there --- .../Testing/WorkflowEnvironmentTests.cs | 34 ---------------- .../Worker/GeneralWorkerTests.cs | 39 +++++++++++++++++++ 2 files changed, 39 insertions(+), 34 deletions(-) create mode 100644 tests/Temporalio.Tests/Worker/GeneralWorkerTests.cs diff --git a/tests/Temporalio.Tests/Testing/WorkflowEnvironmentTests.cs b/tests/Temporalio.Tests/Testing/WorkflowEnvironmentTests.cs index 367790017..5993eea96 100644 --- a/tests/Temporalio.Tests/Testing/WorkflowEnvironmentTests.cs +++ b/tests/Temporalio.Tests/Testing/WorkflowEnvironmentTests.cs @@ -50,17 +50,6 @@ public async Task RunAsync() public Task SomeSignalAsync() => Task.CompletedTask; } - [Workflow] - public class VoidWorkflowThatFails - { - [WorkflowRun] - public async Task RunAsync() - { - await Task.Yield(); - throw new ApplicationFailureException("Intentional failure", nonRetryable: true); - } - } - [OnlyIntelFact] public async Task StartTimeSkippingAsync_SlowWorkflowAutoSkip_ProperlySkips() { @@ -301,27 +290,4 @@ public async Task StartLocal_SearchAttributes_ProperlyRegistered() }); Assert.Equal(attrVals, (await handle.DescribeAsync()).TypedSearchAttributes); } - - [Fact] - public async Task ExecuteAsync_VoidWorkflowFailure_PropagatesException() - { - // This test verifies that ExecuteAsync(Func) properly propagates exceptions - // from void-returning workflows. This is a regression test for a bug where - // ContinueWith with OnlyOnRanToCompletion caused exceptions to be swallowed. - string queue = $"tq-{Guid.NewGuid()}"; - await using var env = await WorkflowEnvironment.StartLocalAsync(); - using var worker = new TemporalWorker( - env.Client, - new TemporalWorkerOptions(queue).AddWorkflow()); - - var exc = await Assert.ThrowsAsync(async () => - await worker.ExecuteAsync(async () => - await env.Client.ExecuteWorkflowAsync( - (VoidWorkflowThatFails wf) => wf.RunAsync(), - new(id: $"wf-{Guid.NewGuid()}", taskQueue: queue)))); - - Assert.NotNull(exc.InnerException); - var appExc = Assert.IsType(exc.InnerException); - Assert.Equal("Intentional failure", appExc.Message); - } } \ No newline at end of file diff --git a/tests/Temporalio.Tests/Worker/GeneralWorkerTests.cs b/tests/Temporalio.Tests/Worker/GeneralWorkerTests.cs new file mode 100644 index 000000000..07f246e3f --- /dev/null +++ b/tests/Temporalio.Tests/Worker/GeneralWorkerTests.cs @@ -0,0 +1,39 @@ +using Temporalio.Worker; +using Temporalio.Workflows; +using Xunit; +using Xunit.Abstractions; + +namespace Temporalio.Tests.Worker; + +public class GeneralWorkerTests : TestBase +{ + public GeneralWorkerTests(ITestOutputHelper output) + : base(output) + { + } + + [Workflow] + public class VoidWorkflow + { + [WorkflowRun] + public async Task RunAsync() + { + } + } + + [Fact] + public async Task ExecuteAsync_VoidWorkflowFailure_PropagatesException() + { + // This test verifies that ExecuteAsync(Func) properly propagates exceptions + // from void-returning tasks. This is a regression test for a bug where + // ContinueWith with OnlyOnRanToCompletion caused exceptions to be swallowed. + await using var env = await Temporalio.Testing.WorkflowEnvironment.StartLocalAsync(); + using var worker = new TemporalWorker( + env.Client, + new TemporalWorkerOptions($"tq-{Guid.NewGuid()}").AddWorkflow()); + + // Throw an arbitrary exception type to verify it is propagated out of the worker execution. + await Assert.ThrowsAsync(async () => + await worker.ExecuteAsync(async () => throw new InvalidOperationException(null))); + } +} \ No newline at end of file From 45ed3edcec6fb6cc67a3fdc922f53bd08c08c257 Mon Sep 17 00:00:00 2001 From: Austin Deal Date: Thu, 22 Jan 2026 13:18:29 -0800 Subject: [PATCH 3/6] PR feedback: use WorkflowEnvironmentTestBase and dummy activity --- src/Temporalio/Workflows/Semaphore.cs | 2 +- .../Worker/GeneralWorkerTests.cs | 22 +++++-------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/Temporalio/Workflows/Semaphore.cs b/src/Temporalio/Workflows/Semaphore.cs index 2546e8136..11e26b4bb 100644 --- a/src/Temporalio/Workflows/Semaphore.cs +++ b/src/Temporalio/Workflows/Semaphore.cs @@ -186,7 +186,7 @@ private Task WaitInternalAsync( { CurrentCount--; return true; - } + } return false; }, default, diff --git a/tests/Temporalio.Tests/Worker/GeneralWorkerTests.cs b/tests/Temporalio.Tests/Worker/GeneralWorkerTests.cs index 07f246e3f..0f5557931 100644 --- a/tests/Temporalio.Tests/Worker/GeneralWorkerTests.cs +++ b/tests/Temporalio.Tests/Worker/GeneralWorkerTests.cs @@ -1,36 +1,26 @@ using Temporalio.Worker; -using Temporalio.Workflows; using Xunit; using Xunit.Abstractions; namespace Temporalio.Tests.Worker; -public class GeneralWorkerTests : TestBase +public class GeneralWorkerTests : WorkflowEnvironmentTestBase { - public GeneralWorkerTests(ITestOutputHelper output) - : base(output) + public GeneralWorkerTests(ITestOutputHelper output, WorkflowEnvironment env) + : base(output, env) { } - [Workflow] - public class VoidWorkflow - { - [WorkflowRun] - public async Task RunAsync() - { - } - } - [Fact] public async Task ExecuteAsync_VoidWorkflowFailure_PropagatesException() { // This test verifies that ExecuteAsync(Func) properly propagates exceptions // from void-returning tasks. This is a regression test for a bug where // ContinueWith with OnlyOnRanToCompletion caused exceptions to be swallowed. - await using var env = await Temporalio.Testing.WorkflowEnvironment.StartLocalAsync(); + static void Ignored() => throw new NotImplementedException(); using var worker = new TemporalWorker( - env.Client, - new TemporalWorkerOptions($"tq-{Guid.NewGuid()}").AddWorkflow()); + Env.Client, + new TemporalWorkerOptions($"tq-{Guid.NewGuid()}").AddActivity(Ignored)); // Throw an arbitrary exception type to verify it is propagated out of the worker execution. await Assert.ThrowsAsync(async () => From c70da7b60d876f613cde9b9d8c4232af9277712f Mon Sep 17 00:00:00 2001 From: Austin Deal Date: Thu, 22 Jan 2026 13:22:09 -0800 Subject: [PATCH 4/6] update test name to no longer reflect dependence on WF --- tests/Temporalio.Tests/Worker/GeneralWorkerTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Temporalio.Tests/Worker/GeneralWorkerTests.cs b/tests/Temporalio.Tests/Worker/GeneralWorkerTests.cs index 0f5557931..6f7d74383 100644 --- a/tests/Temporalio.Tests/Worker/GeneralWorkerTests.cs +++ b/tests/Temporalio.Tests/Worker/GeneralWorkerTests.cs @@ -12,7 +12,7 @@ public GeneralWorkerTests(ITestOutputHelper output, WorkflowEnvironment env) } [Fact] - public async Task ExecuteAsync_VoidWorkflowFailure_PropagatesException() + public async Task ExecuteAsync_PropagatesException() { // This test verifies that ExecuteAsync(Func) properly propagates exceptions // from void-returning tasks. This is a regression test for a bug where From 6564f871746708e479a14b6a501acb1574007b03 Mon Sep 17 00:00:00 2001 From: Austin Deal Date: Thu, 22 Jan 2026 14:27:07 -0800 Subject: [PATCH 5/6] revert unintentional ws change to semaphore.cs --- src/Temporalio/Workflows/Semaphore.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Temporalio/Workflows/Semaphore.cs b/src/Temporalio/Workflows/Semaphore.cs index 11e26b4bb..2546e8136 100644 --- a/src/Temporalio/Workflows/Semaphore.cs +++ b/src/Temporalio/Workflows/Semaphore.cs @@ -186,7 +186,7 @@ private Task WaitInternalAsync( { CurrentCount--; return true; - } + } return false; }, default, From fe918e639620239e16e42dbf6ec721fab91af820 Mon Sep 17 00:00:00 2001 From: Austin Deal Date: Wed, 28 Jan 2026 15:39:20 -0800 Subject: [PATCH 6/6] add missing [Activity] attr --- tests/Temporalio.Tests/Worker/GeneralWorkerTests.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Temporalio.Tests/Worker/GeneralWorkerTests.cs b/tests/Temporalio.Tests/Worker/GeneralWorkerTests.cs index 6f7d74383..8f3adec1f 100644 --- a/tests/Temporalio.Tests/Worker/GeneralWorkerTests.cs +++ b/tests/Temporalio.Tests/Worker/GeneralWorkerTests.cs @@ -1,3 +1,4 @@ +using Temporalio.Activities; using Temporalio.Worker; using Xunit; using Xunit.Abstractions; @@ -17,7 +18,9 @@ public async Task ExecuteAsync_PropagatesException() // This test verifies that ExecuteAsync(Func) properly propagates exceptions // from void-returning tasks. This is a regression test for a bug where // ContinueWith with OnlyOnRanToCompletion caused exceptions to be swallowed. + [Activity] static void Ignored() => throw new NotImplementedException(); + using var worker = new TemporalWorker( Env.Client, new TemporalWorkerOptions($"tq-{Guid.NewGuid()}").AddActivity(Ignored));