From b743ebd8f7ee525520c01d4c3e8a0229ee27b5a2 Mon Sep 17 00:00:00 2001 From: Ben Thomas Date: Tue, 15 Oct 2024 15:52:33 -0700 Subject: [PATCH] Updating local process to respect initial state. --- .../Experimental/Process.LocalRuntime/LocalStep.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/dotnet/src/Experimental/Process.LocalRuntime/LocalStep.cs b/dotnet/src/Experimental/Process.LocalRuntime/LocalStep.cs index abc4659125d8..f5257415ef21 100644 --- a/dotnet/src/Experimental/Process.LocalRuntime/LocalStep.cs +++ b/dotnet/src/Experimental/Process.LocalRuntime/LocalStep.cs @@ -231,7 +231,7 @@ protected virtual async ValueTask InitializeStepAsync() this._inputs = this._initialInputs.ToDictionary(kvp => kvp.Key, kvp => kvp.Value?.ToDictionary(kvp => kvp.Key, kvp => kvp.Value)); // Activate the step with user-defined state if needed - KernelProcessStepState? stateObject = null; + KernelProcessStepState stateObject = this._stepInfo.State; Type? stateType = null; if (TryGetSubtypeOfStatefulStep(this._stepInfo.InnerStepType, out Type? genericStepType) && genericStepType is not null) @@ -254,14 +254,17 @@ protected virtual async ValueTask InitializeStepAsync() throw new KernelException(errorMessage); } - stateObject = (KernelProcessStepState?)Activator.CreateInstance(stateType, this.Name, this.Id); - stateType.GetProperty(nameof(KernelProcessStepState.State))?.SetValue(stateObject, Activator.CreateInstance(userStateType)); + var userState = stateType.GetProperty(nameof(KernelProcessStepState.State))?.GetValue(stateObject); + if (userState is null) + { + stateType.GetProperty(nameof(KernelProcessStepState.State))?.SetValue(stateObject, Activator.CreateInstance(userStateType)); + } } else { // The step is a KernelProcessStep with no user-defined state, so we can use the base KernelProcessStepState. stateType = typeof(KernelProcessStepState); - stateObject = new KernelProcessStepState(this.Name, this.Id); + //stateObject = new KernelProcessStepState(this.Name, this.Id); } if (stateObject is null)