mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-22 18:01:58 +00:00
合入 W2-a 的复核修复(nr8/a:导入的 NOT NULL 补值与孤儿行、收尾 dispose、sslmode 换算、PostgreSQL 写入去 NUL、不分大小写搜索 contains_ci、json_eq 两库同语义、JSON 守卫、用户可见列表补决胜键、bubblewrap --clearenv、部署脚本与原子写的几处、README 连接数预算)
# Conflicts: # backend/app/api/schedules.py # backend/app/main.py
This commit is contained in:
@@ -519,7 +519,7 @@ async def _confirm_task(session: AsyncSession, run_id: str, node_id: str) -> str
|
||||
|
||||
return await session.scalar(select(Task.id).where(Task.run_id == run_id, Task.node_id == node_id,
|
||||
Task.kind == "action_confirm")
|
||||
.order_by(Task.created_at.desc()).limit(1))
|
||||
.order_by(Task.created_at.desc(), Task.id.desc()).limit(1))
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
@@ -251,7 +251,8 @@ async def _started_before(hook: AppHook, idem_key: str) -> str | None:
|
||||
|
||||
async with SessionLocal() as session:
|
||||
rows = (await session.execute(select(Run.id, Run.origin).where(
|
||||
Run.app_id == hook.app_id, Run.origin_kind == "hook").order_by(Run.created_at.desc()).limit(500))).all()
|
||||
Run.app_id == hook.app_id, Run.origin_kind == "hook")
|
||||
.order_by(Run.created_at.desc(), Run.id.desc()).limit(500))).all()
|
||||
for run_id, origin in rows:
|
||||
if isinstance(origin, dict) and origin.get("hook") == hook.name and origin.get("hook_key") == idem_key:
|
||||
return run_id
|
||||
@@ -267,12 +268,12 @@ async def _signal(hook: AppHook, request: HookRequest, header_key: str, *, recla
|
||||
async with SessionLocal() as session:
|
||||
task_id = await session.scalar(select(Task.id).where(
|
||||
Task.app_id == hook.app_id, Task.kind == "signal", Task.status == "pending",
|
||||
Task.correlation_key == key).order_by(Task.created_at).limit(1))
|
||||
Task.correlation_key == key).order_by(Task.created_at, Task.id).limit(1))
|
||||
if task_id is None and reclaimed:
|
||||
# 上一次处理到一半服务停了:在等的待办其实已经解决,交回它,不当成没人在等
|
||||
done = (await session.execute(select(Task.id, Task.run_id).where(
|
||||
Task.app_id == hook.app_id, Task.kind == "signal", Task.status != "pending",
|
||||
Task.correlation_key == key).order_by(Task.created_at.desc()).limit(1))).first()
|
||||
Task.correlation_key == key).order_by(Task.created_at.desc(), Task.id.desc()).limit(1))).first()
|
||||
if done is not None:
|
||||
return {"task_id": done[0], "run_id": done[1]}
|
||||
if task_id is None:
|
||||
@@ -409,7 +410,7 @@ async def recent_receipts(session: AsyncSession, app_id: str, name: str,
|
||||
.scalars())
|
||||
rows = list((await session.execute(
|
||||
select(HookReceipt).where(HookReceipt.hook_id.in_(ids or [""]), HookReceipt.status != "signature")
|
||||
.order_by(HookReceipt.received_at.desc()).limit(max(1, min(limit, RECEIPTS_MAX))))).scalars())
|
||||
.order_by(HookReceipt.received_at.desc(), HookReceipt.id.desc()).limit(max(1, min(limit, RECEIPTS_MAX))))).scalars())
|
||||
return {"items": [{"idem_key": r.idem_key, "status": r.status,
|
||||
"received_at": r.received_at.isoformat() if r.received_at else None,
|
||||
"run_id": r.run_id, "task_id": r.task_id, "detail": r.detail} for r in rows],
|
||||
|
||||
@@ -922,7 +922,7 @@ async def tick(now: datetime | None = None) -> list[str]:
|
||||
and_(Task.remind_at.is_not(None), Task.remind_at <= now),
|
||||
and_(Task.due_at.is_not(None), Task.due_at <= now, action == "reject"),
|
||||
and_(Task.due_at.is_not(None), Task.due_at <= now, action == "escalate", Task.escalation_level == 0),
|
||||
)).order_by(Task.due_at))).scalars())
|
||||
)).order_by(Task.due_at, Task.id))).scalars())
|
||||
done: list[str] = []
|
||||
for task_id in due:
|
||||
try:
|
||||
@@ -1104,7 +1104,8 @@ async def _assignments(session: AsyncSession, task_ids: list[str], *, fresh: boo
|
||||
) -> dict[str, list[TaskAssignment]]:
|
||||
if not task_ids:
|
||||
return {}
|
||||
stmt = select(TaskAssignment).where(TaskAssignment.task_id.in_(task_ids)).order_by(TaskAssignment.created_at)
|
||||
stmt = (select(TaskAssignment).where(TaskAssignment.task_id.in_(task_ids))
|
||||
.order_by(TaskAssignment.created_at, TaskAssignment.id))
|
||||
if fresh:
|
||||
stmt = stmt.execution_options(populate_existing=True)
|
||||
out: dict[str, list[TaskAssignment]] = {}
|
||||
@@ -1135,7 +1136,7 @@ def _mine(principal: Any) -> Any:
|
||||
async def list_tasks(principal: Any, *, assigned: str = "me", statuses: list[str] | None = None,
|
||||
app_id: str | None = None, run_id: str | None = None, limit: int = 100) -> list[dict[str, Any]]:
|
||||
async with SessionLocal() as session:
|
||||
stmt = select(Task).order_by(Task.created_at.desc()).limit(limit)
|
||||
stmt = select(Task).order_by(Task.created_at.desc(), Task.id.desc()).limit(limit)
|
||||
if statuses:
|
||||
stmt = stmt.where(Task.status.in_(statuses))
|
||||
if app_id:
|
||||
|
||||
Reference in New Issue
Block a user