{"record":{"id":"4b9491003ee63d8b","repo":"microsoft/semantic-kernel","slug":"runtime-is-not-started","errorCode":null,"errorMessage":"Runtime is not started","messagePattern":"Runtime is not started","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/runtime/in_process/in_process_runtime.py","lineNumber":674,"sourceCode":"        self._run_context = RunContext(self)\n\n    async def close(self) -> None:\n        \"\"\"Calls :meth:`stop` if applicable and the :meth:`Agent.close` method on all instantiated agents.\"\"\"\n        # stop the runtime if it hasn't been stopped yet\n        if self._run_context is not None:\n            await self.stop()\n        # close all the agents that have been instantiated\n        for agent_id in self._instantiated_agents:\n            agent = await self._get_agent(agent_id)\n            await agent.close()\n\n    async def stop(self) -> None:\n        \"\"\"Immediately stop the runtime message processing loop.\n\n        The currently processing message will be completed, but all others following it will be discarded.\n        \"\"\"\n        if self._run_context is None:\n            raise RuntimeError(\"Runtime is not started\")\n\n        try:\n            await self._run_context.stop()\n        finally:\n            self._run_context = None\n            self._message_queue = Queue()\n\n    async def stop_when_idle(self) -> None:\n        \"\"\"Stop the runtime message processing loop when there is no outstanding message being processed or queued.\n\n        This is the most common way to stop the runtime.\n        \"\"\"\n        if self._run_context is None:\n            raise RuntimeError(\"Runtime is not started\")\n\n        try:\n            await self._run_context.stop_when_idle()\n        finally:","sourceCodeStart":656,"sourceCodeEnd":692,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/runtime/in_process/in_process_runtime.py#L656-L692","documentation":"InProcessRuntime.stop() requires an active run context (_run_context is not None). If the runtime was never started (or already stopped), _run_context is None and stop() raises RuntimeError. This is the immediate-stop variant.","triggerScenarios":"Calling await runtime.stop() before runtime.start(), or calling stop() after the runtime was already stopped (double-stop). The close() method guards against this by checking _run_context before calling stop().","commonSituations":"Test teardown calling stop() unconditionally. Application shutdown logic calling stop() defensively when the runtime may or may not have been started.","solutions":["Guard the stop call: check runtime._run_context is not None, or prefer runtime.close() which handles this internally.","Ensure start() is called and awaited before any stop call.","Use try/finally around start/stop pairs so stop is only reached if start succeeded."],"exampleFix":"# before\nawait runtime.stop()  # raises if never started\n\n# after\nif runtime._run_context is not None:\n    await runtime.stop()\n# or simply:\nawait runtime.close()  # internally guards","handlingStrategy":"validation","validationCode":"# Guard stop() calls\nif runtime._run_context is not None:\n    await runtime.stop()\n# Or use close() which guards internally:\nawait runtime.close()","typeGuard":"null","tryCatchPattern":"try:\n    await runtime.stop()\nexcept RuntimeError:\n    pass  # already stopped — not an error condition","preventionTips":["Prefer runtime.close() over stop() for idempotent teardown.","Track started state with a boolean flag in your application code.","Wrap start/stop in try/finally so stop only runs if start succeeded."],"tags":["agent-runtime","lifecycle","stop","in-process-runtime","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}