Agent web jobs now stop after Brain consolidation and enter needs_review with a persisted review queue (blocking: high-severity, low-confidence, sensitive-category findings; audit sample of clean clusters). Humans decide confirm/reject/unsure/needs_clarification via new review API and frontend queue; a finalizer applies decisions (rejections suppressed with reason codes), performs bounded targeted reruns for clarifications, drafts RFIs only for kept issues, and only then marks the job done and sends the final email. Two-phase email (review-required, then final report), per-decision feedback labels with redacted aggregate metrics, restart recovery from job artifacts, and CLI --no-review bypass. Classic pipeline unchanged. 65 non-LLM tests.
46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
"""Human-review decision schema and validation."""
|
|
|
|
from typing import Optional
|
|
|
|
DECISIONS = {"confirm", "reject", "unsure", "needs_clarification"}
|
|
REASON_CODES = {
|
|
"wrong_cluster_link",
|
|
"same_value_different_representation",
|
|
"not_a_contradiction",
|
|
"missing_evidence",
|
|
"extraction_misread",
|
|
"code_path_not_applicable",
|
|
"duplicate",
|
|
"severity_too_high",
|
|
"severity_too_low",
|
|
"other",
|
|
}
|
|
|
|
|
|
def validate_decision(raw: dict) -> Optional[dict]:
|
|
"""Normalize a reviewer decision payload, or return None if invalid."""
|
|
if not isinstance(raw, dict):
|
|
return None
|
|
decision = str(raw.get("decision") or "").strip()
|
|
if decision not in DECISIONS:
|
|
return None
|
|
reason_code = raw.get("reason_code")
|
|
if decision == "reject":
|
|
reason_code = str(reason_code or "").strip()
|
|
if reason_code not in REASON_CODES:
|
|
return None
|
|
elif reason_code is not None:
|
|
reason_code = str(reason_code).strip() or None
|
|
if reason_code and reason_code not in REASON_CODES:
|
|
return None
|
|
return {
|
|
"review_item_id": str(raw.get("review_item_id") or "").strip(),
|
|
"decision": decision,
|
|
"reason_code": reason_code,
|
|
"category_correction": raw.get("category_correction"),
|
|
"severity_correction": raw.get("severity_correction"),
|
|
"comment": str(raw.get("comment") or "").strip(),
|
|
"clarification_answer": raw.get("clarification_answer"),
|
|
"reviewed_at": raw.get("reviewed_at"),
|
|
}
|