Skip to content

Secure, Fast, and Extensible Sandbox runtime for AI agents.

refactor(server): trim comments in template phase reads

高然66498185871b
diff --git a/server/opensandbox_server/api/templates.py b/server/opensandbox_server/api/templates.py
index 546ba7dd2..d8ddbc57c 100644
--- a/server/opensandbox_server/api/templates.py
+++ b/server/opensandbox_server/api/templates.py
@@ -68,9 +68,7 @@ def _get_template_service() -> FastSandboxTemplateService:
detail=_TEMPLATE_NOT_K8S_DETAIL,
)
_service = FastSandboxTemplateService(config)
- # Watch-driven convergence: the watch reactor is the only path that moves
- # CR build phase into the DB rows; reads (including the create gate) trust
- # the DB and never re-read the CR.
+ # The watch is the only CR->DB phase path; reads trust the DB.
_service.start_background_sync()
return _service
diff --git a/server/opensandbox_server/services/templates/template_service.py b/server/opensandbox_server/services/templates/template_service.py
index 8c1e34b94..ba7f7b0c9 100644
--- a/server/opensandbox_server/services/templates/template_service.py
+++ b/server/opensandbox_server/services/templates/template_service.py
@@ -354,20 +354,14 @@ class FastSandboxTemplateService:
unknown or non-Succeeded templates both yield 404, so no existence
information leaks.
- The DB row is the read authority: the watch reactor is the only
- writer of build-phase transitions (CR status -> watch event -> row),
- so this gate is a pure DB read on the sandbox-create hot path.
+ Reads the DB row only; the watch reactor converges build phase.
"""
namespace = self._resolve_namespace()
record = self._repo().get(template_id, namespace)
if record is None:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=_TEMPLATE_NOT_FOUND)
if record.phase in (FastSandboxTemplatePhase.PENDING, FastSandboxTemplatePhase.BUILDING):
- # Non-terminal row on the create gate: make sure the namespace
- # watch is alive so the row still converges (e.g. the watch
- # failed to start when the template was created). Healthy
- # deployments pay a set-membership check; start() is
- # non-blocking either way.
+ # Re-arm the watch so a non-terminal row cannot get stuck.
self._ensure_namespace_watch(namespace)
if record.phase is not FastSandboxTemplatePhase.SUCCEEDED:
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=_TEMPLATE_NOT_FOUND)
@@ -442,11 +436,7 @@ class FastSandboxTemplateService:
# -- status sync -------------------------------------------------------------
#
- # The watch reactor (start_background_sync / _on_template_event) is the
- # ONLY path that moves CR build phase into the DB rows; reads (including
- # the sandbox-create gate) trust the DB projection and never re-read the
- # CR. "CRD is gone" is likewise event-driven: the DELETED watch event
- # fails the row (template_service watch handler below).
+ # The watch reactor is the only CR->DB phase path; reads trust the DB.
def _update_phase(
self,
diff --git a/server/tests/test_templates.py b/server/tests/test_templates.py
index 451c4d5d6..37aa1be2f 100644
--- a/server/tests/test_templates.py
+++ b/server/tests/test_templates.py
@@ -123,9 +123,7 @@ class _FakeTemplateCRs:
def _converge(service, crs, namespace: str, name: str, event: str = "MODIFIED") -> None:
- """Deliver the CR store's current state through the watch reactor — the
- only path that moves build phase into DB rows (reads never re-read the
- CR, so tests must simulate the event to converge a row)."""
+ """Deliver the CR store's current state through the watch reactor."""
handler = service._on_template_event(namespace)
if event == "DELETED":
handler("DELETED", {"metadata": {"name": name}})
@@ -447,8 +445,7 @@ def test_resolve_artifact_requires_succeeded(service, crs):
def test_resolve_gate_trusts_db_row_not_crd(service, crs):
- """The create gate reads the DB projection only; CR state reaches it
- exclusively through the watch reactor."""
+ """The create gate reads the DB projection only."""
record = service.create_template(_create_request(entrypoint=["sleep", "1"]))
# CR already says Succeeded but the event has not been delivered: 404.
@@ -467,9 +464,7 @@ def test_resolve_gate_trusts_db_row_not_crd(service, crs):
def test_resolve_restarts_watch_for_non_terminal_rows(service, crs, repo):
- """A row that never converged (its namespace watch failed to start when
- the template was created) still gets a watch retry on the create gate,
- so PENDING rows cannot get stuck permanently."""
+ """A non-terminal row re-arms its namespace watch on the create gate."""
record = service_record("tpl-stuck", "ns-1")
repo.create(record)
assert "ns-1" not in service._watched_namespaces