Merge release-v171 into main#975
Conversation
[Bug] Single-sbatch termination handling
📝 WalkthroughWalkthroughChangesSlurm job lifecycle
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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 `@src/cloudai/systems/slurm/single_sbatch_runner.py`:
- Around line 190-193: Update the job submission flow around _submit_test so
placeholder jobs returned in dry-run mode are neither appended to tracking nor
passed to SlurmSystem.kill(); gate both operations on self.mode == "run". Add a
regression test covering shutdown during dry-run and verify no cancellation is
issued for the placeholder job.
- Around line 192-203: Move the self.shutting_down check and
self.system.kill(job) call inside the try/finally scope in the job monitoring
flow, preserving the existing loop behavior. Ensure self.jobs.remove(job) always
executes, including when killing the job raises.
In `@tests/test_single_sbatch_runner.py`:
- Around line 534-555: Extend the shutdown regression coverage around
test_run_tracks_and_cancels_job_on_shutdown with a cancellation-failure case
where SlurmSystem.kill raises, asserting runner.jobs is still cleared, and a
dry-run case asserting shutdown does not invoke Slurm cancellation. Reuse the
existing runner/job setup and monitoring shutdown flow, varying only the mode
and kill behavior.
🪄 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: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Enterprise
Run ID: d3a4d7e5-0f13-432d-8a55-7ac8810ba561
📒 Files selected for processing (2)
src/cloudai/systems/slurm/single_sbatch_runner.pytests/test_single_sbatch_runner.py
| self.jobs.append(job) | ||
|
|
||
| if self.shutting_down: | ||
| self.system.kill(job) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Do not cancel placeholder jobs in dry-run mode.
Dry-run _submit_test returns a SlurmJob with ID 0; this unconditional call reaches SlurmSystem.kill() and invokes scancel(0). Gate tracking and cancellation on self.mode == "run", and add a dry-run shutdown regression test.
🤖 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 `@src/cloudai/systems/slurm/single_sbatch_runner.py` around lines 190 - 193,
Update the job submission flow around _submit_test so placeholder jobs returned
in dry-run mode are neither appended to tracking nor passed to
SlurmSystem.kill(); gate both operations on self.mode == "run". Add a regression
test covering shutdown during dry-run and verify no cancellation is issued for
the placeholder job.
| if self.shutting_down: | ||
| self.system.kill(job) | ||
|
|
||
| is_completed = False | ||
| while not is_completed: | ||
| if self.shutting_down: | ||
| break | ||
| is_completed = True if self.mode == "dry-run" else self.system.is_job_completed(job) | ||
| time.sleep(self.system.monitor_interval) | ||
| try: | ||
| while not is_completed: | ||
| if self.shutting_down: | ||
| break | ||
| is_completed = True if self.mode == "dry-run" else self.system.is_job_completed(job) | ||
| time.sleep(self.system.monitor_interval) | ||
| finally: | ||
| self.jobs.remove(job) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Keep cancellation inside the cleanup-protected scope.
If self.system.kill(job) raises, it executes before the try/finally, leaving job in self.jobs. Move the shutdown check into the try block so tracking is removed even when scancel fails.
Proposed fix
- if self.shutting_down:
- self.system.kill(job)
-
- is_completed = False
try:
+ if self.shutting_down:
+ self.system.kill(job)
+ is_completed = False
while not is_completed:📝 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.
| if self.shutting_down: | |
| self.system.kill(job) | |
| is_completed = False | |
| while not is_completed: | |
| if self.shutting_down: | |
| break | |
| is_completed = True if self.mode == "dry-run" else self.system.is_job_completed(job) | |
| time.sleep(self.system.monitor_interval) | |
| try: | |
| while not is_completed: | |
| if self.shutting_down: | |
| break | |
| is_completed = True if self.mode == "dry-run" else self.system.is_job_completed(job) | |
| time.sleep(self.system.monitor_interval) | |
| finally: | |
| self.jobs.remove(job) | |
| try: | |
| if self.shutting_down: | |
| self.system.kill(job) | |
| is_completed = False | |
| while not is_completed: | |
| if self.shutting_down: | |
| break | |
| is_completed = True if self.mode == "dry-run" else self.system.is_job_completed(job) | |
| time.sleep(self.system.monitor_interval) | |
| finally: | |
| self.jobs.remove(job) |
🤖 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 `@src/cloudai/systems/slurm/single_sbatch_runner.py` around lines 192 - 203,
Move the self.shutting_down check and self.system.kill(job) call inside the
try/finally scope in the job monitoring flow, preserving the existing loop
behavior. Ensure self.jobs.remove(job) always executes, including when killing
the job raises.
| def test_run_tracks_and_cancels_job_on_shutdown(sleep_tr: TestRun, slurm_system: SlurmSystem) -> None: | ||
| tc = TestScenario(name="tc", test_runs=[sleep_tr]) | ||
| runner = SingleSbatchRunner(mode="run", system=slurm_system, test_scenario=tc, output_path=slurm_system.output_path) | ||
| job = SlurmJob(sleep_tr, id=123) | ||
| runner._submit_test = Mock(return_value=job) | ||
| runner.handle_dse = Mock() | ||
| runner.on_job_completion = Mock() | ||
|
|
||
| def shutdown_during_monitoring(monitored_job: SlurmJob) -> bool: | ||
| assert monitored_job is job | ||
| assert runner.jobs == [job] | ||
| runner.shutdown() | ||
| return False | ||
|
|
||
| with ( | ||
| patch.object(SlurmSystem, "is_job_completed", side_effect=shutdown_during_monitoring), | ||
| patch.object(SlurmSystem, "kill") as kill, | ||
| ): | ||
| runner.run() | ||
|
|
||
| kill.assert_called_once_with(job) | ||
| assert runner.jobs == [] |
There was a problem hiding this comment.
🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win
Add regression coverage for cancellation failures and dry-run shutdown.
These tests cover successful mode="run" cancellation only. Add cases asserting that a raised kill() still clears runner.jobs, and that shutdown in mode="dry-run" does not call Slurm cancellation.
Also applies to: 558-576, 578-594
🤖 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 `@tests/test_single_sbatch_runner.py` around lines 534 - 555, Extend the
shutdown regression coverage around test_run_tracks_and_cancels_job_on_shutdown
with a cancellation-failure case where SlurmSystem.kill raises, asserting
runner.jobs is still cleared, and a dry-run case asserting shutdown does not
invoke Slurm cancellation. Reuse the existing runner/job setup and monitoring
shutdown flow, varying only the mode and kill behavior.
Summary
Upstream release v1.7.1 changes into main
Test Plan
Additional Notes