Skip to content

feat(cli): add gym job list, status and info - #5344

Merged
prokotg merged 17 commits into
mainfrom
prokotg/gym-job-status
Nov 19, 2026
Merged

prokotg merged 17 commits into
mainfrom
prokotg/gym-job-status

Conversation

@prokotg

@prokotg prokotg commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Stacked on #5295: this branch is based on prokotg/gym-job-foundation, so the diff shows only this PR. I retarget it to main when #5295 merges.

  • gym job list, status and info. list reads this machine's job index and never touches the network. status is the only command that asks the scheduler, for the given ids or the newest submissions. info describes one submission and where its parts are.
  • The status and info operations (operations.py). status groups records by connection_key and asks each connection once, all connections at the same time. A connection that fails makes its jobs UNKNOWN and hides nothing else. The executor's state is then reconciled with the files the job wrote (below).
  • Slurm is Inspectable (slurm_status.py). One script per host runs a single squeue --me --all for the whole batch, a single sacct -j over every job id any of them has had, and reads each job directory's state files. Jobs are found by the directory they run in, compared as the same file (-ef), so a resumed job, a job started by hand and a symlinked directory are still seen.
  • ObservedStatus.job_ids (every job id seen, so info can show a chain without knowing any executor's files), jobs.list_submissions, and the two state-file names as constants in jobs.py.
  • The text the commands print is rendered by cli/job_render.py, which imports nothing that talks to a scheduler (a test checks it). cli/job.py keeps the commands.
  • A new Job Management docs page.

Reconciliation, in this order: an active state stands; otherwise .gym_chain_incomplete makes the job FAILED with the reason the job wrote; otherwise eval.exit decides SUCCEEDED or FAILED; otherwise the executor's state stands. CANCELLED is never overridden, because a file left by an earlier attempt would mask a cancel. Roll-up per submission: running wins, then queued, failed, cancelled; only all-succeeded succeeds.

PR plan

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

  1. feat(orchestration): add job-management interfaces and types #5295: the types, the capability interfaces, the operations declared, and the submit-time log plan.
  2. This PR: 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.

What it prints

$ gym job status
gym-job-20261029T093012Z-4f1a9c  cluster-a  RUNNING (1 RUNNING, 2 SUCCEEDED)
  BENCHMARK  STATE      JOB ID                     DETAIL
  gpqa       SUCCEEDED  8123401                    COMPLETED
  ruler      RUNNING    8123455 (record: 8123402)  RUNNING
  ifbench    SUCCEEDED  8123403                    COMPLETED

gym-job-20261028T154501Z-77be02  cluster-a  FAILED (1 FAILED)
  BENCHMARK  STATE   JOB ID   DETAIL
  ruler      FAILED  8119870  FAILED
             Chain stopped at the walltime cap with rollouts missing; resubmit to continue.
             logs: gym job logs gym-job-20261028T154501Z-77be02 ruler --tail 100

That is real output of the CLI over a job index and job directories, with stand-ins for squeue and sacct. status takes several ids; --benchmark is strict with ids and a selector without; --json prints the same data.

Validation

  • 67 new tests. The Slurm script is run for real in a shell against stand-in squeue and sacct (same-file matching through a symlink, one squeue and one sacct for a whole batch, state files with quotes and newlines, squeue or sacct failing, a job directory with spaces and quotes, a non-numeric recorded id never reaching the script). The CLI is driven through main() and its whole stdout is parsed as JSON.
  • Two mutations confirmed the tests can fail: comparing directories as strings instead of as the same file fails the symlink test, and asking connections one at a time fails the concurrency test (a barrier that only passes if both are being asked at once).
  • Orchestration and CLI tests (jobs, operations, Slurm status, script and executor, resubmit, Kubernetes, submit, API, telemetry, eval submit and gym job CLIs): 836 passed, 3 failed. All 3 also fail on clean main on macOS (two use GNU sed -i; test_memory_profiler_uses_spawned_server_metadata).
  • Full unit suite: 13382 passed, 50 failed. All 50 also fail on clean origin/main (sandbox, docker compose, harbor, super35 launcher, CI-environment, telemetry, the opensandbox Slurm-eval tests, and the sed tests above).
  • The generated job scripts are still byte-identical (six scripts diffed). ruff and pre-commit pass.

Known gaps

  • Not run on a Slurm cluster. The commands use squeue --me --all --noheader --format='%i|%T|%Z' and sacct -j IDS -X -P -n -o JobID,State,ExitCode; if a cluster has sacct disabled, a finished job reads UNKNOWN unless its files say how it ended.
  • eval.exit is written by the export wrapper, which is not on main; without it a finished job takes the scheduler's verdict.
  • progress is not reported yet.
  • Kubernetes records: status and info fail with UnsupportedOperationError.
  • cancel, cancel_submission and logs are still declared only.

Rollout evidence

N/A: no agent, verifier or model behavior is touched; the commands only read.

@prokotg prokotg added feature New capabilities, enhancements, or enablement work area:orchestration Job submission, deployment, services, and lifecycle management area:cli Command-line interfaces and user-facing command behavior labels Oct 30, 2026
@copy-pr-bot

copy-pr-bot Bot commented Oct 30, 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 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:40
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team October 30, 2026 07:41
@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

@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 WITH CARE — 5 RISK findings and 2 NOTE suggestions.

Completed the light, broad review of all 17 changed files and their affected paths. The findings cover incorrect terminal-state reporting, failed file reads becoming false failures, error rendering suppressing healthy results, malformed index entries, and two user-facing inconsistencies.

Read-only source review: no tests or live Slurm commands were executed. Suggested patches and acceptance checks require author verification.


Inline comments (escaped v1):

  • nemo_gym/cli/job_render.py line 99: RISK — Multiline connection errors abort the entire text report

    Failure: SSH connection failures contain newlines, which status preserves in detail. For example, detail="RuntimeError: SSH failed\nPermission denied" produces multiple physical table rows. The subsequent splitlines() and zip(..., strict=True) raise ValueError, so text status exits with a zip-length error and prints neither the unreachable submission nor healthy submissions. Expected: UNKNOWN with the connection reason, while other results remain visible.

    Correction: Could you keep this table cell single-line, without changing the underlying status or JSON? Replace this line with:

            detail = " ".join((job.detail or "-").splitlines()) or "-"
            rows.append((job.benchmark, job.state.value, job_id, detail))
    

    Preservation / acceptance: Proposed regression: query two connections, one raising RuntimeError("SSH failed\nPermission denied") and one returning SUCCEEDED. Text output must contain both submissions, UNKNOWN with both error fragments, and SUCCEEDED, without exiting unsuccessfully. JSON must still parse and retain the original newline in detail. Retain the exact existing status-rendering assertion, including resumed-versus-recorded IDs and failure/logs lines. Static reasoning only; please verify the suggestion before adoption.

  • nemo_gym/orchestration/executors/slurm_status.py line 201: RISK — Preserve queue-query failures before consulting accounting

    Failure: With recorded ID 100, no state files, failing squeue, and accounting output 100|COMPLETED|0:0, _observe() returns SUCCEEDED before reaching this error branch. A newer job started in the same directory cannot be discovered after the queue query fails, so an old completion can falsely describe the current run and the error disappears. This contradicts the UNKNOWN-on-scheduler-error contract.

    Correction: Move the existing guard immediately before the accounting-selection loop, removing its old copy:

        if squeue_error:
            return ObservedStatus(state=JobState.UNKNOWN, detail=f"squeue failed: {squeue_error}", **common)

    The invariant is that a failed queue query cannot establish the absence of newer active work merely because a known ID has accounting data.

    Preservation / acceptance: Keep all known IDs and readable files in the UNKNOWN result, allowing existing file reconciliation to operate. Proposed checks: failing squeue plus the completed accounting row above must yield UNKNOWN with squeue failed; adding a readable state file must retain it in files. Healthy queue queries must retain the finished-accounting assertions. A RUNNING queue row with failing sacct must still yield RUNNING. These checks were not executed; please verify the proposed move.

  • nemo_gym/orchestration/executors/slurm_status.py line 192: RISK — Do not substitute a predecessor's outcome for missing newest accounting

    Failure: With chain 100\n101\n, an empty successful queue response, no state files, and accounting containing only 100|TIMEOUT|0:0, this loop skips missing ID 101 and reports FAILED for 100. An older COMPLETED row similarly produces false success. The newest attempt's outcome is unknown, not the predecessor's outcome; the resume producer explicitly accommodates accounting lag.

    Correction: Only the newest known ID may supply the terminal accounting verdict. Since job_ids is already sorted ascending, replace this loop header with:

        for job_id in job_ids[-1:]:
    

    If that ID has no accounting row, fall through to UNKNOWN/error handling rather than borrowing an older result.

    Preservation / acceptance: Keep active-state selection ahead of accounting, retain the full ID list and readable files, and allow UNKNOWN to be reconciled by existing state-file rules. Proposed regressions: chain 100/101 with only predecessor TIMEOUT or COMPLETED must yield UNKNOWN; adding 101|COMPLETED|0:0 must yield SUCCEEDED with ID 101. Retain the existing newest-chain assertion and the RUNNING-800-over-PENDING-900 assertion. Static reasoning only; verify the suggestion before adoption.

  • nemo_gym/orchestration/executors/slurm_status.py line 83: RISK — Omit failed state-file reads instead of emitting empty content

    Failure: An existing but unreadable .gym_chain_incomplete passes -f. When head fails, the remaining pipeline and echo still emit a file marker containing empty content. The parser treats that as a real marker, and reconciliation turns it into FAILED, potentially overriding a completed job. The file contract instead requires unreadable files to be absent.

    Correction: Emit a marker only when the bounded read and encoding succeed. Replace the current generated if/echo lines inside the file loop with these list entries:

                f'  if [ -f "$dir/$_f" ] && _encoded=$(set -o pipefail; head -c {_STATE_FILE_BYTES} "$dir/$_f" 2>/dev/null | base64 | tr -d "\\n"); then',
                f'    echo "{_MARK}file:{tag}:$_f:$_encoded"',
                '  fi',

    Subshell-local pipefail checks the read without changing surrounding error handling. Successfully read empty files must remain distinguishable from failed reads.

    Preservation / acceptance: Proposed regression: use a head stand-in that exits nonzero for the incomplete marker; it must be absent from files, and a completed job must remain SUCCEEDED. A readable empty marker must still return "" and trigger the existing incomplete-chain rule. Another readable state file and scheduler results must survive the failed read. Retain the 4096-byte bound and the quotes/newlines/Unicode and quoted-directory assertions. No shell checks were executed; please verify the suggested code.

  • nemo_gym/orchestration/jobs.py line 460: RISK — Skip valid JSON that is not a record object

    Failure: Alongside a valid indexed submission, put [] in another *.json index file. Decoding succeeds, but SubmissionRecord.load() calls payload.get(), raising AttributeError outside this handler. Offline listing and status without IDs then abort instead of warning and returning valid submissions. null, strings, and numbers fail similarly.

    Correction: Validate the decoded shape before calling load(), routing malformed cache data through the existing warning-and-skip branch. Replace the current load statement with:

    payload = json.loads(path.read_text(encoding="utf-8"))
    if not isinstance(payload, dict):
        raise ValueError("Job record must be a JSON object")
    records.append(SubmissionRecord.load(payload))

    This restores the invariant that one malformed index entry cannot hide valid records, without broadly catching programming errors.

    Preservation / acceptance: Proposed regression: parameterize a second indexed file over [], null, "not a record", and 123, alongside one valid record. Listing must return the valid record and warn with the bad filename; limit=1 must still return it. Retain the existing index assertions: newest-first sorting, limiting, and warnings for invalid JSON and future schemas. Keep older-record compatibility. Explicit-ID loading need not change for this localized repair. Tests were not executed; please verify the suggested code.

  • nemo_gym/cli/job.py line 48: NOTE — Suggestion: count matching submissions in the pagination hint

    Failure: With one gpqa submission and one ruler submission, gym job status --benchmark gpqa shows every matching result but prints 1 of 2 submissions shown (--all for the rest). Adding --all cannot reveal the excluded submission because selection precedes limiting. The hint should describe omitted matching results, not excluded records.

    Correction: Replace this line with a count using the same eligibility rule:

            eligible = list_submissions()
            if benchmarks:
                wanted = set(benchmarks)
                eligible = [record for record in eligible if wanted <= {job.benchmark for job in record.benchmarks}]
            total = len(eligible)
    

    Preservation / acceptance: Extend the selector test with text output: its two-record setup must show gpqa without a pagination hint. With three matching records, one nonmatching record, and --limit 1, expect 1 of 3, not 1 of 4. Retain the unfiltered 1 of 2 assertion and absence of a hint with --all. Explicit-ID and JSON behavior should remain unchanged. Proposed checks only; verify the suggestion before adoption.

  • fern/versions/latest/pages/orchestration/troubleshooting.mdx line 216: NOTE — Suggestion: update the status FAQ for the new commands

    Failure: This answer still says no Gym command tracks status, which becomes incorrect with the newly registered command. Users entering through troubleshooting are directed away from the feature this PR adds.

    Correction: Replace the paragraph with the supported workflow while retaining scheduler tools as an option:

    Use `gym job status ID` for one submission, or `gym job status` for the newest submissions in this machine's index. `gym job info ID` shows directories and planned logs. See [Job Management](/main/orchestration/job-management). Slurm's `squeue` and `sacct` remain available for scheduler details.
    

    Preservation / acceptance: Static check: the FAQ no longer denies the command's existence, distinguishes live status from descriptive info, and links to the new guide at its auto-discovered bleeding-edge route. Keep scheduler tools available as an alternative; do not imply job list reports live state. No documentation build was executed.

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

@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
marta-sd
marta-sd previously approved these changes Nov 2, 2026

@marta-sd marta-sd 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.

Approving with some non-blocking suggestions

Comment thread nemo_gym/orchestration/operations.py Resolved
Comment thread nemo_gym/orchestration/job_commands.py Resolved
Comment thread nemo_gym/orchestration/job_commands.py Resolved
Comment thread nemo_gym/cli/job.py Resolved
)
for record in records
]
return _table(("ID", "SUBMITTED", "CLUSTER", "EXECUTOR", "BENCHMARKS"), rows)

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.

