From 5de46d514a0baf61f53597f1c2e6e296dd1f0684 Mon Sep 17 00:00:00 2001 From: sinohqb Date: Tue, 18 Aug 2026 17:22:30 +0800 Subject: [PATCH] fix(intelligent-eval): trigger worker/planner with isolated session MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit t480 排查:评估 cd636d71 一直'等待 OpenClaw 创建会话',scan loop 每 60s 触发 worker,但 worker 被触发后 0 次工具调用、直接幻觉输出'评估 pending_approval' (实际 executing),任务永不认领。 根因:openclaw agent --agent main 复用 main 持久 session,多次触发累积上下文 缓存(~12 万 token)后 LLM 不再执行 worker skill 的 API 步骤。 验证:独立 --session-id 触发 worker → 正常取任务、建会话、close。 修复:worker/planner 触发命令加 --session-id(每次唯一 agenteval-worker-*/planner-*), 避免 main session 污染;timeout 300→600(独立 session 首次加载 skill 更慢)。 测试:触发断言含 --session-id,901 passed --- backend/agenteval/web/app.py | 13 +++++++++++-- .../test_intelligent_eval_scan_scheduler.py | 6 ++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/backend/agenteval/web/app.py b/backend/agenteval/web/app.py index 2ec1c10..0d1e5d6 100644 --- a/backend/agenteval/web/app.py +++ b/backend/agenteval/web/app.py @@ -2,6 +2,7 @@ import asyncio import logging +import time from contextlib import asynccontextmanager from pathlib import Path @@ -213,13 +214,18 @@ async def _trigger_intelligent_worker() -> bool: "agent", "--agent", "main", + # 必须用独立 session:`--agent main` 复用 main 持久 session,多次触发 + # 累积上下文缓存(~12 万 token)后 LLM 不再执行 worker skill 的 API + # 步骤,直接幻觉输出(如"评估 pending_approval")而不取任务建会话。 + "--session-id", + f"agenteval-worker-{int(time.time())}", "-m", worker_msg, "--json", ], capture_output=True, text=True, - timeout=300, + timeout=600, ) _logger.info("Worker 触发完成 exit=%s", proc.returncode) if proc.returncode != 0: @@ -264,13 +270,16 @@ async def _trigger_intelligent_planner() -> bool: "agent", "--agent", "main", + # 同 worker:独立 session 避免 main 持久 session 上下文缓存污染 + "--session-id", + f"agenteval-planner-{int(time.time())}", "-m", planner_msg, "--json", ], capture_output=True, text=True, - timeout=300, + timeout=600, ) _logger.info("Planner 触发完成 exit=%s", proc.returncode) if proc.returncode != 0: diff --git a/tests/integration/test_intelligent_eval_scan_scheduler.py b/tests/integration/test_intelligent_eval_scan_scheduler.py index 84040bd..517e38b 100644 --- a/tests/integration/test_intelligent_eval_scan_scheduler.py +++ b/tests/integration/test_intelligent_eval_scan_scheduler.py @@ -79,6 +79,9 @@ def test_trigger_worker_calls_docker_exec(monkeypatch): assert "docker" in joined and "openclaw" in joined assert "agenteval-intelligent-worker" in joined assert "--agent" in joined and "main" in joined + # 独立 session:避免 main 持久 session 上下文缓存污染导致 worker 幻觉不执行 + assert "--session-id" in joined + assert "agenteval-worker-" in joined def test_trigger_worker_msg_has_execute_semantics(monkeypatch): @@ -154,6 +157,9 @@ def test_trigger_planner_calls_docker_exec(monkeypatch): joined = " ".join(calls[0]) assert "docker" in joined and "openclaw" in joined assert "agenteval-intelligent-planner" in joined + # 独立 session(同 worker 防上下文缓存污染) + assert "--session-id" in joined + assert "agenteval-planner-" in joined assert "立即完成当前任务" in joined assert "不要等待下一节拍" in joined