Skip to content

feat(orchestration): add job-management interfaces and types - #5295

Merged
prokotg merged 9 commits into
mainfrom
prokotg/gym-job-foundation
Nov 19, 2026
Merged

prokotg merged 9 commits into
mainfrom
prokotg/gym-job-foundation

Conversation

@prokotg

@prokotg prokotg commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Executor capabilities (executors/capabilities.py). BaseExecutor now requires only run. Each further feature is an opt-in interface: Resubmittable, Inspectable, Terminable (extends Inspectable), LogReadable (extends Inspectable). Every method of a capability is abstract, so one cannot be half implemented; the exceptions are two optional hooks that carry a default. require(executor, Capability, operation) returns the executor typed as the capability or raises UnsupportedOperationError.
    • SlurmExecutor(BaseExecutor, Resubmittable). KubernetesExecutor(BaseExecutor): its stub that raised for resubmit is gone, and submit.resubmit now gets the same UnsupportedOperationError from require.
  • The policy as functions (operations.py): status, info, cancel, cancel_submission and logs take an executor typed as the capability they need. They are declared only and raise NotImplementedError until PR 2 or 3; log_sources is implemented. The module imports no executor, and a test enforces it.
  • The role of each module is written in the docstring of nemo_gym/orchestration/__init__.py.
  • Job-management types in jobs.py: JobState, ObservedStatus, JobStatus, SubmissionStatus, JobInfo, Failure, Progress, JobRef, LogSource.
  • BenchmarkJob.log_sources: the logs a job was set up to write, planned at submit. Defaulted, so old records load with [] and SCHEMA_VERSION stays 1.
  • Slurm's log layout comes from one function, log_path(). The --output flags and the new planned_log_sources() both use it, so the plan cannot drift from the script. SlurmExecutor.run stores the plan on every benchmark.
  • The generated job scripts are byte-identical (six scripts diffed before and after).
  • job-records.mdx documents the field.

PR plan

Five PRs, Slurm only. Goal: status, cancel and logs for a submitted run without going to the scheduler.

  1. This PR: the types, the capability interfaces, the operations declared, and the submit-time log plan.
  2. Read-only commands: the logic of status and info, Slurm Inspectable, gym job list, status, info.
  3. gym job cancel and gym job logs (--tail): the logic of cancel, cancel_submission and logs, Slurm Terminable and LogReadable.
  4. feat(cli): tell the user what to type after gym eval submit #5357: gym eval submit tells you what to type next.
  5. feat(cli): add gym job resubmit #5444: gym job resubmit; gym eval resubmit stays as a deprecated alias until 2026-11-23, with a test that fails then.

Not in these five: logs --follow, Kubernetes job management, progress, services declaring their own log sources.

Interface design

gym job list    [--limit N] [--json]
gym job info    ID [BENCH] [--config] [--json]
gym job status  [ID ...] [--benchmark NAME[,NAME...]] [--limit N | --all] [--json]
gym job cancel  ID BENCH
gym job cancel  ID --all --confirm ID
gym job logs    ID BENCH [--source NAME] [--instance ID] [--tail N] [--follow]
gym job resubmit ID BENCH

list is offline; status is the only command that queries the scheduler (no ids: the newest 10 submissions). Cancelling a whole submission needs its id typed. --benchmark is strict with ids.

What an executor implements:

Interface Methods Needed for Slurm in
BaseExecutor run(config, *, dry_run=False) -> SubmissionRecord | None gym eval submit exists
Resubmittable resubmit(record, benchmark) -> BenchmarkJob gym job resubmit exists
Inspectable connection_key(record) -> str, query_states(refs: list[JobRef]) -> dict[JobKey, ObservedStatus]; optional: read_run_files(record, paths) -> dict[Path, str | None], read_progress(record, job) -> Progress | None status, info 2
Terminable(Inspectable) terminate(record, job) -> None cancel 3
LogReadable(Inspectable) stream_logs(record, job, *, source: LogSource, tail, follow) -> Iterator[str] logs 3

