mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-21 18:12:02 +00:00
修正审批恢复的运行耗时:停在审批上之后的收尾不再同时算进执行和等待
- 每一段的执行时长以前一直计到收尾结束,等待时长又从 run.interrupted 算起。停在审批上之后 写审批记录、发事件这一截被两边都算,执行 + 等待比墙钟还长:平时只差几毫秒,机器一忙就差出几十毫秒 (全量并行测试里约每 20 遍失败一次的那条就是它) - 现在这一段的执行算到引擎发出中断的那一刻为止(LangGraph 这一轮的节点都跑完了才发出中断), 之后的收尾不算执行;执行、等待、墙钟由构造保证对得上账,不再靠容差 - 新测试把中断后的收尾人为拖慢 0.4 秒,稳定复现以前的重复计算;全量测试并行连跑 26 遍全过
This commit is contained in:
@@ -591,6 +591,10 @@ class RunManager:
|
||||
error_node: str | None = None
|
||||
|
||||
deadline: asyncio.Timeout | None = None
|
||||
# 停在审批上的那一刻:这一段的执行算到这里为止。后面写审批记录、发 run.interrupted 是收尾,
|
||||
# 等待从 run.interrupted 算起——以前执行一直计到 finally,收尾那一截执行和等待两边都算,
|
||||
# active + wait 比墙钟还长(机器一忙就差出几十毫秒)
|
||||
paused: float | None = None
|
||||
async with self._semaphore:
|
||||
try:
|
||||
async with SessionLocal() as session:
|
||||
@@ -655,8 +659,11 @@ class RunManager:
|
||||
if mode == "custom":
|
||||
await self._handle_custom(run_id, chunk)
|
||||
elif mode == "updates":
|
||||
# LangGraph 这一轮的节点都跑完了才发出中断:此刻引擎已经停下
|
||||
at = time.perf_counter()
|
||||
if await self._handle_updates(run_id, chunk):
|
||||
interrupted = True
|
||||
paused = at if paused is None else paused
|
||||
|
||||
snapshot = await app.aget_state(config)
|
||||
final_state = dict(snapshot.values or {})
|
||||
@@ -710,7 +717,8 @@ class RunManager:
|
||||
error_node = terminal[1].get("node_id")
|
||||
logger.exception("run %s 失败", run_id)
|
||||
finally:
|
||||
elapsed = int((time.perf_counter() - started) * 1000)
|
||||
stop = paused if status == "interrupted" and paused is not None else time.perf_counter()
|
||||
elapsed = int((stop - started) * 1000)
|
||||
self._finalizing.add(run_id)
|
||||
try:
|
||||
await self._finalize(run_id, status, error, final_state, elapsed,
|
||||
|
||||
Reference in New Issue
Block a user