{"record":{"id":"f3a0ce7ea9a44288","repo":"microsoft/semantic-kernel","slug":"a-step-cannot-be-activated-before-it-has-been-init","errorCode":null,"errorMessage":"A step cannot be activated before it has been initialized.","messagePattern":"A step cannot be activated before it has been initialized\\.","errorType":"exception","errorClass":"KernelException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Experimental/Process.Runtime.Dapr/Actors/StepActor.cs","lineNumber":355,"sourceCode":"        }\n#pragma warning restore CA1031 // Do not catch general exception types\n    }\n\n    internal virtual Dictionary<string, Dictionary<string, object?>?> GenerateInitialInputs()\n    {\n        return this.FindInputChannels(this._functions, this._logger);\n    }\n\n    /// <summary>\n    /// Initializes the step with the provided step information.\n    /// </summary>\n    /// <returns>A <see cref=\"ValueTask\"/></returns>\n    /// <exception cref=\"KernelException\"></exception>\n    protected virtual async ValueTask ActivateStepAsync()\n    {\n        if (this._stepInfo is null)\n        {\n            throw new KernelException(\"A step cannot be activated before it has been initialized.\").Log(this._logger);\n        }\n\n        // Instantiate an instance of the inner step object\n        KernelProcessStep stepInstance = (KernelProcessStep)ActivatorUtilities.CreateInstance(this._kernel.Services, this._innerStepType!);\n        var kernelPlugin = KernelPluginFactory.CreateFromObject(stepInstance, pluginName: this._stepInfo.State.Name);\n\n        // Load the kernel functions\n        foreach (KernelFunction f in kernelPlugin)\n        {\n            this._functions.Add(f.Name, f);\n        }\n\n        // Initialize the input channels\n        this._initialInputs = this.GenerateInitialInputs();\n        this._inputs = this._initialInputs.ToDictionary(kvp => kvp.Key, kvp => kvp.Value?.ToDictionary(kvp => kvp.Key, kvp => kvp.Value));\n\n        // Activate the step with user-defined state if needed\n        KernelProcessStepState? stateObject = null;","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Experimental/Process.Runtime.Dapr/Actors/StepActor.cs#L337-L373","documentation":"ActivateStepAsync is the lazy one-time initialization that instantiates the step, loads kernel functions, and sets up input channels. It requires _stepInfo to be non-null, which is set by InitializeStep (called from InitializeStepAsync or OnActivateAsync). If ActivateStepAsync runs before initialization, this KernelException is thrown.","triggerScenarios":"The lazy _activateTask fires (triggered by HandleMessageAsync, ToDaprStepInfoAsync, or PrepareIncomingMessagesAsync) before InitializeStepAsync has been called and before OnActivateAsync found persisted state. The _stepInfo field is still null.","commonSituations":"A step actor proxy is used without calling InitializeStepAsync first. The actor is re-activated from scratch (no persisted state) and a method triggers lazy activation before initialization. A race between proxy creation and initialization.","solutions":["Call and await InitializeStepAsync before any method that triggers lazy activation (message processing, state extraction).","Ensure that for re-activated actors, the Dapr state store contains ActorStateKeys.StepInfoState so OnActivateAsync can call InitializeStep.","If the actor is fresh, always initialize first: InitializeStepAsync must be the first call after creating the proxy."],"exampleFix":"// before\nvar stepProxy = factory.CreateActorProxy<IStep>(stepId, nameof(StepActor));\nawait stepProxy.ProcessIncomingMessagesAsync(); // triggers lazy activation, throws\n\n// after\nvar stepProxy = factory.CreateActorProxy<IStep>(stepId, nameof(StepActor));\nawait stepProxy.InitializeStepAsync(stepInfo, parentProcessId);\nawait stepProxy.ProcessIncomingMessagesAsync();","handlingStrategy":"validation","validationCode":"// Ensure InitializeStepAsync is called before any method that triggers lazy activation:\nawait stepActor.InitializeStepAsync(stepInfo, parentProcessId);\n// Only then call methods that internally trigger _activateTask:\nawait stepActor.PrepareIncomingMessagesAsync();\nawait stepActor.ProcessIncomingMessagesAsync();\nawait stepActor.ToDaprStepInfoAsync();","typeGuard":null,"tryCatchPattern":"try\n{\n    await stepActor.ToDaprStepInfoAsync();\n}\ncatch (KernelException ex) when (ex.Message.Contains(\"cannot be activated before it has been initialized\"))\n{\n    logger.LogError(\"Step actor activated before InitializeStepAsync. Call initialization first.\");\n}","preventionTips":["Always call InitializeStepAsync first when creating a new step actor proxy.","Verify the Dapr state store has StepInfoState for re-activated actors.","Do not trigger lazy activation (via message processing or state extraction) on uninitialized actors."],"tags":["dapr","process-runtime","initialization","activation","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}