The policy, in operations.py:

Operation Signature Logic in
status (executor: Inspectable, records, benchmarks=None) -> list[SubmissionStatus] 2
info (executor: Inspectable, record, benchmark=None) -> JobInfo 2
cancel (executor: Terminable, record, benchmark) -> JobStatus 3
cancel_submission (executor: Terminable, record, *, confirm: str) -> list[JobStatus] 3
logs (executor: LogReadable, record, benchmark, *, source="driver", instance=None, tail=None, follow=False) -> Iterator[str] 3
log_sources (record, benchmark) -> list[LogSource]; reads the record, no executor here

LogSource is name, kind (driver or service), instance, location. On Slurm the location is a job-directory-relative path with a {job_id} placeholder.

The operations call capability methods, never the other way round:

CLI                          submit.py                  operations.py / executor capabilities
                             load record, resolve       [O] operation (operations.py)
                             executor, require()        [A] abstract method of a capability
                                                        [opt] optional hook   [B] provided by BaseExecutor

gym eval submit -c cfg  ──>  submit(config) ──────────> [A] run(config) -> SubmissionRecord | None
                                                              └─> [B] persist()

gym job list            ──>  list_submissions() ──────> local index only, no executor -> list[SubmissionRecord]

gym job info ID [BENCH] ──>  info(id, bench) ─────────> [O] info(executor, record, benchmark=None) -> JobInfo
                                                              ├─> [A] query_states
                                                              ├─> [O] log_sources   (from the record, no remote call)
                                                              └─> [opt] read_run_files (resolved config)

gym job status [ID..] -b A,B > status(ids=None, ...) ─> [O] status(executor, records, benchmarks=None) -> list[SubmissionStatus]
                                                              ├─> [A] connection_key(record)   (group the records)
                                                              ├─> [A] query_states   (one call per group, groups run concurrently)
                                                              ├─> state files come back inside ObservedStatus
                                                              ├─> [opt] read_progress     (deferred)
                                                              └─> map ObservedStatus -> state, reconcile

gym job cancel ID BENCH ─>   cancel(id, bench) ───────> [O] cancel(executor, record, benchmark) -> JobStatus
                                                              ├─> [A] query_states   (re-query, skip terminal)
                                                              ├─> [A] terminate(record, job)
                                                              └─> [A] query_states   (observed state after the kill)

gym job cancel ID --all ─>   cancel_submission() ─────> [O] cancel_submission(executor, record, *, confirm) -> list[JobStatus]
        --confirm ID                                          ├─> check confirm == gym_job_id
                                                              ├─> [O] status([record])
                                                              ├─> per live benchmark: [A] terminate
                                                              └─> [A] query_states   (observed states after the kills)

gym job logs ID BENCH ──>    logs(...) ───────────────> [O] logs(executor, record, benchmark, *, source, instance, ...) -> Iterator[str]
                                                              ├─> [A] query_states   (find the current job)
                                                              ├─> [O] log_sources    (from the record; resolve source and instance)
                                                              └─> [A] stream_logs(record, job, source=<LogSource>, ...)

gym job resubmit ID B  ──>   resubmit(id, bench) ─────> [A] resubmit(record, benchmark) -> BenchmarkJob
                                                              └─> [B] persist_record()

(no CLI command)             log_sources(id, bench) ──> [O] log_sources(record, benchmark) -> list[LogSource]
                                                              └─> reads BenchmarkJob.log_sources (no remote call)

