From 5ac1ab3eac10859ee95ad4a6cd38f7d925568197 Mon Sep 17 00:00:00 2001 From: dadachann <185672915+dadachann@users.noreply.github.com> Date: Sat, 25 Jul 2026 21:56:14 +0800 Subject: [PATCH] fix(plugin): keep runtime identity stable across restarts --- src/langbot/pkg/plugin/connector.py | 8 +++++++- tests/unit_tests/plugin/test_connector_static.py | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/langbot/pkg/plugin/connector.py b/src/langbot/pkg/plugin/connector.py index 8b65d20c6..b92bd2382 100644 --- a/src/langbot/pkg/plugin/connector.py +++ b/src/langbot/pkg/plugin/connector.py @@ -133,7 +133,7 @@ class PluginRuntimeConnector(ManagedRuntimeConnector): 'shared' if getattr(getattr(ap, 'deployment', None), 'mode', 'oss') == 'cloud' else 'oss_dev' ) self.runtime_identity: RuntimeIdentity | None = None - self._runtime_id = str(uuid.uuid4()) + self._runtime_id = self._build_runtime_id() self.worker_policy: PluginWorkerPolicy | None = None self._execution_context: contextvars.ContextVar[ExecutionContext | None] = contextvars.ContextVar( f'{self.__class__.__name__}_{id(self)}_execution_context', @@ -149,6 +149,12 @@ class PluginRuntimeConnector(ManagedRuntimeConnector): self._generation = 0 self._connected = asyncio.Event() + @staticmethod + def _build_runtime_id() -> str: + """Return the durable identity of this instance's shared Runtime.""" + + return f'{constants.instance_id}:plugin-runtime' + def _runtime_handler(self) -> handler.RuntimeConnectionHandler: runtime_handler = getattr(self, 'handler', None) if runtime_handler is None: diff --git a/tests/unit_tests/plugin/test_connector_static.py b/tests/unit_tests/plugin/test_connector_static.py index 8c88b9707..2db33b708 100644 --- a/tests/unit_tests/plugin/test_connector_static.py +++ b/tests/unit_tests/plugin/test_connector_static.py @@ -53,3 +53,10 @@ class TestParsePluginId: author, name = connector.PluginRuntimeConnector._parse_plugin_id('lang-bot/my_rag_engine') assert author == 'lang-bot' assert name == 'my_rag_engine' + + +def test_runtime_id_is_stable_across_core_restarts(monkeypatch): + connector = get_connector_module() + monkeypatch.setattr(connector.constants, 'instance_id', 'instance-a') + + assert connector.PluginRuntimeConnector._build_runtime_id() == 'instance-a:plugin-runtime'