Skip to content

docs: improved documentation on interactive runs#437

Open
cmeesters wants to merge 1 commit into
mainfrom
docs/update_on_interactive_jobs
Open

docs: improved documentation on interactive runs#437
cmeesters wants to merge 1 commit into
mainfrom
docs/update_on_interactive_jobs

Conversation

@cmeesters

@cmeesters cmeesters commented Mar 13, 2026

Copy link
Copy Markdown
Member

Added a note on (hopefully more stable) interactive runs

Summary by CodeRabbit

  • Documentation
    • Updated interactive SLURM usage guidance with a new recommended workflow for managing SLURM environment variables when running Snakemake jobs. Enhanced documentation includes improved examples and explanatory notes for clarity.

@cmeesters cmeesters requested a review from jonasfreimuth March 13, 2026 10:25
@coderabbitai

coderabbitai Bot commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

Updated SLURM interactive usage guidance in docs/further.md by replacing an admonition about extra wait times with a new workflow that unsets SLURM-related environment variables and executes Snakemake via srun. Preserves information about salloc subshell behavior with accompanying examples and rationale.

Changes

Cohort / File(s) Summary
SLURM Usage Documentation
docs/further.md
Replaced outdated guidance on interactive SLURM jobs with updated workflow: unsetting SLURM environment variables, executing via srun, and added explanatory notes with examples clarifying the rationale and salloc subshell behavior.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰 A tale of SLURM so fine and bright,
Variables unset, workflows take flight!
No more waits that linger long,
With srun's power, we hop along!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'docs: improved documentation on interactive runs' directly aligns with the changeset, which updates guidance on interactive SLURM usage in docs/further.md with a new workflow for executing Snakemake runs.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch docs/update_on_interactive_jobs
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cmeesters cmeesters added the documentation Improvements or additions to documentation label Mar 13, 2026
@cmeesters cmeesters moved this to In review in Snakemake Hackathon 2026 Mar 13, 2026

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/further.md`:
- Line 839: The line using Bash-specific expansion "unset ${!SLURM*}" is not
portable; replace it with a POSIX-safe approach: iterate over environment names
matching the SLURM_ prefix (e.g. parse `env` output and extract names starting
with "SLURM_") and call unset on each name, or alternatively make the snippet
explicitly require Bash (add a shebang or note) and keep the current expansion;
update the occurrence of "unset ${!SLURM*}" accordingly.
- Around line 839-840: The example currently unsets SLURM_* then runs srun which
breaks allocation binding because srun needs SLURM_JOB_ID (or --jobid); either
preserve required variables (keep SLURM_JOB_ID and any other needed SLURM_* env
vars) when running srun, or capture the job id before unsetting and pass it
explicitly to srun (use the captured value with --jobid="$SLURM_JOB_ID") so that
the srun snakemake invocation can attach to the salloc allocation; update the
snippet around the unset ${!SLURM*} and the srun snakemake call accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d8de6c4a-16f3-4ecd-be75-fd8a4b6357cc

📥 Commits

Reviewing files that changed from the base of the PR and between c6e8893 and e56bb06.

📒 Files selected for processing (1)
  • docs/further.md

Comment thread docs/further.md
Note that `salloc` opens a subshell. Exit it before starting another interactive job in the same terminal -- even if the previous job has completed.
Once the allocation is granted do
```console
unset ${!SLURM*}

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.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🌐 Web query:

Is unset ${!SLURM*}POSIX-compliant, or Bash-specific? What is a shell-portable way to unset all environment variables prefixed withSLURM_?

💡 Result:

unset ${!SLURM*} is Bash-specific, not POSIX: ${!prefix*} is a Bash parameter-expansion form that expands to the names of variables whose names begin with prefix (i.e., “names matching prefix”).[1][2]

A POSIX /bin/sh–portable way to unset all environment variables whose names start with SLURM_ is to generate the variable names from env and pass them to unset:

# POSIX sh
for name in $(env | sed -n 's/^\(SLURM_[A-Za-z_][A-Za-z0-9_]*\)=.*/\1/p'); do
  unset "$name"
done

unset itself (for unsetting variables by name) is specified by POSIX.[3]

Sources: Bash manual on indirect/prefix name expansions[1], BashFAQ noting ${!...} is not POSIX[2], POSIX unset spec[3].

[1] (gnu.org)
[2] (mywiki.wooledge.org)
[3] (mirror.math.princeton.edu)

Citations:


Use a shell-portable way to unset SLURM_* variables.

unset ${!SLURM*} uses Bash-specific parameter expansion and will fail in other shells (sh, dash, ksh, zsh, etc.). Replace with a POSIX-portable approach:

for var in $(env | sed -n 's/^\(SLURM_[A-Za-z_][A-Za-z0-9_]*\)=.*/\1/p'); do
  unset "$var"
done

Alternatively, explicitly require Bash in the snippet if preferred.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/further.md` at line 839, The line using Bash-specific expansion "unset
${!SLURM*}" is not portable; replace it with a POSIX-safe approach: iterate over
environment names matching the SLURM_ prefix (e.g. parse `env` output and
extract names starting with "SLURM_") and call unset on each name, or
alternatively make the snippet explicitly require Bash (add a shebang or note)
and keep the current expansion; update the occurrence of "unset ${!SLURM*}"
accordingly.

Comment thread docs/further.md
Comment on lines +839 to +840
unset ${!SLURM*}
srun snakemake ...

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.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🌐 Web query:

When launched inside an existing sallocsession, doessrunrequireSLURM_JOB_ID(or otherSLURM_* env vars) to bind to that allocation? If yes, what is the recommended command order when needing a clean environment for child processes?

💡 Result:

Yes. To have srun create a job step inside an existing allocation, it must be able to identify the parent allocation via either SLURM_JOB_ID or srun --jobid=<jobid>; --jobid “behave[s] exactly as if the SLURM_JOB_ID environment variable was set.” [1][2]

Recommended order when you need a clean environment:

  1. Start/enter the allocation normally (so you can capture the job id), e.g. salloc ...
  2. Save the job id, then scrub the environment, and call srun using --jobid:
# inside the salloc shell
JOBID="$SLURM_JOB_ID"

env -i HOME="$HOME" PATH="/usr/bin:/bin" TERM="$TERM" \
  srun --jobid="$JOBID" --export=NONE <your_command>

Notes:

  • env -i cleans the environment for the srun client process, so you must pass the allocation identity via --jobid (since you removed SLURM_JOB_ID). [1][2]
  • --export=NONE prevents your (now-minimal) submission environment from being propagated to the launched tasks/step (Slurm will still set its own SLURM_* variables for the step). [2]

Sources:
[1] Cornell CVW “Execution: srun” (existing allocation requires --jobid or SLURM_JOB_ID)
[2] Slurm srun man page (--jobid, --export)


The code as shown will break allocation binding—srun requires SLURM_JOB_ID (or --jobid parameter) to attach to the salloc allocation.

Update the example to either:

  1. Preserve SLURM_JOB_ID (and other required SLURM_* vars), or
  2. Capture the job ID before unsetting and pass it explicitly: srun --jobid="$SLURM_JOB_ID" snakemake ...

Unsetting SLURM_* without providing the --jobid parameter will cause srun to fail to bind to the existing allocation.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/further.md` around lines 839 - 840, The example currently unsets SLURM_*
then runs srun which breaks allocation binding because srun needs SLURM_JOB_ID
(or --jobid); either preserve required variables (keep SLURM_JOB_ID and any
other needed SLURM_* env vars) when running srun, or capture the job id before
unsetting and pass it explicitly to srun (use the captured value with
--jobid="$SLURM_JOB_ID") so that the srun snakemake invocation can attach to the
salloc allocation; update the snippet around the unset ${!SLURM*} and the srun
snakemake call accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

2 participants