fix: add timeout to prompt step subprocess execution (#3768)

The prompt step subprocess.run() had no timeout, allowing a hung
LLM invocation to block the entire workflow engine indefinitely.
The shell step already defaults to 300s timeout.

Add timeout parameter (defaulting to 300s, matching shell step)
and handle subprocess.TimeoutExpired gracefully.
This commit is contained in:
Quratulain-bilal
2026-07-29 01:49:45 +05:00
committed by GitHub
parent 56b1839fba
commit a2b0d0d3c1

View File

@@ -89,8 +89,9 @@ class PromptStep(StepBase):
)
# Attempt CLI dispatch
timeout = config.get("timeout", 300)
dispatch_result = self._try_dispatch(
prompt, integration, model, context
prompt, integration, model, context, timeout=timeout
)
output: dict[str, Any] = {
@@ -136,6 +137,7 @@ class PromptStep(StepBase):
integration_key: str | None,
model: str | None,
context: StepContext,
timeout: int = 300,
) -> dict[str, Any] | None:
"""Dispatch *prompt* directly through the integration CLI."""
if not integration_key or not isinstance(integration_key, str) or not prompt:
@@ -178,6 +180,7 @@ class PromptStep(StepBase):
exec_args,
text=True,
cwd=str(project_root),
timeout=timeout,
)
return {
"exit_code": result.returncode,
@@ -190,6 +193,12 @@ class PromptStep(StepBase):
"stdout": "",
"stderr": "Interrupted by user",
}
except subprocess.TimeoutExpired:
return {
"exit_code": -1,
"stdout": "",
"stderr": f"Prompt timed out after {timeout} seconds.",
}
except OSError:
return None