Skip to content

Conversation

@jan-janssen
Copy link
Member

@jan-janssen jan-janssen commented Jul 12, 2025

Summary by CodeRabbit

  • New Features
    • Added an option to control task termination on shutdown for Flux and Slurm executors.
    • Introduced new validation checks for input parameters and file existence.
    • Added a function to terminate jobs via the queuing system.
  • Bug Fixes
    • Enhanced shutdown handling to support different termination methods for task execution.
  • Tests
    • Added tests for new input validation functions.
    • Updated executor tests to cover the new shutdown termination option.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 12, 2025

Warning

Rate limit exceeded

@jan-janssen has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 22 minutes and 16 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, 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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 2c92b76 and b570ffa.

📒 Files selected for processing (1)
  • executorlib/task_scheduler/file/task_scheduler.py (3 hunks)

"""

Walkthrough

A new boolean parameter, terminate_tasks_on_shutdown, is introduced to the constructors of Flux and Slurm executor classes, with validation and integration into their shutdown logic. Supporting validation functions and termination utilities are added, and shutdown handling is refined for task termination. The create_file_executor function is updated to internally select the appropriate termination function based on this parameter and execution method. Corresponding tests are updated and extended.

Changes

File(s) Change Summary
executorlib/executor/flux.py,
executorlib/executor/slurm.py
Added terminate_tasks_on_shutdown parameter to executor class constructors, with validation and integration.
executorlib/standalone/inputcheck.py Added validation functions: check_file_exists, check_log_obj_size, check_terminate_tasks_on_shutdown.
executorlib/task_scheduler/file/queue_spawner.py Added terminate_with_pysqa function for queue-based termination logic.
executorlib/task_scheduler/file/shared.py Refined shutdown logic in execute_tasks_h5 to branch termination based on function identity.
executorlib/task_scheduler/file/task_scheduler.py Modified create_file_executor to select termination function internally based on terminate_tasks_on_shutdown and execution method.
tests/test_standalone_inputcheck.py Added tests for check_log_obj_size and check_terminate_tasks_on_shutdown validation functions.
tests/test_fluxclusterexecutor.py Updated tests to include terminate_tasks_on_shutdown parameter in executor instantiations.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Executor (Flux/Slurm)
    participant InputCheck
    participant FileExecutor
    participant QueueSpawner

    User->>Executor: Instantiate with terminate_tasks_on_shutdown
    Executor->>InputCheck: Validate terminate_tasks_on_shutdown
    Executor->>FileExecutor: create_file_executor with terminate_tasks_on_shutdown
    FileExecutor->>QueueSpawner: Select terminate_function internally
    User->>Executor: Shutdown
    Executor->>FileExecutor: Shutdown, calls terminate_function if set
    FileExecutor->>QueueSpawner: terminate_with_pysqa (if applicable)
Loading

Possibly related PRs

  • Remove default terminate function #717: Both PRs modify how the terminate_function is handled and passed to create_file_executor, reflecting changes in task termination management during executor shutdown.

Poem

A toggle for shutdown, so neat and so new,
Now tasks can be ended—when told what to do!
With checks in the code and tests in the suite,
Executors behave and shutdown’s complete.
🐇 Hopping through queues, I tidy and mend—
Terminate tasks, and then I suspend!
"""

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link

codecov bot commented Jul 12, 2025

Codecov Report

Attention: Patch coverage is 95.45455% with 1 line in your changes missing coverage. Please review.

Project coverage is 96.91%. Comparing base (a4cac80) to head (b570ffa).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
executorlib/task_scheduler/file/task_scheduler.py 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #715      +/-   ##
==========================================
- Coverage   96.94%   96.91%   -0.03%     
==========================================
  Files          30       30              
  Lines        1343     1363      +20     
==========================================
+ Hits         1302     1321      +19     
- Misses         41       42       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

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 (2)
executorlib/standalone/inputcheck.py (2)

210-214: Fix missing space in error message.

The error message has missing spaces between sentences.

-            "log_obj_size is not supported for the executorlib.SlurmClusterExecutor and executorlib.FluxClusterExecutor."
-            "Please use log_obj_size=False instead of log_obj_size=True."
+            "log_obj_size is not supported for the executorlib.SlurmClusterExecutor and executorlib.FluxClusterExecutor. "
+            "Please use log_obj_size=False instead of log_obj_size=True."