Validation

  • 30 new tests: a capability cannot be half implemented, require names the executor and the operation, the optional hooks default to nothing, log_sources reads the record, cancel_submission cannot be called without confirm, operations.py imports no executor (I checked it fails when it does), and the log plan. The plan test asserts the planned locations equal the --output flags in the generated script, for five configs (plain, Ray with workers, prefill/decode, per-node, collector); it fails if the plan drifts.
  • Orchestration tests (jobs, operations, Slurm script and executor, resubmit, Kubernetes, submit, API, telemetry, eval submit CLI): 608 passed, 2 failed. Both fail on clean main on macOS too (GNU sed -i).
  • Full unit suite: 13288 passed, 51 failed. All 51 also fail on clean origin/main (sandbox, docker compose, harbor, super35 launcher, CI-environment, telemetry, the opensandbox Slurm-eval tests, and the two sed tests above). An earlier run crashed with a pytest INTERNALERROR and was discarded.
  • ruff and pre-commit pass.

Known gaps

  • status, info, cancel, cancel_submission and logs are declared only: they raise NotImplementedError until PR 2 or 3.
  • Not run on a Slurm cluster: the scripts are byte-identical and the only runtime change is one record field.
  • A service named driver already shares the driver's log file; the plan lists both.
  • LogSource.instance is always None until services declare their instances.

Rollout evidence

N/A: no agent, verifier or model behavior is touched.

@prokotg prokotg added feature New capabilities, enhancements, or enablement work area:orchestration Job submission, deployment, services, and lifecycle management labels Oct 29, 2026
@copy-pr-bot

copy-pr-bot Bot commented Oct 29, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@prokotg prokotg changed the title feat(orchestration): add job status types and plan log sources at submit feat(orchestration): add job management types, executor primitives and submit-time log plan Oct 29, 2026
@prokotg prokotg changed the title feat(orchestration): add job management types, executor primitives and submit-time log plan refactor(orchestration): split executor interfaces into capabilities, add job types and log plan Oct 29, 2026
@prokotg prokotg changed the title refactor(orchestration): split executor interfaces into capabilities, add job types and log plan feat(orchestration): add job-management interfaces and types Oct 29, 2026
@prokotg
prokotg added this pull request to stack #5351 October 30, 2026 06:06
@prokotg
prokotg marked this pull request as ready for review October 30, 2026 07:34
@prokotg

prokotg commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

/review

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the needs-review PR is ready for code review and waiting on a reviewer label Oct 30, 2026

@svcnvidia-nemo-ci svcnvidia-nemo-ci left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHIP — LGTM — no concerns found.

Reviewed all 15 changed files and directly affected submit/resubmit, record-loading, log-rendering, and persistence paths. The capability refactor preserves supported Slurm resubmission and unsupported Kubernetes handling. The defaulted record field preserves legacy loading, and planned logs match the inspected service, Ray, prefill/decode, and telemetry rendering branches.

The declared-only job-management operations are consistent with this PR’s stated scope. Static review only; tests and Slurm execution were not run.

Note: formal approval is not available for this request, so this review is posted as a comment only.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

marta-sd
marta-sd previously approved these changes Nov 2, 2026
@prokotg

prokotg commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 0fe7cf1

@prokotg

