Secure, Fast, and Extensible Sandbox runtime for AI agents.
fix(server): break the import cycle between fsb service and idle_pause
Maohao1674bd044d5b
diff --git a/server/opensandbox_server/integrations/idle_pause/sweeper.py b/server/opensandbox_server/integrations/idle_pause/sweeper.pyindex 3010250f5..3fc8f4648 100644--- a/server/opensandbox_server/integrations/idle_pause/sweeper.py+++ b/server/opensandbox_server/integrations/idle_pause/sweeper.py@@ -81,9 +81,7 @@ from opensandbox_server.integrations.idle_pause.redis_client import (close_idle_pause_redis_client,connect_idle_pause_redis_from_config,)-from opensandbox_server.services.composite_service import CompositeSandboxServicefrom opensandbox_server.services.fast_sandbox.endpoint import build_endpoint-from opensandbox_server.services.fast_sandbox.service import FastSandboxServicelogger = logging.getLogger(__name__)@@ -542,6 +540,11 @@ async def start_idle_pause_sweeper(logger.info("idle_pause disabled for non-kubernetes runtime (fsb backend only)")return None+ # Imported here: FastSandboxService imports this package for its idle+ # policy helpers, so a module-level import would be circular.+ from opensandbox_server.services.composite_service import CompositeSandboxService+ from opensandbox_server.services.fast_sandbox.service import FastSandboxService+fsb = Noneif isinstance(sandbox_service, CompositeSandboxService):fsb = sandbox_service.fsb_servicediff --git a/server/tests/test_module_imports.py b/server/tests/test_module_imports.pynew file mode 100644index 000000000..6b0c44cb4--- /dev/null+++ b/server/tests/test_module_imports.py@@ -0,0 +1,44 @@+# Copyright 2026 The OpenSandbox Authors+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.++"""Modules import on their own, not only after ``opensandbox_server.main``.++The test session imports ``main`` first (see conftest.py), which hides an+import cycle, so each import runs in a fresh interpreter.+"""++import subprocess+import sys++import pytest+++ "module",+ [+ "opensandbox_server.services",+ "opensandbox_server.services.fast_sandbox.service",+ "opensandbox_server.services.snapshot_service",+ "opensandbox_server.api.lifecycle",+ "opensandbox_server.integrations.idle_pause",+ ],+)+def test_module_imports_in_a_fresh_interpreter(module: str) -> None:+ result = subprocess.run(+ [sys.executable, "-c", f"import {module}"],+ capture_output=True,+ text=True,+ timeout=60,+ )+ assert result.returncode == 0, result.stderr