INNER CODE UNIT · Python
_wait_until_running
deeplethe/forkd · sdk/mcp/sandstorm_mcp/server.py:91
def _wait_until_running(c: httpx.Client, sandbox_id: str, deadline: float) -> dict[str, Any]:
"""Block until a node reports this sandbox running, and return it.
The master answers a create before any node has acted on it, and an exec
that arrives first fails. A node reports the address only for a sandbox
with processes, so that is the signal. ping is not: its ok also needs
something listening inside.
"""
pause = 0.05
while True:
r = c.get(f"/v1/sandboxes/{sandbox_id}")
r.raise_for_status()
seen = r.json()
if seen.get("ip"):
return seen
reason = seen.get("last_error") or "no reason recorded"
if seen.get("error_attempts", 0) >= MAX_START_FAILURES:
raise RuntimeError(f"sandbox {sandbox_id} failed to start: {reason}")