221-226: Fix missing space in error message.

The error message has missing spaces between sentences.

-            "terminate_tasks_on_shutdown is not supported for the executorlib.SingleNodeExecutor, "
-            "executorlib.SlurmJobExecutor and executorlib.FluxJobExecutor."
-            "Please use terminate_tasks_on_shutdown=True instead of terminate_tasks_on_shutdown=False."
+            "terminate_tasks_on_shutdown is not supported for the executorlib.SingleNodeExecutor, "
+            "executorlib.SlurmJobExecutor and executorlib.FluxJobExecutor. "
+            "Please use terminate_tasks_on_shutdown=True instead of terminate_tasks_on_shutdown=False."
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3e0d914 and 084f500.

📒 Files selected for processing (6)
  • executorlib/executor/flux.py (10 hunks)
  • executorlib/executor/slurm.py (10 hunks)
  • executorlib/standalone/inputcheck.py (1 hunks)
  • executorlib/task_scheduler/file/queue_spawner.py (1 hunks)
  • executorlib/task_scheduler/file/shared.py (2 hunks)
  • tests/test_standalone_inputcheck.py (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
tests/test_standalone_inputcheck.py (1)
executorlib/standalone/inputcheck.py (2)
  • check_terminate_tasks_on_shutdown (217-226)
  • check_log_obj_size (206-214)
executorlib/task_scheduler/file/shared.py (1)
executorlib/task_scheduler/file/subprocess_spawner.py (1)
  • terminate_subprocess (55-64)
executorlib/executor/slurm.py (3)
executorlib/standalone/inputcheck.py (2)
  • check_log_obj_size (206-214)
  • check_terminate_tasks_on_shutdown (217-226)
executorlib/task_scheduler/file/task_scheduler.py (1)
  • create_file_executor (77-118)
executorlib/task_scheduler/file/queue_spawner.py (1)
  • terminate_with_pysqa (84-102)
executorlib/executor/flux.py (3)
executorlib/standalone/inputcheck.py (2)
  • check_log_obj_size (206-214)
  • check_terminate_tasks_on_shutdown (217-226)
executorlib/task_scheduler/file/task_scheduler.py (1)
  • create_file_executor (77-118)
executorlib/task_scheduler/file/queue_spawner.py (1)
  • terminate_with_pysqa (84-102)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: benchmark (ubuntu-latest, 3.13, .ci_support/environment-openmpi.yml)
  • GitHub Check: unittest_openmpi (ubuntu-latest, 3.11)
  • GitHub Check: benchmark (ubuntu-latest, 3.13, .ci_support/environment-mpich.yml)
  • GitHub Check: unittest_openmpi (ubuntu-latest, 3.13)
  • GitHub Check: notebooks
  • GitHub Check: unittest_openmpi (macos-latest, 3.13)
  • GitHub Check: unittest_mpich (macos-latest, 3.13)
  • GitHub Check: unittest_flux_openmpi
  • GitHub Check: unittest_win
  • GitHub Check: notebooks_integration
🔇 Additional comments (16)
tests/test_standalone_inputcheck.py (2)

21-22: LGTM!

The imports for the new validation functions are correctly added.


125-131: LGTM!

The test correctly validates that check_log_obj_size raises a ValueError when log_obj_size=True, which matches the expected behavior of the validation function.

executorlib/task_scheduler/file/queue_spawner.py (1)

84-103: LGTM!

The terminate_with_pysqa function correctly implements job termination for queuing systems. The function signature and implementation align well with the shutdown handling logic in shared.py and the conditional assignment in the executor classes.

executorlib/task_scheduler/file/shared.py (1)

90-102: LGTM!

The conditional shutdown handling logic correctly distinguishes between different termination function signatures. The identity check for terminate_subprocess and the different parameter passing patterns align well with the respective function signatures.

executorlib/executor/slurm.py (5)

6-9: LGTM!

The import additions for the new validation functions are correctly placed.


101-102: LGTM!

The parameter additions to the constructor signature are correctly implemented with appropriate defaults.


161-161: LGTM!

The validation call for log_obj_size is correctly placed and follows the established pattern.


169-177: LGTM!

The conditional import and assignment of the termination function is well-implemented. The logic correctly imports terminate_with_pysqa only when needed and assigns the appropriate termination function based on the parameter value.


360-362: LGTM!

The validation call for terminate_tasks_on_shutdown is correctly implemented and follows the established validation pattern.

executorlib/executor/flux.py (7)

7-7: New imports look good.

The imports for check_log_obj_size and check_terminate_tasks_on_shutdown are properly added and align with the new functionality being introduced.

Also applies to: 12-12


67-67: Parameter addition is consistent.

The terminate_tasks_on_shutdown parameter is properly added to both the class docstring and constructor signature with the correct default value of True.

Also applies to: 108-108


170-172: Input validation is properly implemented.

The validation call for terminate_tasks_on_shutdown is correctly placed and follows the established pattern for other parameter validations in the constructor.


154-154: Documentation updates are consistent.

The parameter documentation is properly updated in both class docstrings and constructor docstrings to reflect the new terminate_tasks_on_shutdown and log_obj_size parameters.

Also applies to: 257-258, 295-296, 338-339


355-355: Input validation for log_obj_size is properly placed.

The validation call ensures that log_obj_size is False for FluxClusterExecutor, which aligns with the validation function's purpose.


363-370: Conditional termination function assignment logic is correct.

The logic properly imports and assigns the terminate_with_pysqa function when terminate_tasks_on_shutdown is True, and sets it to None otherwise. The import is correctly placed within the conditional block to avoid unnecessary imports.


388-388: Termination function parameter is correctly passed.

The terminate_function parameter is properly passed to create_file_executor, enabling the task scheduler to handle termination as intended.

plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
log_obj_size: bool = False,
terminate_tasks_on_shutdown: bool = True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Ensure parameter consistency between executor classes.

The terminate_tasks_on_shutdown parameter is added to SlurmJobExecutor constructor but unlike SlurmClusterExecutor, it's not actually used in the implementation logic. The parameter is validated but not propagated to the underlying executor creation.

Consider either:

  1. Removing the parameter from SlurmJobExecutor if termination control is not supported
  2. Implementing the termination logic similar to SlurmClusterExecutor
  3. Documenting why the parameter exists but isn't used

Let me check if this parameter should be used in the create_slurm_executor function:


🏁 Script executed:

#!/bin/bash
# Description: Check if create_slurm_executor supports termination function parameter

# Search for terminate_function parameter in create_slurm_executor
ast-grep --pattern 'def create_slurm_executor($$$) {
  $$$
}'

