fix(km): 修復 KM 寫入全為 unknown 的根因 (三個節點)
Some checks are pending
CD Pipeline / build-and-deploy (push) Has started running
Some checks are pending
CD Pipeline / build-and-deploy (push) Has started running
Bug-A: approval_execution.py 呼叫不存在的 get_incident() → AttributeError 被 except 吞掉 → alertname/alert_category/affected_services 全用預設值 修復: 改用 get_from_working_memory() + get_from_episodic_memory() 雙路徑 Bug-B: _record_to_incident() 從 PG 還原 Incident 時漏掉 notification_type + alert_category 欄位 → km_conversion 讀到 None 修復: 加入這兩個欄位的還原 Bug-C: main.py working_memory_warmup 重建 Incident 時同樣遺漏 notification_type + alert_category 修復: 同步補上 2026-04-15 Claude Sonnet 4.6 Asia/Taipei
This commit is contained in:
@@ -276,6 +276,9 @@ async def lifespan(_app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
closed_at=record.closed_at,
|
||||
ttl_days=record.ttl_days,
|
||||
vectorized=record.vectorized,
|
||||
# ADR-073: 分類欄位必須還原,否則 KM 寫入時全為 "unknown"
|
||||
notification_type=record.notification_type,
|
||||
alert_category=record.alert_category,
|
||||
)
|
||||
if await incident_service.save_to_working_memory(incident):
|
||||
restored += 1
|
||||
|
||||
@@ -628,7 +628,11 @@ class ApprovalExecutionService:
|
||||
if approval.incident_id:
|
||||
try:
|
||||
from src.services.incident_service import get_incident_service
|
||||
_inc = await get_incident_service().get_incident(approval.incident_id)
|
||||
_svc = get_incident_service()
|
||||
# get_from_working_memory (Redis) → fallback get_from_episodic_memory (PG)
|
||||
_inc = await _svc.get_from_working_memory(approval.incident_id)
|
||||
if _inc is None:
|
||||
_inc = await _svc.get_from_episodic_memory(approval.incident_id)
|
||||
if _inc:
|
||||
if _inc.signals:
|
||||
alertname = _inc.signals[0].labels.get("alertname", "unknown") or "unknown"
|
||||
|
||||
@@ -680,6 +680,9 @@ class IncidentService:
|
||||
ttl_days=record.ttl_days,
|
||||
persisted_to_pg=True, # 從 PG 讀取,必為 True
|
||||
vectorized=record.vectorized,
|
||||
# ADR-073: 分類欄位必須從 DB 還原,否則 KM 寫入時全為 "unknown"
|
||||
notification_type=record.notification_type,
|
||||
alert_category=record.alert_category,
|
||||
)
|
||||
|
||||
# =========================================================================
|
||||
|
||||
Reference in New Issue
Block a user