-
Notifications
You must be signed in to change notification settings - Fork 34
feat: add prefix to job uuid #330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -148,6 +148,14 @@ class ExecutorSettings(ExecutorSettingsBase): | |||||||||||||||||||||||||||||||||||||||
"required": False, | ||||||||||||||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||
prefix: str = field( | ||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the type should be |
||||||||||||||||||||||||||||||||||||||||
default="", | ||||||||||||||||||||||||||||||||||||||||
metadata={ | ||||||||||||||||||||||||||||||||||||||||
"help": "Prefix that is added to the job names", | ||||||||||||||||||||||||||||||||||||||||
"env_var": False, | ||||||||||||||||||||||||||||||||||||||||
"required": False | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||
Comment on lines
+151
to
+158
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add input validation for the prefix field. The prefix field lacks validation for SLURM-safe characters and length limits. Since this prefix will be used in job names and shell commands (e.g., Consider adding validation in the field definition or in the prefix: str = field(
default="",
metadata={
- "help": "Prefix that is added to the job names",
+ "help": "Prefix that is added to the job names. Must contain only alphanumeric characters, hyphens, and underscores. Maximum length recommended is 50 characters.",
"env_var": False,
"required": False
}
) Additionally, implement validation logic to ensure the prefix contains only SLURM-safe characters (alphanumeric, hyphens, underscores) and doesn't exceed reasonable length limits. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with the AI, here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cmeesters Thank you for confirming! You're absolutely right that input validation for the prefix field is important to prevent potential issues with SLURM job submission and status checking. Would you like me to implement the validation logic for the prefix field? I can add proper validation that:
This validation could be added either in the 🧠 Learnings used
|
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
# Required: | ||||||||||||||||||||||||||||||||||||||||
|
@@ -181,7 +189,7 @@ def __post_init__(self, test_mode: bool = False): | |||||||||||||||||||||||||||||||||||||||
# run check whether we are running in a SLURM job context | ||||||||||||||||||||||||||||||||||||||||
self.warn_on_jobcontext() | ||||||||||||||||||||||||||||||||||||||||
self.test_mode = test_mode | ||||||||||||||||||||||||||||||||||||||||
self.run_uuid = str(uuid.uuid4()) | ||||||||||||||||||||||||||||||||||||||||
self.run_uuid = self.workflow.executor_settings.prefix + str(uuid.uuid4()) | ||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainValidate prefix before concatenation to prevent command injection. The direct concatenation of prefix and UUID could introduce security and functionality issues if the prefix contains special characters that break shell commands or exceed SLURM naming constraints. The prefixed UUID is used in shell commands (line 467: Apply this diff to add basic validation: def __post_init__(self, test_mode: bool = False):
# run check whether we are running in a SLURM job context
self.warn_on_jobcontext()
self.test_mode = test_mode
+ # Validate prefix for SLURM-safe characters
+ if self.workflow.executor_settings.prefix:
+ import re
+ if not re.match(r'^[a-zA-Z0-9_-]*$', self.workflow.executor_settings.prefix):
+ raise WorkflowError(
+ f"Invalid prefix '{self.workflow.executor_settings.prefix}'. "
+ "Prefix must contain only alphanumeric characters, hyphens, and underscores."
+ )
+ if len(self.workflow.executor_settings.prefix) > 50:
+ raise WorkflowError(
+ f"Prefix '{self.workflow.executor_settings.prefix}' is too long. "
+ "Maximum length is 50 characters."
+ )
self.run_uuid = self.workflow.executor_settings.prefix + str(uuid.uuid4()) 🏁 Script executed: #!/bin/bash
# Check for potential issues with special characters in SLURM job names
# Test common problematic characters that could break shell commands
echo "Testing potential problematic characters in SLURM job names:"
echo "Characters that could cause issues: \$, \`, \", ', |, ;, &, >, <, (, ), {, }, [, ], *, ?, \\, space"
# Check SLURM documentation for job name constraints
echo "Checking SLURM job name constraints..."
scontrol show config | grep -i name || echo "Could not retrieve SLURM config"
# Test if there are any length limits
echo "Checking typical SLURM job name length limits..."
man sbatch | grep -A 5 -B 5 "job-name" || echo "Could not retrieve sbatch manual" Length of output: 948 🏁 Script executed: #!/bin/bash
set -e
echo "== Searching for ‘sacct’ usage =="
rg -n "sacct" .
echo -e "\n== Searching for ‘run_uuid’ usage =="
rg -n "run_uuid" . Length of output: 9846 🏁 Script executed: #!/bin/bash
set -e
echo "== Context around `--job-name` usage in submit_string.py =="
rg -n "--job-name" -A3 -B3 snakemake_executor_plugin_slurm/submit_string.py Length of output: 717 🏁 Script executed: #!/bin/bash
set -e
echo "== Searching for `executor_settings` definition =="
rg -n "class .*Settings" -g "snakemake_executor_plugin_slurm/*.py"
echo -e "\n== Searching for prefix usage in executor_settings =="
rg -n "prefix" -g "snakemake_executor_plugin_slurm/*.py"
echo -e "\n== Searching for where executor_settings.prefix is set =="
rg -n "prefix" -n "executor_settings" -g "snakemake_executor_plugin_slurm/*.py" Length of output: 1023 🏁 Script executed: #!/bin/bash
set -e
echo "== Searching for subprocess usage =="
rg -n "subprocess\." -n 5 snakemake_executor_plugin_slurm/__init__.py Length of output: 2623 🏁 Script executed: #!/bin/bash
set -e
echo "== First 200 lines of submit_string.py =="
sed -n '1,200p' snakemake_executor_plugin_slurm/submit_string.py Length of output: 2649 🏁 Script executed: #!/bin/bash
set -e
echo "== Displaying lines 350-430 of __init__.py for sbatch invocation context =="
sed -n '350,430p' snakemake_executor_plugin_slurm/__init__.py Length of output: 3396 Enforce SLURM-safe The Please add validation in def __post_init__(self, test_mode: bool = False):
# run check whether we are running in a SLURM job context
self.warn_on_jobcontext()
self.test_mode = test_mode
+ # Validate prefix: only allow alphanumeric, hyphens, underscores; cap length
+ prefix = self.workflow.executor_settings.prefix
+ if prefix:
+ import re
+ if not re.fullmatch(r'[A-Za-z0-9_-]+', prefix):
+ raise WorkflowError(
+ f"Invalid prefix '{prefix}'. "
+ "Allowed characters are letters, digits, hyphens, and underscores."
+ )
+ if len(prefix) > 50:
+ raise WorkflowError(
+ f"Prefix '{prefix}' is too long ({len(prefix)} > 50)."
+ )
self.run_uuid = prefix + str(uuid.uuid4())
This ensures 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is no separator - even if the default is "", we might want to see a separator. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also, there is no validation. |
||||||||||||||||||||||||||||||||||||||||
self.logger.info(f"SLURM run ID: {self.run_uuid}") | ||||||||||||||||||||||||||||||||||||||||
self._fallback_account_arg = None | ||||||||||||||||||||||||||||||||||||||||
self._fallback_partition = None | ||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"prefix" is a bit too generic. How about naming the purpose, e.g. "prefix_uuid"?