Length of output: 63


I’m diving deeper into the Slurm executor definitions to verify how (or if) the terminate_tasks_on_shutdown flag is handled. Running targeted searches now:


🏁 Script executed:

#!/bin/bash
# 1. Show SlurmJobExecutor definition and its constructor
rg -n "class SlurmJobExecutor" -n executorlib/executor/slurm.py -C10

# 2. Show SlurmClusterExecutor definition and its constructor
rg -n "class SlurmClusterExecutor" -n executorlib/executor/slurm.py -C10

# 3. Inspect create_slurm_executor signature
rg -n "^def create_slurm_executor" -n executorlib/executor/slurm.py -C5

# 4. Find all calls to create_slurm_executor in this file
rg -n "create_slurm_executor" -n executorlib/executor/slurm.py -C5

Length of output: 5096


Gathering all references to the shutdown flag and both constructor signatures:


🏁 Script executed:

#!/bin/bash
# 1. Find all occurrences of the shutdown flag
rg -n "terminate_tasks_on_shutdown" -n executorlib/executor/slurm.py -C3

# 2. Show both __init__ methods with surrounding context
rg -n "def __init__" -n executorlib/executor/slurm.py -C5

Length of output: 4418


Parameter terminate_tasks_on_shutdown isn’t hooked up in SlurmJobExecutor

In executorlib/executor/slurm.py, SlurmJobExecutor.__init__ declares and validates
terminate_tasks_on_shutdown (line 298 and 360–362) but never applies it—unlike
SlurmClusterExecutor, which conditionally imports terminate_with_pysqa when that flag is true.

• File: executorlib/executor/slurm.py
– SlurmJobExecutor signature (≈line 298):
python … log_obj_size: bool = False, terminate_tasks_on_shutdown: bool = True, ):
– Only check_terminate_tasks_on_shutdown(...) is called; there’s no
if terminate_tasks_on_shutdown: import terminate_with_pysqa or equivalent.

• In contrast, SlurmClusterExecutor (≈lines 99–104 & 166–170) does:
python if terminate_tasks_on_shutdown: from executorlib.task_scheduler.file.queue_spawner import terminate_with_pysqa

Suggested corrective actions:

  1. Remove terminate_tasks_on_shutdown from SlurmJobExecutor if shutdown control isn’t supported.
  2. Mirror cluster behavior by importing/attaching terminate_with_pysqa (or other shutdown hooks) when the flag is true.
  3. Document that the flag is intentionally a no-op in SlurmJobExecutor.
🤖 Prompt for AI Agents
In executorlib/executor/slurm.py at line 298, the parameter
terminate_tasks_on_shutdown is declared in SlurmJobExecutor but not used. To fix
this, either remove terminate_tasks_on_shutdown from SlurmJobExecutor's __init__
if shutdown task termination is not supported, or implement similar logic as in
SlurmClusterExecutor by conditionally importing terminate_with_pysqa and
applying it when terminate_tasks_on_shutdown is true. Additionally, update the
documentation to clarify whether this flag is supported or intentionally a no-op
in SlurmJobExecutor.

# Conflicts:
#	executorlib/executor/flux.py
#	executorlib/executor/slurm.py
#	executorlib/standalone/inputcheck.py
#	tests/test_standalone_inputcheck.py
@jan-janssen jan-janssen marked this pull request as draft July 12, 2025 14:08
@jan-janssen jan-janssen changed the title Remove default terminate function Upgrade terminate function Jul 12, 2025
@jan-janssen jan-janssen marked this pull request as ready for review July 13, 2025 07:59
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/test_fluxclusterexecutor.py (1)

40-40: Parameter addition looks good, but consider enhancing test coverage.

The addition of terminate_tasks_on_shutdown=False is correctly implemented. However, this test doesn't verify that tasks are actually preserved during shutdown when this parameter is False.

Consider adding assertions to verify the actual termination behavior:

# After executor context exit, verify tasks weren't terminated
# (implementation would depend on how termination status can be checked)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 084f500 and 3a81038.

📒 Files selected for processing (5)
  • executorlib/executor/flux.py (10 hunks)
  • executorlib/executor/slurm.py (10 hunks)
  • executorlib/task_scheduler/file/queue_spawner.py (2 hunks)
  • executorlib/task_scheduler/file/shared.py (2 hunks)
  • tests/test_fluxclusterexecutor.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • executorlib/task_scheduler/file/shared.py
  • executorlib/executor/slurm.py
  • executorlib/task_scheduler/file/queue_spawner.py
  • executorlib/executor/flux.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (16)
  • GitHub Check: benchmark (ubuntu-latest, 3.13, .ci_support/environment-openmpi.yml)
  • GitHub Check: benchmark (ubuntu-latest, 3.13, .ci_support/environment-mpich.yml)
  • GitHub Check: unittest_flux_openmpi
  • GitHub Check: unittest_win
  • GitHub Check: unittest_flux_mpich
  • GitHub Check: unittest_mpich (ubuntu-latest, 3.11)
  • GitHub Check: notebooks_integration
  • GitHub Check: unittest_openmpi (macos-latest, 3.13)
  • GitHub Check: unittest_mpich (ubuntu-latest, 3.12)
  • GitHub Check: unittest_old
  • GitHub Check: unittest_openmpi (ubuntu-latest, 3.11)
  • GitHub Check: unittest_openmpi (ubuntu-latest, 3.13)
  • GitHub Check: notebooks
  • GitHub Check: unittest_openmpi (ubuntu-latest, 3.12)
  • GitHub Check: unittest_mpich (ubuntu-latest, 3.13)
  • GitHub Check: unittest_mpich (macos-latest, 3.13)
🔇 Additional comments (2)
tests/test_fluxclusterexecutor.py (2)

54-54: Parameter addition is correct.

The addition of terminate_tasks_on_shutdown=True properly tests the alternate value for this parameter.


64-68: Ignore inconsistent parameter usage comment.

