fix: safer gpu usage - dropping SLURM env to avoid conflicting vars, …#46
Conversation
…explicit node requirement to avoid splitting onto several nodes, if not required.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
💤 Files with no reviewable changes (2)
📝 WalkthroughWalkthroughAdds strict integer validation for GPU/node resource helpers with tests, appends their flags to SMP srun invocations, logs the process environment at executor init, and sanitizes inherited SLURM-related environment variables before launching nested srun processes. ChangesSLURM Resource Helpers and Environment Sanitization
🎯 3 (Moderate) | ⏱️ ~22 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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: 1
🧹 Nitpick comments (1)
snakemake_executor_plugin_slurm_jobstep/__init__.py (1)
320-348: 💤 Low valueInconsistent handling of zero/negative values between GPU and node settings.
get_gpu_settingsilently returns""for zero or negative values (lines 330-331), whileget_node_settingraisesWorkflowErrorfor values ≤ 0 (lines 346-347). This asymmetry may be intentional (allowing GPU disable viagpus: 0while enforcing valid node counts), but consider whether negative GPU values should also raise an error for consistency and clearer user feedback.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@snakemake_executor_plugin_slurm_jobstep/__init__.py` around lines 320 - 348, The GPU handling should mirror node validation for negative values while still allowing zero to explicitly disable GPUs: in get_gpu_setting (using _coerce_int_resource and job.resources lookups for "gpus","gpu","nvidia_gpu") explicitly treat None or 0 as the empty string (no --gpus flag) but raise WorkflowError when gpu_value < 0 with a clear message, instead of silently returning ""; keep positive gpu_value producing f"--gpus={gpu_value}" so behavior is consistent with get_node_setting for invalid negatives.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@snakemake_executor_plugin_slurm_jobstep/__init__.py`:
- Around line 94-95: The debug logging currently prints the entire environment
via self.logger.debug(f"environment: {os.environ}"), which may leak secrets;
replace this with logic that filters and logs only SLURM-related variables
(e.g., keys starting with "SLURM_") or a small explicit whitelist, and if any
non-whitelisted keys must be shown, redact their values (e.g., replace with
"<REDACTED>"). Update the call that uses os.environ in __init__.py so it
constructs a filtered/sanitized dict (only SLURM_* keys or whitelist) and passes
that to self.logger.debug instead of the full os.environ.
---
Nitpick comments:
In `@snakemake_executor_plugin_slurm_jobstep/__init__.py`:
- Around line 320-348: The GPU handling should mirror node validation for
negative values while still allowing zero to explicitly disable GPUs: in
get_gpu_setting (using _coerce_int_resource and job.resources lookups for
"gpus","gpu","nvidia_gpu") explicitly treat None or 0 as the empty string (no
--gpus flag) but raise WorkflowError when gpu_value < 0 with a clear message,
instead of silently returning ""; keep positive gpu_value producing
f"--gpus={gpu_value}" so behavior is consistent with get_node_setting for
invalid negatives.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1a39fca6-b2d2-47ba-94d1-14553c9386a8
📒 Files selected for processing (2)
snakemake_executor_plugin_slurm_jobstep/__init__.pytests/tests.py
| # print environment variables for debugging purposes | ||
| self.logger.debug(f"environment: {os.environ}") |
There was a problem hiding this comment.
Logging full environment may expose sensitive data.
os.environ can contain secrets, API tokens, database credentials, or other sensitive values. Even at debug level, these logs may be captured and stored. Consider logging only SLURM-related variables or sanitizing sensitive keys.
Proposed fix to log only SLURM-related variables
# print environment variables for debugging purposes
- self.logger.debug(f"environment: {os.environ}")
+ slurm_env = {k: v for k, v in os.environ.items() if k.startswith("SLURM")}
+ self.logger.debug(f"SLURM environment: {slurm_env}")📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| # print environment variables for debugging purposes | |
| self.logger.debug(f"environment: {os.environ}") | |
| # print environment variables for debugging purposes | |
| slurm_env = {k: v for k, v in os.environ.items() if k.startswith("SLURM")} | |
| self.logger.debug(f"SLURM environment: {slurm_env}") |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@snakemake_executor_plugin_slurm_jobstep/__init__.py` around lines 94 - 95,
The debug logging currently prints the entire environment via
self.logger.debug(f"environment: {os.environ}"), which may leak secrets; replace
this with logic that filters and logs only SLURM-related variables (e.g., keys
starting with "SLURM_") or a small explicit whitelist, and if any
non-whitelisted keys must be shown, redact their values (e.g., replace with
"<REDACTED>"). Update the call that uses os.environ in __init__.py so it
constructs a filtered/sanitized dict (only SLURM_* keys or whitelist) and passes
that to self.logger.debug instead of the full os.environ.
…tor-plugin-slurm-jobstep into fix/gpu_stabil
🤖 I have created a release *beep* *boop* --- ## [0.6.1](v0.6.0...v0.6.1) (2026-05-27) ### Bug Fixes * safer gpu usage - dropping SLURM env to avoid conflicting vars, … ([#46](#46)) ([d0c515c](d0c515c)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Summary by CodeRabbit
Improvements
Bug Fixes
Tests