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
Functions
Data
API
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.
Resolve the run attribution id: explicit value, then NEMO_GYM_RUN_ID,
then an id generated once per process.
Unlike :func: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).