microsoft/semantic-kernel · error · KernelException
Agent Failure - Run not created for thread: ${threadId}
Error message
Agent Failure - Run not created for thread: ${threadId} What it means
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.)
Source
Thrown at dotnet/src/Agents/OpenAI/Internal/AssistantThreadActions.cs:457
if (!string.IsNullOrEmpty(stepUpdate.Value.Details.CreatedMessageId))
{
messageCreationStepsToProcess.Add(stepUpdate.Value);
}
else
{
ProcessToolCallStep(stepUpdate.Value, agent, messages, threadId, stepFunctionResults);
}
break;
default:
break;
}
}
}
if (run == null)
{
throw new KernelException($"Agent Failure - Run not created for thread: ${threadId}");
}
// Is in terminal state?
if (run.Status.IsTerminal && run.Status != RunStatus.Completed)
{
throw new KernelException($"Agent Failure - Run terminated: {run.Status} [{run.Id}]: {run.LastError?.Message ?? "Unknown"}");
}
if (run.Status == RunStatus.RequiresAction)
{
List<RunStep> activeSteps = [];
await foreach (var step in client.GetRunStepsAsync(run.ThreadId, run.Id, cancellationToken: cancellationToken).ConfigureAwait(false))
{
if (step.Status == RunStepStatus.InProgress)
{
activeSteps.Add(step);
}
}View on GitHub (pinned to c028a0c7dc)
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.
Example fix
// before
await foreach (var r in agent.InvokeStreamingAsync(thread)) { }
// after
try {
await foreach (var r in agent.InvokeStreamingAsync(thread)) { }
}
catch (KernelException ex) when (ex.Message.Contains("Run not created")) {
logger.LogWarning(ex, "No run created; retrying once");
await foreach (var r in agent.InvokeStreamingAsync(thread)) { }
} Defensive patterns
Strategy: retry
Validate before calling
if (string.IsNullOrWhiteSpace(threadId))
throw new ArgumentException("threadId must be a valid thread identifier."); Try / catch
try { await foreach (var r in agent.InvokeStreamingAsync(thread)) { } }
catch (KernelException ex) when (ex.Message.Contains("Run not created")) {
logger.LogWarning(ex, "No run created; retrying once");
await foreach (var r in agent.InvokeStreamingAsync(thread)) { }
} Prevention
- Validate threadId before streaming.
- Confirm auth and endpoint reachability beforehand.
- Treat a single 'Run not created' as transient and retry once.
When it happens
Trigger: 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.
Common situations: Transient network interruption; invalid/expired threadId; auth failure that closed the stream before a run update; service-side error during run creation.
Related errors
- Agent Failure - Run terminated: {run.Status} [{run.Id}]: {ru
- Agent Failure - Run not created for thread: ${threadId}
- The thread could not be created due to an error response fro
- The thread could not be deleted due to an error response fro
- The message could not be added to the thread due to an error
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/e7a793bb94bd9f0c.
Report an issue: GitHub.