Skip to content

Commit 3a0804b

Browse files
authored
feat(sandbox): add main restart policy (ai-openshell/openshell#2798)
* feat(sandbox): add main restart policy Signed-off-by: Drew Newberry <anewberry@nvidia.com> * fix(sandbox): harden policy-driven restarts Signed-off-by: Drew Newberry <anewberry@nvidia.com> * fix(sandbox): address restart review feedback Signed-off-by: Drew Newberry <385+drew@users.noreply.github.com> * fix(sandbox): port restart policy to current runtime Signed-off-by: Drew Newberry <anewberry@nvidia.com> * perf(sandbox): restart promptly after terminal delivery Signed-off-by: Drew Newberry <anewberry@nvidia.com> --------- Signed-off-by: Drew Newberry <anewberry@nvidia.com> Signed-off-by: Drew Newberry <385+drew@users.noreply.github.com>
1 parent 6720fde commit 3a0804b

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

‎src/openshell/sandbox.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,9 @@ class SandboxStatusRef:
448448
phase: int
449449
current_policy_version: int
450450
exit_code: int | None = None
451+
restart_count: int = 0
452+
next_restart_at_ms: int | None = None
453+
main_process_started_at_ms: int | None = None
451454

452455

453456
@dataclass(frozen=True)
@@ -1767,6 +1770,13 @@ def _sandbox_ref(
17671770
exit_code=status.exit_code
17681771
if status is not None and status.HasField("exit_code")
17691772
else None,
1773+
restart_count=status.restart_count if status is not None else 0,
1774+
next_restart_at_ms=status.next_restart_time.ToMilliseconds()
1775+
if status is not None and status.HasField("next_restart_time")
1776+
else None,
1777+
main_process_started_at_ms=status.main_process_started_time.ToMilliseconds()
1778+
if status is not None and status.HasField("main_process_started_time")
1779+
else None,
17701780
),
17711781
labels=sandbox.metadata.labels if sandbox.metadata else {},
17721782
created_from_workload_template=provenance,

‎tests/sandbox_test.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2719,10 +2719,16 @@ def test_sandbox_ref_retains_gateway_labels() -> None:
27192719
def test_sandbox_ref_includes_main_process_result() -> None:
27202720
proto = _make_sandbox_proto("sandbox-1", "job-1")
27212721
proto.status.exit_code = 0
2722+
proto.status.restart_count = 2
2723+
proto.status.next_restart_time.FromMilliseconds(1_700_000_000_000)
2724+
proto.status.main_process_started_time.FromMilliseconds(1_699_999_000_000)
27222725

27232726
status = _sandbox_ref(proto).status
27242727

27252728
assert status.exit_code == 0
2729+
assert status.restart_count == 2
2730+
assert status.next_restart_at_ms == 1_700_000_000_000
2731+
assert status.main_process_started_at_ms == 1_699_999_000_000
27262732

27272733

27282734
def test_returned_labels_are_immutable() -> None:

0 commit comments

Comments
 (0)