|
|
@@ -44,12 +44,14 @@ def run(
|
|
|
discovered_content_items,
|
|
|
decision_by_target_id,
|
|
|
media_by_platform_content_id,
|
|
|
+ paths_by_content_id,
|
|
|
)
|
|
|
reject_records = _build_reject_records(
|
|
|
policy_run_id,
|
|
|
discovered_content_items,
|
|
|
decision_by_target_id,
|
|
|
media_by_platform_content_id,
|
|
|
+ paths_by_content_id,
|
|
|
)
|
|
|
author_assets, author_asset_rows, author_role_rows = _build_author_assets(
|
|
|
run_id,
|
|
|
@@ -101,9 +103,7 @@ def run(
|
|
|
"decision_reason_code": decision["decision_reason_code"],
|
|
|
"search_query_effect_status": decision["search_query_effect_status"],
|
|
|
"score": decision.get("score"),
|
|
|
- "scorecard": decision.get("scorecard", {}),
|
|
|
- "decision_replay_data": decision.get("decision_replay_data", {}),
|
|
|
- "source_evidence": decision["source_evidence"],
|
|
|
+ "source_evidence_ref": _source_evidence_ref(decision),
|
|
|
**_v4_explanation_field(decision),
|
|
|
}
|
|
|
for decision in decisions
|
|
|
@@ -181,10 +181,7 @@ def _build_content_assets(
|
|
|
"rule_pack_version": decision["rule_pack_version"],
|
|
|
"strategy_version": decision["strategy_version"],
|
|
|
"source_path_record_ids": path_ids,
|
|
|
- "source_evidence": {
|
|
|
- **decision["source_evidence"],
|
|
|
- "source_path_record_ids": path_ids,
|
|
|
- },
|
|
|
+ "source_evidence_ref": _source_evidence_ref(decision, path_ids),
|
|
|
"content_media_status": media_by_platform_content_id[
|
|
|
platform_content_id
|
|
|
]["content_media_status"],
|
|
|
@@ -225,10 +222,7 @@ def _build_review_records(
|
|
|
"strategy_version": decision["strategy_version"],
|
|
|
"decision_reason_code": decision["decision_reason_code"],
|
|
|
"source_path_record_ids": path_ids,
|
|
|
- "source_evidence": {
|
|
|
- **decision["source_evidence"],
|
|
|
- "source_path_record_ids": path_ids,
|
|
|
- },
|
|
|
+ "source_evidence_ref": _source_evidence_ref(decision, path_ids),
|
|
|
"content_media_status": media_by_platform_content_id[
|
|
|
platform_content_id
|
|
|
]["content_media_status"],
|
|
|
@@ -245,6 +239,7 @@ def _build_reject_records(
|
|
|
discovered_content_items: list[dict[str, Any]],
|
|
|
decision_by_target_id: dict[str, dict[str, Any]],
|
|
|
media_by_platform_content_id: dict[str, dict[str, Any]],
|
|
|
+ paths_by_content_id: dict[str, list[str]],
|
|
|
) -> list[dict[str, Any]]:
|
|
|
reject_records: list[dict[str, Any]] = []
|
|
|
for item in discovered_content_items:
|
|
|
@@ -252,6 +247,7 @@ def _build_reject_records(
|
|
|
decision = decision_by_target_id[platform_content_id]
|
|
|
if decision["decision_action"] != "REJECT_CONTENT":
|
|
|
continue
|
|
|
+ path_ids = paths_by_content_id.get(platform_content_id, [])
|
|
|
reject_records.append(
|
|
|
_with_v4_explanation(
|
|
|
{
|
|
|
@@ -259,8 +255,9 @@ def _build_reject_records(
|
|
|
"policy_run_id": policy_run_id,
|
|
|
"main_decision_reason_code": decision["decision_reason_code"],
|
|
|
"decision_id": decision["decision_id"],
|
|
|
+ "source_path_record_ids": path_ids,
|
|
|
"media_snapshot": _media_snapshot(media_by_platform_content_id.get(platform_content_id)),
|
|
|
- "source_evidence": decision["source_evidence"],
|
|
|
+ "source_evidence_ref": _source_evidence_ref(decision, path_ids),
|
|
|
},
|
|
|
decision,
|
|
|
)
|
|
|
@@ -273,6 +270,7 @@ def _build_technical_retry_records(
|
|
|
discovered_content_items: list[dict[str, Any]],
|
|
|
decision_by_target_id: dict[str, dict[str, Any]],
|
|
|
media_by_platform_content_id: dict[str, dict[str, Any]],
|
|
|
+ paths_by_content_id: dict[str, list[str]],
|
|
|
) -> list[dict[str, Any]]:
|
|
|
retry_records: list[dict[str, Any]] = []
|
|
|
for item in discovered_content_items:
|
|
|
@@ -280,6 +278,7 @@ def _build_technical_retry_records(
|
|
|
decision = decision_by_target_id[platform_content_id]
|
|
|
if decision["decision_action"] != "TECHNICAL_RETRY_REQUIRED":
|
|
|
continue
|
|
|
+ path_ids = paths_by_content_id.get(platform_content_id, [])
|
|
|
retry_records.append(
|
|
|
_with_v4_explanation(
|
|
|
{
|
|
|
@@ -288,8 +287,9 @@ def _build_technical_retry_records(
|
|
|
"main_decision_reason_code": decision["decision_reason_code"],
|
|
|
"decision_id": decision["decision_id"],
|
|
|
"technical_retry_status": "retry_required",
|
|
|
+ "source_path_record_ids": path_ids,
|
|
|
"media_snapshot": _media_snapshot(media_by_platform_content_id.get(platform_content_id)),
|
|
|
- "source_evidence": decision["source_evidence"],
|
|
|
+ "source_evidence_ref": _source_evidence_ref(decision, path_ids),
|
|
|
},
|
|
|
decision,
|
|
|
)
|
|
|
@@ -312,6 +312,19 @@ def _media_snapshot(media: dict[str, Any] | None) -> dict[str, Any]:
|
|
|
return {key: value for key, value in snapshot.items() if value is not None}
|
|
|
|
|
|
|
|
|
+def _source_evidence_ref(
|
|
|
+ decision: dict[str, Any],
|
|
|
+ source_path_record_ids: list[str] | None = None,
|
|
|
+) -> dict[str, Any]:
|
|
|
+ ref = {
|
|
|
+ "decision_id": decision.get("decision_id"),
|
|
|
+ "decision_target_id": decision.get("decision_target_id"),
|
|
|
+ }
|
|
|
+ if source_path_record_ids is not None:
|
|
|
+ ref["source_path_record_ids"] = source_path_record_ids
|
|
|
+ return {key: value for key, value in ref.items() if value is not None}
|
|
|
+
|
|
|
+
|
|
|
def _with_v4_explanation(
|
|
|
record: dict[str, Any],
|
|
|
decision: dict[str, Any],
|
|
|
@@ -338,14 +351,12 @@ def _v4_decision_explanation(decision: dict[str, Any]) -> dict[str, Any]:
|
|
|
"query_relevance_score": scorecard.get("query_relevance_score"),
|
|
|
"platform_performance_score": scorecard.get("platform_performance_score"),
|
|
|
"score": decision.get("score"),
|
|
|
- "platform_performance_components": scorecard.get("platform_performance_components", []),
|
|
|
"missing_observable_fields": scorecard.get("missing_observable_fields", []),
|
|
|
"decision_action": decision.get("decision_action"),
|
|
|
"decision_reason_code": decision.get("decision_reason_code"),
|
|
|
"search_query_effect_status": decision.get("search_query_effect_status"),
|
|
|
"allow_walk": replay_data.get("allow_walk"),
|
|
|
"allow_walk_reason": replay_data.get("allow_walk_reason"),
|
|
|
- "walk_gate_snapshot": replay_data.get("walk_gate_snapshot"),
|
|
|
}
|
|
|
for optional_field in [
|
|
|
"score_missing",
|