No tests in tests/test_fluxclusterexecutor.py use the terminate_tasks_on_shutdown argument—none of the three with FluxClusterExecutor(...) blocks include it. The original observation about “other two test methods” was incorrect. You can disregard this review comment.

Likely an incorrect or invalid review comment.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1740dfc and 0b3472a.

📒 Files selected for processing (4)
  • executorlib/executor/flux.py (9 hunks)
  • executorlib/executor/slurm.py (9 hunks)
  • executorlib/task_scheduler/file/queue_spawner.py (1 hunks)
  • executorlib/task_scheduler/file/task_scheduler.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • executorlib/task_scheduler/file/queue_spawner.py
  • executorlib/executor/slurm.py
  • executorlib/executor/flux.py
🧰 Additional context used
🧬 Code Graph Analysis (1)
executorlib/task_scheduler/file/task_scheduler.py (2)
executorlib/task_scheduler/file/subprocess_spawner.py (1)
  • terminate_subprocess (55-64)
executorlib/task_scheduler/file/queue_spawner.py (2)
  • execute_with_pysqa (11-81)
  • terminate_with_pysqa (84-104)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (17)
  • GitHub Check: notebooks_integration
  • GitHub Check: notebooks
  • GitHub Check: benchmark (ubuntu-latest, 3.13, .ci_support/environment-openmpi.yml)
  • GitHub Check: benchmark (ubuntu-latest, 3.13, .ci_support/environment-mpich.yml)
  • GitHub Check: minimal
  • GitHub Check: unittest_mpich (ubuntu-latest, 3.12)
  • GitHub Check: unittest_openmpi (macos-latest, 3.13)
  • GitHub Check: unittest_old
  • GitHub Check: unittest_mpich (ubuntu-latest, 3.13)
  • GitHub Check: unittest_openmpi (ubuntu-latest, 3.11)
  • GitHub Check: unittest_mpich (ubuntu-latest, 3.11)
  • GitHub Check: unittest_openmpi (ubuntu-latest, 3.12)
  • GitHub Check: unittest_openmpi (ubuntu-latest, 3.13)
  • GitHub Check: unittest_mpich (macos-latest, 3.13)
  • GitHub Check: unittest_win
  • GitHub Check: unittest_flux_mpich
  • GitHub Check: unittest_flux_openmpi
🔇 Additional comments (4)
executorlib/task_scheduler/file/task_scheduler.py (4)

16-16: LGTM: Import addition is consistent with the new functionality.

The import of terminate_subprocess aligns with the conditional logic that uses this function for subprocess termination.


20-23: LGTM: Updated import structure supports the new termination functionality.

The import changes properly include terminate_with_pysqa alongside the existing execute_with_pysqa import, maintaining consistency in the module structure.


27-27: LGTM: Appropriate fallback handling for missing dependency.

Setting terminate_with_pysqa = None when pysqa is not available is consistent with the existing pattern and properly handled in the conditional logic below.


116-121: No changes needed: pysqa fallback already handled safely

The import block in task_scheduler.py falls back by setting

execute_with_pysqa = execute_in_subprocess  
terminate_with_pysqa = None

when pysqa isn’t available. As a result, the default execute_function becomes execute_in_subprocess, and the second branch

elif terminate_tasks_on_shutdown and execute_function == execute_in_subprocess:
    terminate_function = terminate_subprocess

always applies—there is no case where terminate_with_pysqa (and thus terminate_function) is unexpectedly None while execute_function != execute_in_subprocess. No additional None check is required.

disable_dependencies: bool = False,
execute_function: Callable = execute_with_pysqa,
terminate_function: Optional[Callable] = None,
terminate_tasks_on_shutdown: bool = True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Add parameter validation to ensure type safety.

The new terminate_tasks_on_shutdown parameter should be validated to ensure it's a boolean type, similar to other parameter validations in this function.

According to the AI summary, there should be a check_terminate_tasks_on_shutdown validation function. Add the validation call:

 check_flux_log_files(flux_log_files=flux_log_files)
+check_terminate_tasks_on_shutdown(terminate_tasks_on_shutdown=terminate_tasks_on_shutdown)

Let me verify if the validation function exists:


🏁 Script executed:

#!/bin/bash
# Search for the validation function mentioned in the AI summary
rg -A 5 "check_terminate_tasks_on_shutdown"

