diff --git a/src/langbot/pkg/provider/modelmgr/modelmgr.py b/src/langbot/pkg/provider/modelmgr/modelmgr.py index 7031dfa6e..cac971906 100644 --- a/src/langbot/pkg/provider/modelmgr/modelmgr.py +++ b/src/langbot/pkg/provider/modelmgr/modelmgr.py @@ -161,9 +161,14 @@ class ModelManager: self.ap.logger.info('LangBot Space Models service is disabled, skipping sync.') return - # Space model synchronization is a legacy OSS-singleton facility. A - # cloud instance must receive tenant model projections from its control - # plane and must never infer one Workspace for this global operation. + # Space model synchronization is a legacy OSS-singleton facility. Cloud + # receives tenant model projections from its control plane and must not + # resolve an OSS-local Workspace outside a tenant-scoped unit of work. + cloud_runtime = getattr(getattr(self.ap.persistence_mgr, 'mode', None), 'value', None) == 'cloud_runtime' + if cloud_runtime: + self.ap.logger.info('Skipping legacy LangBot Space model sync in Cloud Runtime.') + return + try: binding = await self.ap.workspace_service.get_local_execution_binding() except WorkspaceError as exc: diff --git a/tests/unit_tests/provider/test_model_manager.py b/tests/unit_tests/provider/test_model_manager.py index a9aafff86..5c2005ccd 100644 --- a/tests/unit_tests/provider/test_model_manager.py +++ b/tests/unit_tests/provider/test_model_manager.py @@ -8,6 +8,7 @@ and error handling without calling real LLM APIs. from __future__ import annotations import pytest +from types import SimpleNamespace from unittest.mock import AsyncMock, Mock from langbot.pkg.provider.modelmgr.modelmgr import ModelManager @@ -70,6 +71,20 @@ async def test_model_manager_skips_space_sync_when_disabled(mock_app_for_modelmg app.space_service.get_models.assert_not_called() +@pytest.mark.asyncio +async def test_model_manager_skips_legacy_space_sync_in_cloud_runtime(mock_app_for_modelmgr): + """Cloud startup must not resolve an OSS-local Workspace for legacy model sync.""" + app = mock_app_for_modelmgr + app.instance_config.data = {'space': {'disable_models_service': False}} + app.persistence_mgr.mode = SimpleNamespace(value='cloud_runtime') + + model_mgr = ModelManager(app) + model_mgr.load_models_from_db = AsyncMock() + await model_mgr.initialize() + + app.workspace_service.get_local_execution_binding.assert_not_awaited() + + # ============================================================================ # Model Loading Tests # ============================================================================