feat(intelligent-eval): platform audit backfill for decision logs + disable legacy cron workers
Some checks failed
CI / test (push) Failing after 35s

- _supplement_decision_logs: executing evals missing a decision log get a
  platform-derived execute_session (deficit) or start_analysis (all sessions
  done) entry. Audit backfill only — records observable state, does not change
  agent execution. Called each scan tick after requeue+scan.
- t480 legacy cron workers (5) disabled: superseded by platform-triggered
  headless agent (plan C); they kept firing every minute and failing on
  Channel-required.
This commit is contained in:
sinohqb 2026-08-17 05:11:18 +08:00
parent 71c7cd3d39
commit 25920280f6
2 changed files with 97 additions and 0 deletions

View File

@ -42,6 +42,60 @@ def _has_pending_task() -> bool:
session.close() session.close()
def _supplement_decision_logs(session) -> int:
"""Platform audit backfill for decision logs.
方案③的决策日志由 OpenClaw agent 上报LLM 自主尽力而为异常路径
如卡死恢复后重试agent 可能跳过上报导致决策过程页面为空这里按评估
状态推导决策并补录欠账时补 execute_session所有会话完成后补
start_analysis只补"该类型缺失"不重复且只记录状态不改变 agent
的实际执行
Returns:
补录的决策日志条数
"""
from agenteval.intelligent_eval.decision_logs import create_decision_log
from agenteval.intelligent_eval.models import IntelligentEvalStatus
from agenteval.storage.db import IntelligentEvalDB, IntelligentEvalDecisionLogDB, IntelligentEvalSessionDB
from sqlmodel import select
evals = session.exec(
select(IntelligentEvalDB).where(IntelligentEvalDB.status == IntelligentEvalStatus.EXECUTING.value)
).all()
added = 0
for ev in evals:
plan = ev.get_plan() if ev.plan else {}
estimated = plan.get("estimated_sessions", 0)
sessions = session.exec(
select(IntelligentEvalSessionDB).where(IntelligentEvalSessionDB.eval_id == ev.id)
).all()
completed = sum(1 for s in sessions if s.status == "completed")
types = {
l.decision_type
for l in session.exec(
select(IntelligentEvalDecisionLogDB).where(
IntelligentEvalDecisionLogDB.eval_id == ev.id
)
).all()
}
if "execute_session" not in types and completed < estimated:
create_decision_log(
ev.id, "execute_session", "平台兜底:时段欠账需执行会话", "platform",
{"platform_supplemented": True, "completed": completed, "estimated": estimated},
session,
)
added += 1
elif "start_analysis" not in types and sessions and completed >= estimated:
create_decision_log(
ev.id, "start_analysis", "平台兜底:所有会话已完成开始分析", "platform",
{"platform_supplemented": True, "completed": completed, "estimated": estimated},
session,
)
added += 1
return added
async def _trigger_intelligent_worker() -> bool: async def _trigger_intelligent_worker() -> bool:
"""Trigger OpenClaw's headless agent to run the intelligent-eval worker skill. """Trigger OpenClaw's headless agent to run the intelligent-eval worker skill.
@ -111,6 +165,10 @@ async def _intelligent_eval_scan_loop() -> None:
n = scan_and_enqueue_tasks(session) n = scan_and_enqueue_tasks(session)
if n: if n:
_logger.info("智能评估扫描:入队 %d 个 Worker 任务", n) _logger.info("智能评估扫描:入队 %d 个 Worker 任务", n)
# 审计兜底agent 未上报决策日志时,平台按评估状态补录
added = _supplement_decision_logs(session)
if added:
_logger.info("决策日志兜底:补录 %d", added)
finally: finally:
session.close() session.close()
except Exception as exc: except Exception as exc:

View File

@ -108,3 +108,42 @@ def test_trigger_worker_msg_has_execute_semantics(monkeypatch):
assert "立即完成当前任务" in joined assert "立即完成当前任务" in joined
assert "agenteval-intelligent-worker" in joined assert "agenteval-intelligent-worker" in joined
assert "agenteval-intelligent-analyst" in joined assert "agenteval-intelligent-analyst" in joined
def test_supplement_execute_session_log(monkeypatch, db_session):
"""Executing eval with deficit and no execute_session log → platform backfills."""
from agenteval.intelligent_eval.models import IntelligentEvalStatus
from agenteval.storage.db import IntelligentEvalDB
import agenteval.web.app as app_mod
ev = IntelligentEvalDB(
name="supp-eval", target_id="t1",
status=IntelligentEvalStatus.EXECUTING.value, started_at=__import__("agenteval.storage.db", fromlist=["utc_now"]).utc_now(),
)
ev.set_plan({"time_distribution": [{"time_slot": "0-1h", "sessions": 1}], "estimated_sessions": 1})
db_session.add(ev)
db_session.commit()
assert app_mod._supplement_decision_logs(db_session) == 1
# second call: already backfilled → 0
assert app_mod._supplement_decision_logs(db_session) == 0
def test_supplement_start_analysis_log(monkeypatch, db_session):
"""Executing eval with all sessions completed and no start_analysis → backfill."""
from agenteval.intelligent_eval.models import IntelligentEvalStatus
from agenteval.storage.db import IntelligentEvalDB, IntelligentEvalSessionDB, utc_now
import agenteval.web.app as app_mod
ev = IntelligentEvalDB(
name="supp-eval2", target_id="t1",
status=IntelligentEvalStatus.EXECUTING.value, started_at=utc_now(),
)
ev.set_plan({"time_distribution": [{"time_slot": "0-1h", "sessions": 1}], "estimated_sessions": 1})
db_session.add(ev)
db_session.commit()
s = IntelligentEvalSessionDB(eval_id=ev.id, target_id=ev.target_id, status="completed", goal="g")
db_session.add(s)
db_session.commit()
assert app_mod._supplement_decision_logs(db_session) == 1