Skip to content

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

fix(server): treat only NotFound as proof an fsb snapshot is absent

Maohaoeb363b74f1e3
diff --git a/server/opensandbox_server/services/fast_sandbox/snapshot_runtime.py b/server/opensandbox_server/services/fast_sandbox/snapshot_runtime.py
index 4bf1b9180..4d0045b40 100644
--- a/server/opensandbox_server/services/fast_sandbox/snapshot_runtime.py
+++ b/server/opensandbox_server/services/fast_sandbox/snapshot_runtime.py
@@ -170,18 +170,24 @@ class FastSandboxSnapshotRuntime:
message=f"Failed to create fsb snapshot {snapshot_name}: {exc}",
)
# The request is durable and idempotent by request_id, so it may
- # have been persisted before the error (e.g. a lost reply). Report
- # an existing snapshot as submitted whatever its phase: a failed
- # status would leave it without a record, and convergence records
- # its terminal state once the row exists.
+ # have been persisted before the error (e.g. a lost reply). Unless
+ # FastPath confirms it is absent, report it as submitted whatever
+ # its phase: a failed status would leave it without a record, and
+ # convergence records its terminal state, or its absence, once the
+ # row exists.
try:
self._fastpath.get_sandbox_snapshot(ns, snapshot_name)
- except FastPathError:
+ except FastPathNotFound:
return SnapshotRuntimeStatus(
state=SnapshotState.FAILED,
reason="snapshot_runtime_create_failed",
message=f"Failed to create fsb snapshot {snapshot_name}: {exc}",
)
+ except FastPathError as probe_exc:
+ logger.warning(
+ f"Could not check fsb snapshot {snapshot_name} after a failed create "
+ f"({exc}): {probe_exc}"
+ )
return SnapshotRuntimeStatus(
state=SnapshotState.CREATING,
reason="snapshot_runtime_submitted",
diff --git a/server/tests/test_fsb_snapshot_runtime.py b/server/tests/test_fsb_snapshot_runtime.py
index 97f93fa43..4c6f60a3a 100644
--- a/server/tests/test_fsb_snapshot_runtime.py
+++ b/server/tests/test_fsb_snapshot_runtime.py
@@ -250,6 +250,21 @@ def test_create_snapshot_fails_when_no_snapshot_was_persisted() -> None:
assert "deadline exceeded" in (status.message or "")
+def test_create_snapshot_is_submitted_when_the_probe_also_fails() -> None:
+ # Only NotFound proves the snapshot was never persisted. If FastPath is
+ # restarting, the probe fails like the create did; report it as submitted
+ # so the row is written and converges, instead of risking an orphan.
+ fastpath = FakeFastPathClient()
+ fastpath.create_error = FastPathError("UNAVAILABLE", "connection refused")
+ fastpath.get_snapshot_error = FastPathError("UNAVAILABLE", "connection refused")
+ runtime, _, _ = _runtime(fastpath=fastpath)
+
+ status = runtime.create_snapshot(SNAPSHOT_ID, SANDBOX_ID, namespace="tenant-a")
+
+ assert status.state == SnapshotState.CREATING
+ assert status.reason == "snapshot_runtime_submitted"
+
+
def test_create_snapshot_maps_failed_precondition_to_conflict() -> None:
fastpath = FakeFastPathClient()
fastpath.create_error = FastPathError(