Maybe we could re-use table printing logic we have for listing commands?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I kept the plain one on purpose: rich.Table wraps long ids at 80 columns when piped, which breaks copy/grep of a job id. Happy to switch if you think that is not worth it.

Comment thread nemo_gym/cli/main.py Resolved
Comment thread nemo_gym/cli/main.py Resolved
prokotg and others added 7 commits November 18, 2026 16:45
…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]>
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the risk:high Autobot PR risk: high label Nov 18, 2026
…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]>
status groups the records by connection and asks each connection once, all
connections at the same time, then reconciles what the executor reports
with the files the job wrote: a chain that stopped early or the exit code
of the run decides a finished job, and a cancelled job is never overridden.
A connection that fails makes its jobs UNKNOWN and hides nothing else.
info describes a submission with the job ids observed and its resolved
config. Also adds the local-index lister and ObservedStatus.job_ids.

Signed-off-by: Tomasz Grzegorzek <[email protected]>
SlurmExecutor is Inspectable: one script per host runs a single squeue
for the whole batch and a single sacct over every job id any of them has
had, and reads each job directory's state files. Jobs are found by the
directory they run in, compared as the same file, so resumed jobs, jobs
started by hand and symlinked directories are still seen.

Signed-off-by: Tomasz Grzegorzek <[email protected]>
gym job list reads this machine's job index and never touches the
network; gym job status is the only command that asks the scheduler, for
the given ids or the newest submissions; gym job info describes one
submission and where its parts are. Documented in a new Job Management
page.

Signed-off-by: Tomasz Grzegorzek <[email protected]>
The functions that turn data into the text a person reads now live in
job_render.py and import nothing that talks to a scheduler; a test checks
that. job.py keeps the commands, which call the dispatch layer, prompt and
set exit codes.

Signed-off-by: Tomasz Grzegorzek <[email protected]>
Slurm status: name the answer kinds, never let an old accounting row stand
in for a failed queue query or a missing newest job, and drop a state file
that could not be read instead of reporting it empty. Skip index files that
are valid JSON but not a record. CLI: keep a multi-line detail in its table
row, count only matching submissions in the pagination note, name the
command in the override error, and move the clean-exit handling into a
decorator next to the config-error one. Update the status FAQ.

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

prokotg commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test bb42d3a

@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/44494132889

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue because a pull request earlier in the stack was removed 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/44497330925

Merged via the queue into main with commit 6b58b6e Nov 19, 2026
135 of 141 checks passed
Base automatically changed from prokotg/gym-job-foundation to main November 19, 2026 09:50
@prokotg
prokotg deleted the prokotg/gym-job-status 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:cli Command-line interfaces and user-facing command behavior 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.

4 participants