fix: give final acceptance a shared retry budget and diagnostics

This commit is contained in:
chenmingxuan committed 2026-10-18 20:51:19 +08:00
1 parent 50638d4130
commit 32441e79c4
18 files changed
+779 -40

No files matched your search

@@ -27,6 +27,12 @@ def request_diagnostics(
sql += " LIMIT ? OFFSET ?"
params += (limit, offset)
rows = conn.execute(sql, params).fetchall()
review_rows = conn.execute(
"SELECT payload FROM traces WHERE session_id = ? "
"AND type = 'final_review_diagnostic' ORDER BY timestamp DESC"
+ (" LIMIT ?" if limit is not None else ""),
(session_id, limit) if limit is not None else (session_id,),
).fetchall()
requests = []
seen = set()
running = bool(session and session["status"] in {"running", "resuming"})
@@ -65,12 +71,36 @@ def request_diagnostics(
if isinstance(value.get(field), (int, float))
}
requests.append(value)
final_reviews = []
for row in review_rows:
try:
value = json.loads(row["payload"])
except (ValueError, TypeError):
continue
if not isinstance(value, dict):
continue
value["active"] = (
running and offset == 0 and not final_reviews and value.get("status") == "running"
)
if value["active"] and isinstance(value.get("started_at"), (int, float)):
value["elapsed_seconds"] = round(max(0.0, time.time() - value["started_at"]), 3)
value["remaining_seconds"] = round(
max(0.0, value.get("total_seconds", 0.0) - value["elapsed_seconds"]), 3
)
value["budget_observed_at"] = time.time()
value["timestamps_utc"] = {
field: datetime.fromtimestamp(value[field], UTC).isoformat()
for field in ("started_at", "deadline_at", "ended_at")
if isinstance(value.get(field), (int, float))
}
final_reviews.append(value)
return {
"schema_version": 1,
"session_id": session_id,
"session_status": session["status"] if session else "unknown",
"collected_at": time.time(),
"requests": requests,
"final_reviews": final_reviews,
"total": total,
"offset": offset,
"next_offset": offset + limit if limit is not None and offset + limit < total else None,