fix(api): 簽核後更新 Incident 狀態為 RESOLVED

根因: 簽核成功後 Incident.status 未更新,導致刷新頁面後 Y/n 按鈕重現

修復:
- proposal_service.py: 新增 resolve_incident_after_approval() 方法
- approvals.py: sign_approval 成功後呼叫更新 Incident 狀態
- 使用 metadata.incident_id 反查關聯的 Incident

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
OG T
2026-03-23 21:37:50 +08:00
parent 7db42ffdac
commit ac3bf97920
2 changed files with 79 additions and 0 deletions

View File

@@ -501,6 +501,70 @@ class ProposalService:
error=str(e),
)
# =========================================================================
# Phase 6.5: 簽核完成後更新 Incident 狀態
# =========================================================================
async def resolve_incident_after_approval(
self,
incident_id: str,
approval_id: str | None = None,
) -> bool:
"""
簽核完成後更新 Incident 狀態為 RESOLVED
當 Approval 達到所需簽核數時呼叫,更新:
1. incident.status → RESOLVED
2. incident.decision.state → completed (如果有)
Args:
incident_id: Incident ID
approval_id: 簽核的 Approval ID (用於日誌)
Returns:
是否更新成功
"""
try:
incident = await self._load_incident(incident_id)
if not incident:
logger.warning(
"resolve_incident_not_found",
incident_id=incident_id,
approval_id=approval_id,
)
return False
# 更新狀態
old_status = incident.status
incident.status = IncidentStatus.RESOLVED
incident.updated_at = datetime.now(timezone.utc)
# 更新 decision.state (如果有)
if incident.decision:
incident.decision.state = "completed"
# 持久化
await self._persist_incident(incident)
logger.info(
"incident_resolved_after_approval",
incident_id=incident_id,
approval_id=approval_id,
old_status=old_status.value,
new_status="resolved",
)
return True
except Exception as e:
logger.exception(
"resolve_incident_error",
incident_id=incident_id,
approval_id=approval_id,
error=str(e),
)
return False
# =============================================================================
# Singleton