Skip to content

Commit 9c756e7

Browse files
committed
fix: validate _get_max_threads() return value
Coerce to int and clamp to minimum of 1 to prevent: - Semaphore(0) deadlocks - Divide-by-zero in threads_per_command calculation - Issues from non-numeric config values https://claude.ai/code/session_01XGuw7AxoKRWHr9EZX1SDXi
1 parent 949a9bd commit 9c756e7

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/workflow/CommandExecutor.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,25 @@ def _get_max_threads(self) -> int:
3333
In online mode, uses the configured value directly from settings.
3434
3535
Returns:
36-
int: Maximum number of threads to use for parallel processing.
36+
int: Maximum number of threads to use for parallel processing (minimum 1).
3737
"""
3838
import streamlit as st
3939
settings = st.session_state.get("settings", {})
4040
max_threads_config = settings.get("max_threads", {"local": 4, "online": 2})
4141

4242
if settings.get("online_deployment", False):
43-
return max_threads_config.get("online", 2)
43+
value = max_threads_config.get("online", 2)
4444
else:
4545
default = max_threads_config.get("local", 4)
4646
params = self.parameter_manager.get_parameters_from_json()
47-
return params.get("max_threads", default)
47+
value = params.get("max_threads", default)
48+
49+
# Validate: coerce to int and clamp to minimum of 1
50+
try:
51+
value = int(value)
52+
except (TypeError, ValueError):
53+
value = 1
54+
return max(1, value)
4855

4956
def run_multiple_commands(
5057
self, commands: list[str]

0 commit comments

Comments
 (0)