fix(agent99): rotate outcome reconciliation cohorts

This commit is contained in:
ogt
2026-07-15 05:03:57 +08:00
parent ea677f0f1d
commit 096f61ed69
2 changed files with 67 additions and 1 deletions

View File

@@ -2215,14 +2215,37 @@ class PostgresAgent99DispatchLedger:
]),
)
# Prioritize observed delivery/outcome lanes; pending crash
# recovery candidates are polled after them.
# recovery candidates are polled after them. Heartbeat is
# also the durable poll cursor: each selected cohort is
# touched below so unresolved old runs cannot starve newer
# outcomes forever.
.order_by(
(AwoooPRunState.state == "pending").asc(),
AwoooPRunState.heartbeat_at.asc().nullsfirst(),
AwoooPRunState.created_at.asc(),
)
.limit(max(1, min(int(limit), 100)))
)
rows = result.all()
if rows:
await db.execute(
update(AwoooPRunState)
.where(
AwoooPRunState.project_id
== (project_id or "awoooi"),
AwoooPRunState.agent_id
== AGENT99_DISPATCH_AGENT_ID,
AwoooPRunState.run_id.in_([
row.run_id for row in rows
]),
AwoooPRunState.state.in_([
"pending",
"running",
"waiting_tool",
]),
)
.values(heartbeat_at=_utc_now_naive())
)
except Exception as exc:
logger.warning(
"agent99_dispatch_reconciliation_list_failed",