feat: 优化非阻塞 hook 超时处理,添加全局安全阀支持;为插件 Supervisor 添加自定义 IPC socket 后缀以避免冲突

This commit is contained in:
DrSmoothl
2026-03-13 00:20:03 +08:00
parent f3270d4d41
commit e445c483b0
2 changed files with 12 additions and 8 deletions

View File

@@ -345,7 +345,8 @@ class WorkflowExecutor:
) -> None:
"""Non-blocking hook 调用,只读,忽略结果。"""
timeout_ms = step.metadata.get("timeout_ms", 0)
timeout_sec = timeout_ms / 1000 if timeout_ms > 0 else None
# 使用 hook 声明的超时,但无声明时回退到全局安全阀,防止 task 泄漏
timeout_sec = timeout_ms / 1000 if timeout_ms > 0 else _get_blocking_timeout()
try:
coro = invoke_fn(step.plugin_id, step.name, {
@@ -354,10 +355,9 @@ class WorkflowExecutor:
"message": message,
"stage_outputs": ctx.stage_outputs,
})
if timeout_sec:
await asyncio.wait_for(coro, timeout=timeout_sec)
else:
await coro
await asyncio.wait_for(coro, timeout=timeout_sec)
except asyncio.TimeoutError:
logger.warning(f"[{ctx.trace_id}] non-blocking hook {step.full_name} 超时 ({timeout_sec}s)")
except Exception as e:
logger.debug(f"[{ctx.trace_id}] non-blocking hook {step.full_name}: {e}")

View File

@@ -82,20 +82,24 @@ class PluginRuntimeManager:
return
# 从配置读取自定义 IPC socket 路径(留空则自动生成)
socket_path = _cfg.ipc_socket_path or None
socket_path_base = _cfg.ipc_socket_path or None
# 当用户指定了自定义路径时,为两个 Supervisor 添加后缀以避免 UDS 冲突
builtin_socket = f"{socket_path_base}-builtin" if socket_path_base else None
thirdparty_socket = f"{socket_path_base}-thirdparty" if socket_path_base else None
# 创建两个 Supervisor各自拥有独立的 socket / Runner 子进程
if builtin_dirs:
self._builtin_supervisor = PluginSupervisor(
plugin_dirs=builtin_dirs,
socket_path=socket_path,
socket_path=builtin_socket,
)
self._register_capability_impls(self._builtin_supervisor)
if thirdparty_dirs:
self._thirdparty_supervisor = PluginSupervisor(
plugin_dirs=thirdparty_dirs,
socket_path=socket_path,
socket_path=thirdparty_socket,
)
self._register_capability_impls(self._thirdparty_supervisor)