microsoft/semantic-kernel · error · InvalidOperationException

The process cannot be started before it has been initialized

Error message

The process cannot be started before it has been initialized.

What it means

Thrown as InvalidOperationException by ProcessActor.StartAsync when _isInitialized is false. The process actor must first be initialized via InitializeProcessAsync (which builds the step graph and saves state) before StartAsync can launch the Pregel execution loop. Calling StartAsync on a fresh or un-initialized actor triggers this guard.

Source

Thrown at dotnet/src/Experimental/Process.Runtime.Dapr/Actors/ProcessActor.cs:85

        await this.StateManager.AddStateAsync(ActorStateKeys.StepParentProcessId, parentProcessId).ConfigureAwait(false);
        await this.StateManager.AddStateAsync(ActorStateKeys.StepActivatedState, true).ConfigureAwait(false);
        if (!string.IsNullOrWhiteSpace(eventProxyStepId))
        {
            await this.StateManager.AddStateAsync(ActorStateKeys.EventProxyStepId, eventProxyStepId).ConfigureAwait(false);
        }
        await this.StateManager.SaveStateAsync().ConfigureAwait(false);
    }

    /// <summary>
    /// Starts the process with an initial event and an optional kernel.
    /// </summary>
    /// <param name="keepAlive">Indicates if the process should wait for external events after it's finished processing.</param>
    /// <returns> <see cref="Task"/></returns>
    public Task StartAsync(bool keepAlive)
    {
        if (!this._isInitialized)
        {
            throw new InvalidOperationException("The process cannot be started before it has been initialized.").Log(this._logger);
        }

        this._processCancelSource = new CancellationTokenSource();
        this._processTask = this._joinableTaskFactory.RunAsync(()
            => this.Internal_ExecuteAsync(keepAlive: keepAlive, cancellationToken: this._processCancelSource.Token));

        return Task.CompletedTask;
    }

    /// <summary>
    /// Starts the process with an initial event and then waits for the process to finish. In this case the process will not
    /// keep alive waiting for external events after the internal messages have stopped.
    /// </summary>
    /// <param name="processEvent">Required. The <see cref="KernelProcessEvent"/> to start the process with.</param>
    /// <returns>A <see cref="Task"/></returns>
    public async Task RunOnceAsync(string processEvent)
    {
        Verify.NotNull(processEvent, nameof(processEvent));

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Always call InitializeProcessAsync with a valid DaprProcessInfo before calling StartAsync.
  2. Verify the Dapr state store is healthy so that OnActivateAsync can restore the process on re-activation.
  3. Ensure the actor id used for StartAsync matches the one used during InitializeProcessAsync.
  4. Use the DaprKernelProcessContext API rather than calling actor methods directly.

Example fix

// before - calling StartAsync without initialization
await processActor.StartAsync(keepAlive: true);
// after - initialize first
await processActor.InitializeProcessAsync(processInfo, parentProcessId).ConfigureAwait(false);
await processActor.StartAsync(keepAlive: true).ConfigureAwait(false);
Defensive patterns

Strategy: validation

Validate before calling

// Always initialize the process actor before starting it
await processActor.InitializeProcessAsync(processInfo, parentProcessId).ConfigureAwait(false);
// Then start
await processActor.StartAsync(keepAlive: true).ConfigureAwait(false);

Prevention

When it happens

Trigger: ProcessActor.StartAsync is called before InitializeProcessAsync has completed, or the actor was re-activated from scratch (no persisted state) and OnActivateAsync did not find existing process info to restore, leaving _isInitialized false.

Common situations: Calling StartAsync directly on a new ProcessActor without going through InitializeProcessAsync; a Dapr actor re-activation where the state store lost the persisted process info; incorrect actor id causing activation of a fresh actor instead of the intended one; state store connectivity issues during OnActivateAsync.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/66293b1f99607c7f. Report an issue: GitHub.