fix(awooop): strengthen outbound truth references
All checks were successful
Code Review / ai-code-review (push) Successful in 10s
CD Pipeline / tests (push) Successful in 1m12s
CD Pipeline / build-and-deploy (push) Successful in 3m33s
CD Pipeline / post-deploy-checks (push) Successful in 1m15s

This commit is contained in:
Your Name
2026-05-13 12:04:26 +08:00
parent 7d506b785d
commit 7fa9f743dd
6 changed files with 102 additions and 2 deletions

View File

@@ -785,6 +785,8 @@ async def fetch_truth_chain(source_id: str, project_id: str = "awoooi") -> dict[
AND (
run_id::text = :source_id
OR content_preview ILIKE :needle
OR coalesce(source_envelope #> '{source_refs,incident_ids}', '[]'::jsonb) ? :source_id
OR coalesce(source_envelope #> '{source_refs,code_refs}', '[]'::jsonb) ? :source_id
)
ORDER BY queued_at DESC
LIMIT :limit

View File

@@ -514,7 +514,7 @@ async def record_outbound_message(
content_hash, content_preview, content_redacted,
redaction_version, source_envelope,
provider_message_id,
send_status, queued_at,
send_status, queued_at, sent_at,
triggered_by_state, waiting_since
) VALUES (
:project_id, :run_id, :conversation_event_id,
@@ -523,6 +523,7 @@ async def record_outbound_message(
:redaction_version, CAST(:source_envelope AS jsonb),
:provider_message_id,
:send_status, NOW(),
CASE WHEN :send_status = 'sent' THEN NOW() ELSE NULL END,
:triggered_by_state, :waiting_since
)
RETURNING message_id

View File

@@ -69,6 +69,7 @@ POLLING_LEADER_WATCH = 30 # seconds - 非 Leader Pod 每 30s 嘗試接管
logger = structlog.get_logger(__name__)
_TELEGRAM_BOT_URL_RE = re.compile(r"(api\.telegram\.org/bot)[^/\s]+")
_INCIDENT_ID_RE = re.compile(r"\bINC-\d{8}-[A-Z0-9]{4,}\b")
_CODE_REF_RE = re.compile(r"<code>([0-9a-f]{7,12})</code>", re.IGNORECASE)
def _top_gateway_bucket(
@@ -213,6 +214,9 @@ def _reply_markup_summary(payload: dict) -> dict[str, object]:
def _outbound_source_envelope(method: str, payload: dict) -> dict[str, object]:
"""Build a redaction-friendly source envelope for Channel Hub replay."""
text = str(payload.get("text") or payload.get("caption") or "")
incident_ids = sorted(set(_INCIDENT_ID_RE.findall(text)))
code_refs = sorted(set(match.group(1) for match in _CODE_REF_RE.finditer(text)))
return {
"adapter": "legacy_telegram_gateway",
"method": method,
@@ -222,6 +226,10 @@ def _outbound_source_envelope(method: str, payload: dict) -> dict[str, object]:
"disable_web_page_preview": payload.get("disable_web_page_preview"),
"has_reply_context": _has_reply_context(payload),
"reply_markup": _reply_markup_summary(payload),
"source_refs": {
"incident_ids": incident_ids[:20],
"code_refs": code_refs[:20],
},
}
# 2026-04-27 Claude Sonnet 4.6: B3 — LLM 動態 Telegram 按鈕 Feature Flag