Skip to content

fix(spur-spank): rename SPANK exports to Slurm-compatible symbols#429

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

fix(spur-spank): rename SPANK exports to Slurm-compatible symbols#429
shiv-tyagi merged 3 commits into
ROCm:mainfrom
biluriuday:issue-294

Conversation

@biluriuday

@biluriuday biluriuday commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Fix SPANK ABI and wire up plugin env/args (#294)

Existing Slurm SPANK plugins failed against Spur's host: the API symbols used a spur_spank_* prefix, and even after loading, plugins couldn't affect the job. This makes the SPANK host drop-in compatible with Slurm's spank.h.

What changed

ABI / symbol compatibility

  • Renamed exports to Slurm's names and aligned signatures to spank.h: spank_get_item, spank_setenv (added the overwrite arg), plus new spank_getenv, spank_unsetenv, spank_job_control_{set,get,unset}env, spank_strerror, and the slurm_error/info/verbose/debug/debug2/debug3 + slurm_spank_log loggers.
  • Fixed SpankItem discriminants to match Slurm's enum spank_item (previously mis-ordered, so S_JOB_ID returned the gid).
  • Added ESPANK_* return codes; spank_get_item now returns ESPANK_NOT_AVAIL for known-but-unsupported items vs ESPANK_BAD_ARG for unknown ids.
  • Made spurd export these symbols in its dynamic symbol table so dlopen'd plugins resolve them, via linker flags (--undefined + --export-dynamic, guarded on the target OS) in spurd/build.rs.

Functional wiring

  • invoke_hook now threads a caller-owned SpankHandle, so plugin env edits persist and are visible across hooks/plugins.
  • The executor seeds the handle from the job's env + context, runs Init/TaskInit after the env is assembled, and folds plugin env changes back into the launched job (both container and command paths).
  • Plugstack arguments are now delivered to hooks as ac/argv (previously always 0/NULL).

Testing

  • Unit/integration tests updated and extended (spur-spank + t58_spank): item-ID ordering, setenv overwrite semantics, getenv round-trip/errors, env-in seeding, NOT_AVAIL vs BAD_ARG.
  • cargo clippy --workspace --exclude spur-ffi --all-targets clean.
  • End-to-end on the bare-metal cluster: built a real SPANK plugin (slurm_spank_task_init) using spank_setenv/spank_get_item and a plugstack arg. Confirmed it loads (SPANK plugins loaded count=1) and a job sees the injected env (SPUR_SPANK_TEST=hello_from_spank, SPUR_SPANK_ARG=arg_from_plugstack).

Known limitations / follow-ups

  • Logging functions are non-variadic (stable Rust can't define C-variadic fns), so printf-style format specifiers aren't expanded — the format string is logged verbatim.
  • spank_get_item supports scalar items only (no S_JOB_ARGV/S_JOB_ENV or pid-to-id lookups).
  • Hooks run in the spurd process, not the forked/privilege-dropped task.
  • job_control_env isn't yet wired into prolog/epilog.
  • Option-registration symbols (spank_option_register, etc.) are not yet provided.

Rename spur_spank_* exports to spank_*/slurm_* and align signatures and
item IDs to spank.h so existing Slurm SPANK plugins resolve their symbols.
Export dynamic symbols from spurd so plugins can dlsym them.

Co-authored-by: Cursor <cursoragent@cursor.com>
@biluriuday
biluriuday requested a review from powderluv as a code owner July 13, 2026 07:19
Copilot AI review requested due to automatic review settings July 13, 2026 07:19
@codecov-commenter

codecov-commenter commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.40720% with 96 lines in your changes missing coverage. Please review.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #429      +/-   ##
==========================================
+ Coverage   70.85%   71.99%   +1.14%     
==========================================
  Files         140      141       +1     
  Lines       41849    43196    +1347     
==========================================
+ Hits        29650    31095    +1445     
+ Misses      12199    12101      -98     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Renames the SPANK host exports to Slurm-compatible spank_*/slurm_* symbols and adjusts ABI-facing signatures/IDs so existing Slurm SPANK plugins can resolve and call into Spur’s host process (spurd).

Changes:

  • Add a spurd build script to export dynamic symbols for runtime dlopen/dlsym resolution.
  • Align spur-spank exported symbol names, return codes, item IDs, and add basic env/job-control env helpers plus Slurm-style logging symbol stubs.
  • Extend SPANK-focused tests to validate item ID discriminants and spank_setenv/spank_getenv behavior.

Reviewed changes

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

File Description
crates/spurd/build.rs Adds linker argument emission to export dynamic symbols from the spurd binary.
crates/spur-tests/src/t58_spank.rs Adds test coverage for Slurm item ID discriminants and env round-trip behavior.
crates/spur-spank/src/lib.rs Renames exports to spank_*/slurm_*, aligns enums/return codes, adds env helpers + symbol retention anchor.

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

Comment thread crates/spur-spank/src/lib.rs
Comment thread crates/spur-spank/src/lib.rs
Comment thread crates/spur-spank/src/lib.rs Outdated
Thread a caller-owned SpankHandle through invoke_hook so plugin env edits
survive and are merged into the launched job's environment, seed the handle
from the job env/context, and pass plugstack arguments to hooks as ac/argv.

Move exported-symbol retention to the linker (--undefined + --export-dynamic,
guarded on the target OS) and drop the runtime anchor. Return ESPANK_NOT_AVAIL
for known-but-unsupported spank_get_item ids.

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

@shiv-tyagi shiv-tyagi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A few suggestions, all minor, nothing blocking. Symbol/enum ordering against spank.h looks correct and the tests are thorough. PTAL.

Comment thread crates/spurd/build.rs Outdated
Comment thread crates/spurd/src/agent_server.rs
Comment thread crates/spur-tests/src/t58_spank.rs Outdated
Scope dynamic symbol export with a generated --dynamic-list instead of
--export-dynamic so only the SPANK API is exposed. Seed uid/gid into the
TaskExit/JobEpilog handle for parity with the launch path. Drop the item-id
test in spur-tests that duplicates the spur-spank unit test.

Co-authored-by: Cursor <cursoragent@cursor.com>
@shiv-tyagi
shiv-tyagi merged commit 3620047 into ROCm:main Jul 15, 2026
14 checks passed
@biluriuday
biluriuday deleted the issue-294 branch July 15, 2026 16:52
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.

4 participants