Skip to content

fix: Circumvent problematic Slurm re-submission#49

Open
selten wants to merge 4 commits into
snakemake:mainfrom
selten:348-jobstep-oom
Open

fix: Circumvent problematic Slurm re-submission#49
selten wants to merge 4 commits into
snakemake:mainfrom
selten:348-jobstep-oom

Conversation

@selten

@selten selten commented Jun 11, 2026

Copy link
Copy Markdown

Tested to fix snakemake/snakemake-executor-plugin-slurm#348 combined with snakemake/snakemake-executor-plugin-slurm#470. This code was generated with help from AI.

Summary by CodeRabbit

  • New Features

    • Inherited attempt state is now read and temporarily applied during job execution, affecting resource calculation and retry behavior.
  • Bug Fixes

    • Job attempt value is reliably restored after execution to preserve completion tracking.
  • Chores

    • Added debug logging of the process environment to aid diagnostics.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@selten, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 45 minutes and 3 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9a2d3804-1feb-4301-8b27-84b523003005

📥 Commits

Reviewing files that changed from the base of the PR and between f1ee425 and 9c8affb.

📒 Files selected for processing (1)
  • tests/test_attempt_sync.py
📝 Walkthrough

Walkthrough

The SLURM executor reads an inherited attempt value from workflow.executor_settings._inherited_attempt during initialization (stored on self.inherited_attempt) and logs a debug dump of os.environ. In run_job, when self.inherited_attempt is set, it temporarily overrides job.attempt and calls job.reset_params_and_resources() for resource calculation before executing _run_job_impl(job), then restores the original job.attempt and resets params/resources in a finally block.

Changes

Attempt inheritance for retry escalation

Layer / File(s) Summary
Initialization: read inherited attempt
snakemake_executor_plugin_slurm_jobstep/__init__.py
Read workflow.executor_settings._inherited_attempt, assign to self.inherited_attempt (or None), log the inherited value when present, and emit a debug dump of os.environ.
Runtime: temporary job.attempt override
snakemake_executor_plugin_slurm_jobstep/__init__.py
In run_job, if self.inherited_attempt is present, save the original job.attempt, set job.attempt = self.inherited_attempt, call job.reset_params_and_resources() to recalc resources, execute _run_job_impl(job), and in finally restore the original job.attempt and call reset_params_and_resources() again.

Sequence Diagram(s)

sequenceDiagram
  participant Workflow as Workflow
  participant SLURMInit as SLURM Executor __init__
  participant SLURMRun as SLURM Executor run_job
  participant JobImpl as _run_job_impl

  Workflow->>SLURMInit: provide executor_settings._inherited_attempt
  SLURMInit->>SLURMInit: set self.inherited_attempt
  SLURMInit->>SLURMInit: debug dump os.environ
  Workflow->>SLURMRun: call run_job(job)
  SLURMRun->>SLURMRun: save original_attempt = job.attempt
  SLURMRun->>SLURMRun: job.attempt = self.inherited_attempt
  SLURMRun->>SLURMRun: job.reset_params_and_resources()
  SLURMRun->>JobImpl: call _run_job_impl(job)
  JobImpl-->>SLURMRun: return
  SLURMRun->>SLURMRun: job.attempt = original_attempt (finally)
  SLURMRun->>SLURMRun: job.reset_params_and_resources()
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly references the main change: circumventing problematic Slurm re-submission behavior, which aligns with the PR's objective of addressing OOM handling in issue #348.
Linked Issues check ✅ Passed The PR implements mechanism to read inherited attempt values and preserve original job.attempt during resource calculation, enabling Snakemake to handle OOM escalation rather than jobstep retrying with same resources.
Out of Scope Changes check ✅ Passed All changes are scoped to reading inherited attempt values and managing job.attempt during resource calculation, directly addressing the OOM re-submission issue without introducing unrelated modifications.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@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: 1

🧹 Nitpick comments (1)
snakemake_executor_plugin_slurm_jobstep/__init__.py (1)

111-130: Confirm job.attempt mutation is supported and restored safely

Snakemake’s job object exposes attempt with a setter, so assigning job.attempt is supported at the Python/API level. This code scopes the mutation to _run_job_impl(job) and restores the original value in finally, reducing side-effect risk.

🤖 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 111 - 130,
The current run_job mutates job.attempt to inherited_attempt and restores it in
finally; ensure this is safe by verifying the job object supports setting
attempt, so keep the pattern but add a guard: in run_job check hasattr(job,
"attempt") and whether assignment is allowed before saving original_attempt and
assigning self.inherited_attempt, call _run_job_impl(job) in the try block, and
always restore original_attempt in the finally only if you previously saved it;
reference run_job, self.inherited_attempt, original_attempt, _run_job_impl, and
job.attempt when making these checks and the guarded restore.
🤖 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 93-107: The code parses SNAKEMAKE_ATTEMPT into
self.inherited_attempt but doesn't enforce it being positive; update the parsing
logic in the block handling inherited_attempt (SNAKEMAKE_ATTEMPT) so after
converting to int you verify the value is >= 1, set self.inherited_attempt only
if it is >= 1 and log an info message, otherwise log a warning (similar to the
existing ValueError branch) and set self.inherited_attempt = None; keep the
existing ValueError handling for non-integers.

---

Nitpick comments:
In `@snakemake_executor_plugin_slurm_jobstep/__init__.py`:
- Around line 111-130: The current run_job mutates job.attempt to
inherited_attempt and restores it in finally; ensure this is safe by verifying
the job object supports setting attempt, so keep the pattern but add a guard: in
run_job check hasattr(job, "attempt") and whether assignment is allowed before
saving original_attempt and assigning self.inherited_attempt, call
_run_job_impl(job) in the try block, and always restore original_attempt in the
finally only if you previously saved it; reference run_job,
self.inherited_attempt, original_attempt, _run_job_impl, and job.attempt when
making these checks and the guarded restore.
🪄 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: 02c06f40-8236-4c9d-bac2-ffc7c3164ca0

📥 Commits

Reviewing files that changed from the base of the PR and between c09349d and 0979896.

📒 Files selected for processing (1)
  • snakemake_executor_plugin_slurm_jobstep/__init__.py

Comment thread snakemake_executor_plugin_slurm_jobstep/__init__.py Outdated
@selten selten changed the title Circumvent problematic Slurm re-submission fix: Circumvent problematic Slurm re-submission Jun 11, 2026
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.

OOM handling for jobstep plugin

1 participant