Length of output: 2496


🏁 Script executed:

#!/bin/bash
# List all validation calls in the FileTaskScheduler initializer
rg -n "executorlib/task_scheduler/file/task_scheduler.py" -A 5 "check_"

Length of output: 116


🏁 Script executed:

#!/bin/bash
# Verify the FileTaskScheduler initializer and existing validation calls
echo "---- FileTaskScheduler class and __init__ ----"
rg -n "class FileTaskScheduler" -A 20 executorlib/task_scheduler/file/task_scheduler.py

echo
echo "---- Existing check_ calls in the file ----"
rg -n "check_" executorlib/task_scheduler/file/task_scheduler.py || echo "No check_ calls found in task_scheduler.py"

Length of output: 2219


🏁 Script executed:

#!/bin/bash
# Show import statements for validation functions in FileTaskScheduler
sed -n '1,15p' executorlib/task_scheduler/file/task_scheduler.py

Length of output: 579


Ensure terminate_tasks_on_shutdown is validated

The new terminate_tasks_on_shutdown: bool = True parameter isn’t currently being checked in FileTaskScheduler. You should:

• Import the validator

 from executorlib.standalone.inputcheck import (
     check_executor,
     check_flux_executor_pmi_mode,
     check_flux_log_files,
     check_hostname_localhost,
     check_max_workers_and_cores,
     check_nested_flux_executor,
+    check_terminate_tasks_on_shutdown,
 )

• Add the validation call in __init__, e.g. after the existing checks:

     check_flux_log_files(flux_log_files=flux_log_files)
+    check_terminate_tasks_on_shutdown(
+        terminate_tasks_on_shutdown=terminate_tasks_on_shutdown
+    )

This matches the pattern of other parameter validations and ensures type safety.

📝 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.

Suggested change
terminate_tasks_on_shutdown: bool = True,
# In executorlib/task_scheduler/file/task_scheduler.py
from executorlib.standalone.inputcheck import (
check_executor,
check_flux_executor_pmi_mode,
check_flux_log_files,
check_hostname_localhost,
check_max_workers_and_cores,
check_nested_flux_executor,
check_terminate_tasks_on_shutdown,
)
# … other code …
class FileTaskScheduler:
def __init__(
self,
executor,
flux_executor_pmi_mode,
flux_log_files,
hostname_localhost,
max_workers,
nested_flux_executor,
terminate_tasks_on_shutdown: bool = True,
):
check_executor(executor=executor)
check_flux_executor_pmi_mode(flux_executor_pmi_mode=flux_executor_pmi_mode)
check_flux_log_files(flux_log_files=flux_log_files)
check_terminate_tasks_on_shutdown(
terminate_tasks_on_shutdown=terminate_tasks_on_shutdown
)
# … rest of initialization …
🤖 Prompt for AI Agents
In executorlib/task_scheduler/file/task_scheduler.py at line 98, the new
parameter terminate_tasks_on_shutdown is added but not validated. To fix this,
import the validator function used for parameter checks and add a validation
call for terminate_tasks_on_shutdown in the __init__ method of
FileTaskScheduler, following the pattern of existing parameter validations to
ensure type safety.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
executorlib/task_scheduler/file/task_scheduler.py (1)

98-98: Add parameter validation to ensure type safety.

The new terminate_tasks_on_shutdown parameter should be validated to ensure it's a boolean type, similar to other parameter validations in this function.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0b3472a and 2c92b76.

