{"record":{"id":"e7a793bb94bd9f0c","repo":"microsoft/semantic-kernel","slug":"agent-failure-run-not-created-for-thread-thre-e7a793","errorCode":null,"errorMessage":"Agent Failure - Run not created for thread: ${threadId}","messagePattern":"Agent Failure - Run not created for thread: (.+?)","errorType":"exception","errorClass":"KernelException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Agents/OpenAI/Internal/AssistantThreadActions.cs","lineNumber":457,"sourceCode":"                            if (!string.IsNullOrEmpty(stepUpdate.Value.Details.CreatedMessageId))\n                            {\n                                messageCreationStepsToProcess.Add(stepUpdate.Value);\n                            }\n                            else\n                            {\n                                ProcessToolCallStep(stepUpdate.Value, agent, messages, threadId, stepFunctionResults);\n                            }\n\n                            break;\n                        default:\n                            break;\n                    }\n                }\n            }\n\n            if (run == null)\n            {\n                throw new KernelException($\"Agent Failure - Run not created for thread: ${threadId}\");\n            }\n\n            // Is in terminal state?\n            if (run.Status.IsTerminal && run.Status != RunStatus.Completed)\n            {\n                throw new KernelException($\"Agent Failure - Run terminated: {run.Status} [{run.Id}]: {run.LastError?.Message ?? \"Unknown\"}\");\n            }\n\n            if (run.Status == RunStatus.RequiresAction)\n            {\n                List<RunStep> activeSteps = [];\n                await foreach (var step in client.GetRunStepsAsync(run.ThreadId, run.Id, cancellationToken: cancellationToken).ConfigureAwait(false))\n                {\n                    if (step.Status == RunStepStatus.InProgress)\n                    {\n                        activeSteps.Add(step);\n                    }\n                }","sourceCodeStart":439,"sourceCodeEnd":475,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Agents/OpenAI/Internal/AssistantThreadActions.cs#L439-L475","documentation":"In the streaming Invoke path, after consuming the stream of updates the local 'run' variable is still null, meaning no ThreadRun update ever arrived. The code throws because it cannot continue without a run object. (Note: the message uses '${threadId}' which renders a literal '$' before the id due to a misplaced interpolation marker.)","triggerScenarios":"Streaming an assistant invocation where the service returned no ThreadRun update — an empty stream, a dropped connection mid-stream, or an error before the run was created.","commonSituations":"Transient network interruption; invalid/expired threadId; auth failure that closed the stream before a run update; service-side error during run creation.","solutions":["Verify the threadId is valid and the thread still exists before streaming.","Retry the streaming invocation once for transient drops.","Check authentication and endpoint connectivity if it fails repeatedly.","Inspect any server-side logs/telemetry for why no run was created."],"exampleFix":"// before\nawait foreach (var r in agent.InvokeStreamingAsync(thread)) { }\n// after\ntry {\n    await foreach (var r in agent.InvokeStreamingAsync(thread)) { }\n}\ncatch (KernelException ex) when (ex.Message.Contains(\"Run not created\")) {\n    logger.LogWarning(ex, \"No run created; retrying once\");\n    await foreach (var r in agent.InvokeStreamingAsync(thread)) { }\n}","handlingStrategy":"retry","validationCode":"if (string.IsNullOrWhiteSpace(threadId))\n    throw new ArgumentException(\"threadId must be a valid thread identifier.\");","typeGuard":null,"tryCatchPattern":"try { await foreach (var r in agent.InvokeStreamingAsync(thread)) { } }\ncatch (KernelException ex) when (ex.Message.Contains(\"Run not created\")) {\n    logger.LogWarning(ex, \"No run created; retrying once\");\n    await foreach (var r in agent.InvokeStreamingAsync(thread)) { }\n}","preventionTips":["Validate threadId before streaming.","Confirm auth and endpoint reachability beforehand.","Treat a single 'Run not created' as transient and retry once."],"tags":["openai","assistant-run","streaming","network"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}