fix: finalize Flow v2 authoritative cutover semantics

This commit is contained in:
plx
2026-08-16 01:58:12 +00:00
parent 213ba6b41b
commit f96b1b3d6e
6 changed files with 73 additions and 8 deletions

View File

@@ -77,6 +77,12 @@ def _active_obligations(obligations: Iterable[Mapping[str, Any]]) -> list[Mappin
and not row.get("resolved_at") and not row.get("superseded_by_task_id")]
def _unanswered_inbound(row: Mapping[str, Any]) -> bool:
inbound = _dt(row.get("latest_public_inbound"))
outbound = _dt(row.get("latest_public_outbound"))
return bool(inbound and (outbound is None or outbound <= inbound))
def _ref(row: Mapping[str, Any]) -> dict[str, Any]:
return {"source": "task", "id": str(row.get("id") or ""), "status": "pending",
"action_code": _code(row.get("action_code")),
@@ -149,7 +155,11 @@ def decide_authoritative_operation(
picked = choose(("REVIEW_MANUALLY", "REVIEW_REQUIRED", "REVIEW", "REVIEW_RECONSTRUCTED_PROCESS"), "review", "ACTIVE_REVIEW_OBLIGATION")
picked = picked or choose(("SUPPORT",), "do_now", "ACTIVE_SUPPORT_OBLIGATION")
if state == "INQUIRY" or business_action == "SEND_INFO":
valid_send_info = [row for row in by_code.get("SEND_INFO", []) if (
state != "AWAITING_CUSTOMER" or _unanswered_inbound(row)
)]
if valid_send_info and (state in {"INQUIRY", "AWAITING_CUSTOMER"} or business_action == "SEND_INFO"):
by_code["SEND_INFO"] = valid_send_info
picked = picked or choose(("SEND_INFO",), "do_now", "ACTIVE_RESPONSE_OBLIGATION")
picked = picked or choose(("CALL_CUSTOMER",), "do_now", "EXPLICIT_CALL_OBLIGATION")
if picked: