Files
solution-erp/.claude/agent-memory/database-agent/MEMORY.md
pqhuy1987 a20cde89fb
All checks were successful
Deploy SOLUTION_ERP / build-deploy (push) Successful in 4m19s
[CLAUDE] App: golive harden — LeaveBalance concurrency + ItTicket authz-order + DocxRenderer + Travel/Vehicle tests
Pre-golive verification (S56) surfaced 4 issues; all fixed + verified (228 test pass, 0 build warning).

#3 LeaveBalance lost-update (DB11 concurrency): terminal-approve deduction was an in-memory read-modify-write (UsedDays += NumDays) under a bare SaveChanges, so two concurrent terminal approvals of the same (user,type,year) lost an update. Fix: atomic server-side ExecuteUpdateAsync (UsedDays = UsedDays + n) inside an explicit Serializable transaction (matches the codegen/Proposal/TravelVehicle convention; serializes the auto-create-row race too). Exactly-once guard (Status != DaGuiDuyet) intact. No migration.

#5 ItTicket reassign existence-oracle: AssignItTicketHandler checked ticket-NotFound before the Admin-OR-dept-IT Forbidden guard. Reordered so authorization runs first -> fail-closed (a non-IT/non-admin caller gets Forbidden for any ticketId, existent or not).

#6 DocxRenderer CS8602: null-guard MainDocumentPart + Document with clear exceptions (cleared 2 build warnings -> 0).

#4 Travel/Vehicle ApproveV2: added smoke tests (Submit->Approve terminal + outsider-Forbidden) — previously zero coverage.

Tests 216 -> 228 (+12). database-agent DB-layer review PASS; em-main cross-stack review clean (reviewer workflow stage did not emit StructuredOutput -> em-main covered the cross-stack review by reading every diff). Bundles agent-memory harvest (S56).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-09 17:51:38 +07:00

