fix: agent tools follow Settings Queue timeout

The hidden 600s agent_tool_timeout_sec never appeared in Settings, so tool calls still died after Queue timeout was set to wait forever.
This commit is contained in:
Benjiyaya
2026-09-27 04:23:57 +08:00
parent 18bedfc394
commit 4a74b4c8f9
11 changed files with 39 additions and 38 deletions
@@ -308,9 +308,9 @@ def register(registry: ToolRegistry) -> None:
executor=t_wait_for_jobs,
category="video",
requires_project=False,
# Owns its own wait contract (timeout_sec → queue_poll_timeout_sec):
# exempt from the per-tool wall-clock cap, which would otherwise
# cut a legitimate long render wait short.
# Owns its own wait (timeout_sec → queue_poll_timeout_sec, 0 = until
# done): exempt from the same Queue timeout wrapping every other
# tool, so a long render wait is not cut short by a second clock.
long_running=True,
)
)
@@ -48,9 +48,13 @@ EXPORT_VIDEO_DENIED_NAMES = frozenset({"export_video", "exportVideo"})
def _tool_timeout_sec() -> float:
"""Per-tool wall-clock cap from Settings; 0 = disabled."""
"""Wall-clock cap for one agent tool call: Settings → Queue → Timeout.
Same value as the ComfyUI job poll (``queue_poll_timeout_sec``). 0 waits
until the tool finishes.
"""
try:
t = float(settings.agent_tool_timeout_sec)
t = float(settings.queue_poll_timeout_sec)
except (TypeError, ValueError, AttributeError):
return 0.0
return max(0.0, t)
@@ -91,8 +95,9 @@ class ToolDefinition:
category: str = "general"
destructive: bool = False # flagged in descriptions; pre-execute guard uses it
requires_approval: bool = False # HITL: blocked unless the user explicitly asked
# True → exempt from the per-tool wall-clock timeout (agent_tool_timeout_sec);
# the tool owns its own wait contract (e.g. wait_for_jobs → queue_poll_timeout_sec).
# True → exempt from the Queue timeout wall clock;
# the tool owns its own wait contract (e.g. wait_for_jobs uses the same
# queue_poll_timeout_sec, including 0 = wait until done).
long_running: bool = False
@@ -281,8 +286,8 @@ class ToolRegistry:
try:
result = await self._execute_with_timeout(t, ctx, args)
except TimeoutError:
# Per-tool wall-clock cap (0 = disabled): a hung tool must stall
# its step, not the session. CancelledError passes through so the
# Per-tool wall clock is Settings → Queue → Timeout. 0 waits
# until the tool finishes. CancelledError passes through so the
# Stop button keeps working.
return {
"ok": False,
+5 -9
View File
@@ -118,17 +118,15 @@ class Settings(BaseSettings):
queue_concurrency: int = 1
queue_poll_interval_sec: float = 2.0
# How long the worker keeps polling ComfyUI /history before giving up.
# Long video workflows routinely exceed 10 minutes; 0 = poll until the job
# completes or is cancelled. Default 1800s (30 min).
# How long the worker keeps polling ComfyUI /history before giving up,
# and the wall-clock cap on one agent tool call. Long video workflows
# routinely exceed 10 minutes; 0 = wait until the job or tool finishes.
# Default 1800s (30 min). wait_for_jobs opts out of the tool cap and
# applies this same value itself.
queue_poll_timeout_sec: float = 1800.0
queue_max_retries: int = 2
agent_max_steps: int = 24
agent_hardening_prompt: str = DEFAULT_AGENT_HARDENING_PROMPT
# Wall-clock cap on ONE tool execution inside the agent loop. Guards
# against a hung tool stalling a session indefinitely; 0 = disabled.
# Long-by-contract tools (wait_for_jobs) opt out via long_running=True.
agent_tool_timeout_sec: float = 600.0
# Character budget (~4 chars/token) for the derived LLM history — the
# 40-turn cap alone can still overflow a context window with heavy
# multi-step turns. Oldest whole turns drop first; 0 = disabled.
@@ -329,7 +327,6 @@ class Settings(BaseSettings):
"queue_max_retries": self.queue_max_retries,
"agent_max_steps": self.agent_max_steps,
"agent_hardening_prompt": self.agent_hardening_prompt,
"agent_tool_timeout_sec": self.agent_tool_timeout_sec,
"agent_history_char_budget": self.agent_history_char_budget,
"h3_rewrite_extra_body": dict(self.h3_rewrite_extra_body or {}),
"dry_run": bool(self.dry_run),
@@ -414,7 +411,6 @@ class Settings(BaseSettings):
"queue_max_retries": self.queue_max_retries,
"agent_max_steps": self.agent_max_steps,
"agent_hardening_prompt": self.agent_hardening_prompt,
"agent_tool_timeout_sec": self.agent_tool_timeout_sec,
"agent_history_char_budget": self.agent_history_char_budget,
"h3_rewrite_extra_body": dict(self.h3_rewrite_extra_body or {}),
"dry_run": bool(self.dry_run),