feat(governance): attach km archive history to dedupe groups
All checks were successful
Code Review / ai-code-review (push) Successful in 11s
CD Pipeline / tests (push) Successful in 6m56s
Type Sync Check / check-type-sync (push) Successful in 6m51s
CD Pipeline / build-and-deploy (push) Successful in 4m43s
CD Pipeline / post-deploy-checks (push) Successful in 1m47s

This commit is contained in:
Your Name
2026-05-20 10:20:01 +08:00
parent 9b0f68f6c4
commit edb6daef88
6 changed files with 255 additions and 40 deletions

View File

@@ -1,3 +1,94 @@
## 2026-05-20T98 KM archive history 綁定 dedupe group read model
**觸發**
- T97 已在 Work Items 的 KM 草稿去重卡片顯示「封存 / 回測歷史」。
- 但 history row 來源仍是同頁 `governance queue?event_type=knowledge_degradation&size=20` 的分頁資料;當 dispatch 總量變大或 archive/recheck row 排在 20 筆之外時Operator 可能仍看不到已發生的 owner 封存 / stale ratio 回測。
- 這會讓「前端是否真的同步流程狀態」留下 pagination blind spot。
**修正**
- `KnowledgeReviewDraftDedupeGroup` 新增 `archive_history: list[DispatchItem]`
- `query_km_review_draft_dedupe()` 會針對本次 dedupe groups 的 `governance_event_id` 額外讀取:
- `hermes_km_review_dedupe_owner_archive`
- `hermes_km_stale_ratio_recheck`
- 每個 event 最多帶最近 3 筆 archive / recheck dispatch history並重用 `DispatchItem` read model因此欄位和 Work Items queue 一致:
- `dispatch_status`
- `executor_type`
- `workflow_stage`
- `dry_run_plan_fingerprint`
- `archived_count`
- `stale_ratio_snapshot`
- Work Items 前端改成優先讀 `group.archive_history`;若 production API 尚未升級或 group 無 history再 fallback 到 T97 的 queue item 匹配。
- 邊界T98 仍是 read-only read model不自動寫 KM、不自動封存、不改 owner approval / fingerprint guard。
**Local verification**
```text
python3 -m py_compile apps/api/src/models/governance.py apps/api/src/services/governance_query_service.py
-> ok
/Users/ogt/awoooi/apps/api/.venv/bin/python -m ruff check apps/api/src/models/governance.py apps/api/src/services/governance_query_service.py apps/api/tests/test_ai_governance_endpoints.py
-> All checks passed
DATABASE_URL=postgresql+asyncpg://test:test@localhost:5432/test /Users/ogt/awoooi/apps/api/.venv/bin/python -m pytest apps/api/tests/test_ai_governance_endpoints.py -q
-> 39 passed
DATABASE_URL=postgresql+asyncpg://test:test@localhost:5432/test /Users/ogt/awoooi/apps/api/.venv/bin/python -m pytest apps/api/tests/test_ai_governance_endpoints.py apps/api/tests/test_governance_dispatcher.py apps/api/tests/test_hermes_kb_growth_worker.py -q
-> 62 passed
pnpm --dir apps/web exec next lint --file 'src/app/[locale]/awooop/work-items/page.tsx'
-> No ESLint warnings or errors
pnpm --dir apps/web exec tsc --noEmit --pretty false
-> ok
node -e 'JSON.parse(...)'
-> i18n json ok
cd apps/api && /Users/ogt/awoooi/apps/api/.venv/bin/python ../../scripts/generate-schemas.py && cd ../../packages/shared-types && pnpm generate:types
-> packages/shared-types 無 diff
NEXT_PUBLIC_API_URL=https://awoooi.wooo.work pnpm --dir apps/web run build
-> compiled and generated 90/90 static pages
git diff --check
-> pass
```
**Local interactive smokelive production API bridge只允許 GET無寫入**
```text
Local dev:
NEXT_PUBLIC_API_URL=https://awoooi.wooo.work pnpm --dir apps/web dev --hostname 127.0.0.1 --port 3030
Playwright:
-> live production GET bridge
-> 對 km-review-drafts/dedupe response 注入 1 筆 archive_history row
-> 不允許任何非 GET request
Checks:
-> injectedHistory=true
-> historyVisible=true
-> rowVisible=true
-> blockedWrites=0
-> pageErrors=0
Note:
-> bridge smoke 有 2 個非目標 API resource 599未影響 archive_history row 驗證production deploy 後需用正式域名再驗證 API schema。
Screenshot:
/tmp/awoooi-t98-km-archive-history-row-local.png
```
**Production deploy / smoke**
```text
Pending推 Gitea main 後驗證 dedupe API group 已含 archive_history key並以 production Work Items 確認頁面無 console / page error。
```
**目前整體進度**
- AwoooP 告警可觀測鏈:約 99.1%。
- 低風險自動修復閉環:約 95%。
- 前端 AI 自動化管理介面同步:約 98.7%。
- 治理告警可讀性 / 可處置性:約 99.0%。
- AI Agent ownership 可追溯性:約 98.2%。
- KM healthcheck 派工可追蹤性:約 99.7%。
- Hermes KB growth 草稿 / owner review 閉環:約 99.6%。
- 完整 AI 自動化管理產品化:約 97.5%。
## 2026-05-20T97 KM archive / stale ratio history 持久呈現
**觸發**

View File

@@ -2359,6 +2359,15 @@ Phase 6 完成後
- Production`14697ba2 feat(governance): surface km archive audit history` 已推 Gitea maindeploy marker `8a306975 chore(cd): deploy 14697ba [skip ci]`Gitea runs `2559` CD、`2560` Code Review、`2561` Type Sync 全 success。Production health healthy/prod/mock_mode=false。`GET /ai/governance/queue?dispatch_status=all&event_type=knowledge_degradation&size=20``total=205``table_pending=false`sample item 已含 `dry_run_plan_fingerprint` / `archived_count` / `stale_ratio_snapshot` 欄位。`GET /ai/governance/km-review-drafts/dedupe?limit=100``total_review_drafts=100``event_group_total=45``duplicate_draft_total=55`。Work Items production smoke 顯示 nav、KM healthcheck panel、KM 草稿去重視圖、封存 / 回測歷史區塊與 empty statepageErrors=0 / consoleErrors=0 / failedResponses=[],截圖 `/tmp/awoooi-t97-km-archive-history-production.png`。目前 `historyRowVisible=false` 是正確狀態,因為本輪沒有對 production KM 做 owner confirm 封存;一旦 owner confirm 寫入 archive / recheck dispatch該區塊會顯示 history row。
- 目前進度更新:前端 AI 自動化管理介面同步約 98.6%;治理告警可讀性 / 可處置性約 98.9%AI Agent ownership 可追溯性約 98.0%KM healthcheck 派工可追蹤性約 99.7%Hermes KB growth 草稿 / owner review 閉環約 99.5%;完整 AI 自動化管理產品化約 97.3%。
**T98 KM archive history 綁定 dedupe group read model2026-05-20 台北)**
- 觸發T97 的 history UI 仍依賴同頁 governance queue `size=20` 分頁資料archive/recheck dispatch row 一旦不在該頁Operator 仍可能看不到已發生的 owner 封存或 stale ratio 回測。
- 修正:`KnowledgeReviewDraftDedupeGroup` 新增 `archive_history: list[DispatchItem]``query_km_review_draft_dedupe()` 會針對本次 dedupe groups 的 `governance_event_id` 直接讀取最近 3 筆 `hermes_km_review_dedupe_owner_archive` / `hermes_km_stale_ratio_recheck` dispatch並重用 `DispatchItem` read model 帶出 status、stage、fingerprint、archived_count、stale_ratio_snapshot。
- UIWork Items 前端優先讀 `group.archive_history`;若 API 尚未升級或 group 無 history再 fallback 到 T97 的 queue item 匹配。這把「封存 / 回測歷史」從旁路分頁猜測改成 dedupe group 自帶證據。
- 邊界T98 仍是 read-only read model不自動寫 KM、不封存 production KM、不改 owner approval / fingerprint guard。
- Local verification`py_compile` okruff ok治理 endpoint 單檔 `39 passed`;治理 endpoint / dispatcher / Hermes worker tests `62 passed`Work Items Next lint ok`tsc --noEmit` oki18n JSON parse okshared-types regenerate 後無 diffproduction build 成功產出 90/90 static pages`git diff --check` pass。Local Playwright live production API bridge 對 dedupe response 注入 1 筆 archive_history row確認 `Hermesowner 確認封存` 與 fingerprint 顯示blockedWrites=0截圖 `/tmp/awoooi-t98-km-archive-history-row-local.png`
- Productionpending推 Gitea main 後驗證 dedupe API group 已含 archive_history key並以 production Work Items 確認頁面無 console / page error。
- 目前進度更新:前端 AI 自動化管理介面同步約 98.7%;治理告警可讀性 / 可處置性約 99.0%AI Agent ownership 可追溯性約 98.2%KM healthcheck 派工可追蹤性約 99.7%Hermes KB growth 草稿 / owner review 閉環約 99.6%;完整 AI 自動化管理產品化約 97.5%。
---
### 2026-04-20 晚 (台北) — C1-C4 全流程串接 — Playbook 鏈路保護commit de2d34d