nemo_gym.sandbox.attribution
nemo_gym.sandbox.attribution
Automatic job attribution (team / user / workload / run) for sandbox metadata.
Sandbox providers merge these keys into every sandbox’s metadata so cluster
operators can attribute running sandboxes to the team, user, and workload that
created them (on OpenSandbox, metadata becomes queryable Kubernetes labels on
the sandbox). Each field resolves from explicit configuration first, then
NEMO_GYM_* environment variables, then Slurm job environment variables,
then (for user only) the OS login name and (for workload) the server
instance’s config path. Fields that cannot be resolved are omitted rather than
guessed.
run identifies one launch of the creating process so a run’s sandboxes can
be listed or garbage-collected exactly, even when the same user runs the same
workload twice. It resolves from explicit configuration, then NEMO_GYM_RUN_ID,
then a per-process generated id.
Module Contents
Classes
Functions
Data
DEFAULT_ATTRIBUTION_KEY_PREFIX
API
Job attribution merged into every sandbox’s metadata (Kubernetes labels on OpenSandbox and OpenShell).
Providers that propagate sandbox metadata as Kubernetes labels make attribution queryable at the
cluster level (e.g. kubectl get pods -l nemo-gym.nvidia.com/team=my-team). key_prefix
namespaces the label keys (Kubernetes prefixed-key convention); set it to "" for bare
team / user / workload / run keys.
Unset fields are auto-detected: NEMO_GYM_TEAM / NEMO_GYM_USER / NEMO_GYM_WORKLOAD
environment variables first, then Slurm job env vars (SLURM_JOB_ACCOUNT /
SLURM_JOB_USER / SLURM_JOB_NAME), then the OS login name for user (root is
ignored) and the gym CLI’s NEMO_GYM_CONFIG_PATH server instance name for workload.
Fields that cannot be resolved are omitted. run scopes sandboxes to one launch of the
creating process (NEMO_GYM_RUN_ID, else generated per process and logged) so a run’s
sandboxes can be listed and cleaned up exactly. Explicit SandboxSpec.metadata keys
always take precedence over attribution keys.
The prefixed attribution keys for a new sandbox (empty when disabled); values are raw.
Log the resolved attribution metadata once per process.
The generated run id only exists in this process, so surfacing it in the logs
is what lets operators later filter or garbage-collect this run’s sandboxes.
Resolve team / user / workload attribution metadata.
Parameters:
Explicit team; falls back to NEMO_GYM_TEAM, then SLURM_JOB_ACCOUNT.
Explicit user; falls back to NEMO_GYM_USER, then SLURM_JOB_USER,
then the OS login name (root is ignored — containers run as root by
default, so it attributes the image, not a person).
Explicit workload; falls back to NEMO_GYM_WORKLOAD, then
SLURM_JOB_NAME, then NEMO_GYM_CONFIG_PATH (the server instance
name the gym CLI sets on every server process it spawns).
Environment mapping override, for testing. Defaults to os.environ.
Returns: dict[str, str]
A dict with only the resolved keys among team, user, and workload.
An id unique to this process (a forked child gets its own).
run (see resolve_run_id) can be shared by every process of a job and is overridable through
NEMO_GYM_RUN_ID, so it cannot tell this process’s sandboxes from a sibling’s. This id can, which is what
lets a provider clean up only its own process’s sandboxes.
Resolve the run attribution id: explicit value, then NEMO_GYM_RUN_ID,
then an id generated once per process.
Unlike resolve_attribution fields, run is always resolvable. It scopes
sandboxes to one launch of the creating process, so an interrupted run’s sandboxes
can be listed and cleaned up exactly (team / user / workload cannot
distinguish two runs of the same workload by the same user).
Make value a valid Kubernetes label value: invalid characters become _, at most 63 characters.
An empty value stays empty; a value with no valid character becomes metadata.