{"record":{"id":"c7dedc42bdaaba43","repo":"microsoft/semantic-kernel","slug":"the-process-must-have-an-id-set","errorCode":null,"errorMessage":"The process must have an Id set","messagePattern":"The process must have an Id set","errorType":"exception","errorClass":"KernelException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Experimental/Process.Core/Workflow/WorkflowBuilder.cs","lineNumber":328,"sourceCode":"        return Task.CompletedTask;\n    }\n\n    #endregion\n\n    #region FromProcess\n\n    /// <summary>\n    /// Builds a workflow from a kernel process.\n    /// </summary>\n    /// <param name=\"process\"></param>\n    /// <returns></returns>\n    public static Task<Workflow> BuildWorkflow(KernelProcess process)\n    {\n        Verify.NotNull(process);\n\n        Workflow workflow = new()\n        {\n            Id = process.State.Id ?? throw new KernelException(\"The process must have an Id set\"),\n            Description = process.Description,\n            FormatVersion = \"1.0\",\n            Name = process.State.Name,\n            Nodes = [new Node { Id = \"End\", Type = \"declarative\", Version = \"1.0\", Description = \"Terminal state\" }],\n            Variables = [],\n        };\n\n        // Add variables\n        foreach (var thread in process.Threads)\n        {\n            workflow.Variables.Add(thread.Key, new VariableDefinition()\n            {\n                Type = VariableType.Thread,\n            });\n        }\n\n        if (process.UserStateType != null)\n        {","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Experimental/Process.Core/Workflow/WorkflowBuilder.cs#L310-L346","documentation":"Thrown by the static `BuildWorkflow(KernelProcess)` when `process.State.Id` is null. The workflow requires a stable identifier to serialize, so a process without an Id is rejected at construction of the `Workflow` object. It is a KernelException thrown inline in the object initializer.","triggerScenarios":"Construct a `KernelProcess` (or its `KernelProcessState`) without assigning an Id and pass it to `BuildWorkflow`; build a process from a builder that never called `.WithId(...)` / never set the id; deserialize a process whose state lost its Id.","commonSituations":"Programmatic process construction where the Id was assumed to auto-generate; tests that create a throwaway process without an Id; serialization round-trips that drop the Id field.","solutions":["Assign a non-null Id when creating the process: `process.State.Id = \"myProcess\"` or via the builder's id parameter.","If loading from JSON/YAML, ensure the source contains an `id` field and the deserializer maps it to `State.Id`.","Add a guard before calling BuildWorkflow: `if (process.State.Id is null) throw ...` with a clearer message."],"exampleFix":"// before\nvar process = new KernelProcess(state, steps, edges);\nawait WorkflowBuilder.BuildWorkflow(process);\n// after\nstate.Id = \"myProcess\";\nvar process = new KernelProcess(state, steps, edges);\nawait WorkflowBuilder.BuildWorkflow(process);","handlingStrategy":"validation","validationCode":"if (process?.State?.Id is null || string.IsNullOrWhiteSpace(process.State.Id))\n    throw new InvalidOperationException(\"Cannot build a workflow from a process with no Id; assign process.State.Id first.\");\nawait WorkflowBuilder.BuildWorkflow(process);","typeGuard":"bool HasProcessId(KernelProcess p) => !string.IsNullOrWhiteSpace(p?.State?.Id);","tryCatchPattern":"try { await WorkflowBuilder.BuildWorkflow(process); }\ncatch (KernelException ex) when (ex.Message.Contains(\"must have an Id\"))\n{ _logger.LogError(ex, \"Process missing Id before workflow build.\"); throw; }","preventionTips":["Always construct KernelProcess with an explicit id via the builder or state initializer.","Centralize process construction in a factory that enforces a non-null Id.","When deserializing, assert the source has an id field."],"tags":["workflow","process-framework","validation","serialization","configuration"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}