DocFast session 125: BUG-100 fix, codebase audit

This commit is contained in:
Hoid 2026-03-04 14:07:18 +01:00
parent 391f092c38
commit a9a6dc1e13
3 changed files with 43 additions and 3 deletions

View file

@ -1,3 +1,11 @@
## BUG-100: Usage flush transaction error handling broken — one bad key poisons entire batch
- **Date:** 2026-03-04
- **Severity:** MEDIUM
- **Issue:** `flushDirtyEntries()` in `src/middleware/usage.ts` wraps all usage writes in a single PostgreSQL transaction (`BEGIN`/`COMMIT`) with per-key `try/catch` inside the loop. In PostgreSQL, if any single INSERT fails inside a transaction, the transaction enters an "aborted" state and ALL subsequent queries fail with "current transaction is aborted, commands ignored until end of transaction block." The per-key error recovery is ineffective — one bad key causes all remaining keys in the batch to silently fail.
- **Impact:** If any single usage INSERT fails (e.g., constraint violation, type error), ALL remaining usage counts in that flush batch are lost. Could cause usage count divergence between in-memory and DB.
- **Fix:** Remove the transaction wrapper and flush each key independently, or use SAVEPOINTs.
- **Status:** ✅ FIXED — commit d2f819d. Removed transaction wrapper, each key flushes independently with its own client. 1 TDD test added. 464 tests total, all passing. Pushed to main (staging auto-deploy).
## BUG-099: provisionedSessions Set in billing.ts grows unbounded (memory leak)
- **Date:** 2026-03-03
- **Severity:** LOW