fix(api): Phase R-R2.2 首席架構師 72/100 P2 修復

P2-01 signal_worker.py: persisted_to_pg 改用 getattr 防 BrainIncident AttributeError
P2-02 IIncidentEngine Protocol: update_incident_status → update_status 對齊 brain 實作
P2-03 config.py USE_NEW_ENGINE: 標記失效 + 回滾路徑更正 (git revert 而非 kubectl)
ADR-046: Option B (IncidentConverter) 決策完成,待實作清單更新
ADR-024: 審查結論 + 正式回滾指令更新
Skill 02: v2.5 版本記錄

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
OG T
2026-03-31 22:33:08 +08:00
parent cd91560e0b
commit 2ba61acf72
6 changed files with 39 additions and 22 deletions

View File

@@ -54,16 +54,12 @@ class Settings(BaseSettings):
# ==========================================================================
# Phase 16: leWOOOgo 積木化絞殺者模式 (Strangler Fig Pattern)
# 2026-03-26 統帥批准立即執行
#
# 功能開關:
# - False: 使用 apps/api 內嵌版本 (當前)
# - True: 使用 lewooogo-brain/lewooogo-data 套件版本
#
# 回滾指令: kubectl set env deployment/awoooi-api USE_NEW_ENGINE=false
# 2026-04-01 ogt: Phase R-R2 完成,內嵌版本已移除,此開關已失效 (ADR-046 P2-03)
# 回滾方式: git revert c7b3f8f d17b67c + kubectl rollout restart deployment/awoooi-api
# ==========================================================================
USE_NEW_ENGINE: bool = Field(
default=False,
description="Phase 16: True=lewooogo packages, False=內嵌版本",
default=True,
description="[已失效] Phase R-R2 後內嵌版本已移除,此開關無消費者,僅保留供環境相容性",
)
# ==========================================================================

View File

@@ -76,12 +76,12 @@ class IIncidentEngine(Protocol):
"""取得指定 Incident"""
...
async def update_incident_status(
async def update_status(
self,
incident_id: str,
status: str,
) -> Incident | None:
"""更新 Incident 狀態"""
status: Any, # IncidentStatus enum (lewooogo-brain)
) -> bool:
"""更新 Incident 狀態 (2026-04-01 ogt: 簽名與 lewooogo-brain 對齊, ADR-046 P2-02)"""
...

View File

@@ -399,7 +399,7 @@ class SignalWorker:
severity=incident.severity.value,
signal_count=len(incident.signals),
affected_services=incident.affected_services,
persisted_to_pg=incident.persisted_to_pg,
persisted_to_pg=getattr(incident, "persisted_to_pg", False), # 2026-04-01 ogt: BrainIncident 無此欄位 (ADR-046 P2-01)
)
else:
span.set_attribute("signal.processing_failed", True)

View File

@@ -9,7 +9,9 @@
| 項目 | 狀態 |
|------|------|
| **Phase R-R2.1** | ✅ **架構審查 P0+P1 修復** `d17b67c` (key prefix/型別/死碼) 80→92/100 |
| **Phase R-R2.1 首席審查** | ✅ **72/100 條件通過** P2-01/02/03 修復 (`signal_worker` + `IIncidentEngine` + `USE_NEW_ENGINE`) |
| **ADR-046** | ✅ **Option B 決策完成** IncidentConverter 轉換層 (Phase R-R3+ Sprint 實作) |
| **Phase R-R2.1** | ✅ **架構審查 P0+P1 修復** `d17b67c` (key prefix/型別/死碼) |
| **Phase R-R3** | ✅ **已完成** (Phase 22 架構修復中建立, 9 repos) |
| **ADR-046** | 📋 **待統帥決策** 跨套件 Incident 型別統一 (Option B: IncidentConverter) |
| **Phase R-R2** | ✅ **完成** (#121 #122 `c7b3f8f` -971 行 legacy code#123 暫緩至 R-R3) |

View File

@@ -174,8 +174,9 @@ kubectl set env deployment/awoooi-api USE_NEW_LAYER=false
| R3 | 抽取 Repository 層 | ✅ | Phase 22 (repositories/) |
| R4 | 瘦身 Router 層 | 🔴 待執行 | - |
> Phase R-R2.1 架構審查通過 (80/100)。P0+P1 已修復 (`d17b67c`)
> P2 技術債 (ADR-013 時間格式) 移至下個 Sprint
> Phase R-R2.1 首席架構師正式審查72/100 條件通過
> P0+P1 全部修復。P2 技術債清單見 ADR-046
> 回滾方式已更新git revert c7b3f8f d17b67c + kubectl rollout restart (USE_NEW_ENGINE 旗標已失效)。
## 相關文件

View File

@@ -2,7 +2,7 @@
| 項目 | 內容 |
|------|------|
| **狀態** | 📋 待決策 |
| **狀態** | ✅ 決策完成 (Option B 採用) |
| **日期** | 2026-04-01 |
| **決策者** | 首席架構師 + 統帥 |
| **觸發** | Phase R-R2.1 架構審查 P2-01 |
@@ -67,12 +67,30 @@ def local_to_brain(local_incident: Incident) -> BrainIncident: ...
- `_record_to_incident` 返回型別標注為 `Any`P0-01 修復)
- 不阻擋現有業務邏輯
## 後續行動
## 決策結果 (2026-04-01 首席架構師審查)
- [ ] 首席架構師決策選擇方案
- [ ] 若選 Option B建立 `src/utils/incident_converter.py`
- [ ] 更新 `IncidentDbAdapter._record_to_incident` 返回正確型別
- [ ] 更新 `IncidentMemoryAdapter` 型別標注
**採用 Option BIncidentConverter 轉換層**
首席架構師審查評分 72/100 (條件通過),確認 Option B 為最佳方案。
### 緊急修復已完成 (P2-01)
- `signal_worker.py:402``persisted_to_pg` 改為 `getattr(incident, "persisted_to_pg", False)`
### 待實作 (Phase R-R3+ Sprint)
- [ ] 建立 `src/utils/incident_converter.py`
- `brain_to_local(BrainIncident) -> Incident`
- `local_to_brain(Incident) -> BrainIncident`
- [ ] `IncidentDbAdapter._record_to_incident` 返回型別從 `Any` 改為 `Incident`
- [ ] `IncidentMemoryAdapter.load_incident` 返回型別從 `Any` 改為 `Incident`
- [ ] `signal_worker.py` process_signal 返回後轉換
- [ ] 移除 `USE_NEW_ENGINE` config 項 (已標記為失效)
### 三個跨邊界轉換點
| 位置 | 方向 | 狀態 |
|------|------|------|
| `IncidentDbAdapter._record_to_incident()` | DB→local | ⬜ 待實作 |
| `IncidentMemoryAdapter.load_incident()` | brain→local | ⬜ 待實作 |
| `signal_worker.py process_signal()` | brain→local | 🟡 getattr 暫緩 |
## 相關文件