Python
Log sandbox deletions (reap and provider) and failed creates, with the caller
Devika Verma63bc085683d2
diff --git a/coworker/sandbox/providers/openshell.py b/coworker/sandbox/providers/openshell.pyindex 809fd542..141bc590 100644--- a/coworker/sandbox/providers/openshell.py+++ b/coworker/sandbox/providers/openshell.py@@ -242,6 +242,7 @@ class OpenShellProvider:try:_cli(*args, "--", *command, timeout=600) # the first create pulls the imageexcept RuntimeError as exc:+ log.warning("sandbox create failed for %s: %s", self.sandbox_name, exc)if "bind" in str(exc).lower() and "enable" in str(exc).lower():raise OpenShellUnavailable("The OpenShell gateway does not allow bind mounts, so it cannot give a sandbox your folders. Set `enable_bind_mounts = true` under `[openshell.drivers.docker]` in the gateway config (`openworker machine sandbox setup` does this).") from excraise@@ -298,6 +299,9 @@ class OpenShellProvider:self.create()def _delete(self) -> None:+ import traceback++ log.info("deleting sandbox %s, from:\n%s", self.sandbox_name, "".join(traceback.format_stack(limit=8)))try:_cli("sandbox", "delete", self.sandbox_name, timeout=90, check=False)except (subprocess.TimeoutExpired, OpenShellUnavailable):diff --git a/coworker/sandbox/registry.py b/coworker/sandbox/registry.pyindex d5ba05f5..bbf4accd 100644--- a/coworker/sandbox/registry.py+++ b/coworker/sandbox/registry.py@@ -12,6 +12,7 @@ gone (a crash, a kill) so they do not pile up.from __future__ import annotationsimport json+import loggingimport osimport sqlite3import threading@@ -21,6 +22,8 @@ from typing import Any, Optionalfrom ..secrets import state_dir+log = logging.getLogger(__name__)+LOCAL_MACHINE = "local"MAX_ENV = "OPENWORKER_SANDBOX_MAX"DEFAULT_MAX = 20@@ -148,6 +151,9 @@ class SandboxRegistry:listed = []openshell_names = {str(s.get("name") or s.get("metadata", {}).get("name") or "") for s in listed} - {""}for name in sorted(openshell_names - owned):+ # Say so: a deletion here is a sandbox nobody claims. If a live server is in+ # fact building it, the log line is how that shows up.+ log.info("reap: deleting OpenShell sandbox %s (not owned by a live server; owned=%s, pid=%d)", name, sorted(owned), os.getpid())try:openshell._cli("sandbox", "delete", name, timeout=90, check=False)removed.append(name)