Skip to content

Parse SchedMD pre-release / zero-padded Slurm versions robustly - #200

Merged
gunchu merged 2 commits into
facebookresearch:mainfrom
sdmcclain:fix-slurm-version-prerelease-parse
Jul 14, 2026
Merged

Parse SchedMD pre-release / zero-padded Slurm versions robustly#200
gunchu merged 2 commits into
facebookresearch:mainfrom
sdmcclain:fix-slurm-version-prerelease-parse

Conversation

@sdmcclain

Copy link
Copy Markdown
Contributor

Summary

slurm_version() parsed the Slurm version with tuple(int(v) for v in version.split(".")), which assumes every dot-separated component is a plain integer. SchedMD pre-release builds append a -<n>pre<n> suffix to the micro version, so sinfo -V reports e.g. slurm 26.05.2-0pre1 and int("2-0pre1") raises ValueError: invalid literal for int() with base 10: '2-0pre1'. This crashes every caller — for example gcm's slurm_monitor poller — on clusters running Slurm built from a SchedMD development branch rather than a tagged release.

Parse the numeric release with packaging.version.Version after stripping the non-PEP440 pre-release suffix. packaging also normalizes the zero-padded YY.MM minor (26.05 -> 26), which strict SemVer rejects outright. The Tuple[int, ...] return type is unchanged so existing comparisons (e.g. slurm_version() >= (23, 2)) keep working, and any unexpected string falls back to the original split. Adds packaging (pure-Python, already ubiquitous) to dependencies.

Test Plan

Exercised the patched slurm_version() with the version string mocked to each SchedMD form — including the zero-padded pre-release the old int() split crashed on:

$ python -c "
from unittest.mock import patch
import clusterscope.lib as lib
for s in ['26.05.2-0pre1', '24.11.2-0pre1', '24.05.0', '25.11']:
    with patch.object(lib, 'get_unified_info') as m:
        m.return_value.get_slurm_version.return_value = s
        print(f'{s:16} -> {lib.slurm_version()}')
"
26.05.2-0pre1    -> (26, 5, 2)
24.11.2-0pre1    -> (24, 11, 2)
24.05.0          -> (24, 5, 0)
25.11            -> (25, 11)

## Summary

`slurm_version()` parsed the Slurm version with `tuple(int(v) for v in version.split("."))`, which assumes every dot-separated component is a plain integer. SchedMD pre-release builds append a `-<n>pre<n>` suffix to the micro version, so `sinfo -V` reports e.g. `slurm 26.05.2-0pre1` and `int("2-0pre1")` raises `ValueError: invalid literal for int() with base 10: '2-0pre1'`. This crashes every caller — for example gcm's `slurm_monitor` poller — on clusters running Slurm built from a SchedMD development branch rather than a tagged release.

Parse the numeric release with `packaging.version.Version` after stripping the non-PEP440 pre-release suffix. `packaging` also normalizes the zero-padded `YY.MM` minor (`26.05` -> `26`), which strict SemVer rejects outright. The `Tuple[int, ...]` return type is unchanged so existing comparisons (e.g. `slurm_version() >= (23, 2)`) keep working, and any unexpected string falls back to the original split. Adds `packaging` (pure-Python, already ubiquitous) to `dependencies`.

## Test Plan

Exercised the patched `slurm_version()` with the version string mocked to each SchedMD form — including the zero-padded pre-release the old `int()` split crashed on:

```
$ python -c "
from unittest.mock import patch
import clusterscope.lib as lib
for s in ['26.05.2-0pre1', '24.11.2-0pre1', '24.05.0', '25.11']:
    with patch.object(lib, 'get_unified_info') as m:
        m.return_value.get_slurm_version.return_value = s
        print(f'{s:16} -> {lib.slurm_version()}')
"
26.05.2-0pre1    -> (26, 5, 2)
24.11.2-0pre1    -> (24, 11, 2)
24.05.0          -> (24, 5, 0)
25.11            -> (25, 11)
```
@sdmcclain
sdmcclain requested review from gunchu and skalyan as code owners July 13, 2026 19:11
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 13, 2026
Comment thread clusterscope/lib.py Outdated
Address review feedback: catch only `packaging.version.InvalidVersion` (the sole expected failure when normalizing the SchedMD version string) instead of a bare `except Exception`, so unexpected errors propagate rather than silently hitting the legacy split.
@gunchu
gunchu merged commit bd155d2 into facebookresearch:main Jul 14, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants