From a562db404899116cef7e0d3ee13b371398b1de16 Mon Sep 17 00:00:00 2001 From: OG T Date: Sat, 4 Apr 2026 18:00:05 +0800 Subject: [PATCH] =?UTF-8?q?fix(phase25):=20=E9=A6=96=E5=B8=AD=E6=9E=B6?= =?UTF-8?q?=E6=A7=8B=E5=B8=AB=20Review=20C1/C2/I1/I3=20=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit C1: NemotronProvider.privacy_level cloud→local NIM 部署在 192.168.0.188 內網,非官方雲端 API 可納入 DIAGNOSE _local_fallback_chain 隱私邊界 C2: adopt() 端點暫停,返回 501 API Pod 執行 git add -A 有安全風險 ADR-057 起草後改用 Gitea PR API 實作 I1: timeout log 修正,記錄實際套用的 timeout 值 原本永遠記錄 NEMOTRON_TIMEOUT_SECONDS=45 現在記錄依 task_type 選擇的正確值 I3: route_sync() 補 DIAGNOSE 隱私邊界 async route() 已有 _local_fallback_chain sync 版本遺漏,此次補齊 Co-Authored-By: Claude Sonnet 4.6 --- apps/api/src/api/v1/drift.py | 16 +++++++--------- apps/api/src/services/ai_providers/nemotron.py | 13 ++++++++----- apps/api/src/services/ai_router.py | 6 +++++- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/apps/api/src/api/v1/drift.py b/apps/api/src/api/v1/drift.py index 03e86d6d..57ac0666 100644 --- a/apps/api/src/api/v1/drift.py +++ b/apps/api/src/api/v1/drift.py @@ -116,19 +116,17 @@ async def rollback_drift(report_id: str) -> dict: @router.post("/reports/{report_id}/adopt", summary="承認變更並更新 Git") -async def adopt_drift(report_id: str) -> dict: +async def adopt_drift(_report_id: str) -> dict: """ 承認 K8s 漂移,更新 Git 使其與實際狀態一致 - 人工確認後才執行,git commit + push gitea main + ⚠️ 2026-04-04 ogt: C2 首席架構師裁示 — 暫時停用(ADR-057 起草後再啟用) + API Pod 內執行 git add -A 有安全風險,改用 Gitea PR API 實作後才開放。 """ - report = _recent_reports.get(report_id) - if not report: - raise HTTPException(status_code=404, detail=f"Report {report_id} not found") - - remediator = get_drift_remediator() - result = await remediator.adopt(report) - return result + raise HTTPException( + status_code=501, + detail="adopt() 端點暫停開放。ADR-057 起草後將改由 Gitea PR API 實作。", + ) # ============================================================================= diff --git a/apps/api/src/services/ai_providers/nemotron.py b/apps/api/src/services/ai_providers/nemotron.py index accf328d..b3744b5a 100644 --- a/apps/api/src/services/ai_providers/nemotron.py +++ b/apps/api/src/services/ai_providers/nemotron.py @@ -111,8 +111,10 @@ class NemotronProvider: @property def privacy_level(self) -> str: - # NIM 是雲端 GPU,首席架構師 Q2 裁示: cloud 等級 - return "cloud" + # 2026-04-04 ogt: Phase 25 首席架構師裁示 — NIM 部署在 192.168.0.188(內網 GPU) + # 非 NVIDIA 官方雲端 API,屬 local infra,可納入 DIAGNOSE 隱私邊界 + # 原標注 cloud 錯誤(Q2 裁示前的預設),此次更正 + return "local" async def analyze( self, @@ -227,11 +229,12 @@ class NemotronProvider: except asyncio.TimeoutError: latency_ms = (time.perf_counter() - start) * 1000 - timeout_secs = getattr(settings, "NEMOTRON_TIMEOUT_SECONDS", 30) + # 2026-04-04 ogt: I1 修正 — 使用實際套用的 timeout(依 task_type 選擇) logger.warning( "nemotron_provider_timeout", incident_id=incident_id, - timeout_seconds=timeout_secs, + timeout_seconds=timeout, + task_type=task_type, latency_ms=round(latency_ms, 1), ) return AIResult( @@ -239,7 +242,7 @@ class NemotronProvider: success=False, provider=self.name, latency_ms=latency_ms, - error=f"Tool calling timeout after {timeout_secs}s", + error=f"Tool calling timeout after {timeout}s", ) except Exception as e: diff --git a/apps/api/src/services/ai_router.py b/apps/api/src/services/ai_router.py index fd6c69f8..fda1ffd8 100644 --- a/apps/api/src/services/ai_router.py +++ b/apps/api/src/services/ai_router.py @@ -536,7 +536,11 @@ class AIRouter: ) # 建立 Fallback 鏈 - fallback_chain = self._build_fallback_chain(provider) + # 2026-04-04 ogt: I3 修正 — route_sync 也須尊重 DIAGNOSE 隱私邊界 + if intent == IntentType.DIAGNOSE: + fallback_chain = [fc for fc in self._local_fallback_chain if fc[0] != provider] + else: + fallback_chain = self._build_fallback_chain(provider) # 延遲預算 latency_budget = PROVIDER_LATENCY_BUDGET.get(provider, 30000)