fix(alerts): correct telegram execution truth
Some checks failed
CD Pipeline / tests (push) Failing after 52s
CD Pipeline / build-and-deploy (push) Has been skipped
CD Pipeline / post-deploy-checks (push) Has been skipped
Code Review / ai-code-review (push) Successful in 11s

This commit is contained in:
Your Name
2026-05-31 13:58:21 +08:00
parent 943a6feacf
commit e2ab879636
15 changed files with 624 additions and 49 deletions

View File

@@ -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: