microsoft/autogen · error · RuntimeError
Runtime is not running.
Error message
Runtime is not running.
What it means
GrpcWorkerAgentRuntime.stop() refuses to stop a runtime that is not running: if _running is False it raises RuntimeError('Runtime is not running.'). Stop is only valid after a successful start(), making the lifecycle strict and errors loud.
Source
Thrown at python/packages/autogen-ext/src/autogen_ext/runtimes/grpc/_worker_runtime.py:311
case "response":
task = asyncio.create_task(self._process_response(message.response))
self._background_tasks.add(task)
task.add_done_callback(self._raise_on_exception)
task.add_done_callback(self._background_tasks.discard)
case "cloudEvent":
task = asyncio.create_task(self._process_event(message.cloudEvent))
self._background_tasks.add(task)
task.add_done_callback(self._raise_on_exception)
task.add_done_callback(self._background_tasks.discard)
case None:
logger.warning("No message")
except Exception as e:
logger.error("Error in read loop", exc_info=e)
async def stop(self) -> None:
"""Stop the runtime immediately."""
if not self._running:
raise RuntimeError("Runtime is not running.")
self._running = False
# Wait for all background tasks to finish.
final_tasks_results = await asyncio.gather(*self._background_tasks, return_exceptions=True)
for task_result in final_tasks_results:
if isinstance(task_result, Exception):
logger.error("Error in background task", exc_info=task_result)
# Close the host connection.
if self._host_connection is not None:
try:
await self._host_connection.close()
except asyncio.CancelledError:
pass
# Cancel the read task.
if self._read_task is not None:
self._read_task.cancel()
try:
await self._read_task
except asyncio.CancelledError:View on GitHub (pinned to 027ecf0a37)
Solutions
- Mirror the runtime lifecycle: only stop what you started, tracking a started flag
- In cleanup code, tolerate the error: try/except RuntimeError around stop()
- Prefer stopping inside the same scope that called start() (async context manager pattern)
Example fix
# before
finally:
await runtime.stop() # RuntimeError if never started
# after
finally:
if runtime._running:
await runtime.stop()
# or: wrap in try/except RuntimeError and ignore Defensive patterns
Strategy: try-catch
Validate before calling
if runtime._running: # private but reliable mirror of the check
await runtime.stop() Try / catch
try:
await runtime.stop()
except RuntimeError as e:
if "not running" in str(e):
pass # nothing to stop
else:
raise Prevention
- Keep start/stop in the same scope (context manager pattern)
- Set a started flag and check it before stop()
- In shutdown hooks, tolerate stop() failures
When it happens
Trigger: Calling `await runtime.stop()` before start(), after stop() already completed, or in a shutdown/cleanup path where start() was skipped because setup failed early.
Common situations: finally blocks and signal handlers that unconditionally stop the runtime; error paths where start() raised before setting _running; double-stop in atexit/asyncio shutdown hooks.
Related errors
- Connection is not open.
- Runtime is already running.
- Host connection is not set.
- Runtime must be running when sending message.
- Runtime must be running when publishing message.
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/d730b95f37bfdf6d.
Report an issue: GitHub.