feat(awooop): show source ref gap prefixes
All checks were successful
CD Pipeline / tests (push) Successful in 1m31s
Code Review / ai-code-review (push) Successful in 25s
CD Pipeline / build-and-deploy (push) Successful in 4m13s
CD Pipeline / post-deploy-checks (push) Successful in 1m34s

This commit is contained in:
Your Name
2026-05-25 19:49:48 +08:00
parent 640e35977f
commit c644cfe993
7 changed files with 160 additions and 0 deletions

View File

@@ -497,6 +497,39 @@ async def _fetch_callback_reply_audit_summary(
'[]'::jsonb
) = '[]'::jsonb
) AS outbound_reply_markup_missing_incident_ref_total,
COALESCE((
SELECT jsonb_agg(
jsonb_build_object(
'prefix', prefix,
'total', total
)
ORDER BY total DESC, prefix ASC
)
FROM (
SELECT
COALESCE(
NULLIF(
source_envelope #>>
'{reply_markup,buttons,0,callback_prefix}',
''
),
'unknown'
) AS prefix,
COUNT(*) AS total
FROM awooop_outbound_message
WHERE project_id = :project_id
AND channel_type = 'telegram'
AND source_envelope #>> '{reply_markup,present}' = 'true'
AND COALESCE(
source_envelope #> '{source_refs,incident_ids}',
'[]'::jsonb
) = '[]'::jsonb
GROUP BY 1
ORDER BY total DESC, prefix ASC
LIMIT 5
) missing_prefixes
), '[]'::jsonb)
AS outbound_reply_markup_missing_incident_ref_top_prefixes,
COUNT(*) FILTER (
WHERE send_status = 'failed'
) AS outbound_failed_total,
@@ -586,6 +619,9 @@ def _callback_reply_audit_summary_from_row(
partial = _safe_int(row.get("callback_snapshot_partial_total"))
missing = _safe_int(row.get("callback_snapshot_missing_total"))
outbound_incident_refs = _safe_int(row.get("outbound_incident_ref_total"))
top_missing_prefixes = _reply_markup_gap_prefixes_from_value(
row.get("outbound_reply_markup_missing_incident_ref_top_prefixes")
)
if callback_total <= 0:
snapshot_status = "no_callback"
@@ -623,6 +659,9 @@ def _callback_reply_audit_summary_from_row(
"outbound_reply_markup_missing_incident_ref_total": _safe_int(
row.get("outbound_reply_markup_missing_incident_ref_total")
),
"outbound_reply_markup_missing_incident_ref_top_prefixes": (
top_missing_prefixes
),
"outbound_failed_total": _safe_int(row.get("outbound_failed_total")),
"callback_total": callback_total,
"callback_sent_total": _safe_int(row.get("callback_sent_total")),
@@ -642,6 +681,24 @@ def _callback_reply_audit_summary_from_row(
}
def _reply_markup_gap_prefixes_from_value(value: Any) -> list[dict[str, Any]]:
if not isinstance(value, list):
return []
prefixes: list[dict[str, Any]] = []
for item in value:
if not isinstance(item, Mapping):
continue
prefix = str(item.get("prefix") or "unknown").strip() or "unknown"
prefixes.append({
"prefix": prefix[:80],
"total": _safe_int(item.get("total")),
})
if len(prefixes) >= 5:
break
return prefixes
async def _fetch_km_stale_completion_summary_for_incident(
*,
project_id: str,