Skip to content

Commit 7e9224a

Browse files
authored
feat(sandbox): add canonical main process (ai-openshell/openshell#2726)
* feat(sandbox): add canonical main process Closes ai-openshell/openshell#2710 Persist and supervise one canonical workload per sandbox, attach sandbox connect to its retained session, and make every unexpected main-process exit terminal. Signed-off-by: Drew Newberry <anewberry@nvidia.com> * feat(sandbox): simplify canonical main process contract Signed-off-by: Drew Newberry <anewberry@nvidia.com> * fix(sandbox): preserve legacy VM main compatibility Signed-off-by: Drew Newberry <anewberry@nvidia.com> * fix(sandbox): preserve main status across driver updates Signed-off-by: Drew Newberry <anewberry@nvidia.com> * fix(sandbox): satisfy macOS process lint Signed-off-by: Drew Newberry <anewberry@nvidia.com> * fix(sandbox): gate Linux exit acknowledgement publisher Signed-off-by: Drew Newberry <anewberry@nvidia.com> * refactor(sandbox): simplify main process plumbing Signed-off-by: Drew Newberry <anewberry@nvidia.com> * fix(supervisor): make controlling tty ioctl portable Signed-off-by: Drew Newberry <anewberry@nvidia.com> * fix(supervisor): initialize canonical process environment Signed-off-by: Drew Newberry <anewberry@nvidia.com> * perf(supervisor): optimize retained main session Signed-off-by: Drew Newberry <anewberry@nvidia.com> * feat(sandbox): detach main session on ctrl-c Signed-off-by: Drew Newberry <anewberry@nvidia.com> * fix(sandbox): use explicit main detach keys Signed-off-by: Drew Newberry <anewberry@nvidia.com> * fix(dev): atomically stage Docker supervisor Signed-off-by: Drew Newberry <anewberry@nvidia.com> * fix(test): align Docker main environment assertion Signed-off-by: Drew Newberry <anewberry@nvidia.com> * feat(sdk): expose canonical main process fields Signed-off-by: Drew Newberry <anewberry@nvidia.com> --------- Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent edce0f9 commit 7e9224a

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎src/openshell/_proto/__init__.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
# Sandbox messages and phase enums moved into openshell.proto. Keep aliases on
44
# datamodel_pb2 so existing Python callers and E2E tests continue to work.
5-
for _name in ("Sandbox", "SandboxSpec", "SandboxTemplate"):
5+
for _name in (
6+
"Sandbox",
7+
"SandboxSpec",
8+
"SandboxTemplate",
9+
):
610
if not hasattr(datamodel_pb2, _name):
711
setattr(datamodel_pb2, _name, getattr(openshell_pb2, _name))
812

‎src/openshell/sandbox.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ def _normalize_bearer(
130130
class SandboxStatusRef:
131131
phase: int
132132
current_policy_version: int
133+
exit_code: int | None = None
133134

134135

135136
class _ImmutableLabels(dict[str, str]):
@@ -1092,6 +1093,9 @@ def _sandbox_ref(sandbox: openshell_pb2.Sandbox) -> SandboxRef:
10921093
status=SandboxStatusRef(
10931094
phase=status.phase if status else 0,
10941095
current_policy_version=status.current_policy_version if status else 0,
1096+
exit_code=status.exit_code
1097+
if status is not None and status.HasField("exit_code")
1098+
else None,
10951099
),
10961100
labels=sandbox.metadata.labels if sandbox.metadata else {},
10971101
)

‎tests/sandbox_test.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,6 +1772,15 @@ def test_sandbox_ref_retains_gateway_labels() -> None:
17721772
assert dict(ref.labels) == {"aiq": "deep-research", "env": "dev"}
17731773

17741774

1775+
def test_sandbox_ref_includes_main_process_result() -> None:
1776+
proto = _make_sandbox_proto("sandbox-1", "job-1")
1777+
proto.status.exit_code = 0
1778+
1779+
status = _sandbox_ref(proto).status
1780+
1781+
assert status.exit_code == 0
1782+
1783+
17751784
def test_returned_labels_are_immutable() -> None:
17761785
proto = _make_sandbox_proto("sandbox-1", "job-1", {"aiq": "deep-research"})
17771786
ref = _sandbox_ref(proto)

0 commit comments

Comments
 (0)