Skip to content

Commit 7378ef1

Browse files
authored
fix(sandbox): complete successful main processes (ai-openshell/openshell#2884)
1 parent 7ce6c0b commit 7378ef1

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

‎src/openshell/sandbox.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,18 @@ def _wait_for_phase(
887887
sandbox = self.get(sandbox_name, workspace=workspace)
888888
if sandbox.status.phase == target_phase:
889889
return sandbox
890+
if (
891+
target_phase == openshell_pb2.SANDBOX_PHASE_READY
892+
and sandbox.status.phase == openshell_pb2.SANDBOX_PHASE_COMPLETED
893+
):
894+
return sandbox
895+
if (
896+
target_phase == openshell_pb2.SANDBOX_PHASE_READY
897+
and sandbox.status.phase == openshell_pb2.SANDBOX_PHASE_STOPPED
898+
):
899+
raise SandboxError(
900+
f"sandbox {sandbox_name} stopped before becoming ready"
901+
)
890902
if sandbox.status.phase == openshell_pb2.SANDBOX_PHASE_ERROR:
891903
raise SandboxError(f"sandbox {sandbox_name} entered error phase")
892904
time.sleep(1)

‎tests/sandbox_test.py‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,6 +2146,41 @@ def test_stop_and_start_forward_workspace_and_return_phase() -> None:
21462146
assert starting.phase == openshell_pb2.SANDBOX_PHASE_STARTING
21472147

21482148

2149+
@pytest.mark.parametrize(
2150+
("phase", "should_succeed"),
2151+
[
2152+
(openshell_pb2.SANDBOX_PHASE_COMPLETED, True),
2153+
(openshell_pb2.SANDBOX_PHASE_ERROR, False),
2154+
],
2155+
)
2156+
def test_wait_ready_handles_terminal_main_process_results(
2157+
phase: openshell_pb2.SandboxPhase, should_succeed: bool
2158+
) -> None:
2159+
class TerminalStub(_FakeSandboxStub):
2160+
def GetSandbox(
2161+
self,
2162+
request: openshell_pb2.GetSandboxRequest,
2163+
timeout: float | None = None,
2164+
) -> Any:
2165+
_ = timeout
2166+
return SimpleNamespace(
2167+
sandbox=_make_sandbox_proto(
2168+
"sandbox-1",
2169+
request.name,
2170+
phase=phase,
2171+
workspace=request.workspace,
2172+
)
2173+
)
2174+
2175+
client = _client_with_fake_stub(TerminalStub())
2176+
if should_succeed:
2177+
result = client.wait_ready("job-1", workspace="default", timeout_seconds=0.1)
2178+
assert result.phase == openshell_pb2.SANDBOX_PHASE_COMPLETED
2179+
else:
2180+
with pytest.raises(SandboxError, match="entered error phase"):
2181+
client.wait_ready("job-1", workspace="default", timeout_seconds=0.1)
2182+
2183+
21492184
def test_create_without_args_sends_empty_metadata() -> None:
21502185
stub = _FakeSandboxStub()
21512186
client = _client_with_fake_stub(stub)

0 commit comments

Comments
 (0)