Skip to content

feat(spur-cli): honor SRUN_/SALLOC_/SLURM_ env-var defaults for srun …#421

Merged
shiv-tyagi merged 2 commits into
ROCm:mainfrom
biluriuday:issue-279
Jul 15, 2026
Merged

feat(spur-cli): honor SRUN_/SALLOC_/SLURM_ env-var defaults for srun …#421
shiv-tyagi merged 2 commits into
ROCm:mainfrom
biluriuday:issue-279

Conversation

@biluriuday

@biluriuday biluriuday commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

…and salloc

Summary

Adds environment-variable defaults for srun and salloc, aligning Spur with Slurm's precedence model (closes #279). Also fixes --gres CLI parsing to match Slurm semantics.

Precedence for every affected flag is now: CLI arg > SPUR_* native twin > SLURM_*/SRUN_*/SALLOC_* > built-in default.

What changed

  • New shared helper module (env_defaults.rs)apply_str/apply_string/apply_flag/apply_csv resolve multi-alias env vars with correct CLI precedence, detected via ArgMatches::value_source. Includes a shared EnvGuard test fixture and unit tests.
  • srun — parses into ArgMatches, then applies SLURM_* (plus genuine SRUN_* where Slurm uses them) and SPUR_* twins as defaults. This lets srun inside an allocation inherit SLURM_NTASKS/SLURM_CPUS_PER_TASK/SLURM_NNODES, so a step sizes to the allocation instead of the bare -n1 -c1 defaults.
  • salloc — same pattern for SALLOC_*/SPUR_*. Stays Slurm-faithful: --nodes, --ntasks, --cpus-per-task, and --job-name have no env var in real Slurm, so Spur ignores them too.
  • --gres fix (srun + salloc) — added value_delimiter = ',' + overrides_with = "gres" so a comma-list (--gres=gpu:1,fpga:2) expands to multiple GRES and a repeated --gres replaces (last wins), matching Slurm and Spur's own sbatch. Previously the CLI kept comma-lists as one un-parseable element and accumulated repeated flags.

Design notes

  • Clap's #[arg(env=...)] supports only one env var per flag, so multi-alias resolution is done in a post-parse step keyed off value_source (keeps CLI-set detection accurate even with overrides_with).
  • Env-dependent tests run serially (serial_test) and use EnvGuard, which clears all SPUR_/SLURM_/SALLOC_/SRUN_-prefixed vars on construction/drop, keeping them independent of the runner's environment and of each other.

Testing

  • cargo clippy -p spur-cli --all-targets — clean.
  • cargo test -p spur-cli — all 151 tests pass (new unit tests cover defaults, CLI override, alias precedence, numeric/bool/CSV parsing, gres comma-split, and last-wins).
  • Bare-metal cluster e2e (3 nodes, non-Raft): verified on the deployed binaries:
    • salloc: SALLOC_PARTITION env default applied; CLI -p overrides it.
    • srun: SLURM_NTASKS env default applied to submitted job; CLI -n overrides it; SPUR_NTASKS takes precedence over the SLURM_NTASKS twin.

Known gap / follow-up

sbatch still resolves env defaults via clap's single SBATCH_* attribute per flag and does not yet honor SPUR_* twins (e.g. SPUR_PARTITION), unlike srun/salloc. Unifying sbatch onto env_defaults is deferred to a follow-up PR since it must preserve sbatch's CLI > env > #SBATCH directive precedence.

…and salloc

Co-authored-by: Cursor <cursoragent@cursor.com>

Copilot AI 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.

Pull request overview

Adds Slurm-compatible environment-variable defaulting for srun/salloc (with SPUR_* native twins and CLI precedence), and updates --gres parsing to match Slurm’s comma-splitting + last-wins behavior.

Changes:

  • Introduces env_defaults.rs helpers to apply ordered env-var aliases only when a flag wasn’t set on the CLI (via ArgMatches::value_source).
  • Updates srun and salloc to parse into ArgMatches, then apply env defaults post-parse.
  • Fixes --gres to split comma-lists and make repeated --gres replace previous values (last wins).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
crates/spur-cli/src/srun.rs Switches to matches-based parsing, applies env defaults, and updates --gres parsing semantics.
crates/spur-cli/src/salloc.rs Switches to matches-based parsing, applies env defaults, and updates --gres parsing semantics.
crates/spur-cli/src/main.rs Registers the new shared env-defaults module.
crates/spur-cli/src/env_defaults.rs Adds shared env resolution helpers and env-isolation test guard + unit tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/spur-cli/src/srun.rs
Comment thread crates/spur-cli/src/env_defaults.rs
Comment thread crates/spur-cli/src/env_defaults.rs
@codecov-commenter

codecov-commenter commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.15838% with 10 lines in your changes missing coverage. Please review.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #421      +/-   ##
==========================================
+ Coverage   70.86%   71.21%   +0.34%     
==========================================
  Files         140      141       +1     
  Lines       41849    42390     +541     
==========================================
+ Hits        29656    30185     +529     
- Misses      12193    12205      +12     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…env-var values

Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread crates/spur-cli/src/srun.rs
@shiv-tyagi shiv-tyagi merged commit ac53a26 into ROCm:main Jul 15, 2026
16 checks passed
@biluriuday biluriuday deleted the issue-279 branch July 15, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support SRUN_*/SALLOC_* environment variable defaults for srun/salloc flags

4 participants