35 lines
4.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# database-agent — MEMORY (L1 HOT)
> READ-advisory DB specialist SOLUTION_ERP (.NET 10 EF Core 10 + SQL Server, single `ApplicationDbContext` dbo). Adopt AI_INFRA broadcast `2026-06-08-Agent-database-codebase-agents` (floor DB1DB11), S52 2026-06-08. Seed = em main. **Nấc hiện: executed-file — verified-runtime CHỜ anh restart CLI + spawn-test.**
## Vai trò (FORM tailored SE)
- **READ-advisory tier** — DESIGN/REVIEW/PERF/CONCURRENCY-advise, KHÔNG author file. `implementer-backend` author entity+config+migration; em main solo quyết schema-design cuối. database-agent = deep-DB lens hỗ trợ + review.
- Floor DB1DB11 (canonical, KHÔNG hạ) — chi tiết `.claude/agents/database-agent.md`.
- Skill: `sql-database-assistant` (SQL Server raw, KHÔNG cover EF-Core) + `ef-core-migration` (EF Core 10 pin + 3-file rule). Verify present TRƯỚC wire.
- `store_memory` STRIPPED → ghi finding vào FILE này; em main + re-index → RAG.
## SE facts cốt lõi (DB10 evidence-based — re-ground khi cần)
- **45 migration → 92 tables** (S51). `sys.tables` = ground-truth (narrative count drift "incremented-per-session" → re-ground).
- 2 DB instance: LocalDB `SolutionErp_Dev` (runtime) / `SolutionErp_Design` (design-time) — gotcha designtime-vs-runtime DB (apply migration cả 2 qua `--connection` override). Prod = `.\SQLEXPRESS\SolutionErp`.
- Soft-delete UNIQUE index PHẢI `.HasFilter("[IsDeleted]=0")` (gotcha #57 — 13× pattern; S45 Holiday + S51 LeaveType/Shift/OtPolicy/Vehicle/Driver). EXT backlog: Department/Supplier/Project (Mig 46 worktree).
- Codegen atomic = `WorkflowAppCodeGen.GenerateMaDonTuAsync` dùng `IsolationLevel.Serializable` tx (Prefix-keyed sequence) — pattern ĐÚNG tham chiếu cho concurrency.
## 🎯 DB11 gap đã biết (concurrency — vai trò chính)
- **S43/S56 LeaveBalance lost-update — FIX DESIGNED S56 (approach A, NO migration).** `ApproveLeaveRequestHandler` terminal DaDuyet branch (LeaveOtApprovalFeatures.cs:355-386) đọc `bal.UsedDays` in-memory + `+= p.NumDays` + bare SaveChanges → 2 concurrent terminal-approve cùng (User,Type,Year) lost-update. **Fix:** wrap terminal-branch trong explicit `BeginTransactionAsync` → (1) SaveChanges persist opinion-upsert + status=DaDuyet + ensure balance-row exists (insert UsedDays=0 nếu absent), (2) `ExecuteUpdateAsync(SET UsedDays = UsedDays + n)` atomic DB-side race-free, (3) Commit. Atomic-with-approval preserved (1 tx all-or-nothing). Exactly-once untouched (early `Status != DaGuiDuyet` guard :296). NO ambient TransactionBehavior (chỉ ValidationBehavior) → handler own tx boundary. **Cast `(DbContext)db` để reach Database** (IApplicationDbContext chỉ expose DbSet+SaveChangesAsync). Existing terminal test (Case 4 :226) assert Status/Level/opinion-count only — KHÔNG assert UsedDays-on-tracked → ExecuteUpdate (bypass tracker) WON'T break suite. Spec authoritative → implementer-backend author.
- OtRequest terminal KHÔNG trừ phép (chỉ status) → no lost-update bên OT.
- P11-D SLA flags (`SlaWarnedSent`/`SlaBreached`) + P11-F codegen = concurrency-sensitive → DB11 lens áp được.
## Boundary (⟂)
- vs implementer-backend: DESIGN/REVIEW vs AUTHOR (KHÔNG double-touch migration file).
- vs investigator-codebase: deep DB-layer (introspection/query-plan/concurrency) vs broad grep/audit.
- vs reviewer: DB-layer design-review (DB6/DB11/DB5) TRƯỚC author vs adversarial pre-commit cross-stack.
- KHÔNG: FE · business-logic · deploy · session-lifecycle audit.
## Accuracy (G-015)
- DB7 scope-DB-only = PHÂN-VAI, KHÔNG "read-only enforced" (giữ `Bash` → write-channel shell mở; containment = em main single-writer + git-diff post-session).
- Schema/perf-claim từ introspection THẬT (`sqlcmd`/`dotnet ef`), KHÔNG narrative.
## Log
- **S52 (2026-06-08):** Seeded (em main, adap-apply database-agent). Roster 10→11. Nấc executed-file. CHỜ restart + spawn-test → verified-runtime.
- **S56 (2026-06-09) — pre-golive verify (2nd real spawn, verified-runtime ✓):** Schema/Mig integrity P11 + S55 master-data = SOLID. Mig 42-48 applied IDENTICALLY Dev+Design+prod `.\SQLEXPRESS` (48 mig / 92 tables, **NO S53-style unapplied-local drift**); 0 pending model-snapshot diff; **9 gotcha-#57 filtered-unique** confirmed BOTH EF config (HasFilter×13) AND DB (`filter_definition=([IsDeleted]=(0))`) incl Vehicle/Driver day-1; FK đúng (LeaveBalance→LeaveType Restrict + UNIQUE(User,Type,Year); 4× LevelOpinions Cascade(parent)/Restrict(Level)+UNIQUE composite; ItTicket SLA nullable). **DB11 FAIL (1 major, fast-follow KHÔNG blocker):** `LeaveBalance.UsedDays += NumDays` @ `LeaveOtApprovalFeatures.cs:361-386` chạy bare SaveChanges (no tx / no RowVersion / READ COMMITTED) → concurrent double-approve lost-update. **S43 gap STILL OPEN.** Fix-pattern sẵn repo: Serializable tx (codegen `:34`) HOẶC RowVersion+retry (1 mig). Low-prob ~30 user, recoverable Admin Adjustment. Tag [s56, pre-golive-verify, schema-pass, db11-lostupdate-open].