# CI/CD Monitor Agent — Persistent Memory > **Persistent diary cross-session.** Auto-injected first 200 lines / 25KB at spawn. > Update BEFORE every stop. Curate when > 25KB. --- ## 🎯 Role baseline Read-only CI/CD pipeline + post-deploy verifier for SOLUTION_ERP. Polls Gitea Actions API, verifies test gate + deploy ship + prod health. Tools: Read, Grep, Glob, Bash, WebFetch. Output: PASS/FAIL verdict + evidence under 500 words. **Spawn cost ~150K tokens** — trade-off để catch fail tự động không phụ thuộc em main nhớ verify. --- ## 🚨 Recurring CI/CD bug patterns (catch with priority) ### Gotcha #39 — act_runner github.com TCP timeout - **Symptom:** CI run hang ở "Set up job" → timeout 21s, run stays "queued" forever - **Verify:** log line `Error: dial tcp ... github.com:443 ... i/o timeout` - **Fix:** manual checkout bypass đã hardcode trong `.gitea/workflows/deploy.yml` (run #108/#109), pass at #110. KHÔNG revert. Nếu pattern returns → escalate em main check VPS network ### Gotcha #40 — npm cache `tsc not found` - **Symptom:** `build_fe_admin` fail sau khi enable `cache: npm` ở `actions/setup-node@v4` - **Verify:** log line `sh: tsc: command not found` hoặc `npm error code ETIMEDOUT` - **Fix:** DISABLED npm cache rolled back ở `a21790d`. KHÔNG re-enable. Build time chấp nhận ~3 min thay vì optimize ### Gotcha #41 — paths-ignore docs-only skip - **Symptom:** Commit code thật mà CI không trigger (run list không có entry mới) - **Verify:** `git diff --name-only HEAD~1 HEAD` vs `paths-ignore: ['docs/**', '**/*.md', '.claude/skills/**']` - **Fix:** Nếu commit có code thật bị skip nhầm → check pattern conflict. Nếu commit chỉ docs → expected behavior (saving ~9 min deploy / commit MD-only) ### Gotcha #25 — IIS WebSocket / module exclusion - **Symptom:** `notification-hub/negotiate` returns 401 hoặc 404 prod (FE SignalR connect fail) - **Verify:** `curl -X POST https://api.solutions.com.vn/notification-hub/negotiate` → non-200 - **Fix:** IIS WebSocket module enable trong `web.config` của site api.solutions.com.vn (skill `iis-deploy-runbook`) ### Deploy ship verification — bundle hash unchanged - **Symptom:** commit push success + Gitea action success + status PASS, **nhưng prod không có thay đổi visible** (user UAT báo "đã deploy mà không thấy") - **Root cause candidates:** - IIS app pool chưa recycle → giữ assembly cũ trong memory - NSSM service script không copy file đúng folder - Browser cache (rare nếu Vite hash chuẩn) - **Verify:** `curl -s https://admin.solutions.com.vn/ | grep -oE '/assets/index-[a-z0-9]+\.js'` — hash giữ nguyên = ship fail - **Fix:** SSH `vietreport-vps "Restart-WebAppPool admin.solutions.com.vn"` + recheck bundle hash ### Migration drift prod vs repo - **Symptom:** Latest mig trong repo (vd Mig 27) nhưng prod chưa có (DbInitializer startup fail) - **Verify:** Compare `ls Migrations/*.cs` vs `sqlcmd ... __EFMigrationsHistory` - **Fix:** Check `Program.cs` startup hook `app.MigrateDatabase()` còn không + app pool recycle. Hoặc manual `dotnet ef database update --connection prod` qua SSH --- ## 📋 5-stage checklist (apply EVERY run) ### Stage 1: Push happened + filter check - `git log -1 --format='%H %s'` — latest commit - `git log origin/main..HEAD` — must be empty (synced) - `git diff --name-only HEAD~1 HEAD` vs `paths-ignore` — nếu chỉ docs → SKIPPED-DOCS ### Stage 2: Gitea Actions poll (max 10 iter × 60s) - API: `https://git.baocaogiaoduc.vn/api/v1/repos/vietreport-admin/solution-erp/actions/runs?limit=5` - Match `head_sha == $commitSha` → get `runId` - Status: queued / in_progress / completed - Conclusion (when completed): success / failure / cancelled / timed_out ### Stage 3: Test gate verify (Domain 58 + Infra 23 baseline) - Logs grep: `Passed:` line per stage - Phase 9 UAT exception: test count may be lower nếu em main skip per chunk (memory `feedback_uat_skip_verify`) — NOT a failure - Delta from baseline → report ### Stage 4: Post-deploy live verify (if SUCCESS) - Auth login → bearer (admin + nv.test for non-admin gotcha #44 check) - 3-5 endpoint smoke 2XX expected (include endpoint mới trong commit) - FE bundle hash 2 app changed (compare pre vs post) - SignalR negotiate (gotcha #25 — if commit relates notification) - EF migration latest prod == latest repo ### Stage 5: Report PASS/FAIL with evidence + MEMORY.md update --- ## ⚠️ Anti-patterns observed (DO NOT) 1. ❌ Push fix code — READ only, escalate to em main 2. ❌ Speculate fail cause without log evidence 3. ❌ Skip post-deploy live verify khi SUCCESS — bundle hash là biggest catch 4. ❌ Skip MEMORY.md update 5. ❌ Poll forever (max 10 iter ~10 min timeout) 6. ❌ Auto-rollback — escalate với recommendation, KHÔNG tự chạy 7. ❌ Verify khi commit docs-only — SKIPPED-DOCS + return ngay --- ## 🧠 SOLUTION_ERP CI/CD essentials - **Gitea:** https://git.baocaogiaoduc.vn/vietreport-admin/solution-erp - **Workflow:** `.gitea/workflows/deploy.yml` (test gate 2 step + build BE + build FE × 2 + deploy) - **Path filter:** `paths-ignore: ['docs/**', '**/*.md', '.claude/skills/**']` (gotcha #41) - **Prod URLs:** api / admin / eoffice `.solutions.com.vn` - **SSH VPS:** `ssh vietreport-vps` (user=Administrator, key=id_ed25519) - **DB prod:** `.\SQLEXPRESS` / `SolutionErp` / vrapp user - **Tests baseline:** 104/104 (58 Domain + 46 Infra = 23 codegen + 6 PE WF + 3 PE Guard S21 t3 + 7 ReturnMode + 7 DraftGuard + 5 AuthorizePolicy + 1 V2 actor scope reject) — S22+1 +1 test. Re-verified S22 chốt cuối 23:25 (Verify push range `3d725c4..cc8a7d3`). - **Mig latest repo:** Mig 30 `20260513160703_AddAllowApproverEditBudgetToLevels` (S22+5 — per-NV F4 admin opt-in cho Approver edit Section ngân sách ChoDuyet branch). Prev Mig 29 (S21 t5 refactor per-NV) preserved. - **Gitea Actions API path:** `/api/v1/repos/{owner}/{repo}/actions/tasks?limit=N` (NOT `/runs` — returns 404). Public no-auth read OK. Fields: `id`, `run_number`, `head_sha`, `status` (queued/running/success/failure/cancelled), `conclusion`, `created_at`, `updated_at`, `display_title`. - **Mig latest prod:** sqlcmd `__EFMigrationsHistory ORDER BY MigrationId DESC TOP 5` - **Bearer test:** - Admin: `admin@solutions.com.vn / Admin@123456` (full) - UAT non-admin: `nv.test@solutions.com.vn / TestUser@123456` (Drafter CCM — verify gotcha #44 silent 403 patterns) --- ## 🔑 Critical config (gotcha cross-ref) - Node CI pin: `20.x` (memory `feedback_node_cicd` — bài học NamGroup) - MediatR pin: `12.4.1` (gotcha #1) - Swashbuckle pin: `6.9.0` (gotcha #2) - act_runner: manual checkout bypass github.com (gotcha #39) - npm cache: DISABLED (gotcha #40 — KHÔNG re-enable) Flag commit nếu thấy ` 25KB → archive recent runs to `archive/.md` - Duplicate failure patterns → merge into single entry (vd act_runner timeout x3 → 1 entry) - Stale > 3 months → remove Last curate: 2026-05-13 23:30 (added S22 chốt cuối cumulative verify Run #189-193 sequence + Mig 30 schema live + 3 new endpoint wire + 33 user role-based + bundle rotate 2/2 + test baseline 104 + Discovery #3 Gitea push tip paths-ignore eval. Disproven spec hypothesis re: gotcha #47 `.claude/agent-memory/**` trigger — `**/*.md` glob already catches `.md` files at any depth. Gotcha #47 kept as preventive for non-.md future state files.)