📒 Files selected for processing (1)
  • executorlib/task_scheduler/file/task_scheduler.py (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
executorlib/task_scheduler/file/task_scheduler.py (2)
executorlib/task_scheduler/file/subprocess_spawner.py (1)
  • terminate_subprocess (55-64)
executorlib/task_scheduler/file/queue_spawner.py (2)
  • execute_with_pysqa (11-81)
  • terminate_with_pysqa (84-104)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (17)
  • GitHub Check: notebooks_integration
  • GitHub Check: notebooks
  • GitHub Check: minimal
  • GitHub Check: unittest_old
  • GitHub Check: unittest_win
  • GitHub Check: unittest_openmpi (ubuntu-latest, 3.11)
  • GitHub Check: unittest_flux_openmpi
  • GitHub Check: unittest_mpich (ubuntu-latest, 3.12)
  • GitHub Check: unittest_flux_mpich
  • GitHub Check: benchmark (ubuntu-latest, 3.13, .ci_support/environment-openmpi.yml)
  • GitHub Check: unittest_openmpi (ubuntu-latest, 3.13)
  • GitHub Check: benchmark (ubuntu-latest, 3.13, .ci_support/environment-mpich.yml)
  • GitHub Check: unittest_openmpi (macos-latest, 3.13)
  • GitHub Check: unittest_openmpi (ubuntu-latest, 3.12)
  • GitHub Check: unittest_mpich (ubuntu-latest, 3.13)
  • GitHub Check: unittest_mpich (ubuntu-latest, 3.11)
  • GitHub Check: unittest_mpich (macos-latest, 3.13)
🔇 Additional comments (3)
executorlib/task_scheduler/file/task_scheduler.py (3)

16-16: LGTM: Import addition looks correct.

Adding terminate_subprocess to the import aligns with the new termination logic requirements.


20-23: LGTM: Import expansion is well-structured.

The import is properly expanded to include terminate_with_pysqa alongside the existing execute_with_pysqa.


27-27: LGTM: Proper fallback handling for missing dependency.

Setting terminate_with_pysqa = None in the ImportError block is appropriate when pysqa is not available.

Comment on lines 116 to 121
if terminate_tasks_on_shutdown and execute_function != execute_in_subprocess:
terminate_function = terminate_with_pysqa
elif terminate_tasks_on_shutdown and execute_function == execute_in_subprocess:
terminate_function = terminate_subprocess
else:
terminate_function = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix potential None assignment and improve logic robustness.

The conditional logic has a critical issue: when terminate_tasks_on_shutdown is True and execute_function != execute_in_subprocess, it assigns terminate_with_pysqa to terminate_function, but terminate_with_pysqa could be None if pysqa is not available (line 27).

Apply this diff to handle the None case safely:

-    if terminate_tasks_on_shutdown and execute_function != execute_in_subprocess:
-        terminate_function = terminate_with_pysqa
+    if terminate_tasks_on_shutdown and execute_function != execute_in_subprocess:
+        if terminate_with_pysqa is not None:
+            terminate_function = terminate_with_pysqa
+        else:
+            terminate_function = None
     elif terminate_tasks_on_shutdown and execute_function == execute_in_subprocess:
         terminate_function = terminate_subprocess
     else:
         terminate_function = None

Alternatively, consider raising an informative error when termination is requested but not available:

-    if terminate_tasks_on_shutdown and execute_function != execute_in_subprocess:
-        terminate_function = terminate_with_pysqa
+    if terminate_tasks_on_shutdown and execute_function != execute_in_subprocess:
+        if terminate_with_pysqa is None:
+            raise ImportError("pysqa is required for task termination but is not available")
+        terminate_function = terminate_with_pysqa
📝 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.

Suggested change
if terminate_tasks_on_shutdown and execute_function != execute_in_subprocess:
terminate_function = terminate_with_pysqa
elif terminate_tasks_on_shutdown and execute_function == execute_in_subprocess:
terminate_function = terminate_subprocess
else:
terminate_function = None
if terminate_tasks_on_shutdown and execute_function != execute_in_subprocess:
if terminate_with_pysqa is not None:
terminate_function = terminate_with_pysqa
else:
terminate_function = None
elif terminate_tasks_on_shutdown and execute_function == execute_in_subprocess:
terminate_function = terminate_subprocess
else:
terminate_function = None
🤖 Prompt for AI Agents
In executorlib/task_scheduler/file/task_scheduler.py around lines 116 to 121,
the current logic assigns terminate_with_pysqa to terminate_function without
checking if terminate_with_pysqa is None, which can cause issues if pysqa is
unavailable. To fix this, add a check to ensure terminate_with_pysqa is not None
before assignment; if it is None, either set terminate_function to None safely
or raise an informative error indicating termination is requested but not
supported. This will make the logic more robust and prevent runtime errors.

@jan-janssen jan-janssen merged commit 595a1a1 into main Jul 13, 2025
130 of 145 checks passed
@jan-janssen jan-janssen deleted the terminate_function branch July 13, 2025 09:00
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.

2 participants