This commit is contained in:
@@ -50,6 +50,9 @@ DIRECT_MAPPING_RETRY_CANDIDATE_DECISION_PACKAGE_POLICY = (
|
||||
DIRECT_MAPPING_RETRY_CANDIDATE_EXCEPTION_AUTO_RESOLUTION_POLICY = (
|
||||
"read_only_pchome_growth_direct_mapping_retry_candidate_exception_auto_resolution"
|
||||
)
|
||||
DIRECT_MAPPING_RETRY_CANDIDATE_EXCEPTION_RESOLUTION_CLOSEOUT_POLICY = (
|
||||
"read_only_pchome_growth_direct_mapping_retry_candidate_exception_resolution_closeout"
|
||||
)
|
||||
AI_AUTOMATION_READINESS_POLICY = "read_only_pchome_growth_ai_automation_readiness"
|
||||
EVIDENCE_ENRICHMENT_PREVIEW_POLICY = "read_only_pchome_growth_evidence_enrichment_preview"
|
||||
EVIDENCE_SOURCE_PREVIEW_POLICY = "read_only_pchome_growth_evidence_source_preview"
|
||||
@@ -2566,6 +2569,109 @@ def build_pchome_direct_mapping_retry_candidate_exception_auto_resolution_packag
|
||||
}
|
||||
|
||||
|
||||
def build_pchome_direct_mapping_retry_candidate_exception_resolution_closeout_package(
|
||||
payload: dict[str, Any],
|
||||
batch_size: int = 5,
|
||||
*,
|
||||
execute_search: bool = False,
|
||||
execute_retry_search: bool = False,
|
||||
limit_per_product: int = 8,
|
||||
max_terms_per_product: int = 5,
|
||||
min_score: float = 0.45,
|
||||
search_func: Any = None,
|
||||
) -> dict[str, Any]:
|
||||
"""Close out retry-candidate exception artifacts into machine-verifiable receipts."""
|
||||
auto_resolution = build_pchome_direct_mapping_retry_candidate_exception_auto_resolution_package(
|
||||
payload,
|
||||
batch_size=batch_size,
|
||||
execute_search=execute_search,
|
||||
execute_retry_search=execute_retry_search,
|
||||
limit_per_product=limit_per_product,
|
||||
max_terms_per_product=max_terms_per_product,
|
||||
min_score=min_score,
|
||||
search_func=search_func,
|
||||
)
|
||||
package = auto_resolution.get("retry_exception_auto_resolution_package") or {}
|
||||
artifacts = list(package.get("retry_exception_auto_resolution_artifacts") or [])
|
||||
closeout_receipts = _build_candidate_exception_resolution_closeout_receipts(
|
||||
artifacts,
|
||||
execute_retry_search=execute_retry_search,
|
||||
limit_per_product=limit_per_product,
|
||||
max_terms_per_product=max_terms_per_product,
|
||||
min_score=min_score,
|
||||
search_func=search_func,
|
||||
)
|
||||
closeout_summary = _summarize_exception_resolution_closeout_receipts(closeout_receipts)
|
||||
|
||||
selected_direct_count = int((auto_resolution.get("summary") or {}).get("selected_direct_mapping_count") or 0)
|
||||
artifact_count = int(
|
||||
(auto_resolution.get("summary") or {}).get("retry_exception_auto_resolution_artifact_count") or 0
|
||||
)
|
||||
if not selected_direct_count:
|
||||
result = "NO_DIRECT_MAPPING_TARGETS"
|
||||
elif closeout_receipts:
|
||||
result = "DIRECT_MAPPING_RETRY_CANDIDATE_EXCEPTION_RESOLUTION_CLOSEOUT_READY"
|
||||
elif artifact_count:
|
||||
result = "DIRECT_MAPPING_RETRY_CANDIDATE_EXCEPTION_AUTO_RESOLUTION_READY"
|
||||
else:
|
||||
result = "WAITING_FOR_RETRY_CANDIDATE_EXCEPTIONS"
|
||||
|
||||
return {
|
||||
"policy": DIRECT_MAPPING_RETRY_CANDIDATE_EXCEPTION_RESOLUTION_CLOSEOUT_POLICY,
|
||||
"result": result,
|
||||
"success": bool(auto_resolution.get("success")),
|
||||
"generated_at": auto_resolution.get("generated_at"),
|
||||
"source_policy": auto_resolution.get("policy"),
|
||||
"stats": auto_resolution.get("stats") or {},
|
||||
"backlog": auto_resolution.get("backlog") or {},
|
||||
"summary": {
|
||||
"direct_mapping_count": int((auto_resolution.get("summary") or {}).get("direct_mapping_count") or 0),
|
||||
"selected_direct_mapping_count": selected_direct_count,
|
||||
"upstream_retry_candidate_count": int(
|
||||
(auto_resolution.get("summary") or {}).get("retry_candidate_count") or 0
|
||||
),
|
||||
"retry_candidate_decision_count": int(
|
||||
(auto_resolution.get("summary") or {}).get("retry_candidate_decision_count") or 0
|
||||
),
|
||||
"retry_machine_review_exception_count": int(
|
||||
(auto_resolution.get("summary") or {}).get("retry_machine_review_exception_count") or 0
|
||||
),
|
||||
"retry_exception_auto_resolution_artifact_count": artifact_count,
|
||||
"retry_exception_resolution_closeout_receipt_count": len(closeout_receipts),
|
||||
**closeout_summary,
|
||||
"retry_exception_closeout_retry_candidate_count": closeout_summary.get("retry_candidate_count", 0),
|
||||
"writes_database_count": 0,
|
||||
"persists_candidate_count": 0,
|
||||
},
|
||||
"retry_exception_resolution_closeout_package": {
|
||||
"stage": "P2_retry_candidate_exception_resolution_closeout",
|
||||
"execute_search": bool(execute_search),
|
||||
"execute_retry_search": bool(execute_retry_search),
|
||||
"closeout_receipts": closeout_receipts,
|
||||
"resolution_mode": "ai_controlled_read_only",
|
||||
"manual_review_mode": "exception_only",
|
||||
},
|
||||
"upstream_retry_exception_auto_resolution_summary": auto_resolution.get("summary") or {},
|
||||
"next_actions": [
|
||||
"Route evidence-delta closeouts into no-write verifier input when identity delta is resolved.",
|
||||
"Feed retry-search candidates back into retry candidate decision package when candidate_count is nonzero.",
|
||||
"Keep database writes behind controlled apply, rollback, verifier, and production readback.",
|
||||
],
|
||||
"safety": {
|
||||
"read_only_preview": True,
|
||||
"executes_search": bool(execute_search),
|
||||
"executes_retry_search": bool(execute_retry_search),
|
||||
"writes_database": False,
|
||||
"persists_candidate": False,
|
||||
"syncs_external_offers": False,
|
||||
"dispatches_telegram": False,
|
||||
"llm_calls_in_preview": False,
|
||||
"gemini_allowed": False,
|
||||
"requires_production_version_truth": True,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def build_pchome_evidence_enrichment_preview(payload: dict[str, Any], batch_size: int = 5) -> dict[str, Any]:
|
||||
"""Build a read-only evidence enrichment package for mapping targets."""
|
||||
operator_preview = build_pchome_mapping_operator_preview(payload, batch_size=batch_size)
|
||||
|
||||
Reference in New Issue
Block a user