fix: M2 on_failure assignee 从 tasks 表读取 + infrastructure 防递归(司马懿 Review #65)
CI / lint (pull_request) Successful in 7s
CI / test (pull_request) Failing after 9s
CI / notify-on-failure (pull_request) Successful in 1s

M2: on_failure 中 assignee = meta.get('from', '') 读到 'system' 而非实际 Agent
→ 改为 SELECT must_haves, assignee FROM tasks 直接读 tasks.assignee 字段

附带:infrastructure failure 改为直接 DB INSERT,不走 _send_toolchain_task 防递归
This commit is contained in:
cfdaily
2026-06-13 23:47:12 +08:00
parent a5d5d2d974
commit 3bca794902
2 changed files with 62 additions and 34 deletions
+38 -22
View File
@@ -297,22 +297,24 @@ class ToolchainHandler(BaseTaskHandler):
logger.info("Toolchain %s: verify failed (%s), marked failed",
task_id, verify.reason)
# 读取 must_haves 获取事件上下文
# 读取 must_hives 获取事件上下文 + assignee 从 tasks 表读取
meta = {}
assignee = agent_id
try:
conn = get_connection(db_path)
row = conn.execute(
"SELECT must_haves FROM tasks WHERE id=?", (task_id,)
"SELECT must_haves, assignee FROM tasks WHERE id=?", (task_id,)
).fetchone()
if row and row["must_haves"]:
meta = json.loads(row["must_haves"])
if row:
if row["must_haves"]:
meta = json.loads(row["must_haves"])
assignee = row["assignee"] or agent_id
conn.close()
except Exception:
pass
action_type = meta.get("action_type", "")
context_data = meta.get("context", {})
assignee = meta.get("assignee", "") or meta.get("from", "")
# 三分路决策
route = self._classify_failure(verify)
@@ -403,29 +405,43 @@ class ToolchainHandler(BaseTaskHandler):
self, task_id: str, agent_id: str,
verify: VerifyResult, db_path: Path,
) -> None:
"""基础设施失败 → _send_toolchain_task @jiangwei-infra(防递归)"""
# 直接在 _toolchain DB 创建 task(不走 Gitea webhook)
"""基础设施失败 → 直接在 _toolchain DB 创建 task @jiangwei-infra防递归"""
try:
from src.api.toolchain_routes import _send_toolchain_task
_send_toolchain_task(
to_agent="jiangwei-infra",
title=f"[基础设施] Gitea API 不可用 - {task_id}",
description=(
f"Gitea API 不可用,原任务 {task_id} 无法通过正常路径处理。\n"
f"请检查 Gitea 服务状态和网络连通性。"
),
event_type="infrastructure_failure",
action_type="infrastructure_failure",
steps=[
from datetime import datetime
new_task_id = f"tc-{int(datetime.now().timestamp() * 1000)}"
must_hives = json.dumps({
"event_type": "infrastructure_failure",
"action_type": "infrastructure_failure",
"steps": [
"检查 Gitea 服务状态(http://192.168.2.154:3000)",
"检查网络连通性",
"恢复后提交 action report",
],
context_data={"original_task_id": task_id, "verify_reason": verify.reason},
source="toolchain_handler",
"context": {"original_task_id": task_id, "verify_reason": verify.reason},
"from": "system",
"source": "toolchain_handler_on_failure",
}, ensure_ascii=False)
conn = get_connection(db_path)
conn.execute(
"INSERT INTO tasks (id, title, description, assignee, assigned_by, "
"must_haves, task_type, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
(
new_task_id,
f"[基础设施] Gitea API 不可用 - {task_id}",
f"Gitea API 不可用,原任务 {task_id} 无法通过正常路径处理。\n"
f"请检查 Gitea 服务状态和网络连通性。",
"jiangwei-infra",
"system",
must_hives,
"toolchain",
"pending",
)
)
logger.info("Toolchain %s: infrastructure failure → task created for jiangwei-infra",
task_id)
conn.commit()
conn.close()
logger.info(
"Toolchain %s: infrastructure failure → task %s created for jiangwei-infra",
task_id, new_task_id)
except Exception as e:
logger.error(
"Toolchain %s: failed to create infrastructure_failure task: %s",