mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-26 06:16:09 +00:00
fix(plugin): keep runtime identity stable across restarts
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user