docs: improved documentation on interactive runs#437
Conversation
WalkthroughUpdated SLURM interactive usage guidance in Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
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*} |
There was a problem hiding this comment.
🧩 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"
doneunset 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:
- 1: https://www.gnu.org/s/bash/manual/html_node/Shell-Parameter-Expansion.html
- 2: https://mywiki.wooledge.org/BashFAQ/006?utm_source=openai
- 3: https://mirror.math.princeton.edu/pub/oldlinux/Linux.old/Ref-docs/POSIX/C952.pdf
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"
doneAlternatively, 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.
| unset ${!SLURM*} | ||
| srun snakemake ... |
There was a problem hiding this comment.
🧩 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:
- Start/enter the allocation normally (so you can capture the job id), e.g.
salloc ... - Save the job id, then scrub the environment, and call
srunusing--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 -icleans the environment for thesrunclient process, so you must pass the allocation identity via--jobid(since you removedSLURM_JOB_ID). [1][2]--export=NONEprevents your (now-minimal) submission environment from being propagated to the launched tasks/step (Slurm will still set its ownSLURM_*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:
- Preserve
SLURM_JOB_ID(and other requiredSLURM_*vars), or - 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.
Added a note on (hopefully more stable) interactive runs
Summary by CodeRabbit