Azure / Azure/azure-functions-durable-powershell

Activity exception with circular references causes "Non-Deterministic workflow detected" instead of surfacing the real error

Open
#112 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
9
Forks
14
Avg merge
1d 23h
Merged PRs (30d)
5

Description

## Environment

- Azure Functions Host: 4.1051.300.1
- Durable Extension: 3.12.5
- Extension Bundle: `[4.*, 5.0.0)`
- PowerShell Worker: 7.4
- OS: Linux (App Service)

## Description

When a PowerShell activity function throws an exception, the orchestrator crashes with "Non-Deterministic workflow detected" instead of surfacing the actual error in `runtimeStatus: "Failed"`.

## Root Cause

PowerShell `ErrorRecord` objects contain circular references (`PSObject → ErrorRecord → InvocationInfo → PSObject`). The Durable SDK serializes activity results/exceptions using `Newtonsoft.Json` with default settings, which throws `JsonSerializationException` on circular references. This serialization failure is then misinterpreted as non-determinism.

## Steps to Reproduce

1. Create a PowerShell Durable Functions orchestrator that calls an activity
2. Have the activity throw any terminating error (e.g., a failed REST call)
3. Query the orchestration status via `GET /runtime/webhooks/durabletask/instances/{id}`
4. `runtimeStatus` shows `"Failed"` with message `"Non-Deterministic workflow detected"`
5. The actual exception message is lost

## Workaround

In `profile.ps1`, override Newtonsoft defaults before any orchestration runs:

```powershell
Add-Type -IgnoreWarnings -ReferencedAssemblies ([Newtonsoft.Json.JsonConvert].Assembly.Location) -TypeDefinition @'
using Newtonsoft.Json;
public static class DurableSdkSerializationFix {
public static void Apply() {
JsonConvert.DefaultSettings = () => new JsonSerializerSettings {
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
};
}
}
'@
[DurableSdkSerializationFix]::Apply()
```

`-IgnoreWarnings` suppresses a CS1701 warning from System.Runtime version mismatch 6.0 → 8.0.

## Expected Behavior

The SDK should handle circular references gracefully (e.g., use `ReferenceLoopHandling.Ignore` or sanitize PowerShell error objects before serialization) and surface the real exception message in the orchestration status.

Contributor guide

Open the contributing guide

Research direction

Start with the PowerShell activity reproduction and inspect the serialization behavior described for ErrorRecord objects and Newtonsoft.Json. Use the runtime status GET endpoint to compare the reported failure with the activity's actual exception, and review profile.ps1 as the documented workaround. Done means circular references no longer produce a misleading non-determinism error and the orchestration status surfaces the real exception message.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, powershell
Domain
backend, distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.