Compare commits
No commits in common. "5a81c570c0bcd8246e6d3ea48715f574a911853c" and "84627a3c6afa83cb4269e1972b90d33c7df4d651" have entirely different histories.
5a81c570c0
...
84627a3c6a
@ -130,16 +130,47 @@ def list_decision_logs(eval_id: str, session: Session) -> list[dict]:
|
||||
return [_log_to_dict(log) for log in logs]
|
||||
|
||||
|
||||
def _supplement_executing(
|
||||
ev: IntelligentEvalDB,
|
||||
sessions: list,
|
||||
completed: int,
|
||||
estimated: int,
|
||||
types: set[str],
|
||||
session: Session,
|
||||
) -> int:
|
||||
"""Supplement decision logs for EXECUTING evals."""
|
||||
def supplement_decision_logs(session: Session) -> int:
|
||||
"""Platform audit backfill for decision logs.
|
||||
|
||||
方案③的决策日志由 OpenClaw agent 上报(LLM 自主,尽力而为)——异常路径
|
||||
(如卡死恢复后重试)agent 可能跳过上报,导致决策过程页面为空。这里按评估
|
||||
状态推导决策并补录:
|
||||
|
||||
- EXECUTING:欠账(completed < estimated)补 execute_session,所有会话
|
||||
完成后补 start_analysis。
|
||||
- COMPLETED:历史评估/异常路径可能完全没有决策日志,回填 execute_session
|
||||
(按 plan 时段逐条)+ start_analysis,让旧报告也有决策过程可看。
|
||||
|
||||
只补"该类型缺失"的,不重复;且只记录状态,不改变 agent 的实际执行。
|
||||
|
||||
Returns:
|
||||
补录的决策日志条数。
|
||||
"""
|
||||
evals = session.exec(
|
||||
select(IntelligentEvalDB).where(
|
||||
IntelligentEvalDB.status.in_(
|
||||
[
|
||||
IntelligentEvalStatus.EXECUTING.value,
|
||||
IntelligentEvalStatus.COMPLETED.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 = {
|
||||
x.decision_type
|
||||
for x in session.exec(
|
||||
select(IntelligentEvalDecisionLogDB).where(IntelligentEvalDecisionLogDB.eval_id == ev.id)
|
||||
).all()
|
||||
}
|
||||
if ev.status == IntelligentEvalStatus.EXECUTING.value:
|
||||
if "execute_session" not in types and completed < estimated:
|
||||
_append_row(
|
||||
ev.id,
|
||||
@ -160,20 +191,8 @@ def _supplement_executing(
|
||||
session,
|
||||
)
|
||||
added += 1
|
||||
return added
|
||||
|
||||
|
||||
def _supplement_completed(
|
||||
ev: IntelligentEvalDB,
|
||||
sessions: list,
|
||||
completed: int,
|
||||
estimated: int,
|
||||
plan: dict,
|
||||
types: set[str],
|
||||
session: Session,
|
||||
) -> int:
|
||||
"""Supplement decision logs for COMPLETED evals (historical backfill)."""
|
||||
added = 0
|
||||
elif ev.status == IntelligentEvalStatus.COMPLETED.value:
|
||||
# 历史回填:completed 评估决策日志全缺失时,按时段补 execute_session
|
||||
if "execute_session" not in types:
|
||||
slots = plan.get("time_distribution") or []
|
||||
if slots:
|
||||
@ -214,54 +233,3 @@ def _supplement_completed(
|
||||
)
|
||||
added += 1
|
||||
return added
|
||||
|
||||
|
||||
def supplement_decision_logs(session: Session) -> int:
|
||||
"""Platform audit backfill for decision logs.
|
||||
|
||||
方案③的决策日志由 OpenClaw agent 上报(LLM 自主,尽力而为)——异常路径
|
||||
(如卡死恢复后重试)agent 可能跳过上报,导致决策过程页面为空。这里按评估
|
||||
状态推导决策并补录:
|
||||
|
||||
- EXECUTING:欠账(completed < estimated)补 execute_session,所有会话
|
||||
完成后补 start_analysis。
|
||||
- COMPLETED:历史评估/异常路径可能完全没有决策日志,回填 execute_session
|
||||
(按 plan 时段逐条)+ start_analysis,让旧报告也有决策过程可看。
|
||||
|
||||
只补"该类型缺失"的,不重复;且只记录状态,不改变 agent 的实际执行。
|
||||
|
||||
Returns:
|
||||
补录的决策日志条数。
|
||||
"""
|
||||
evals = session.exec(
|
||||
select(IntelligentEvalDB).where(
|
||||
IntelligentEvalDB.status.in_(
|
||||
[
|
||||
IntelligentEvalStatus.EXECUTING.value,
|
||||
IntelligentEvalStatus.COMPLETED.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 = {
|
||||
x.decision_type
|
||||
for x in session.exec(
|
||||
select(IntelligentEvalDecisionLogDB).where(IntelligentEvalDecisionLogDB.eval_id == ev.id)
|
||||
).all()
|
||||
}
|
||||
|
||||
if ev.status == IntelligentEvalStatus.EXECUTING.value:
|
||||
added += _supplement_executing(ev, sessions, completed, estimated, types, session)
|
||||
elif ev.status == IntelligentEvalStatus.COMPLETED.value:
|
||||
added += _supplement_completed(ev, sessions, completed, estimated, plan, types, session)
|
||||
|
||||
return added
|
||||
|
||||
@ -226,8 +226,8 @@ def submit_report(session: Session, eval_id: str, report: dict[str, Any]) -> Int
|
||||
(不完整证据),不再阻塞报告提交。
|
||||
"""
|
||||
repo = IntelligentEvalRepository(session)
|
||||
eval_sessions = IntelligentEvalSessionRepository(session).list_by_eval(eval_id)
|
||||
if any(s.status == IntelligentEvalSessionStatus.RUNNING for s in eval_sessions):
|
||||
sessions = IntelligentEvalSessionRepository(session).list_by_eval(eval_id)
|
||||
if any(s.status == IntelligentEvalSessionStatus.RUNNING for s in sessions):
|
||||
raise IntelligentEvalTransitionError("存在进行中的会话,不能提交报告")
|
||||
# ADR-0011:submit 边界把 scores 归一到 {overall, dimensions} 单一规范结构
|
||||
if report.get("scores"):
|
||||
@ -432,36 +432,29 @@ def expire_stale_running_sessions(session: Session) -> int:
|
||||
now = utc_now()
|
||||
# SQLite 读出为 naive datetime,阈值须同为 naive 才能在 Python 侧比较
|
||||
threshold = now.replace(tzinfo=None) - timedelta(minutes=SESSION_IDLE_EXPIRE_MINUTES)
|
||||
|
||||
# 单次查询获取所有 running 会话及其最后消息时间(避免 N+1 查询)
|
||||
stmt = (
|
||||
select(
|
||||
IntelligentEvalSessionDB,
|
||||
func.max(IntelligentEvalMessageDB.created_at).label("last_message_at"),
|
||||
)
|
||||
.outerjoin(
|
||||
IntelligentEvalMessageDB,
|
||||
IntelligentEvalMessageDB.session_id == IntelligentEvalSessionDB.id,
|
||||
)
|
||||
.where(IntelligentEvalSessionDB.status == "running")
|
||||
.group_by(IntelligentEvalSessionDB.id)
|
||||
)
|
||||
rows = session.exec(stmt).all()
|
||||
rows = session.exec(
|
||||
select(IntelligentEvalSessionDB).where(IntelligentEvalSessionDB.status == "running")
|
||||
).all()
|
||||
|
||||
expired = 0
|
||||
for session_row, last_message_at in rows:
|
||||
last_activity = last_message_at or session_row.created_at
|
||||
for row in rows:
|
||||
last_message_at = session.exec(
|
||||
select(func.max(IntelligentEvalMessageDB.created_at)).where(
|
||||
IntelligentEvalMessageDB.session_id == row.id
|
||||
)
|
||||
).one()
|
||||
last_activity = last_message_at or row.created_at
|
||||
if last_activity is None or last_activity >= threshold:
|
||||
continue
|
||||
session_row.status = IntelligentEvalSessionStatus.EXPIRED.value
|
||||
session_row.closed_at = now
|
||||
row.status = IntelligentEvalSessionStatus.EXPIRED.value
|
||||
row.closed_at = now
|
||||
expired += 1
|
||||
append_decision_log(
|
||||
session_row.eval_id,
|
||||
row.eval_id,
|
||||
"session_expired",
|
||||
f"平台兜底:会话 {SESSION_IDLE_EXPIRE_MINUTES} 分钟无新轮次,置为过期(不完整证据)",
|
||||
"platform",
|
||||
{"platform_supplemented": True, "session_id": session_row.id, "turn_count": session_row.turn_count},
|
||||
{"platform_supplemented": True, "session_id": row.id, "turn_count": row.turn_count},
|
||||
session,
|
||||
)
|
||||
|
||||
@ -681,16 +674,16 @@ def evals_needing_analyst_nudge(session: Session) -> list[str]:
|
||||
|
||||
needing: list[str] = []
|
||||
for row in executing:
|
||||
eval_sessions = session.exec(
|
||||
sessions = session.exec(
|
||||
select(IntelligentEvalSessionDB).where(IntelligentEvalSessionDB.eval_id == row.id)
|
||||
).all()
|
||||
if not eval_sessions or any(s.status not in _TERMINAL_SESSION_STATUSES for s in eval_sessions):
|
||||
if not sessions or any(s.status not in _TERMINAL_SESSION_STATUSES for s in sessions):
|
||||
continue
|
||||
# 冒烟教训:窗口未结束且会话数未达计划时,未来时段到期后还要建会话,
|
||||
# 此时催促 analyst 会让报告提前收敛(漏掉后续时段的证据)
|
||||
if _window_has_pending_future_slots(row, eval_sessions, now):
|
||||
if _window_has_pending_future_slots(row, sessions, now):
|
||||
continue
|
||||
closed_moments = [s.closed_at for s in eval_sessions if s.closed_at is not None]
|
||||
closed_moments = [s.closed_at for s in sessions if s.closed_at is not None]
|
||||
if not closed_moments:
|
||||
continue
|
||||
last_closed = max(closed_moments)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user