nemo_gym.agent_utils.process_supervisor

View as Markdown

Standalone Linux process supervisor to upload beside a sandboxed harness.

Uses only the standard library; Gym need not be installed in the task sandbox. The receipt confirms descendant cleanup independently of the harness result.

Module Contents

Classes

NameDescription
CleanupReceiptOutcome written only after supervision and bounded cleanup finish.

Functions

NameDescription
_drain_childrenReap tool descendants, including processes that detached with setsid().
_positive_seconds-
_superviseEnforce a harness deadline, then acknowledge cleanup after all descendants exit.
exec_timeoutReserve TERM grace, harness process reaping, and descendant draining.
mainRun COMMAND and atomically write its cleanup receipt outside the task workdir.

Data

CLEANUP_PHASE_COUNT

DEFAULT_CLEANUP_TIMEOUT

API

class nemo_gym.agent_utils.process_supervisor.CleanupReceipt

Bases: typing.TypedDict

Outcome written only after supervision and bounded cleanup finish.

cleanup_confirmed
bool
error
str | None
return_code
int | None
timed_out
bool
nemo_gym.agent_utils.process_supervisor._drain_children(
timeout: float
) -> None

Reap tool descendants, including processes that detached with setsid().

nemo_gym.agent_utils.process_supervisor._positive_seconds(
value: str
) -> float
nemo_gym.agent_utils.process_supervisor._supervise(
command: list[str],
timeout: float,
cleanup_timeout: float = DEFAULT_CLEANUP_TIMEOUT,
stop_path: pathlib.Path | None = None

Enforce a harness deadline, then acknowledge cleanup after all descendants exit.

nemo_gym.agent_utils.process_supervisor.exec_timeout(
timeout: float,
cleanup_timeout: float = DEFAULT_CLEANUP_TIMEOUT
) -> float

Reserve TERM grace, harness process reaping, and descendant draining.

The extra 30 seconds cover startup, polling, and receipt I/O beyond those bounded cleanup phases. Keep their count shared with the controller budget.

nemo_gym.agent_utils.process_supervisor.main() -> int

Run COMMAND and atomically write its cleanup receipt outside the task workdir.

nemo_gym.agent_utils.process_supervisor.CLEANUP_PHASE_COUNT = 3
nemo_gym.agent_utils.process_supervisor.DEFAULT_CLEANUP_TIMEOUT = 10.0