fix(alerts): correct telegram execution truth
This commit is contained in:
@@ -659,6 +659,7 @@ class ApprovalDBService:
|
||||
approval_id: UUID,
|
||||
success: bool,
|
||||
error_message: str | None = None,
|
||||
execution_kind: str | None = None,
|
||||
) -> None:
|
||||
"""
|
||||
更新執行狀態
|
||||
@@ -669,21 +670,36 @@ class ApprovalDBService:
|
||||
"""
|
||||
async with get_db_context() as db:
|
||||
status = ApprovalStatus.EXECUTION_SUCCESS if success else ApprovalStatus.EXECUTION_FAILED
|
||||
values: dict = {"status": status}
|
||||
result = await db.execute(
|
||||
select(ApprovalRecord).where(ApprovalRecord.id == str(approval_id))
|
||||
)
|
||||
record = result.scalar_one_or_none()
|
||||
if record is None:
|
||||
logger.warning(
|
||||
"approval_execution_status_update_missing",
|
||||
id=str(approval_id),
|
||||
success=success,
|
||||
)
|
||||
return
|
||||
|
||||
record.status = status
|
||||
if not success and error_message:
|
||||
# 截斷至合理長度,避免爆欄位
|
||||
values["rejection_reason"] = str(error_message)[:2000]
|
||||
await db.execute(
|
||||
update(ApprovalRecord)
|
||||
.where(ApprovalRecord.id == str(approval_id))
|
||||
.values(**values)
|
||||
)
|
||||
record.rejection_reason = str(error_message)[:2000]
|
||||
if execution_kind:
|
||||
# 2026-05-31 ogt + Codex: OBSERVE/NO_ACTION 仍需 terminal 狀態,
|
||||
# 但前台/報表必須能分辨「未執行修復」而非真正 execution success。
|
||||
metadata = dict(record.extra_metadata or {})
|
||||
metadata["execution_kind"] = execution_kind
|
||||
metadata["repair_executed"] = execution_kind != "no_action"
|
||||
record.extra_metadata = metadata
|
||||
|
||||
logger.info(
|
||||
"approval_execution_status_updated",
|
||||
id=str(approval_id),
|
||||
success=success,
|
||||
has_error=bool(error_message),
|
||||
execution_kind=execution_kind,
|
||||
)
|
||||
|
||||
async def update_incident_id(self, approval_id: UUID, incident_id: str) -> None:
|
||||
|
||||
Reference in New Issue
Block a user