prokotg commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Design note: recovery options and Resubmittable (after rebasing onto #6228)

Resubmittable.resubmit(record, benchmark) stays the plain two-argument contract. Slurm's resubmit (ChainRecovery in slurm/chain.py) takes 17 more keyword-only options, and submit.recover passes them, conditionally, through a Resubmittable-typed reference.

  • Compatible at runtime. Slurm's signature is a superset, so require passes. KubernetesExecutor is not Resubmittable and gets the same UnsupportedOperationError its old stub raised.
  • The declared contract is narrower than the calls. An executor that implements only the declared signature would fail inside recover. The Resubmittable docstring now says so.
  • Test doubles must opt in. require checks nominally, so the recovery tests' FakeExecutor now subclasses Resubmittable.

Where the 17 options stand today. Kubernetes uses none, and only Slurm implements resubmit:

Scheduler-neutral in meaning (9) Slurm vocabulary (8)
keep_budget, extend_retries, extend_attempts accounted_walltime_s, accounting_snapshot, accounting_reconciled
repin, repin_reason max_walltime, walltime_reason, segment_walltime
server_spinup_timeout_seconds, spinup_timeout_reason fresh_restart, operator_continuation
unsafe_resume_reason, rerun_masked

Main's recovery hooks (recovery_evidence, recovery_decision, reverify_judge_failures, walltime_plan, gym_pin, export_tracking, installed_commit) stay as default methods on BaseExecutor, outside the capability pattern. recovery_evidence also takes an overlapping set of controls (extend_retries, extend_attempts, max_walltime, the spin-up pair, the rerun flag), so recover builds the same values twice.

Planned follow-up, its own PR after this stack lands (it rewrites main's recovery call paths, so it does not belong in a rebase): a typed RecoveryControls object and a Recoverable capability that owns resubmit-with-controls and the recovery hooks, with Resubmittable staying the plain version. The controls split into the scheduler-neutral part and a Slurm part, so Slurm's walltime and accounting vocabulary does not leak into a neutral type.

@prokotg
prokotg force-pushed the prokotg/gym-job-foundation branch from 86d3e42 to 7836130 Compare November 18, 2026 15:38
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the risk:high Autobot PR risk: high label Nov 18, 2026
prokotg and others added 9 commits November 18, 2026 16:45
Adds the types for job management (JobState, ObservedStatus, JobStatus,
Failure, Progress, SubmissionStatus, JobRef, LogSource) in the
executor-agnostic jobs module, and a defaulted BenchmarkJob.log_sources.

The Slurm executor now plans each job's log sources with the same
function that renders the job script's --output flags, and stores them
in the record, so a reader can find a job's logs without listing the run
directory. The generated job scripts are byte-identical.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Signed-off-by: Tomasz Grzegorzek <[email protected]>
…cutor

Adds connection_key, query_states, terminate and stream_logs, which raise
UnsupportedOperationError until an executor implements them, the optional
read_run_files and read_progress with defaults, and log_sources, which
reads the planned sources from the record. They are not abstract so that
executors that only submit keep working.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Signed-off-by: Tomasz Grzegorzek <[email protected]>
…cutor

Adds status, info, cancel, cancel_submission and logs to BaseExecutor
with their contracts, and the JobInfo and BenchmarkInfo types info
returns. Their bodies land with the logic in the following changes;
cancel_submission takes its confirmation as a required keyword so a
whole submission is never cancelled by accident.

Signed-off-by: Tomasz Grzegorzek <[email protected]>
…lities

BaseExecutor now requires only run. Resubmit, status, cancel and logs are
opt-in capability interfaces (Resubmittable, Inspectable, Terminable,
LogReadable) in executors/capabilities.py, with every method abstract so
a capability cannot be half implemented. The job operations move off the
executor into functions in operations.py that take an executor typed as
the capability they need and import no executor module; a test enforces
that. Slurm is Resubmittable; Kubernetes drops its raising resubmit stub
and submit.resubmit reports the missing capability through require.

Signed-off-by: Tomasz Grzegorzek <[email protected]>
BaseExecutor no longer imports BenchmarkJob, and the Kubernetes executor no
longer imports UnsupportedOperationError; neither was a name the module
defined.

Signed-off-by: Tomasz Grzegorzek <[email protected]>
…module

The stats file path added on main uses LOGS_DIRNAME, which the log path helper had made unused here.

Signed-off-by: Tomasz Grzegorzek <[email protected]>
@prokotg
prokotg force-pushed the prokotg/gym-job-foundation branch from 7836130 to e574c28 Compare November 19, 2026 08:20
@prokotg

prokotg commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test e574c28

@prokotg
prokotg added this pull request to the merge queue Nov 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/44494130276

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 19, 2026
@prokotg
prokotg added this pull request to the merge queue Nov 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/44497328661

Merged via the queue into main with commit eeaa50f Nov 19, 2026
70 checks passed
@prokotg
prokotg deleted the prokotg/gym-job-foundation branch November 19, 2026 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:orchestration Job submission, deployment, services, and lifecycle management feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer risk:high Autobot PR risk: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants