Files
hermes-agent/tools/process_registry_wait.py
huanshan5195 e1ac37eba1 fix(agent): generic tool deadline no longer clips a tool's own timeout
Both runners bound one call at timeouts.tools.sequential_call /
.concurrent_batch, 420s by default. Several tools are handed a longer budget by
their own schema and config: `terminal` advertises a 600s foreground cap
(FOREGROUND_MAX_TIMEOUT) and honours TERMINAL_TIMEOUT, `process_manage
action=wait` blocks for its `timeout` clamped by that same setting.

So a foreground `terminal(timeout=600)` — explicitly allowed, and below the cap
that would have promoted it to a background process — died at 420s with
"Error executing tool 'terminal': timed out after 420.0s" and no output at all,
where the tool's own timeout would have returned the partial output it had
collected plus exit code 124. `process_manage action=wait` is worse: the
background process keeps running, so the model gets nothing back and re-issues
the identical call.

A tool can now declare what one call may legitimately block for
(ToolEntry.deadline_floor, a fn(args) -> seconds | None, resolved through
registry.get_deadline_floor). Both runners raise their generic deadline to the
longest floor any member of the batch declared, plus a small grace so the
tool's own timeout is the one that fires. A tool that declares nothing keeps
exactly the bound it has today, and a floor never introduces a deadline where
the generic one is disabled.

Same shape as the instances already tracked in #110035 (wait_for_human asks for
600s) and #109089 (a2a_call ignores a2a_agents.<peer>.timeout); this fixes the
two terminal-toolset ones and gives those a mechanism to declare through.

The TERMINAL_TIMEOUT clamp that ProcessRegistry.wait() applies now lives in
process_registry_wait.py next to process_manage's floor, so the two read one
rule and process_registry.py, already past the 2,000-line target, shrinks
instead of growing.
2026-11-15 11:49:27 -08:00

33 lines
1.1 KiB
Python

"""How long ``process_manage action=wait`` may block for one call.
Shared by :meth:`ProcessRegistry.wait`, which enforces the window, and by the tool's
``deadline_floor`` declaration, which lets the generic tool deadline clear that same window
instead of cutting the wait short (see ``ToolEntry.deadline_floor``).
"""
import os
def max_wait_timeout() -> int:
"""``TERMINAL_TIMEOUT``: the default wait, and the cap on a requested one."""
try:
return int(os.getenv("TERMINAL_TIMEOUT", "180"))
except (ValueError, TypeError):
return 180
def process_deadline_floor(args: dict) -> float | None:
"""Only ``wait`` blocks; it mirrors :meth:`ProcessRegistry.wait` — the requested window
clamped by ``TERMINAL_TIMEOUT``, or that default when none was requested."""
if args.get("action") != "wait":
return None
max_timeout = float(max_wait_timeout())
requested = args.get("timeout")
if requested is None:
return max_timeout
try:
requested = float(requested)
except (TypeError, ValueError):
return max_timeout
return min(requested, max_timeout) if requested > 0 else None